Author: rhauch
Date: 2009-04-01 20:03:04 -0400 (Wed, 01 Apr 2009)
New Revision: 802
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/inmemory/InMemoryNode.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/inmemory/InMemoryRepository.java
Log:
Change to the InMemory connector to make adding nodes more efficient.
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/inmemory/InMemoryNode.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/inmemory/InMemoryNode.java 2009-04-01
23:16:08 UTC (rev 801)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/inmemory/InMemoryNode.java 2009-04-02
00:03:04 UTC (rev 802)
@@ -24,9 +24,10 @@
package org.jboss.dna.graph.connector.inmemory;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.LinkedList;
-import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.UUID;
import net.jcip.annotations.NotThreadSafe;
import org.jboss.dna.graph.ExecutionContext;
@@ -45,7 +46,8 @@
private InMemoryNode parent;
private Path.Segment name;
private final Map<Name, Property> properties = new HashMap<Name,
Property>();
- private final List<InMemoryNode> children = new
LinkedList<InMemoryNode>();
+ private final LinkedList<InMemoryNode> children = new
LinkedList<InMemoryNode>();
+ final Set<Name> existingNames = new HashSet<Name>();
public InMemoryNode( UUID uuid ) {
assert uuid != null;
@@ -90,7 +92,7 @@
/**
* @return children
*/
- protected List<InMemoryNode> getChildren() {
+ LinkedList<InMemoryNode> getChildren() {
return children;
}
@@ -109,8 +111,8 @@
}
public InMemoryNode setProperty( ExecutionContext context,
- String name,
- Object... values ) {
+ String name,
+ Object... values ) {
PropertyFactory propertyFactory = context.getPropertyFactory();
Name propertyName = context.getValueFactories().getNameFactory().create(name);
return setProperty(propertyFactory.create(propertyName, values));
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/inmemory/InMemoryRepository.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/inmemory/InMemoryRepository.java 2009-04-01
23:16:08 UTC (rev 801)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/inmemory/InMemoryRepository.java 2009-04-02
00:03:04 UTC (rev 802)
@@ -28,6 +28,7 @@
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
+import java.util.ListIterator;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
@@ -316,10 +317,22 @@
InMemoryNode node = new InMemoryNode(uuid);
nodesByUuid.put(node.getUuid(), node);
node.setParent(parentNode);
- Path.Segment newName =
context.getValueFactories().getPathFactory().createSegment(name);
+ // Find the last node with this same name ...
+ int nextIndex = 1;
+ if (parentNode.existingNames.contains(name)) {
+ ListIterator<InMemoryNode> iter =
parentNode.getChildren().listIterator(parentNode.getChildren().size());
+ while (iter.hasPrevious()) {
+ InMemoryNode prev = iter.previous();
+ if (prev.getName().getName().equals(name)) {
+ nextIndex = prev.getName().getIndex() + 1;
+ break;
+ }
+ }
+ }
+ Path.Segment newName =
context.getValueFactories().getPathFactory().createSegment(name, nextIndex);
node.setName(newName);
parentNode.getChildren().add(node);
- correctSameNameSiblingIndexes(context, parentNode, name);
+ parentNode.existingNames.add(name);
return node;
}
Show replies by date