You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by st...@apache.org on 2012/01/06 17:40:43 UTC
svn commit: r1228255 - in
/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model:
AbstractNode.java ChildNodeEntries.java ChildNodeEntriesBasic.java
Author: stefan
Date: Fri Jan 6 16:40:43 2012
New Revision: 1228255
URL: http://svn.apache.org/viewvc?rev=1228255&view=rev
Log:
flat hierarchy support (WIP):
refactored child node entries collection
Added:
jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntriesBasic.java
- copied, changed from r1228068, jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntries.java
Modified:
jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/AbstractNode.java
jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntries.java
Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/AbstractNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/AbstractNode.java?rev=1228255&r1=1228254&r2=1228255&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/AbstractNode.java (original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/AbstractNode.java Fri Jan 6 16:40:43 2012
@@ -21,7 +21,6 @@ import org.apache.jackrabbit.mk.store.No
import org.apache.jackrabbit.mk.util.AbstractRangeIterator;
import org.apache.jackrabbit.mk.util.EmptyIterator;
import org.apache.jackrabbit.mk.util.PathUtils;
-import org.apache.jackrabbit.mk.util.RangeIterator;
import java.util.HashMap;
import java.util.HashSet;
@@ -38,21 +37,21 @@ public abstract class AbstractNode imple
protected HashMap<String, String> properties;
- protected ChildNodeEntries childEntries;
+ protected ChildNodeEntriesBasic childEntries;
protected AbstractNode() {
this.properties = new HashMap<String, String>();
- this.childEntries = new ChildNodeEntries();
+ this.childEntries = new ChildNodeEntriesBasic();
}
protected AbstractNode(Node other) {
if (other instanceof AbstractNode) {
AbstractNode srcNode = (AbstractNode) other;
this.properties = (HashMap<String, String>) srcNode.properties.clone();
- this.childEntries = (ChildNodeEntries) srcNode.childEntries.clone();
+ this.childEntries = (ChildNodeEntriesBasic) srcNode.childEntries.clone();
} else {
this.properties = new HashMap<String, String>(other.getProperties());
- this.childEntries = new ChildNodeEntries();
+ this.childEntries = new ChildNodeEntriesBasic();
for (Iterator<ChildNodeEntry> it = other.getChildNodeEntries(); it.hasNext(); ) {
ChildNodeEntry cne = it.next();
this.childEntries.add(cne);
@@ -158,7 +157,7 @@ public abstract class AbstractNode imple
// compare child node entries
if (other instanceof AbstractNode) {
- ChildNodeEntries otherEntries = ((AbstractNode) other).childEntries;
+ ChildNodeEntriesBasic otherEntries = ((AbstractNode) other).childEntries;
for (Iterator<ChildNodeEntry> it = childEntries.getAdded(otherEntries); it.hasNext(); ) {
handler.childNodeAdded(it.next());
}
Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntries.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntries.java?rev=1228255&r1=1228254&r2=1228255&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntries.java (original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntries.java Fri Jan 6 16:40:43 2012
@@ -16,199 +16,40 @@
*/
package org.apache.jackrabbit.mk.model;
-import org.apache.jackrabbit.mk.util.AbstractFilteringIterator;
-import org.apache.jackrabbit.mk.util.EmptyIterator;
-import org.apache.jackrabbit.mk.util.RangeIterator;
-
import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.Map;
/**
*
*/
-class ChildNodeEntries implements Cloneable {
-
- protected static final Iterator<ChildNodeEntry> EMPTY_ITER = new EmptyIterator<ChildNodeEntry>();
-
- protected LinkedHashMap<String, ChildNodeEntry> entries;
-
- ChildNodeEntries() {
- entries = new LinkedHashMap<String, ChildNodeEntry>();
- }
-
- @Override
- protected Object clone() {
- ChildNodeEntries clone = null;
- try {
- clone = (ChildNodeEntries) super.clone();
- } catch (CloneNotSupportedException e) {
- // can't possibly get here
- }
- clone.entries = (LinkedHashMap<String, ChildNodeEntry>) entries.clone();
- return clone;
- }
+public interface ChildNodeEntries extends Cloneable {
//-------------------------------------------------------------< read ops >
- int getCount() {
- return entries.size();
- }
-
- ChildNodeEntry get(String name) {
- return entries.get(name);
- }
-
- Iterator<String> getNames(int offset, int count) {
- if (offset < 0 || count < -1) {
- throw new IllegalArgumentException();
- }
-
- if (offset == 0 && count == -1) {
- return entries.keySet().iterator();
- } else {
- if (offset >= entries.size()) {
- return new EmptyIterator<String>();
- }
- if (count == -1 || (offset + count) > entries.size()) {
- count = entries.size() - offset;
- }
- return new RangeIterator<String>(entries.keySet().iterator(), offset, count);
- }
- }
-
- Iterator<ChildNodeEntry> getEntries(int offset, int count) {
- if (offset < 0 || count < -1) {
- throw new IllegalArgumentException();
- }
- if (offset == 0 && count == -1) {
- return entries.values().iterator();
- } else {
- if (offset >= entries.size()) {
- return new EmptyIterator<ChildNodeEntry>();
- }
- if (count == -1 || (offset + count) > entries.size()) {
- count = entries.size() - offset;
- }
- return new RangeIterator<ChildNodeEntry>(entries.values().iterator(), offset, count);
- }
- }
+
+ int getCount();
+
+ ChildNodeEntry get(String name);
+
+ Iterator<String> getNames(int offset, int count);
+
+ Iterator<ChildNodeEntry> getEntries(int offset, int count);
//------------------------------------------------------------< write ops >
- ChildNodeEntry add(ChildNodeEntry entry) {
- return entries.put(entry.getName(), entry);
- }
-
- ChildNodeEntry remove(String name) {
- return entries.remove(name);
- }
-
- ChildNodeEntry rename(String oldName, String newName) {
- if (oldName.equals(newName)) {
- return entries.get(oldName);
- }
- LinkedHashMap<String, ChildNodeEntry> clone =
- (LinkedHashMap<String, ChildNodeEntry>) entries.clone();
- entries.clear();
- ChildNodeEntry oldCNE = null;
- for (Map.Entry<String, ChildNodeEntry> entry : clone.entrySet()) {
- if (entry.getKey().equals(oldName)) {
- oldCNE = entry.getValue();
- entries.put(newName, new ChildNodeEntry(newName, oldCNE.getId()));
- } else {
- entries.put(entry.getKey(), entry.getValue());
- }
- }
- return oldCNE;
- }
-
- ChildNodeEntry moveAfter(String name, String sibling) {
- ChildNodeEntry target = entries.remove(name);
- if (target == null) {
- return null;
- }
-
- if (sibling == null) {
- // move to bottom (re-adding it will append it)
- entries.put(target.getName(), target);
- return target;
- } else {
- LinkedHashMap<String, ChildNodeEntry> clone =
- (LinkedHashMap<String, ChildNodeEntry>) entries.clone();
- entries.clear();
- for (Map.Entry<String, ChildNodeEntry> entry : clone.entrySet()) {
- entries.put(entry.getKey(), entry.getValue());
- if (entry.getKey().equals(sibling)) {
- entries.put(name, target);
- }
- }
- }
- return target;
- }
-
- ChildNodeEntry moveBefore(String name, String sibling) {
- ChildNodeEntry target = entries.remove(name);
- if (target == null) {
- return null;
- }
-
- if (sibling == null) {
- // move to bottom (re-adding it will append it)
- entries.put(target.getName(), target);
- return target;
- } else {
- LinkedHashMap<String, ChildNodeEntry> clone =
- (LinkedHashMap<String, ChildNodeEntry>) entries.clone();
- entries.clear();
- for (Map.Entry<String, ChildNodeEntry> entry : clone.entrySet()) {
- entries.put(entry.getKey(), entry.getValue());
- if (entry.getKey().equals(sibling)) {
- entries.put(name, target);
- }
- }
- }
- return target;
- }
+
+ ChildNodeEntry add(ChildNodeEntry entry);
+
+ ChildNodeEntry remove(String name);
+
+ ChildNodeEntry rename(String oldName, String newName);
+
+ ChildNodeEntry moveAfter(String name, String sibling);
+
+ ChildNodeEntry moveBefore(String name, String sibling);
//-------------------------------------------------------------< diff ops >
- Iterator<ChildNodeEntry> getAdded(final ChildNodeEntries other) {
- if (entries.equals(other)) {
- return EMPTY_ITER;
- }
-
- return new AbstractFilteringIterator<ChildNodeEntry>(other.getEntries(0, -1)) {
- @Override
- protected boolean include(ChildNodeEntry entry) {
- return !entries.containsKey(entry.getName());
- }
- };
- }
-
- Iterator<ChildNodeEntry> getRemoved(final ChildNodeEntries other) {
- if (entries.equals(other)) {
- return EMPTY_ITER;
- }
-
- return new AbstractFilteringIterator<ChildNodeEntry>(entries.values().iterator()) {
- @Override
- protected boolean include(ChildNodeEntry entry) {
- return other.get(entry.getName()) == null;
- }
- };
- }
-
- Iterator<ChildNodeEntry> getModified(final ChildNodeEntries other) {
- if (entries.equals(other)) {
- return EMPTY_ITER;
- }
-
- return new AbstractFilteringIterator<ChildNodeEntry>(entries.values().iterator()) {
- @Override
- protected boolean include(ChildNodeEntry entry) {
- ChildNodeEntry namesake = other.get(entry.getName());
- return (namesake != null && !namesake.getId().equals(entry.getId()));
- }
- };
- }
- //--------------------------------------------------------< inner classes >
+ Iterator<ChildNodeEntry> getAdded(final ChildNodeEntries other);
+
+ Iterator<ChildNodeEntry> getRemoved(final ChildNodeEntries other);
+
+ Iterator<ChildNodeEntry> getModified(final ChildNodeEntries other);
}
Copied: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntriesBasic.java (from r1228068, jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntries.java)
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntriesBasic.java?p2=jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntriesBasic.java&p1=jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntries.java&r1=1228068&r2=1228255&rev=1228255&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntries.java (original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntriesBasic.java Fri Jan 6 16:40:43 2012
@@ -27,21 +27,31 @@ import java.util.Map;
/**
*
*/
-class ChildNodeEntries implements Cloneable {
+public class ChildNodeEntriesBasic implements ChildNodeEntries {
protected static final Iterator<ChildNodeEntry> EMPTY_ITER = new EmptyIterator<ChildNodeEntry>();
protected LinkedHashMap<String, ChildNodeEntry> entries;
- ChildNodeEntries() {
+ ChildNodeEntriesBasic() {
entries = new LinkedHashMap<String, ChildNodeEntry>();
}
+ //------------------------------------------------------------< overrides >
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof ChildNodeEntriesBasic) {
+ return entries.equals(((ChildNodeEntriesBasic) obj).entries);
+ }
+ return false;
+ }
+
@Override
protected Object clone() {
- ChildNodeEntries clone = null;
+ ChildNodeEntriesBasic clone = null;
try {
- clone = (ChildNodeEntries) super.clone();
+ clone = (ChildNodeEntriesBasic) super.clone();
} catch (CloneNotSupportedException e) {
// can't possibly get here
}
@@ -50,15 +60,16 @@ class ChildNodeEntries implements Clonea
}
//-------------------------------------------------------------< read ops >
- int getCount() {
+
+ public int getCount() {
return entries.size();
}
- ChildNodeEntry get(String name) {
+ public ChildNodeEntry get(String name) {
return entries.get(name);
}
- Iterator<String> getNames(int offset, int count) {
+ public Iterator<String> getNames(int offset, int count) {
if (offset < 0 || count < -1) {
throw new IllegalArgumentException();
}
@@ -76,7 +87,7 @@ class ChildNodeEntries implements Clonea
}
}
- Iterator<ChildNodeEntry> getEntries(int offset, int count) {
+ public Iterator<ChildNodeEntry> getEntries(int offset, int count) {
if (offset < 0 || count < -1) {
throw new IllegalArgumentException();
}
@@ -94,15 +105,16 @@ class ChildNodeEntries implements Clonea
}
//------------------------------------------------------------< write ops >
- ChildNodeEntry add(ChildNodeEntry entry) {
+
+ public ChildNodeEntry add(ChildNodeEntry entry) {
return entries.put(entry.getName(), entry);
}
- ChildNodeEntry remove(String name) {
+ public ChildNodeEntry remove(String name) {
return entries.remove(name);
}
- ChildNodeEntry rename(String oldName, String newName) {
+ public ChildNodeEntry rename(String oldName, String newName) {
if (oldName.equals(newName)) {
return entries.get(oldName);
}
@@ -121,7 +133,7 @@ class ChildNodeEntries implements Clonea
return oldCNE;
}
- ChildNodeEntry moveAfter(String name, String sibling) {
+ public ChildNodeEntry moveAfter(String name, String sibling) {
ChildNodeEntry target = entries.remove(name);
if (target == null) {
return null;
@@ -145,33 +157,34 @@ class ChildNodeEntries implements Clonea
return target;
}
- ChildNodeEntry moveBefore(String name, String sibling) {
+ public ChildNodeEntry moveBefore(String name, String sibling) {
ChildNodeEntry target = entries.remove(name);
if (target == null) {
return null;
}
+ LinkedHashMap<String, ChildNodeEntry> clone =
+ (LinkedHashMap<String, ChildNodeEntry>) entries.clone();
+ entries.clear();
if (sibling == null) {
- // move to bottom (re-adding it will append it)
+ // move to top
entries.put(target.getName(), target);
- return target;
+ entries.putAll(clone);
} else {
- LinkedHashMap<String, ChildNodeEntry> clone =
- (LinkedHashMap<String, ChildNodeEntry>) entries.clone();
- entries.clear();
for (Map.Entry<String, ChildNodeEntry> entry : clone.entrySet()) {
- entries.put(entry.getKey(), entry.getValue());
if (entry.getKey().equals(sibling)) {
entries.put(name, target);
}
+ entries.put(entry.getKey(), entry.getValue());
}
}
return target;
}
//-------------------------------------------------------------< diff ops >
- Iterator<ChildNodeEntry> getAdded(final ChildNodeEntries other) {
- if (entries.equals(other)) {
+
+ public Iterator<ChildNodeEntry> getAdded(final ChildNodeEntries other) {
+ if (equals(other)) {
return EMPTY_ITER;
}
@@ -183,8 +196,8 @@ class ChildNodeEntries implements Clonea
};
}
- Iterator<ChildNodeEntry> getRemoved(final ChildNodeEntries other) {
- if (entries.equals(other)) {
+ public Iterator<ChildNodeEntry> getRemoved(final ChildNodeEntries other) {
+ if (equals(other)) {
return EMPTY_ITER;
}
@@ -196,8 +209,8 @@ class ChildNodeEntries implements Clonea
};
}
- Iterator<ChildNodeEntry> getModified(final ChildNodeEntries other) {
- if (entries.equals(other)) {
+ public Iterator<ChildNodeEntry> getModified(final ChildNodeEntries other) {
+ if (equals(other)) {
return EMPTY_ITER;
}
@@ -209,6 +222,4 @@ class ChildNodeEntries implements Clonea
}
};
}
-
- //--------------------------------------------------------< inner classes >
}