From 2a35670e736571c137b85cf5bb4cdf6b85ca2193 Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Sat, 17 Jul 2021 10:24:41 +0200 Subject: [PATCH 01/15] Introduce serial version UIDs and resolve other compilation warnings. --- code/pom.xml | 28 +++- .../concurrenttrees/common/CharSequences.java | 8 +- .../concurrenttrees/common/Iterables.java | 2 +- .../concurrenttrees/common/KeyValuePair.java | 2 +- .../concurrenttrees/common/LazyIterator.java | 2 +- .../concurrenttrees/common/PrettyPrinter.java | 2 +- .../concurrenttrees/common/SetFromMap.java | 120 ++++++++++++++++++ .../radix/ConcurrentRadixTree.java | 18 +-- .../concurrenttrees/radix/RadixTree.java | 2 +- .../concurrenttrees/radix/node/Node.java | 2 +- .../radix/node/NodeFactory.java | 2 +- .../concrete/DefaultByteArrayNodeFactory.java | 4 +- .../concrete/DefaultCharArrayNodeFactory.java | 4 +- .../DefaultCharSequenceNodeFactory.java | 4 +- .../concrete/SmartArrayBasedNodeFactory.java | 4 +- .../bytearray/ByteArrayCharSequence.java | 5 +- .../bytearray/ByteArrayNodeDefault.java | 5 +- .../bytearray/ByteArrayNodeLeafNullValue.java | 3 +- .../bytearray/ByteArrayNodeLeafVoidValue.java | 4 +- .../bytearray/ByteArrayNodeLeafWithValue.java | 3 +- .../ByteArrayNodeNonLeafNullValue.java | 5 +- .../ByteArrayNodeNonLeafVoidValue.java | 6 +- .../chararray/CharArrayNodeDefault.java | 5 +- .../chararray/CharArrayNodeLeafNullValue.java | 3 +- .../chararray/CharArrayNodeLeafVoidValue.java | 4 +- .../chararray/CharArrayNodeLeafWithValue.java | 3 +- .../CharArrayNodeNonLeafNullValue.java | 5 +- .../CharArrayNodeNonLeafVoidValue.java | 6 +- .../charsequence/CharSequenceNodeDefault.java | 5 +- .../CharSequenceNodeLeafNullValue.java | 3 +- .../CharSequenceNodeLeafVoidValue.java | 3 +- .../CharSequenceNodeLeafWithValue.java | 8 +- .../CharSequenceNodeNonLeafNullValue.java | 5 +- .../CharSequenceNodeNonLeafVoidValue.java | 5 +- .../node/concrete/voidvalue/VoidValue.java | 2 +- .../util/AtomicReferenceArrayListAdapter.java | 4 +- .../node/util/NodeCharacterComparator.java | 2 +- .../radix/node/util/NodeCharacterKey.java | 2 +- .../node/util/NodeCharacterProvider.java | 2 +- .../radix/node/util/NodeUtil.java | 2 +- .../radix/node/util/PrettyPrintable.java | 4 +- .../ConcurrentInvertedRadixTree.java | 18 ++- .../radixinverted/InvertedRadixTree.java | 8 +- .../ConcurrentReversedRadixTree.java | 8 +- .../radixreversed/ReversedRadixTree.java | 2 +- .../solver/LCSubstringSolver.java | 7 +- .../suffix/ConcurrentSuffixTree.java | 26 ++-- .../concurrenttrees/suffix/SuffixTree.java | 2 +- .../radix/ConcurrentRadixTreeTest.java | 3 + .../suffix/ConcurrentSuffixTreeTest.java | 18 ++- 50 files changed, 300 insertions(+), 100 deletions(-) create mode 100644 code/src/main/java/com/googlecode/concurrenttrees/common/SetFromMap.java diff --git a/code/pom.xml b/code/pom.xml index 69cc532..bad1d16 100644 --- a/code/pom.xml +++ b/code/pom.xml @@ -50,8 +50,11 @@ maven-compiler-plugin 2.3.2 - 1.6 - 1.6 + 1.5 + 1.5 + true + true + -Xlint:all,-options,-processing @@ -107,6 +110,27 @@ + + + org.codehaus.mojo + animal-sniffer-maven-plugin + 1.16 + + + test + + check + + + + org.codehaus.mojo.signature + java15 + 1.0 + + + + + diff --git a/code/src/main/java/com/googlecode/concurrenttrees/common/CharSequences.java b/code/src/main/java/com/googlecode/concurrenttrees/common/CharSequences.java index d128862..23f468b 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/common/CharSequences.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/common/CharSequences.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,12 +15,6 @@ */ package com.googlecode.concurrenttrees.common; -import java.io.UnsupportedEncodingException; -import java.nio.ByteBuffer; -import java.nio.CharBuffer; -import java.nio.charset.Charset; -import java.nio.charset.CharsetEncoder; -import java.nio.charset.CodingErrorAction; import java.util.Iterator; /** diff --git a/code/src/main/java/com/googlecode/concurrenttrees/common/Iterables.java b/code/src/main/java/com/googlecode/concurrenttrees/common/Iterables.java index dbca4ca..a3bc9ea 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/common/Iterables.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/common/Iterables.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/code/src/main/java/com/googlecode/concurrenttrees/common/KeyValuePair.java b/code/src/main/java/com/googlecode/concurrenttrees/common/KeyValuePair.java index 4bc3f42..05840fb 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/common/KeyValuePair.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/common/KeyValuePair.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/code/src/main/java/com/googlecode/concurrenttrees/common/LazyIterator.java b/code/src/main/java/com/googlecode/concurrenttrees/common/LazyIterator.java index ab87c87..6004cbb 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/common/LazyIterator.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/common/LazyIterator.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * Copyright 2007 The Guava Authors * diff --git a/code/src/main/java/com/googlecode/concurrenttrees/common/PrettyPrinter.java b/code/src/main/java/com/googlecode/concurrenttrees/common/PrettyPrinter.java index b34b6bb..0274bb1 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/common/PrettyPrinter.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/common/PrettyPrinter.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/code/src/main/java/com/googlecode/concurrenttrees/common/SetFromMap.java b/code/src/main/java/com/googlecode/concurrenttrees/common/SetFromMap.java new file mode 100644 index 0000000..a63461b --- /dev/null +++ b/code/src/main/java/com/googlecode/concurrenttrees/common/SetFromMap.java @@ -0,0 +1,120 @@ +/* + * Copyright 2012-2013 Niall Gallagher + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.googlecode.concurrenttrees.common; + +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.Serializable; +import java.util.*; + +/** + * A facade implementation of a Java set for representing a Java map implementation. + * + * @param The element type. + */ +public class SetFromMap extends AbstractSet implements Serializable { + + private static final long serialVersionUID = 1L; + + private final Map delegate; + + private transient Set keySet; + + public SetFromMap(Map delegate) { + this.delegate = delegate; + keySet = delegate.keySet(); + } + + private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { + stream.defaultReadObject(); + keySet = delegate.keySet(); + } + + @Override + public int size() { + return delegate.size(); + } + + @Override + public boolean isEmpty() { + return delegate.isEmpty(); + } + + @Override + public boolean contains(Object o) { + return delegate.containsKey(o); + } + + @Override + public boolean remove(Object o) { + return delegate.remove(o) != null; + } + + @Override + public void clear() { + delegate.clear(); + } + + @Override + public boolean add(E e) { + return delegate.put(e, Boolean.TRUE) == null; + } + + @Override + public Iterator iterator() { + return keySet.iterator(); + } + + @Override + public Object[] toArray() { + return keySet.toArray(); + } + + @Override + public T[] toArray(T[] a) { + return keySet.toArray(a); + } + + @Override + public String toString() { + return keySet.toString(); + } + + @Override + public int hashCode() { + return keySet.hashCode(); + } + + @Override + public boolean equals(Object o) { + return o == this || keySet.equals(o); + } + + @Override + public boolean containsAll(Collection c) { + return keySet.containsAll(c); + } + + @Override + public boolean removeAll(Collection c) { + return keySet.removeAll(c); + } + + @Override + public boolean retainAll(Collection c) { + return keySet.retainAll(c); + } +} diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/ConcurrentRadixTree.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/ConcurrentRadixTree.java index 7f745c8..68b90d2 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/ConcurrentRadixTree.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/ConcurrentRadixTree.java @@ -40,6 +40,8 @@ * @author Niall Gallagher */ public class ConcurrentRadixTree implements RadixTree, PrettyPrintable, Serializable { + + private static final long serialVersionUID = 1L; private final NodeFactory nodeFactory; @@ -413,14 +415,14 @@ public Iterable> getKeyValuePairsForClosestKeys(CharSequence can */ @Override public int size() { - Deque stack = new LinkedList(); - stack.push(this.root); + LinkedList stack = new LinkedList(); + stack.addFirst(this.root); int count = 0; while (true) { if (stack.isEmpty()) { return count; } - Node current = stack.pop(); + Node current = stack.removeFirst(); stack.addAll(current.getOutgoingEdges()); if (current.getValue() != null) { count++; @@ -738,7 +740,7 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - KeyValuePairImpl that = (KeyValuePairImpl) o; + KeyValuePairImpl that = (KeyValuePairImpl) o; return key.equals(that.key); @@ -782,9 +784,9 @@ protected Iterable lazyTraverseDescendants(final CharSequence start public Iterator iterator() { return new LazyIterator() { - Deque stack = new LinkedList(); + final LinkedList stack = new LinkedList(); { - stack.push(new NodeKeyPair(startNode, startKey)); + stack.addFirst(new NodeKeyPair(startNode, startKey)); } @Override @@ -792,7 +794,7 @@ protected NodeKeyPair computeNext() { if (stack.isEmpty()) { return endOfData(); } - NodeKeyPair current = stack.pop(); + NodeKeyPair current = stack.removeFirst(); List childNodes = current.node.getOutgoingEdges(); // -> Iterate child nodes in reverse order and so push them onto the stack in reverse order, @@ -800,7 +802,7 @@ protected NodeKeyPair computeNext() { // This ensures that we actually process nodes in ascending alphabetical order. for (int i = childNodes.size(); i > 0; i--) { Node child = childNodes.get(i - 1); - stack.push(new NodeKeyPair(child, CharSequences.concatenate(current.key, child.getIncomingEdge()))); + stack.addFirst(new NodeKeyPair(child, CharSequences.concatenate(current.key, child.getIncomingEdge()))); } return current; } diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/RadixTree.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/RadixTree.java index f319369..98014b1 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/RadixTree.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/RadixTree.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/Node.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/Node.java index 279f369..2ae3cdd 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/Node.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/Node.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/NodeFactory.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/NodeFactory.java index 6a767b3..f4bdcc2 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/NodeFactory.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/NodeFactory.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultByteArrayNodeFactory.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultByteArrayNodeFactory.java index 3566ed3..378a6c2 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultByteArrayNodeFactory.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultByteArrayNodeFactory.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -37,6 +37,8 @@ */ public class DefaultByteArrayNodeFactory implements NodeFactory { + private static final long serialVersionUID = 1L; + @Override public Node createNode(CharSequence edgeCharacters, Object value, List childNodes, boolean isRoot) { if (edgeCharacters == null) { diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharArrayNodeFactory.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharArrayNodeFactory.java index d6f76ad..9f67589 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharArrayNodeFactory.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharArrayNodeFactory.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -44,6 +44,8 @@ */ public class DefaultCharArrayNodeFactory implements NodeFactory { + private static final long serialVersionUID = 1L; + @Override public Node createNode(CharSequence edgeCharacters, Object value, List childNodes, boolean isRoot) { if (edgeCharacters == null) { diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharSequenceNodeFactory.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharSequenceNodeFactory.java index a873422..665ef39 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharSequenceNodeFactory.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharSequenceNodeFactory.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -45,6 +45,8 @@ */ public class DefaultCharSequenceNodeFactory implements NodeFactory { + private static final long serialVersionUID = 1L; + @Override public Node createNode(CharSequence edgeCharacters, Object value, List childNodes, boolean isRoot) { if (edgeCharacters == null) { diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/SmartArrayBasedNodeFactory.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/SmartArrayBasedNodeFactory.java index cd6e0db..ebad1f6 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/SmartArrayBasedNodeFactory.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/SmartArrayBasedNodeFactory.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -30,6 +30,8 @@ */ public class SmartArrayBasedNodeFactory implements NodeFactory { + private static final long serialVersionUID = 1L; + final NodeFactory charArrayNodeFactory = new DefaultCharArrayNodeFactory(); final NodeFactory byteArrayNodeFactory = new DefaultByteArrayNodeFactory(); diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayCharSequence.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayCharSequence.java index a38f99c..7022cbd 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayCharSequence.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayCharSequence.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -84,6 +84,9 @@ public static byte[] toSingleByteUtf8Encoding(CharSequence charSequence) { } public static class IncompatibleCharacterException extends IllegalStateException { + + private static final long serialVersionUID = 1L; + public IncompatibleCharacterException(String s) { super(s); } diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeDefault.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeDefault.java index 067b03b..99c65b6 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeDefault.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeDefault.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -35,6 +35,7 @@ */ public class ByteArrayNodeDefault implements Node { + private static final long serialVersionUID = 1L; // Characters in the edge arriving at this node from a parent node. // Once assigned, we never modify this... @@ -53,7 +54,7 @@ public class ByteArrayNodeDefault implements Node { private final Object value; public ByteArrayNodeDefault(CharSequence edgeCharSequence, Object value, List outgoingEdges) { - Node[] childNodeArray = outgoingEdges.toArray(new Node[outgoingEdges.size()]); + Node[] childNodeArray = outgoingEdges.toArray(new Node[0]); // Sort the child nodes... Arrays.sort(childNodeArray, new NodeCharacterComparator()); this.outgoingEdges = new AtomicReferenceArray(childNodeArray); diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafNullValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafNullValue.java index 5877be7..900a273 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafNullValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafNullValue.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -31,6 +31,7 @@ */ public class ByteArrayNodeLeafNullValue implements Node { + private static final long serialVersionUID = 1L; // Characters in the edge arriving at this node from a parent node. // Once assigned, we never modify this... diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafVoidValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafVoidValue.java index ea7bd4d..87b02bf 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafVoidValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafVoidValue.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -32,6 +32,8 @@ */ public class ByteArrayNodeLeafVoidValue implements Node { + private static final long serialVersionUID = 1L; + // Characters in the edge arriving at this node from a parent node. // Once assigned, we never modify this... private final byte[] incomingEdgeCharArray; diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafWithValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafWithValue.java index d0b10bd..d8cab38 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafWithValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafWithValue.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -31,6 +31,7 @@ */ public class ByteArrayNodeLeafWithValue implements Node { + private static final long serialVersionUID = 1L; // Characters in the edge arriving at this node from a parent node. // Once assigned, we never modify this... diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafNullValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafNullValue.java index c2ce78b..579e3aa 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafNullValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafNullValue.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -35,6 +35,7 @@ */ public class ByteArrayNodeNonLeafNullValue implements Node { + private static final long serialVersionUID = 1L; // Characters in the edge arriving at this node from a parent node. // Once assigned, we never modify this... @@ -49,7 +50,7 @@ public class ByteArrayNodeNonLeafNullValue implements Node { private final List outgoingEdgesAsList; public ByteArrayNodeNonLeafNullValue(CharSequence edgeCharSequence, List outgoingEdges) { - Node[] childNodeArray = outgoingEdges.toArray(new Node[outgoingEdges.size()]); + Node[] childNodeArray = outgoingEdges.toArray(new Node[0]); // Sort the child nodes... Arrays.sort(childNodeArray, new NodeCharacterComparator()); this.outgoingEdges = new AtomicReferenceArray(childNodeArray); diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafVoidValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafVoidValue.java index 9ce524d..0f7e38c 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafVoidValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafVoidValue.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -36,6 +36,8 @@ */ public class ByteArrayNodeNonLeafVoidValue implements Node { + private static final long serialVersionUID = 1L; + // Characters in the edge arriving at this node from a parent node. // Once assigned, we never modify this... private final byte[] incomingEdgeCharArray; @@ -49,7 +51,7 @@ public class ByteArrayNodeNonLeafVoidValue implements Node { private final List outgoingEdgesAsList; public ByteArrayNodeNonLeafVoidValue(CharSequence edgeCharSequence, List outgoingEdges) { - Node[] childNodeArray = outgoingEdges.toArray(new Node[outgoingEdges.size()]); + Node[] childNodeArray = outgoingEdges.toArray(new Node[0]); // Sort the child nodes... Arrays.sort(childNodeArray, new NodeCharacterComparator()); this.outgoingEdges = new AtomicReferenceArray(childNodeArray); diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeDefault.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeDefault.java index 67b3ae8..61bdf21 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeDefault.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeDefault.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -51,6 +51,7 @@ */ public class CharArrayNodeDefault implements Node { + private static final long serialVersionUID = 1L; // Characters in the edge arriving at this node from a parent node. // Once assigned, we never modify this... @@ -69,7 +70,7 @@ public class CharArrayNodeDefault implements Node { private final Object value; public CharArrayNodeDefault(CharSequence edgeCharSequence, Object value, List outgoingEdges) { - Node[] childNodeArray = outgoingEdges.toArray(new Node[outgoingEdges.size()]); + Node[] childNodeArray = outgoingEdges.toArray(new Node[0]); // Sort the child nodes... Arrays.sort(childNodeArray, new NodeCharacterComparator()); this.outgoingEdges = new AtomicReferenceArray(childNodeArray); diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafNullValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafNullValue.java index 67b67e2..21a3791 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafNullValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafNullValue.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -29,6 +29,7 @@ */ public class CharArrayNodeLeafNullValue implements Node { + private static final long serialVersionUID = 1L; // Characters in the edge arriving at this node from a parent node. // Once assigned, we never modify this... diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafVoidValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafVoidValue.java index f699aee..f575fa2 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafVoidValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafVoidValue.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -30,6 +30,8 @@ */ public class CharArrayNodeLeafVoidValue implements Node { + private static final long serialVersionUID = 1L; + // Characters in the edge arriving at this node from a parent node. // Once assigned, we never modify this... private final char[] incomingEdgeCharArray; diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafWithValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafWithValue.java index 400ced0..05e0eca 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafWithValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafWithValue.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -29,6 +29,7 @@ */ public class CharArrayNodeLeafWithValue implements Node { + private static final long serialVersionUID = 1L; // Characters in the edge arriving at this node from a parent node. // Once assigned, we never modify this... diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafNullValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafNullValue.java index 0699312..46c4ae6 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafNullValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafNullValue.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -33,6 +33,7 @@ */ public class CharArrayNodeNonLeafNullValue implements Node { + private static final long serialVersionUID = 1L; // Characters in the edge arriving at this node from a parent node. // Once assigned, we never modify this... @@ -47,7 +48,7 @@ public class CharArrayNodeNonLeafNullValue implements Node { private final List outgoingEdgesAsList; public CharArrayNodeNonLeafNullValue(CharSequence edgeCharSequence, List outgoingEdges) { - Node[] childNodeArray = outgoingEdges.toArray(new Node[outgoingEdges.size()]); + Node[] childNodeArray = outgoingEdges.toArray(new Node[0]); // Sort the child nodes... Arrays.sort(childNodeArray, new NodeCharacterComparator()); this.outgoingEdges = new AtomicReferenceArray(childNodeArray); diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafVoidValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafVoidValue.java index abdbbbe..f8b53e2 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafVoidValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafVoidValue.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -34,6 +34,8 @@ */ public class CharArrayNodeNonLeafVoidValue implements Node { + private static final long serialVersionUID = 1L; + // Characters in the edge arriving at this node from a parent node. // Once assigned, we never modify this... private final char[] incomingEdgeCharArray; @@ -47,7 +49,7 @@ public class CharArrayNodeNonLeafVoidValue implements Node { private final List outgoingEdgesAsList; public CharArrayNodeNonLeafVoidValue(CharSequence edgeCharSequence, List outgoingEdges) { - Node[] childNodeArray = outgoingEdges.toArray(new Node[outgoingEdges.size()]); + Node[] childNodeArray = outgoingEdges.toArray(new Node[0]); // Sort the child nodes... Arrays.sort(childNodeArray, new NodeCharacterComparator()); this.outgoingEdges = new AtomicReferenceArray(childNodeArray); diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeDefault.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeDefault.java index ef451f8..42f8d87 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeDefault.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeDefault.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -51,6 +51,7 @@ */ public class CharSequenceNodeDefault implements Node { + private static final long serialVersionUID = 1L; // Characters in the edge arriving at this node from a parent node. // Once assigned, we never modify this... @@ -69,7 +70,7 @@ public class CharSequenceNodeDefault implements Node { private final Object value; public CharSequenceNodeDefault(CharSequence edgeCharSequence, Object value, List outgoingEdges) { - Node[] childNodeArray = outgoingEdges.toArray(new Node[outgoingEdges.size()]); + Node[] childNodeArray = outgoingEdges.toArray(new Node[0]); // Sort the child nodes... Arrays.sort(childNodeArray, new NodeCharacterComparator()); this.outgoingEdges = new AtomicReferenceArray(childNodeArray); diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafNullValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafNullValue.java index 9a6013f..b18a466 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafNullValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafNullValue.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -28,6 +28,7 @@ */ public class CharSequenceNodeLeafNullValue implements Node { + private static final long serialVersionUID = 1L; // Characters in the edge arriving at this node from a parent node. // Once assigned, we never modify this... diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafVoidValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafVoidValue.java index 971aac7..534f802 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafVoidValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafVoidValue.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -34,6 +34,7 @@ */ public class CharSequenceNodeLeafVoidValue implements Node { + private static final long serialVersionUID = 1L; // Characters in the edge arriving at this node from a parent node. // Once assigned, we never modify this... diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafWithValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafWithValue.java index 5618f1c..c8cd472 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafWithValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafWithValue.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,14 +16,9 @@ package com.googlecode.concurrenttrees.radix.node.concrete.charsequence; import com.googlecode.concurrenttrees.radix.node.Node; -import com.googlecode.concurrenttrees.radix.node.util.AtomicReferenceArrayListAdapter; -import com.googlecode.concurrenttrees.radix.node.util.NodeCharacterComparator; -import com.googlecode.concurrenttrees.radix.node.util.NodeUtil; -import java.util.Arrays; import java.util.Collections; import java.util.List; -import java.util.concurrent.atomic.AtomicReferenceArray; /** * Stores incoming edge as a {@link CharSequence} (a view onto the original key) rather than copying the @@ -33,6 +28,7 @@ */ public class CharSequenceNodeLeafWithValue implements Node { + private static final long serialVersionUID = 1L; // Characters in the edge arriving at this node from a parent node. // Once assigned, we never modify this... diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafNullValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafNullValue.java index be43710..2d8d696 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafNullValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafNullValue.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -33,6 +33,7 @@ */ public class CharSequenceNodeNonLeafNullValue implements Node { + private static final long serialVersionUID = 1L; // Characters in the edge arriving at this node from a parent node. // Once assigned, we never modify this... @@ -47,7 +48,7 @@ public class CharSequenceNodeNonLeafNullValue implements Node { private final List outgoingEdgesAsList; public CharSequenceNodeNonLeafNullValue(CharSequence edgeCharSequence, List outgoingEdges) { - Node[] childNodeArray = outgoingEdges.toArray(new Node[outgoingEdges.size()]); + Node[] childNodeArray = outgoingEdges.toArray(new Node[0]); // Sort the child nodes... Arrays.sort(childNodeArray, new NodeCharacterComparator()); this.outgoingEdges = new AtomicReferenceArray(childNodeArray); diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafVoidValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafVoidValue.java index b320440..09f9129 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafVoidValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafVoidValue.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -34,6 +34,7 @@ */ public class CharSequenceNodeNonLeafVoidValue implements Node { + private static final long serialVersionUID = 1L; // Characters in the edge arriving at this node from a parent node. // Once assigned, we never modify this... @@ -48,7 +49,7 @@ public class CharSequenceNodeNonLeafVoidValue implements Node { private final List outgoingEdgesAsList; public CharSequenceNodeNonLeafVoidValue(CharSequence edgeCharSequence, List outgoingEdges) { - Node[] childNodeArray = outgoingEdges.toArray(new Node[outgoingEdges.size()]); + Node[] childNodeArray = outgoingEdges.toArray(new Node[0]); // Sort the child nodes... Arrays.sort(childNodeArray, new NodeCharacterComparator()); this.outgoingEdges = new AtomicReferenceArray(childNodeArray); diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/voidvalue/VoidValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/voidvalue/VoidValue.java index 6cfffbe..2355fce 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/voidvalue/VoidValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/voidvalue/VoidValue.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/AtomicReferenceArrayListAdapter.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/AtomicReferenceArrayListAdapter.java index 26d2567..93cdbfa 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/AtomicReferenceArrayListAdapter.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/AtomicReferenceArrayListAdapter.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -29,6 +29,8 @@ */ public class AtomicReferenceArrayListAdapter extends AbstractList implements Serializable { + private static final long serialVersionUID = 1L; + private final AtomicReferenceArray atomicReferenceArray; public AtomicReferenceArrayListAdapter(AtomicReferenceArray atomicReferenceArray) { diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/NodeCharacterComparator.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/NodeCharacterComparator.java index fb7b91f..163cad0 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/NodeCharacterComparator.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/NodeCharacterComparator.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/NodeCharacterKey.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/NodeCharacterKey.java index e909005..6ddfd2e 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/NodeCharacterKey.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/NodeCharacterKey.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/NodeCharacterProvider.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/NodeCharacterProvider.java index dd503f7..db41d61 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/NodeCharacterProvider.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/NodeCharacterProvider.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/NodeUtil.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/NodeUtil.java index b180a03..b9e4528 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/NodeUtil.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/NodeUtil.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/PrettyPrintable.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/PrettyPrintable.java index 3fe1af0..4506602 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/PrettyPrintable.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/PrettyPrintable.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,5 +24,5 @@ * @author Niall Gallagher */ public interface PrettyPrintable { - public Node getNode(); + Node getNode(); } diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radixinverted/ConcurrentInvertedRadixTree.java b/code/src/main/java/com/googlecode/concurrenttrees/radixinverted/ConcurrentInvertedRadixTree.java index 89e3ff5..a1464d5 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radixinverted/ConcurrentInvertedRadixTree.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radixinverted/ConcurrentInvertedRadixTree.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -37,8 +37,12 @@ */ public class ConcurrentInvertedRadixTree implements InvertedRadixTree, PrettyPrintable, Serializable { + private static final long serialVersionUID = 1L; + static class ConcurrentInvertedRadixTreeImpl extends ConcurrentRadixTree { + private static final long serialVersionUID = 1L; + public ConcurrentInvertedRadixTreeImpl(NodeFactory nodeFactory) { super(nodeFactory); } @@ -266,7 +270,7 @@ public Iterable getKeysPrefixing(final CharSequence document) { @Override public Iterator iterator() { return new LazyIterator() { - Iterator> matchesForCurrentSuffix = radixTree.scanForKeysAtStartOfInput(document).iterator(); + final Iterator> matchesForCurrentSuffix = radixTree.scanForKeysAtStartOfInput(document).iterator(); @Override protected CharSequence computeNext() { @@ -291,7 +295,7 @@ public Iterable getValuesForKeysPrefixing(final CharSequence document) { @Override public Iterator iterator() { return new LazyIterator() { - Iterator> matchesForCurrentSuffix = radixTree.scanForKeysAtStartOfInput(document).iterator(); + final Iterator> matchesForCurrentSuffix = radixTree.scanForKeysAtStartOfInput(document).iterator(); @Override protected O computeNext() { @@ -316,7 +320,7 @@ public Iterable> getKeyValuePairsForKeysPrefixing(final CharSequ @Override public Iterator> iterator() { return new LazyIterator>() { - Iterator> matchesForCurrentSuffix = radixTree.scanForKeysAtStartOfInput(document).iterator(); + final Iterator> matchesForCurrentSuffix = radixTree.scanForKeysAtStartOfInput(document).iterator(); @Override protected KeyValuePair computeNext() { @@ -368,7 +372,7 @@ public Iterable getKeysContainedIn(final CharSequence document) { @Override public Iterator iterator() { return new LazyIterator() { - Iterator documentSuffixes = CharSequences.generateSuffixes(document).iterator(); + final Iterator documentSuffixes = CharSequences.generateSuffixes(document).iterator(); Iterator> matchesForCurrentSuffix = Collections.>emptyList().iterator(); @Override @@ -398,7 +402,7 @@ public Iterable getValuesForKeysContainedIn(final CharSequence document) { @Override public Iterator iterator() { return new LazyIterator() { - Iterator documentSuffixes = CharSequences.generateSuffixes(document).iterator(); + final Iterator documentSuffixes = CharSequences.generateSuffixes(document).iterator(); Iterator> matchesForCurrentSuffix = Collections.>emptyList().iterator(); @Override @@ -428,7 +432,7 @@ public Iterable> getKeyValuePairsForKeysContainedIn(final CharSe @Override public Iterator> iterator() { return new LazyIterator>() { - Iterator documentSuffixes = CharSequences.generateSuffixes(document).iterator(); + final Iterator documentSuffixes = CharSequences.generateSuffixes(document).iterator(); Iterator> matchesForCurrentSuffix = Collections.>emptyList().iterator(); @Override diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radixinverted/InvertedRadixTree.java b/code/src/main/java/com/googlecode/concurrenttrees/radixinverted/InvertedRadixTree.java index 3c43b5f..455e390 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radixinverted/InvertedRadixTree.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radixinverted/InvertedRadixTree.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -113,7 +113,7 @@ public interface InvertedRadixTree extends RadixTree { * @return The longest key in the tree which is a prefix of the given document, or null if no such key is * contained in the tree */ - public CharSequence getLongestKeyPrefixing(CharSequence document); + CharSequence getLongestKeyPrefixing(CharSequence document); /** * Returns the value associated with the longest key in the tree which is a prefix of the given document. @@ -122,7 +122,7 @@ public interface InvertedRadixTree extends RadixTree { * @return The value associated with longest key in the tree which is a prefix of the given document, or null if * no such key is contained in the tree */ - public O getValueForLongestKeyPrefixing(CharSequence document); + O getValueForLongestKeyPrefixing(CharSequence document); /** * Returns the {@link KeyValuePair} for the longest key in the tree which is a prefix of the given document. @@ -131,7 +131,7 @@ public interface InvertedRadixTree extends RadixTree { * @return The {@link KeyValuePair} for the longest key in the tree which is a prefix of the given document, * or null if no such key is contained in the tree */ - public KeyValuePair getKeyValuePairForLongestKeyPrefixing(CharSequence document); + KeyValuePair getKeyValuePairForLongestKeyPrefixing(CharSequence document); /** * Returns a lazy iterable which returns the set of keys in the tree which are contained in the given document. diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radixreversed/ConcurrentReversedRadixTree.java b/code/src/main/java/com/googlecode/concurrenttrees/radixreversed/ConcurrentReversedRadixTree.java index b312186..018e64d 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radixreversed/ConcurrentReversedRadixTree.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radixreversed/ConcurrentReversedRadixTree.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -35,7 +35,11 @@ */ public class ConcurrentReversedRadixTree implements ReversedRadixTree, PrettyPrintable, Serializable { - class ConcurrentReverseRadixTreeImpl extends ConcurrentRadixTree { + private static final long serialVersionUID = 1L; + + static class ConcurrentReverseRadixTreeImpl extends ConcurrentRadixTree { + + private static final long serialVersionUID = 1L; public ConcurrentReverseRadixTreeImpl(NodeFactory nodeFactory) { super(nodeFactory); diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radixreversed/ReversedRadixTree.java b/code/src/main/java/com/googlecode/concurrenttrees/radixreversed/ReversedRadixTree.java index 85ecdb4..c821097 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radixreversed/ReversedRadixTree.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radixreversed/ReversedRadixTree.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/code/src/main/java/com/googlecode/concurrenttrees/solver/LCSubstringSolver.java b/code/src/main/java/com/googlecode/concurrenttrees/solver/LCSubstringSolver.java index 72e8d8a..9a63c02 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/solver/LCSubstringSolver.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/solver/LCSubstringSolver.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,6 +16,7 @@ package com.googlecode.concurrenttrees.solver; import com.googlecode.concurrenttrees.common.CharSequences; +import com.googlecode.concurrenttrees.common.SetFromMap; import com.googlecode.concurrenttrees.radix.ConcurrentRadixTree; import com.googlecode.concurrenttrees.radix.node.Node; import com.googlecode.concurrenttrees.radix.node.NodeFactory; @@ -36,6 +37,8 @@ public class LCSubstringSolver { class ConcurrentSuffixTreeImpl extends ConcurrentRadixTree { + private static final long serialVersionUID = 1L; + public ConcurrentSuffixTreeImpl(NodeFactory nodeFactory) { super(nodeFactory); } @@ -211,6 +214,6 @@ public CharSequence getLongestCommonSubstring() { } protected Set createSetForOriginalKeys() { - return Collections.newSetFromMap(new ConcurrentHashMap()); + return new SetFromMap(new ConcurrentHashMap()); } } diff --git a/code/src/main/java/com/googlecode/concurrenttrees/suffix/ConcurrentSuffixTree.java b/code/src/main/java/com/googlecode/concurrenttrees/suffix/ConcurrentSuffixTree.java index 950d41e..6b739b5 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/suffix/ConcurrentSuffixTree.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/suffix/ConcurrentSuffixTree.java @@ -18,6 +18,7 @@ import com.googlecode.concurrenttrees.common.CharSequences; import com.googlecode.concurrenttrees.common.KeyValuePair; import com.googlecode.concurrenttrees.common.LazyIterator; +import com.googlecode.concurrenttrees.common.SetFromMap; import com.googlecode.concurrenttrees.radix.ConcurrentRadixTree; import com.googlecode.concurrenttrees.radix.node.Node; import com.googlecode.concurrenttrees.radix.node.NodeFactory; @@ -38,7 +39,11 @@ */ public class ConcurrentSuffixTree implements SuffixTree, PrettyPrintable, Serializable { - class ConcurrentSuffixTreeImpl extends ConcurrentRadixTree { + private static final long serialVersionUID = 1L; + + static class ConcurrentSuffixTreeImpl extends ConcurrentRadixTree { + + private static final long serialVersionUID = 1L; public ConcurrentSuffixTreeImpl(NodeFactory nodeFactory) { super(nodeFactory); @@ -197,7 +202,7 @@ void removeSuffixesFromRadixTree(String keyAsString) { * @return A new {@link Set} in which original keys from which a suffix was generated can be stored */ protected Set createSetForOriginalKeys() { - return Collections.newSetFromMap(new ConcurrentHashMap()); + return new SetFromMap(new ConcurrentHashMap()); } /** @@ -234,7 +239,7 @@ public Iterable getValuesForKeysEndingWith(final CharSequence suffix) { @Override public Iterator iterator() { return new LazyIterator() { - Iterator originalKeys = nullSafeIterator(radixTree.getValueForExactKey(suffix)); + final Iterator originalKeys = nullSafeIterator(radixTree.getValueForExactKey(suffix)); @Override protected O computeNext() { @@ -262,7 +267,7 @@ public Iterable> getKeyValuePairsForKeysEndingWith(final CharSeq @Override public Iterator> iterator() { return new LazyIterator>() { - Iterator originalKeys = nullSafeIterator(radixTree.getValueForExactKey(suffix)); + final Iterator originalKeys = nullSafeIterator(radixTree.getValueForExactKey(suffix)); @Override protected KeyValuePair computeNext() { @@ -292,12 +297,12 @@ public Iterable getKeysContaining(final CharSequence fragment) { public Iterator iterator() { return new LazyIterator() { - Iterator> originalKeysSets = radixTree.getValuesForKeysStartingWith(fragment).iterator(); + final Iterator> originalKeysSets = radixTree.getValuesForKeysStartingWith(fragment).iterator(); Iterator keyIterator = Collections.emptyList().iterator(); // A given fragment can be contained many times within the same key, so track keys processed // so far, so that we can avoid re-processing the same key multiple times... - Set keysAlreadyProcessed = new HashSet(); + final Set keysAlreadyProcessed = new HashSet(); @Override protected CharSequence computeNext() { @@ -332,12 +337,12 @@ public Iterable getValuesForKeysContaining(final CharSequence fragment) { public Iterator iterator() { return new LazyIterator() { - Iterator> originalKeysSets = radixTree.getValuesForKeysStartingWith(fragment).iterator(); + final Iterator> originalKeysSets = radixTree.getValuesForKeysStartingWith(fragment).iterator(); Iterator keyIterator = Collections.emptyList().iterator(); // A given fragment can be contained many times within the same key, so track keys processed // so far, so that we can avoid re-processing the same key multiple times... - Set keysAlreadyProcessed = new HashSet(); + final Set keysAlreadyProcessed = new HashSet(); @Override protected O computeNext() { @@ -376,12 +381,12 @@ public Iterable> getKeyValuePairsForKeysContaining(final CharSeq public Iterator> iterator() { return new LazyIterator>() { - Iterator> originalKeysSets = radixTree.getValuesForKeysStartingWith(fragment).iterator(); + final Iterator> originalKeysSets = radixTree.getValuesForKeysStartingWith(fragment).iterator(); Iterator keyIterator = Collections.emptyList().iterator(); // A given fragment can be contained many times within the same key, so track keys processed // so far, so that we can avoid re-processing the same key multiple times... - Set keysAlreadyProcessed = new HashSet(); + final Set keysAlreadyProcessed = new HashSet(); @Override protected KeyValuePair computeNext() { @@ -422,7 +427,6 @@ public int size() { /** * Utility method to return an iterator for the given iterable, or an empty iterator if the iterable is null. */ - @SuppressWarnings({"JavaDoc"}) static Iterator nullSafeIterator(Iterable iterable) { return iterable == null ? Collections.emptyList().iterator() : iterable.iterator(); } diff --git a/code/src/main/java/com/googlecode/concurrenttrees/suffix/SuffixTree.java b/code/src/main/java/com/googlecode/concurrenttrees/suffix/SuffixTree.java index 250e946..d1df4b5 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/suffix/SuffixTree.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/suffix/SuffixTree.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/ConcurrentRadixTreeTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/ConcurrentRadixTreeTest.java index ef38e28..e0983f6 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/ConcurrentRadixTreeTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/ConcurrentRadixTreeTest.java @@ -282,6 +282,9 @@ protected Classification classify(CharSequence key, Node nodeFound, int charsMat } // Override searchTree() to return the InvalidSearchResult... ConcurrentRadixTree tree = new ConcurrentRadixTree(getNodeFactory()) { + + private static final long serialVersionUID = 1L; + @Override SearchResult searchTree(CharSequence key) { return new InvalidSearchResult("FOO", root, 4, 4, null, null); diff --git a/code/src/test/java/com/googlecode/concurrenttrees/suffix/ConcurrentSuffixTreeTest.java b/code/src/test/java/com/googlecode/concurrenttrees/suffix/ConcurrentSuffixTreeTest.java index cfb69eb..5b9645b 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/suffix/ConcurrentSuffixTreeTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/suffix/ConcurrentSuffixTreeTest.java @@ -17,11 +17,13 @@ import com.googlecode.concurrenttrees.common.Iterables; import com.googlecode.concurrenttrees.common.PrettyPrinter; +import com.googlecode.concurrenttrees.common.SetFromMap; import com.googlecode.concurrenttrees.radix.node.NodeFactory; import com.googlecode.concurrenttrees.radix.node.concrete.DefaultCharArrayNodeFactory; import com.googlecode.concurrenttrees.testutil.TestUtility; import org.junit.Test; +import java.lang.reflect.Field; import java.util.*; import java.util.concurrent.ConcurrentHashMap; @@ -435,10 +437,14 @@ public void testGetKeyValuePairsForKeysContaining() throws Exception { } @Test - public void testCreateSetForOriginalKeys() { - // Test the default (production) implementation of this method, should return a set based on ConcurrentHashMap... + public void testCreateSetForOriginalKeys() throws Exception { + // Test the default (production) implementation of this method, should return a SetFromMap wrapper for a ConcurrentHashMap... ConcurrentSuffixTree tree = new ConcurrentSuffixTree(getNodeFactory()); - assertTrue(tree.createSetForOriginalKeys().getClass().equals(Collections.newSetFromMap(new ConcurrentHashMap()).getClass())); + Set setForOriginalKeys = tree.createSetForOriginalKeys(); + assertEquals(setForOriginalKeys.getClass(), SetFromMap.class); + Field delegate = setForOriginalKeys.getClass().getDeclaredField("delegate"); + delegate.setAccessible(true); + assertEquals(delegate.get(setForOriginalKeys).getClass(), ConcurrentHashMap.class); } /** @@ -449,6 +455,9 @@ public void testCreateSetForOriginalKeys() { @SuppressWarnings({"JavaDoc"}) ConcurrentSuffixTree newConcurrentSuffixTreeForUnitTests() { return new ConcurrentSuffixTree(getNodeFactory()) { + + private static final long serialVersionUID = 1L; + // Override this method to return a set which has consistent iteration order, for unit testing... @Override protected Set createSetForOriginalKeys() { @@ -474,6 +483,9 @@ public void testSerialization() { * Note that ordering of original keys is an internal implementation detail and is externally not defined. */ static class ConcurrentSuffixTreeTestImpl extends ConcurrentSuffixTree { + + private static final long serialVersionUID = 1L; + public ConcurrentSuffixTreeTestImpl(NodeFactory nodeFactory) { super(nodeFactory); } @Override protected Set createSetForOriginalKeys() { From bd23cca724fb13b2a9f6e8d8ad64ffe5e97b2e01 Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Sun, 18 Jul 2021 07:31:24 +0200 Subject: [PATCH 02/15] Transform explicit checks on node creation with assertions to avoid overhead of calls within internal API which are assumed to be correct. --- .../concrete/DefaultByteArrayNodeFactory.java | 14 ++++---------- .../concrete/DefaultCharArrayNodeFactory.java | 14 ++++---------- .../DefaultCharSequenceNodeFactory.java | 15 ++++----------- .../radix/node/util/NodeUtil.java | 10 ++++------ .../DefaultByteArrayNodeFactoryTest.java | 18 +++++++++++++++--- .../DefaultCharArrayNodeFactoryTest.java | 18 +++++++++++++++--- .../DefaultCharSequenceNodeFactoryTest.java | 19 ++++++++++++++++--- .../radix/node/util/NodeUtilTest.java | 10 +++------- 8 files changed, 65 insertions(+), 53 deletions(-) diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultByteArrayNodeFactory.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultByteArrayNodeFactory.java index 378a6c2..80342d5 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultByteArrayNodeFactory.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultByteArrayNodeFactory.java @@ -41,16 +41,10 @@ public class DefaultByteArrayNodeFactory implements NodeFactory { @Override public Node createNode(CharSequence edgeCharacters, Object value, List childNodes, boolean isRoot) { - if (edgeCharacters == null) { - throw new IllegalStateException("The edgeCharacters argument was null"); - } - if (!isRoot && edgeCharacters.length() == 0) { - throw new IllegalStateException("Invalid edge characters for non-root node: " + CharSequences.toString(edgeCharacters)); - } - if (childNodes == null) { - throw new IllegalStateException("The childNodes argument was null"); - } - NodeUtil.ensureNoDuplicateEdges(childNodes); + assert edgeCharacters != null : "The edgeCharacters argument was null"; + assert isRoot || edgeCharacters.length() > 0 : "Invalid edge characters for non-root node: " + CharSequences.toString(edgeCharacters); + assert childNodes != null : "The edgeCharacters argument was null"; + assert NodeUtil.hasNoDuplicateEdges(childNodes) : "Duplicate edge detected in list of nodes supplied: " + childNodes; if (childNodes.isEmpty()) { // Leaf node... if (value instanceof VoidValue) { diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharArrayNodeFactory.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharArrayNodeFactory.java index 9f67589..fa96b66 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharArrayNodeFactory.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharArrayNodeFactory.java @@ -48,16 +48,10 @@ public class DefaultCharArrayNodeFactory implements NodeFactory { @Override public Node createNode(CharSequence edgeCharacters, Object value, List childNodes, boolean isRoot) { - if (edgeCharacters == null) { - throw new IllegalStateException("The edgeCharacters argument was null"); - } - if (!isRoot && edgeCharacters.length() == 0) { - throw new IllegalStateException("Invalid edge characters for non-root node: " + CharSequences.toString(edgeCharacters)); - } - if (childNodes == null) { - throw new IllegalStateException("The childNodes argument was null"); - } - NodeUtil.ensureNoDuplicateEdges(childNodes); + assert edgeCharacters != null : "The edgeCharacters argument was null"; + assert isRoot || edgeCharacters.length() > 0 : "Invalid edge characters for non-root node: " + CharSequences.toString(edgeCharacters); + assert childNodes != null : "The edgeCharacters argument was null"; + assert NodeUtil.hasNoDuplicateEdges(childNodes) : "Duplicate edge detected in list of nodes supplied: " + childNodes; if (childNodes.isEmpty()) { // Leaf node... if (value instanceof VoidValue) { diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharSequenceNodeFactory.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharSequenceNodeFactory.java index 665ef39..c9fc701 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharSequenceNodeFactory.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharSequenceNodeFactory.java @@ -49,17 +49,10 @@ public class DefaultCharSequenceNodeFactory implements NodeFactory { @Override public Node createNode(CharSequence edgeCharacters, Object value, List childNodes, boolean isRoot) { - if (edgeCharacters == null) { - throw new IllegalStateException("The edgeCharacters argument was null"); - } - if (!isRoot && edgeCharacters.length() == 0) { - throw new IllegalStateException("Invalid edge characters for non-root node: " + CharSequences.toString(edgeCharacters)); - } - if (childNodes == null) { - throw new IllegalStateException("The childNodes argument was null"); - } - NodeUtil.ensureNoDuplicateEdges(childNodes); - + assert edgeCharacters != null : "The edgeCharacters argument was null"; + assert isRoot || edgeCharacters.length() > 0 : "Invalid edge characters for non-root node: " + CharSequences.toString(edgeCharacters); + assert childNodes != null : "The edgeCharacters argument was null"; + assert NodeUtil.hasNoDuplicateEdges(childNodes) : "Duplicate edge detected in list of nodes supplied: " + childNodes; if (childNodes.isEmpty()) { // Leaf node... diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/NodeUtil.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/NodeUtil.java index b9e4528..03a1d6d 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/NodeUtil.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/NodeUtil.java @@ -81,19 +81,17 @@ else if (cmp > 0) } /** - * Throws an exception if any nodes in the given list represent edges having the same first character. + * Checks if any nodes in the given list represent edges having the same first character. * * @param nodes The list of nodes to validate - * @throws IllegalStateException If a duplicate edge is detected + * @return {@code true} if the supplied edges are free of duplicates. */ - public static void ensureNoDuplicateEdges(List nodes) { + public static boolean hasNoDuplicateEdges(List nodes) { // Sanity check that no two nodes specify an edge with the same first character... Set uniqueChars = new HashSet(nodes.size()); for (Node node : nodes) { uniqueChars.add(node.getIncomingEdgeFirstCharacter()); } - if (nodes.size() != uniqueChars.size()) { - throw new IllegalStateException("Duplicate edge detected in list of nodes supplied: " + nodes); - } + return nodes.size() == uniqueChars.size(); } } diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultByteArrayNodeFactoryTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultByteArrayNodeFactoryTest.java index 61074f5..24bb7b6 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultByteArrayNodeFactoryTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultByteArrayNodeFactoryTest.java @@ -16,30 +16,42 @@ package com.googlecode.concurrenttrees.radix.node.concrete; import com.googlecode.concurrenttrees.radix.node.Node; +import org.junit.Before; import org.junit.Test; import java.util.Collections; +import static junit.framework.Assert.assertTrue; + /** * @author Niall Gallagher */ public class DefaultByteArrayNodeFactoryTest { + private boolean assertions; + + @Before + public void setUp() { + assert assertions = true; + } - @Test(expected = IllegalStateException.class) + @Test(expected = AssertionError.class) public void testCreateNode_NullEdge() throws Exception { + assertTrue(assertions); //noinspection NullableProblems new DefaultByteArrayNodeFactory().createNode(null, 1, Collections.emptyList(), false); } - @Test(expected = IllegalStateException.class) + @Test(expected = AssertionError.class) public void testCreateNode_EmptyEdgeNonRoot() throws Exception { + assertTrue(assertions); //noinspection NullableProblems new DefaultByteArrayNodeFactory().createNode("", 1, Collections.emptyList(), false); } - @Test(expected = IllegalStateException.class) + @Test(expected = AssertionError.class) public void testCreateNode_NullEdges() throws Exception { + assertTrue(assertions); //noinspection NullableProblems new DefaultByteArrayNodeFactory().createNode("FOO", 1, null, false); } diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharArrayNodeFactoryTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharArrayNodeFactoryTest.java index e7ff1c9..83c343a 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharArrayNodeFactoryTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharArrayNodeFactoryTest.java @@ -16,30 +16,42 @@ package com.googlecode.concurrenttrees.radix.node.concrete; import com.googlecode.concurrenttrees.radix.node.Node; +import org.junit.Before; import org.junit.Test; import java.util.Collections; +import static junit.framework.Assert.assertTrue; + /** * @author Niall Gallagher */ public class DefaultCharArrayNodeFactoryTest { + private boolean assertions; + + @Before + public void setUp() { + assert assertions = true; + } - @Test(expected = IllegalStateException.class) + @Test(expected = AssertionError.class) public void testCreateNode_NullEdge() throws Exception { + assertTrue(assertions); //noinspection NullableProblems new DefaultCharArrayNodeFactory().createNode(null, 1, Collections.emptyList(), false); } - @Test(expected = IllegalStateException.class) + @Test(expected = AssertionError.class) public void testCreateNode_EmptyEdgeNonRoot() throws Exception { + assertTrue(assertions); //noinspection NullableProblems new DefaultCharArrayNodeFactory().createNode("", 1, Collections.emptyList(), false); } - @Test(expected = IllegalStateException.class) + @Test(expected = AssertionError.class) public void testCreateNode_NullEdges() throws Exception { + assertTrue(assertions); //noinspection NullableProblems new DefaultCharArrayNodeFactory().createNode("FOO", 1, null, false); } diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharSequenceNodeFactoryTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharSequenceNodeFactoryTest.java index c9a69bd..aeab776 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharSequenceNodeFactoryTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharSequenceNodeFactoryTest.java @@ -16,29 +16,42 @@ package com.googlecode.concurrenttrees.radix.node.concrete; import com.googlecode.concurrenttrees.radix.node.Node; +import org.junit.Before; import org.junit.Test; import java.util.Collections; +import static junit.framework.Assert.assertTrue; + /** * @author Niall Gallagher */ public class DefaultCharSequenceNodeFactoryTest { - @Test(expected = IllegalStateException.class) + private boolean assertions; + + @Before + public void setUp() { + assert assertions = true; + } + + @Test(expected = AssertionError.class) public void testCreateNode_NullEdge() throws Exception { + assertTrue(assertions); //noinspection NullableProblems new DefaultCharSequenceNodeFactory().createNode(null, 1, Collections.emptyList(), false); } - @Test(expected = IllegalStateException.class) + @Test(expected = AssertionError.class) public void testCreateNode_EmptyEdgeNonRoot() throws Exception { + assertTrue(assertions); //noinspection NullableProblems new DefaultCharSequenceNodeFactory().createNode("", 1, Collections.emptyList(), false); } - @Test(expected = IllegalStateException.class) + @Test(expected = AssertionError.class) public void testCreateNode_NullEdges() throws Exception { + assertTrue(assertions); //noinspection NullableProblems new DefaultCharSequenceNodeFactory().createNode("FOO", 1, null, false); } diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/util/NodeUtilTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/util/NodeUtilTest.java index e131b77..2714590 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/util/NodeUtilTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/util/NodeUtilTest.java @@ -26,6 +26,8 @@ import java.util.List; import java.util.concurrent.atomic.AtomicReferenceArray; +import static junit.framework.Assert.assertFalse; + /** * @author Niall Gallagher */ @@ -68,13 +70,7 @@ public void testEnsureNoDuplicateEdges_Negative() throws Exception { nodeFactory.createNode("B", null, Collections.emptyList(), false), nodeFactory.createNode("C", null, Collections.emptyList(), false) ); - try { - NodeUtil.ensureNoDuplicateEdges(nodes); - Assert.fail("Should throw exception"); - } - catch (IllegalStateException expected) { - // Expected - } + assertFalse(NodeUtil.hasNoDuplicateEdges(nodes)); } @Test From c44dfa1d405a78d3f9828f5431cf4f0c45e47b3b Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Sun, 18 Jul 2021 07:44:44 +0200 Subject: [PATCH 03/15] Correct comment in POM file. --- code/pom.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/code/pom.xml b/code/pom.xml index bad1d16..5a14585 100644 --- a/code/pom.xml +++ b/code/pom.xml @@ -43,8 +43,7 @@ org.apache.maven.plugins maven-compiler-plugin From d3478e7db3fa99e47d47b8c6a5b5d43155128e96 Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Sun, 18 Jul 2021 19:42:27 +0200 Subject: [PATCH 04/15] Add automatic module name to manifest file. --- code/pom.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/code/pom.xml b/code/pom.xml index 5a14585..c7a1041 100644 --- a/code/pom.xml +++ b/code/pom.xml @@ -78,6 +78,9 @@ ${project.build.outputDirectory}/META-INF/MANIFEST.MF + + ${project.groupId}.${project.artifactId} + From 3a534ced0cb2b8c100efa7f3fc5f765776294d91 Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Fri, 23 Jul 2021 00:27:04 +0200 Subject: [PATCH 05/15] Avoid constant boxing of characters into wrapper instances. --- .../com/googlecode/concurrenttrees/radix/node/Node.java | 6 +++--- .../node/concrete/bytearray/ByteArrayNodeDefault.java | 4 ++-- .../concrete/bytearray/ByteArrayNodeLeafNullValue.java | 4 ++-- .../concrete/bytearray/ByteArrayNodeLeafVoidValue.java | 4 ++-- .../concrete/bytearray/ByteArrayNodeLeafWithValue.java | 4 ++-- .../concrete/bytearray/ByteArrayNodeNonLeafNullValue.java | 4 ++-- .../concrete/bytearray/ByteArrayNodeNonLeafVoidValue.java | 4 ++-- .../node/concrete/chararray/CharArrayNodeDefault.java | 6 +++--- .../concrete/chararray/CharArrayNodeLeafNullValue.java | 4 ++-- .../concrete/chararray/CharArrayNodeLeafVoidValue.java | 4 ++-- .../concrete/chararray/CharArrayNodeLeafWithValue.java | 4 ++-- .../concrete/chararray/CharArrayNodeNonLeafNullValue.java | 4 ++-- .../concrete/chararray/CharArrayNodeNonLeafVoidValue.java | 4 ++-- .../concrete/charsequence/CharSequenceNodeDefault.java | 6 +++--- .../charsequence/CharSequenceNodeLeafNullValue.java | 4 ++-- .../charsequence/CharSequenceNodeLeafVoidValue.java | 4 ++-- .../charsequence/CharSequenceNodeLeafWithValue.java | 4 ++-- .../charsequence/CharSequenceNodeNonLeafNullValue.java | 4 ++-- .../charsequence/CharSequenceNodeNonLeafVoidValue.java | 4 ++-- .../radix/node/util/NodeCharacterComparator.java | 2 +- .../concurrenttrees/radix/node/util/NodeCharacterKey.java | 8 ++++---- .../radix/node/util/NodeCharacterProvider.java | 2 +- .../concurrenttrees/radix/node/util/NodeUtil.java | 4 ++-- .../bytearray/ByteArrayNodeLeafNullValueTest.java | 2 +- .../charsequence/CharSequenceNodeLeafNullValueTest.java | 2 +- 25 files changed, 51 insertions(+), 51 deletions(-) diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/Node.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/Node.java index 2ae3cdd..1bf3d16 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/Node.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/Node.java @@ -96,7 +96,7 @@ public interface Node extends NodeCharacterProvider, Serializable { * * @return The first character of the "edge" encoded in this node */ - Character getIncomingEdgeFirstCharacter(); + char getIncomingEdgeFirstCharacter(); /** * Returns all characters of the "edge" encoded in this node, belonging to the connection from a parent node to this @@ -126,7 +126,7 @@ public interface Node extends NodeCharacterProvider, Serializable { * @return The child of this node whose edge starts with the given first character, or null if this * node has no such outgoing edge */ - Node getOutgoingEdge(Character edgeFirstCharacter); + Node getOutgoingEdge(char edgeFirstCharacter); /** * Updates the child node reference for a given edge (identified by its first character) to point to a different @@ -136,7 +136,7 @@ public interface Node extends NodeCharacterProvider, Serializable { * edge from this node. *

* This write must be performed atomically, in relation to reads made via - * {@link #getOutgoingEdge(Character)}. + * {@link #getOutgoingEdge(char)}. * * @param childNode The new child node to associated with this edge */ diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeDefault.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeDefault.java index 99c65b6..0873938 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeDefault.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeDefault.java @@ -69,7 +69,7 @@ public CharSequence getIncomingEdge() { } @Override - public Character getIncomingEdgeFirstCharacter() { + public char getIncomingEdgeFirstCharacter() { return (char) (incomingEdgeCharArray[0] & 0xFF); } @@ -79,7 +79,7 @@ public Object getValue() { } @Override - public Node getOutgoingEdge(Character edgeFirstCharacter) { + public Node getOutgoingEdge(char edgeFirstCharacter) { // Binary search for the index of the node whose edge starts with the given character. // Note that this binary search is safe in the face of concurrent modification due to constraints // we enforce on use of the array, as documented in the binarySearchForEdge method... diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafNullValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafNullValue.java index 900a273..8478b34 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafNullValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafNullValue.java @@ -47,7 +47,7 @@ public CharSequence getIncomingEdge() { } @Override - public Character getIncomingEdgeFirstCharacter() { + public char getIncomingEdgeFirstCharacter() { return (char) (incomingEdgeCharArray[0] & 0xFF); } @@ -57,7 +57,7 @@ public Object getValue() { } @Override - public Node getOutgoingEdge(Character edgeFirstCharacter) { + public Node getOutgoingEdge(char edgeFirstCharacter) { return null; } diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafVoidValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafVoidValue.java index 87b02bf..513522e 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafVoidValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafVoidValue.java @@ -48,7 +48,7 @@ public CharSequence getIncomingEdge() { } @Override - public Character getIncomingEdgeFirstCharacter() { + public char getIncomingEdgeFirstCharacter() { return (char) (incomingEdgeCharArray[0] & 0xFF); } @@ -58,7 +58,7 @@ public Object getValue() { } @Override - public Node getOutgoingEdge(Character edgeFirstCharacter) { + public Node getOutgoingEdge(char edgeFirstCharacter) { return null; } diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafWithValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafWithValue.java index d8cab38..61be021 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafWithValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafWithValue.java @@ -52,7 +52,7 @@ public CharSequence getIncomingEdge() { } @Override - public Character getIncomingEdgeFirstCharacter() { + public char getIncomingEdgeFirstCharacter() { return (char) (incomingEdgeCharArray[0] & 0xFF); } @@ -62,7 +62,7 @@ public Object getValue() { } @Override - public Node getOutgoingEdge(Character edgeFirstCharacter) { + public Node getOutgoingEdge(char edgeFirstCharacter) { return null; } diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafNullValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafNullValue.java index 579e3aa..c3e9b81 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafNullValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafNullValue.java @@ -64,7 +64,7 @@ public CharSequence getIncomingEdge() { } @Override - public Character getIncomingEdgeFirstCharacter() { + public char getIncomingEdgeFirstCharacter() { return (char) (incomingEdgeCharArray[0] & 0xFF); } @@ -74,7 +74,7 @@ public Object getValue() { } @Override - public Node getOutgoingEdge(Character edgeFirstCharacter) { + public Node getOutgoingEdge(char edgeFirstCharacter) { // Binary search for the index of the node whose edge starts with the given character. // Note that this binary search is safe in the face of concurrent modification due to constraints // we enforce on use of the array, as documented in the binarySearchForEdge method... diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafVoidValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafVoidValue.java index 0f7e38c..41a6f94 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafVoidValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafVoidValue.java @@ -65,7 +65,7 @@ public CharSequence getIncomingEdge() { } @Override - public Character getIncomingEdgeFirstCharacter() { + public char getIncomingEdgeFirstCharacter() { return (char) (incomingEdgeCharArray[0] & 0xFF); } @@ -75,7 +75,7 @@ public Object getValue() { } @Override - public Node getOutgoingEdge(Character edgeFirstCharacter) { + public Node getOutgoingEdge(char edgeFirstCharacter) { // Binary search for the index of the node whose edge starts with the given character. // Note that this binary search is safe in the face of concurrent modification due to constraints // we enforce on use of the array, as documented in the binarySearchForEdge method... diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeDefault.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeDefault.java index 61bdf21..7d03a91 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeDefault.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeDefault.java @@ -36,7 +36,7 @@ * This implementation stores references to child nodes in an {@link AtomicReferenceArray}, in ascending sorted order * of the first character of the edges which child nodes define. *

- * The {@link #getOutgoingEdge(Character)} method uses binary search to locate a requested node, given the first character + * The {@link #getOutgoingEdge(char)} method uses binary search to locate a requested node, given the first character * of an edge indicated. The node is then read and returned atomically from the {@link AtomicReferenceArray}. *

* The {@link #updateOutgoingEdge(com.googlecode.concurrenttrees.radix.node.Node)} method ensures that any @@ -85,7 +85,7 @@ public CharSequence getIncomingEdge() { } @Override - public Character getIncomingEdgeFirstCharacter() { + public char getIncomingEdgeFirstCharacter() { return incomingEdgeCharArray[0]; } @@ -95,7 +95,7 @@ public Object getValue() { } @Override - public Node getOutgoingEdge(Character edgeFirstCharacter) { + public Node getOutgoingEdge(char edgeFirstCharacter) { // Binary search for the index of the node whose edge starts with the given character. // Note that this binary search is safe in the face of concurrent modification due to constraints // we enforce on use of the array, as documented in the binarySearchForEdge method... diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafNullValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafNullValue.java index 21a3791..db355d6 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafNullValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafNullValue.java @@ -45,7 +45,7 @@ public CharSequence getIncomingEdge() { } @Override - public Character getIncomingEdgeFirstCharacter() { + public char getIncomingEdgeFirstCharacter() { return incomingEdgeCharArray[0]; } @@ -55,7 +55,7 @@ public Object getValue() { } @Override - public Node getOutgoingEdge(Character edgeFirstCharacter) { + public Node getOutgoingEdge(char edgeFirstCharacter) { return null; } diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafVoidValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafVoidValue.java index f575fa2..549eba1 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafVoidValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafVoidValue.java @@ -46,7 +46,7 @@ public CharSequence getIncomingEdge() { } @Override - public Character getIncomingEdgeFirstCharacter() { + public char getIncomingEdgeFirstCharacter() { return incomingEdgeCharArray[0]; } @@ -56,7 +56,7 @@ public Object getValue() { } @Override - public Node getOutgoingEdge(Character edgeFirstCharacter) { + public Node getOutgoingEdge(char edgeFirstCharacter) { return null; } diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafWithValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafWithValue.java index 05e0eca..b500983 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafWithValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafWithValue.java @@ -50,7 +50,7 @@ public CharSequence getIncomingEdge() { } @Override - public Character getIncomingEdgeFirstCharacter() { + public char getIncomingEdgeFirstCharacter() { return incomingEdgeCharArray[0]; } @@ -60,7 +60,7 @@ public Object getValue() { } @Override - public Node getOutgoingEdge(Character edgeFirstCharacter) { + public Node getOutgoingEdge(char edgeFirstCharacter) { return null; } diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafNullValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafNullValue.java index 46c4ae6..bb540cd 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafNullValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafNullValue.java @@ -62,7 +62,7 @@ public CharSequence getIncomingEdge() { } @Override - public Character getIncomingEdgeFirstCharacter() { + public char getIncomingEdgeFirstCharacter() { return incomingEdgeCharArray[0]; } @@ -72,7 +72,7 @@ public Object getValue() { } @Override - public Node getOutgoingEdge(Character edgeFirstCharacter) { + public Node getOutgoingEdge(char edgeFirstCharacter) { // Binary search for the index of the node whose edge starts with the given character. // Note that this binary search is safe in the face of concurrent modification due to constraints // we enforce on use of the array, as documented in the binarySearchForEdge method... diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafVoidValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafVoidValue.java index f8b53e2..9908c47 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafVoidValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafVoidValue.java @@ -63,7 +63,7 @@ public CharSequence getIncomingEdge() { } @Override - public Character getIncomingEdgeFirstCharacter() { + public char getIncomingEdgeFirstCharacter() { return incomingEdgeCharArray[0]; } @@ -73,7 +73,7 @@ public Object getValue() { } @Override - public Node getOutgoingEdge(Character edgeFirstCharacter) { + public Node getOutgoingEdge(char edgeFirstCharacter) { // Binary search for the index of the node whose edge starts with the given character. // Note that this binary search is safe in the face of concurrent modification due to constraints // we enforce on use of the array, as documented in the binarySearchForEdge method... diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeDefault.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeDefault.java index 42f8d87..9a784f1 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeDefault.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeDefault.java @@ -36,7 +36,7 @@ * This implementation stores references to child nodes in an {@link AtomicReferenceArray}, in ascending sorted order * of the first character of the edges which child nodes define. *

- * The {@link #getOutgoingEdge(Character)} method uses binary search to locate a requested node, given the first character + * The {@link #getOutgoingEdge(char)} method uses binary search to locate a requested node, given the first character * of an edge indicated. The node is then read and returned atomically from the {@link AtomicReferenceArray}. *

* The {@link #updateOutgoingEdge(com.googlecode.concurrenttrees.radix.node.Node)} method ensures that any @@ -85,7 +85,7 @@ public CharSequence getIncomingEdge() { } @Override - public Character getIncomingEdgeFirstCharacter() { + public char getIncomingEdgeFirstCharacter() { return incomingEdgeCharSequence.charAt(0); } @@ -95,7 +95,7 @@ public Object getValue() { } @Override - public Node getOutgoingEdge(Character edgeFirstCharacter) { + public Node getOutgoingEdge(char edgeFirstCharacter) { // Binary search for the index of the node whose edge starts with the given character. // Note that this binary search is safe in the face of concurrent modification due to constraints // we enforce on use of the array, as documented in the binarySearchForEdge method... diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafNullValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafNullValue.java index b18a466..98472e6 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafNullValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafNullValue.java @@ -44,7 +44,7 @@ public CharSequence getIncomingEdge() { } @Override - public Character getIncomingEdgeFirstCharacter() { + public char getIncomingEdgeFirstCharacter() { return incomingEdgeCharSequence.charAt(0); } @@ -54,7 +54,7 @@ public Object getValue() { } @Override - public Node getOutgoingEdge(Character edgeFirstCharacter) { + public Node getOutgoingEdge(char edgeFirstCharacter) { return null; } diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafVoidValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafVoidValue.java index 534f802..3e207b2 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafVoidValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafVoidValue.java @@ -50,7 +50,7 @@ public CharSequence getIncomingEdge() { } @Override - public Character getIncomingEdgeFirstCharacter() { + public char getIncomingEdgeFirstCharacter() { return incomingEdgeCharSequence.charAt(0); } @@ -60,7 +60,7 @@ public Object getValue() { } @Override - public Node getOutgoingEdge(Character edgeFirstCharacter) { + public Node getOutgoingEdge(char edgeFirstCharacter) { return null; } diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafWithValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafWithValue.java index c8cd472..b769443 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafWithValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafWithValue.java @@ -50,7 +50,7 @@ public CharSequence getIncomingEdge() { } @Override - public Character getIncomingEdgeFirstCharacter() { + public char getIncomingEdgeFirstCharacter() { return incomingEdgeCharSequence.charAt(0); } @@ -60,7 +60,7 @@ public Object getValue() { } @Override - public Node getOutgoingEdge(Character edgeFirstCharacter) { + public Node getOutgoingEdge(char edgeFirstCharacter) { return null; } diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafNullValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafNullValue.java index 2d8d696..16518d3 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafNullValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafNullValue.java @@ -62,7 +62,7 @@ public CharSequence getIncomingEdge() { } @Override - public Character getIncomingEdgeFirstCharacter() { + public char getIncomingEdgeFirstCharacter() { return incomingEdgeCharSequence.charAt(0); } @@ -72,7 +72,7 @@ public Object getValue() { } @Override - public Node getOutgoingEdge(Character edgeFirstCharacter) { + public Node getOutgoingEdge(char edgeFirstCharacter) { // Binary search for the index of the node whose edge starts with the given character. // Note that this binary search is safe in the face of concurrent modification due to constraints // we enforce on use of the array, as documented in the binarySearchForEdge method... diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafVoidValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafVoidValue.java index 09f9129..3e71416 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafVoidValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafVoidValue.java @@ -63,7 +63,7 @@ public CharSequence getIncomingEdge() { } @Override - public Character getIncomingEdgeFirstCharacter() { + public char getIncomingEdgeFirstCharacter() { return incomingEdgeCharSequence.charAt(0); } @@ -73,7 +73,7 @@ public Object getValue() { } @Override - public Node getOutgoingEdge(Character edgeFirstCharacter) { + public Node getOutgoingEdge(char edgeFirstCharacter) { // Binary search for the index of the node whose edge starts with the given character. // Note that this binary search is safe in the face of concurrent modification due to constraints // we enforce on use of the array, as documented in the binarySearchForEdge method... diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/NodeCharacterComparator.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/NodeCharacterComparator.java index 163cad0..4d98ead 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/NodeCharacterComparator.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/NodeCharacterComparator.java @@ -27,6 +27,6 @@ public class NodeCharacterComparator implements Comparator childNodes, Character edgeFirstCharacter) { + public static int binarySearchForEdge(AtomicReferenceArray childNodes, char edgeFirstCharacter) { // inspired by Collections#indexedBinarySearch() int low = 0; int high = childNodes.length() - 1; @@ -68,7 +68,7 @@ public static int binarySearchForEdge(AtomicReferenceArray childNodes, Cha while (low <= high) { int mid = (low + high) >>> 1; Node midVal = childNodes.get(mid); - int cmp = midVal.getIncomingEdgeFirstCharacter().compareTo(edgeFirstCharacter); + int cmp = midVal.getIncomingEdgeFirstCharacter() - edgeFirstCharacter; if (cmp < 0) low = mid + 1; diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafNullValueTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafNullValueTest.java index 5672c7e..b74ff2b 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafNullValueTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafNullValueTest.java @@ -41,6 +41,6 @@ public void testToString() throws Exception { @Test public void testGetIncomingEdgeFirstCharacter() throws Exception { Node node = new ByteArrayNodeLeafNullValue("FOO"); - Assert.assertEquals(Character.valueOf('F'), node.getIncomingEdgeFirstCharacter()); + Assert.assertEquals('F', node.getIncomingEdgeFirstCharacter()); } } diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafNullValueTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafNullValueTest.java index 721fb4a..61b3f37 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafNullValueTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafNullValueTest.java @@ -41,6 +41,6 @@ public void testToString() throws Exception { @Test public void testGetIncomingEdgeFirstCharacter() { Node node = new CharSequenceNodeLeafNullValue("FOO"); - Assert.assertEquals(Character.valueOf('F'), node.getIncomingEdgeFirstCharacter()); + Assert.assertEquals('F', node.getIncomingEdgeFirstCharacter()); } } From 5b486f4afb3dd1ce162073049cb76a90cf5bdfaa Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Fri, 23 Jul 2021 08:48:01 +0200 Subject: [PATCH 06/15] Avoid allocation of SearchResult instance upon looking up an exact value where from a ConcurrentRadixTree. By avoiding this allocation, looking up a large chunk of values can be done with less GC overhead. Escape analysis on the JVM is unfortunately rather limited such that this allocation is not properly avoided by the JIT in many cases. If this allocation ends up on the hot path, its collection can have a visible impact on throughput. --- .../radix/ConcurrentRadixTree.java | 41 ++++++++++++++++--- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/ConcurrentRadixTree.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/ConcurrentRadixTree.java index 68b90d2..7e6fa1c 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/ConcurrentRadixTree.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/ConcurrentRadixTree.java @@ -101,10 +101,10 @@ public O putIfAbsent(CharSequence key, O value) { */ @Override public O getValueForExactKey(CharSequence key) { - SearchResult searchResult = searchTree(key); - if (searchResult.classification.equals(SearchResult.Classification.EXACT_MATCH)) { + Node searchResult = (Node) searchTree(key, true); + if (searchResult != null) { @SuppressWarnings({"unchecked", "UnnecessaryLocalVariable"}) - O value = (O) searchResult.nodeFound.getValue(); + O value = (O) searchResult.getValue(); return value; } return null; @@ -901,7 +901,21 @@ protected CharSequence transformKeyForResult(CharSequence rawKey) { * parent node, the number of characters of the key which were matched in total and within the edge of the * matched node, and a {@link SearchResult#classification} of the match as described above */ + SearchResult searchTree(CharSequence key) { + return (SearchResult) searchTree(key, false); + } + + /** + * Implements {@link #searchTree(CharSequence)} but gives an option to return the exactly matched node directly + * without allocating a {@link SearchResult}. + * + * @param key a key for which the node matching the longest prefix of the key is required + * @param exactOnly If {@code true}, an exactly matched node is returned if such a node was found or {@code null} + * otherwise. If {@code false}, a {@link SearchResult} is returned. + * @return The resolved {@link SearchResult} or a {@link Node} if {@code exactOnly} was set to {@code true}. + */ + private Object searchTree(CharSequence key, boolean exactOnly) { Node parentNodesParent = null; Node parentNode = null; Node currentNode = root; @@ -931,7 +945,15 @@ SearchResult searchTree(CharSequence key) { charsMatchedInNodeFound++; } } - return new SearchResult(key, currentNode, charsMatched, charsMatchedInNodeFound, parentNode, parentNodesParent); + if (exactOnly) { + if (SearchResult.doClassify(key, currentNode, charsMatched, charsMatchedInNodeFound).equals(Classification.EXACT_MATCH)) { + return currentNode; + } else { + return null; + } + } else { + return new SearchResult(key, currentNode, charsMatched, charsMatchedInNodeFound, parentNode, parentNodesParent); + } } /** @@ -972,6 +994,10 @@ enum Classification { } protected Classification classify(CharSequence key, Node nodeFound, int charsMatched, int charsMatchedInNodeFound) { + return doClassify(key, nodeFound, charsMatched, charsMatchedInNodeFound); + } + + protected static Classification doClassify(CharSequence key, Node nodeFound, int charsMatched, int charsMatchedInNodeFound) { if (charsMatched == key.length()) { if (charsMatchedInNodeFound == nodeFound.getIncomingEdge().length()) { return Classification.EXACT_MATCH; @@ -988,7 +1014,12 @@ else if (charsMatchedInNodeFound < nodeFound.getIncomingEdge().length()) { return Classification.INCOMPLETE_MATCH_TO_MIDDLE_OF_EDGE; } } - throw new IllegalStateException("Unexpected failure to classify SearchResult: " + this); + throw new IllegalStateException("Unexpected failure to classify SearchResult: {" + + "key=" + key + + ", nodeFound=" + nodeFound + + ", charsMatched=" + charsMatched + + ", charsMatchedInNodeFound=" + charsMatchedInNodeFound + + '}'); } @Override From b36476ca0b679e2bf3dd2e2a2d8c184128e20f5d Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Sun, 25 Jul 2021 22:35:05 +0200 Subject: [PATCH 07/15] Avoid CharSequence allocation upon tree search by exposing methods for char-index and length resolution. Ideally, the allocations are removed by escape analysis but the mechanism does not always work as expected such that search can cause significant allocation. --- .../concurrenttrees/common/PrettyPrinter.java | 2 +- .../concurrenttrees/radix/ConcurrentRadixTree.java | 13 ++++++------- .../googlecode/concurrenttrees/radix/node/Node.java | 5 ++++- .../concrete/bytearray/ByteArrayNodeDefault.java | 10 ++++++++++ .../bytearray/ByteArrayNodeLeafNullValue.java | 10 ++++++++++ .../bytearray/ByteArrayNodeLeafVoidValue.java | 10 ++++++++++ .../bytearray/ByteArrayNodeLeafWithValue.java | 10 ++++++++++ .../bytearray/ByteArrayNodeNonLeafNullValue.java | 10 ++++++++++ .../bytearray/ByteArrayNodeNonLeafVoidValue.java | 10 ++++++++++ .../concrete/chararray/CharArrayNodeDefault.java | 10 ++++++++++ .../chararray/CharArrayNodeLeafNullValue.java | 10 ++++++++++ .../chararray/CharArrayNodeLeafVoidValue.java | 10 ++++++++++ .../chararray/CharArrayNodeLeafWithValue.java | 10 ++++++++++ .../chararray/CharArrayNodeNonLeafNullValue.java | 10 ++++++++++ .../chararray/CharArrayNodeNonLeafVoidValue.java | 10 ++++++++++ .../charsequence/CharSequenceNodeDefault.java | 10 ++++++++++ .../charsequence/CharSequenceNodeLeafNullValue.java | 10 ++++++++++ .../charsequence/CharSequenceNodeLeafVoidValue.java | 10 ++++++++++ .../charsequence/CharSequenceNodeLeafWithValue.java | 10 ++++++++++ .../CharSequenceNodeNonLeafNullValue.java | 10 ++++++++++ .../CharSequenceNodeNonLeafVoidValue.java | 10 ++++++++++ .../radixinverted/ConcurrentInvertedRadixTree.java | 10 ++++------ 22 files changed, 195 insertions(+), 15 deletions(-) diff --git a/code/src/main/java/com/googlecode/concurrenttrees/common/PrettyPrinter.java b/code/src/main/java/com/googlecode/concurrenttrees/common/PrettyPrinter.java index 0274bb1..7c6ad06 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/common/PrettyPrinter.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/common/PrettyPrinter.java @@ -83,7 +83,7 @@ static void prettyPrint(Node node, Appendable sb, String prefix, boolean isTail, StringBuilder label = new StringBuilder(); if (isRoot) { label.append("â—‹"); - if (node.getIncomingEdge().length() > 0) { + if (node.getIncomingEdgeLength() > 0) { label.append(" "); } } diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/ConcurrentRadixTree.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/ConcurrentRadixTree.java index 7e6fa1c..74fbdb9 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/ConcurrentRadixTree.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/ConcurrentRadixTree.java @@ -934,9 +934,8 @@ private Object searchTree(CharSequence key, boolean exactOnly) { parentNode = currentNode; currentNode = nextNode; charsMatchedInNodeFound = 0; - CharSequence currentNodeEdgeCharacters = currentNode.getIncomingEdge(); - for (int i = 0, numEdgeChars = currentNodeEdgeCharacters.length(); i < numEdgeChars && charsMatched < keyLength; i++) { - if (currentNodeEdgeCharacters.charAt(i) != key.charAt(charsMatched)) { + for (int i = 0, numEdgeChars = currentNode.getIncomingEdgeLength(); i < numEdgeChars && charsMatched < keyLength; i++) { + if (currentNode.getIncomingEdgeCharacterAt(i) != key.charAt(charsMatched)) { // Found a difference in chars between character in key and a character in current node. // Current node is the deepest match (inexact match).... break outer_loop; @@ -999,18 +998,18 @@ protected Classification classify(CharSequence key, Node nodeFound, int charsMat protected static Classification doClassify(CharSequence key, Node nodeFound, int charsMatched, int charsMatchedInNodeFound) { if (charsMatched == key.length()) { - if (charsMatchedInNodeFound == nodeFound.getIncomingEdge().length()) { + if (charsMatchedInNodeFound == nodeFound.getIncomingEdgeLength()) { return Classification.EXACT_MATCH; } - else if (charsMatchedInNodeFound < nodeFound.getIncomingEdge().length()) { + else if (charsMatchedInNodeFound < nodeFound.getIncomingEdgeLength()) { return Classification.KEY_ENDS_MID_EDGE; } } else if (charsMatched < key.length()) { - if (charsMatchedInNodeFound == nodeFound.getIncomingEdge().length()) { + if (charsMatchedInNodeFound == nodeFound.getIncomingEdgeLength()) { return Classification.INCOMPLETE_MATCH_TO_END_OF_EDGE; } - else if (charsMatchedInNodeFound < nodeFound.getIncomingEdge().length()) { + else if (charsMatchedInNodeFound < nodeFound.getIncomingEdgeLength()) { return Classification.INCOMPLETE_MATCH_TO_MIDDLE_OF_EDGE; } } diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/Node.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/Node.java index 1bf3d16..d78c5f3 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/Node.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/Node.java @@ -98,6 +98,10 @@ public interface Node extends NodeCharacterProvider, Serializable { */ char getIncomingEdgeFirstCharacter(); + int getIncomingEdgeLength(); + + char getIncomingEdgeCharacterAt(int index); + /** * Returns all characters of the "edge" encoded in this node, belonging to the connection from a parent node to this * node. @@ -115,7 +119,6 @@ public interface Node extends NodeCharacterProvider, Serializable { */ Object getValue(); - /** * Returns the child of this node whose edge starts with the given first character. *

diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeDefault.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeDefault.java index 0873938..431d998 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeDefault.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeDefault.java @@ -68,6 +68,16 @@ public CharSequence getIncomingEdge() { return new ByteArrayCharSequence(incomingEdgeCharArray, 0, incomingEdgeCharArray.length); } + @Override + public int getIncomingEdgeLength() { + return incomingEdgeCharArray.length; + } + + @Override + public char getIncomingEdgeCharacterAt(int index) { + return (char) (incomingEdgeCharArray[index] & 0xFF); + } + @Override public char getIncomingEdgeFirstCharacter() { return (char) (incomingEdgeCharArray[0] & 0xFF); diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafNullValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafNullValue.java index 8478b34..af1fb1a 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafNullValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafNullValue.java @@ -51,6 +51,16 @@ public char getIncomingEdgeFirstCharacter() { return (char) (incomingEdgeCharArray[0] & 0xFF); } + @Override + public int getIncomingEdgeLength() { + return incomingEdgeCharArray.length; + } + + @Override + public char getIncomingEdgeCharacterAt(int index) { + return (char) (incomingEdgeCharArray[index] & 0xFF); + } + @Override public Object getValue() { return null; diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafVoidValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafVoidValue.java index 513522e..359397f 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafVoidValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafVoidValue.java @@ -52,6 +52,16 @@ public char getIncomingEdgeFirstCharacter() { return (char) (incomingEdgeCharArray[0] & 0xFF); } + @Override + public int getIncomingEdgeLength() { + return incomingEdgeCharArray.length; + } + + @Override + public char getIncomingEdgeCharacterAt(int index) { + return (char) (incomingEdgeCharArray[index] & 0xFF); + } + @Override public Object getValue() { return VoidValue.SINGLETON; diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafWithValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafWithValue.java index 61be021..42d6b2a 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafWithValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafWithValue.java @@ -56,6 +56,16 @@ public char getIncomingEdgeFirstCharacter() { return (char) (incomingEdgeCharArray[0] & 0xFF); } + @Override + public int getIncomingEdgeLength() { + return incomingEdgeCharArray.length; + } + + @Override + public char getIncomingEdgeCharacterAt(int index) { + return (char) (incomingEdgeCharArray[index] & 0xFF); + } + @Override public Object getValue() { return value; diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafNullValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafNullValue.java index c3e9b81..89425da 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafNullValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafNullValue.java @@ -68,6 +68,16 @@ public char getIncomingEdgeFirstCharacter() { return (char) (incomingEdgeCharArray[0] & 0xFF); } + @Override + public int getIncomingEdgeLength() { + return incomingEdgeCharArray.length; + } + + @Override + public char getIncomingEdgeCharacterAt(int index) { + return (char) (incomingEdgeCharArray[index] & 0xFF); + } + @Override public Object getValue() { return null; diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafVoidValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafVoidValue.java index 41a6f94..9c8bc1f 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafVoidValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafVoidValue.java @@ -69,6 +69,16 @@ public char getIncomingEdgeFirstCharacter() { return (char) (incomingEdgeCharArray[0] & 0xFF); } + @Override + public int getIncomingEdgeLength() { + return incomingEdgeCharArray.length; + } + + @Override + public char getIncomingEdgeCharacterAt(int index) { + return (char) (incomingEdgeCharArray[index] & 0xFF); + } + @Override public Object getValue() { return VoidValue.SINGLETON; diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeDefault.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeDefault.java index 7d03a91..7237433 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeDefault.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeDefault.java @@ -89,6 +89,16 @@ public char getIncomingEdgeFirstCharacter() { return incomingEdgeCharArray[0]; } + @Override + public int getIncomingEdgeLength() { + return incomingEdgeCharArray.length; + } + + @Override + public char getIncomingEdgeCharacterAt(int index) { + return incomingEdgeCharArray[index]; + } + @Override public Object getValue() { return value; diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafNullValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafNullValue.java index db355d6..8e91855 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafNullValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafNullValue.java @@ -49,6 +49,16 @@ public char getIncomingEdgeFirstCharacter() { return incomingEdgeCharArray[0]; } + @Override + public int getIncomingEdgeLength() { + return incomingEdgeCharArray.length; + } + + @Override + public char getIncomingEdgeCharacterAt(int index) { + return incomingEdgeCharArray[index]; + } + @Override public Object getValue() { return null; diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafVoidValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafVoidValue.java index 549eba1..7f909df 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafVoidValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafVoidValue.java @@ -50,6 +50,16 @@ public char getIncomingEdgeFirstCharacter() { return incomingEdgeCharArray[0]; } + @Override + public int getIncomingEdgeLength() { + return incomingEdgeCharArray.length; + } + + @Override + public char getIncomingEdgeCharacterAt(int index) { + return incomingEdgeCharArray[index]; + } + @Override public Object getValue() { return VoidValue.SINGLETON; diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafWithValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafWithValue.java index b500983..069cdf5 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafWithValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafWithValue.java @@ -54,6 +54,16 @@ public char getIncomingEdgeFirstCharacter() { return incomingEdgeCharArray[0]; } + @Override + public int getIncomingEdgeLength() { + return incomingEdgeCharArray.length; + } + + @Override + public char getIncomingEdgeCharacterAt(int index) { + return incomingEdgeCharArray[index]; + } + @Override public Object getValue() { return value; diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafNullValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafNullValue.java index bb540cd..a9b9979 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafNullValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafNullValue.java @@ -66,6 +66,16 @@ public char getIncomingEdgeFirstCharacter() { return incomingEdgeCharArray[0]; } + @Override + public int getIncomingEdgeLength() { + return incomingEdgeCharArray.length; + } + + @Override + public char getIncomingEdgeCharacterAt(int index) { + return incomingEdgeCharArray[index]; + } + @Override public Object getValue() { return null; diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafVoidValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafVoidValue.java index 9908c47..48208dd 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafVoidValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafVoidValue.java @@ -67,6 +67,16 @@ public char getIncomingEdgeFirstCharacter() { return incomingEdgeCharArray[0]; } + @Override + public int getIncomingEdgeLength() { + return incomingEdgeCharArray.length; + } + + @Override + public char getIncomingEdgeCharacterAt(int index) { + return incomingEdgeCharArray[index]; + } + @Override public Object getValue() { return VoidValue.SINGLETON; diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeDefault.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeDefault.java index 9a784f1..7b1cc43 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeDefault.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeDefault.java @@ -89,6 +89,16 @@ public char getIncomingEdgeFirstCharacter() { return incomingEdgeCharSequence.charAt(0); } + @Override + public int getIncomingEdgeLength() { + return incomingEdgeCharSequence.length(); + } + + @Override + public char getIncomingEdgeCharacterAt(int index) { + return incomingEdgeCharSequence.charAt(index); + } + @Override public Object getValue() { return value; diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafNullValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafNullValue.java index 98472e6..281220c 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafNullValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafNullValue.java @@ -48,6 +48,16 @@ public char getIncomingEdgeFirstCharacter() { return incomingEdgeCharSequence.charAt(0); } + @Override + public int getIncomingEdgeLength() { + return incomingEdgeCharSequence.length(); + } + + @Override + public char getIncomingEdgeCharacterAt(int index) { + return incomingEdgeCharSequence.charAt(index); + } + @Override public Object getValue() { return null; diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafVoidValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafVoidValue.java index 3e207b2..d57dcf4 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafVoidValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafVoidValue.java @@ -54,6 +54,16 @@ public char getIncomingEdgeFirstCharacter() { return incomingEdgeCharSequence.charAt(0); } + @Override + public int getIncomingEdgeLength() { + return incomingEdgeCharSequence.length(); + } + + @Override + public char getIncomingEdgeCharacterAt(int index) { + return incomingEdgeCharSequence.charAt(index); + } + @Override public Object getValue() { return VoidValue.SINGLETON; diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafWithValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafWithValue.java index b769443..2ec6f07 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafWithValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafWithValue.java @@ -54,6 +54,16 @@ public char getIncomingEdgeFirstCharacter() { return incomingEdgeCharSequence.charAt(0); } + @Override + public int getIncomingEdgeLength() { + return incomingEdgeCharSequence.length(); + } + + @Override + public char getIncomingEdgeCharacterAt(int index) { + return incomingEdgeCharSequence.charAt(index); + } + @Override public Object getValue() { return value; diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafNullValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafNullValue.java index 16518d3..b465931 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafNullValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafNullValue.java @@ -66,6 +66,16 @@ public char getIncomingEdgeFirstCharacter() { return incomingEdgeCharSequence.charAt(0); } + @Override + public int getIncomingEdgeLength() { + return incomingEdgeCharSequence.length(); + } + + @Override + public char getIncomingEdgeCharacterAt(int index) { + return incomingEdgeCharSequence.charAt(index); + } + @Override public Object getValue() { return null; diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafVoidValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafVoidValue.java index 3e71416..e5e4490 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafVoidValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafVoidValue.java @@ -67,6 +67,16 @@ public char getIncomingEdgeFirstCharacter() { return incomingEdgeCharSequence.charAt(0); } + @Override + public int getIncomingEdgeLength() { + return incomingEdgeCharSequence.length(); + } + + @Override + public char getIncomingEdgeCharacterAt(int index) { + return incomingEdgeCharSequence.charAt(index); + } + @Override public Object getValue() { return VoidValue.SINGLETON; diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radixinverted/ConcurrentInvertedRadixTree.java b/code/src/main/java/com/googlecode/concurrenttrees/radixinverted/ConcurrentInvertedRadixTree.java index a1464d5..bbaad83 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radixinverted/ConcurrentInvertedRadixTree.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radixinverted/ConcurrentInvertedRadixTree.java @@ -84,14 +84,13 @@ protected KeyValuePair computeNext() { } currentNode = nextNode; - CharSequence currentNodeEdgeCharacters = currentNode.getIncomingEdge(); - final int numCharsInEdge = currentNodeEdgeCharacters.length(); + final int numCharsInEdge = currentNode.getIncomingEdgeLength(); if (numCharsInEdge + charsMatched > documentLength) { // This node can't be a match because it is too long... return endOfData(); } for (int i = 0; i < numCharsInEdge; i++) { - if (currentNodeEdgeCharacters.charAt(i) != input.charAt(charsMatched + i)) { + if (currentNode.getIncomingEdgeCharacterAt(i) != input.charAt(charsMatched + i)) { // Found a difference between a character in the input // and a character in the edge represented by current node, // current node is a dead end... @@ -142,14 +141,13 @@ protected KeyValuePair scanForLongestKeyAtStartOfInput(final CharSequence inp } currentNode = nextNode; - CharSequence currentNodeEdgeCharacters = currentNode.getIncomingEdge(); - final int numCharsInEdge = currentNodeEdgeCharacters.length(); + final int numCharsInEdge = currentNode.getIncomingEdgeLength(); if (numCharsInEdge + charsMatched > documentLength) { // This node can't be a match because it is too long... break; } for (int i = 0; i < numCharsInEdge; i++) { - if (currentNodeEdgeCharacters.charAt(i) != input.charAt(charsMatched + i)) { + if (currentNode.getIncomingEdgeCharacterAt(i) != input.charAt(charsMatched + i)) { // Found a difference between a character in the input // and a character in the edge represented by current node, // current node is a dead end... From 3b0a2bede679c6fd9d95b938043cea8cf945f4bd Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Sun, 25 Jul 2021 22:41:22 +0200 Subject: [PATCH 08/15] Create singleton representation of node character comparator. Allocations can trigger significant garbage collection if not erased by escape analysis. --- .../radix/node/concrete/bytearray/ByteArrayNodeDefault.java | 2 +- .../concrete/bytearray/ByteArrayNodeNonLeafNullValue.java | 2 +- .../concrete/bytearray/ByteArrayNodeNonLeafVoidValue.java | 2 +- .../radix/node/concrete/chararray/CharArrayNodeDefault.java | 2 +- .../concrete/chararray/CharArrayNodeNonLeafNullValue.java | 2 +- .../concrete/chararray/CharArrayNodeNonLeafVoidValue.java | 2 +- .../node/concrete/charsequence/CharSequenceNodeDefault.java | 2 +- .../charsequence/CharSequenceNodeNonLeafNullValue.java | 2 +- .../charsequence/CharSequenceNodeNonLeafVoidValue.java | 2 +- .../radix/node/util/NodeCharacterComparator.java | 5 +++++ 10 files changed, 14 insertions(+), 9 deletions(-) diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeDefault.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeDefault.java index 431d998..6ab085e 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeDefault.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeDefault.java @@ -56,7 +56,7 @@ public class ByteArrayNodeDefault implements Node { public ByteArrayNodeDefault(CharSequence edgeCharSequence, Object value, List outgoingEdges) { Node[] childNodeArray = outgoingEdges.toArray(new Node[0]); // Sort the child nodes... - Arrays.sort(childNodeArray, new NodeCharacterComparator()); + Arrays.sort(childNodeArray, NodeCharacterComparator.SINGLETON); this.outgoingEdges = new AtomicReferenceArray(childNodeArray); this.incomingEdgeCharArray = ByteArrayCharSequence.toSingleByteUtf8Encoding(edgeCharSequence); this.value = value; diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafNullValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafNullValue.java index 89425da..5195b74 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafNullValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafNullValue.java @@ -52,7 +52,7 @@ public class ByteArrayNodeNonLeafNullValue implements Node { public ByteArrayNodeNonLeafNullValue(CharSequence edgeCharSequence, List outgoingEdges) { Node[] childNodeArray = outgoingEdges.toArray(new Node[0]); // Sort the child nodes... - Arrays.sort(childNodeArray, new NodeCharacterComparator()); + Arrays.sort(childNodeArray, NodeCharacterComparator.SINGLETON); this.outgoingEdges = new AtomicReferenceArray(childNodeArray); this.incomingEdgeCharArray = ByteArrayCharSequence.toSingleByteUtf8Encoding(edgeCharSequence); this.outgoingEdgesAsList = new AtomicReferenceArrayListAdapter(this.outgoingEdges); diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafVoidValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafVoidValue.java index 9c8bc1f..eefa41e 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafVoidValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafVoidValue.java @@ -53,7 +53,7 @@ public class ByteArrayNodeNonLeafVoidValue implements Node { public ByteArrayNodeNonLeafVoidValue(CharSequence edgeCharSequence, List outgoingEdges) { Node[] childNodeArray = outgoingEdges.toArray(new Node[0]); // Sort the child nodes... - Arrays.sort(childNodeArray, new NodeCharacterComparator()); + Arrays.sort(childNodeArray, NodeCharacterComparator.SINGLETON); this.outgoingEdges = new AtomicReferenceArray(childNodeArray); this.incomingEdgeCharArray = ByteArrayCharSequence.toSingleByteUtf8Encoding(edgeCharSequence); this.outgoingEdgesAsList = new AtomicReferenceArrayListAdapter(this.outgoingEdges); diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeDefault.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeDefault.java index 7237433..c112949 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeDefault.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeDefault.java @@ -72,7 +72,7 @@ public class CharArrayNodeDefault implements Node { public CharArrayNodeDefault(CharSequence edgeCharSequence, Object value, List outgoingEdges) { Node[] childNodeArray = outgoingEdges.toArray(new Node[0]); // Sort the child nodes... - Arrays.sort(childNodeArray, new NodeCharacterComparator()); + Arrays.sort(childNodeArray, NodeCharacterComparator.SINGLETON); this.outgoingEdges = new AtomicReferenceArray(childNodeArray); this.incomingEdgeCharArray = CharSequences.toCharArray(edgeCharSequence); this.value = value; diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafNullValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafNullValue.java index a9b9979..3fc0a9e 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafNullValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafNullValue.java @@ -50,7 +50,7 @@ public class CharArrayNodeNonLeafNullValue implements Node { public CharArrayNodeNonLeafNullValue(CharSequence edgeCharSequence, List outgoingEdges) { Node[] childNodeArray = outgoingEdges.toArray(new Node[0]); // Sort the child nodes... - Arrays.sort(childNodeArray, new NodeCharacterComparator()); + Arrays.sort(childNodeArray, NodeCharacterComparator.SINGLETON); this.outgoingEdges = new AtomicReferenceArray(childNodeArray); this.incomingEdgeCharArray = CharSequences.toCharArray(edgeCharSequence); this.outgoingEdgesAsList = new AtomicReferenceArrayListAdapter(this.outgoingEdges); diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafVoidValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafVoidValue.java index 48208dd..a681fdd 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafVoidValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafVoidValue.java @@ -51,7 +51,7 @@ public class CharArrayNodeNonLeafVoidValue implements Node { public CharArrayNodeNonLeafVoidValue(CharSequence edgeCharSequence, List outgoingEdges) { Node[] childNodeArray = outgoingEdges.toArray(new Node[0]); // Sort the child nodes... - Arrays.sort(childNodeArray, new NodeCharacterComparator()); + Arrays.sort(childNodeArray, NodeCharacterComparator.SINGLETON); this.outgoingEdges = new AtomicReferenceArray(childNodeArray); this.incomingEdgeCharArray = CharSequences.toCharArray(edgeCharSequence); this.outgoingEdgesAsList = new AtomicReferenceArrayListAdapter(this.outgoingEdges); diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeDefault.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeDefault.java index 7b1cc43..5edf4fc 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeDefault.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeDefault.java @@ -72,7 +72,7 @@ public class CharSequenceNodeDefault implements Node { public CharSequenceNodeDefault(CharSequence edgeCharSequence, Object value, List outgoingEdges) { Node[] childNodeArray = outgoingEdges.toArray(new Node[0]); // Sort the child nodes... - Arrays.sort(childNodeArray, new NodeCharacterComparator()); + Arrays.sort(childNodeArray, NodeCharacterComparator.SINGLETON); this.outgoingEdges = new AtomicReferenceArray(childNodeArray); this.incomingEdgeCharSequence = edgeCharSequence; this.value = value; diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafNullValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafNullValue.java index b465931..12bde24 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafNullValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafNullValue.java @@ -50,7 +50,7 @@ public class CharSequenceNodeNonLeafNullValue implements Node { public CharSequenceNodeNonLeafNullValue(CharSequence edgeCharSequence, List outgoingEdges) { Node[] childNodeArray = outgoingEdges.toArray(new Node[0]); // Sort the child nodes... - Arrays.sort(childNodeArray, new NodeCharacterComparator()); + Arrays.sort(childNodeArray, NodeCharacterComparator.SINGLETON); this.outgoingEdges = new AtomicReferenceArray(childNodeArray); this.incomingEdgeCharSequence = edgeCharSequence; this.outgoingEdgesAsList = new AtomicReferenceArrayListAdapter(this.outgoingEdges); diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafVoidValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafVoidValue.java index e5e4490..de78a04 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafVoidValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafVoidValue.java @@ -51,7 +51,7 @@ public class CharSequenceNodeNonLeafVoidValue implements Node { public CharSequenceNodeNonLeafVoidValue(CharSequence edgeCharSequence, List outgoingEdges) { Node[] childNodeArray = outgoingEdges.toArray(new Node[0]); // Sort the child nodes... - Arrays.sort(childNodeArray, new NodeCharacterComparator()); + Arrays.sort(childNodeArray, NodeCharacterComparator.SINGLETON); this.outgoingEdges = new AtomicReferenceArray(childNodeArray); this.incomingEdgeCharSequence = edgeCharSequence; this.outgoingEdgesAsList = new AtomicReferenceArrayListAdapter(this.outgoingEdges); diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/NodeCharacterComparator.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/NodeCharacterComparator.java index 4d98ead..eaf6429 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/NodeCharacterComparator.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/NodeCharacterComparator.java @@ -25,8 +25,13 @@ */ public class NodeCharacterComparator implements Comparator { + NodeCharacterComparator() { + } + @Override public int compare(NodeCharacterProvider o1, NodeCharacterProvider o2) { return o1.getIncomingEdgeFirstCharacter() - o2.getIncomingEdgeFirstCharacter(); } + + public static final Comparator SINGLETON = new NodeCharacterComparator(); } From fe45c762c80e722e979fe8e7f2b850f9417be187 Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Sun, 25 Jul 2021 22:56:35 +0200 Subject: [PATCH 09/15] Avoid stack trace computation in smart node factory to reduce overhead of using fallback. --- .../concrete/DefaultByteArrayNodeFactory.java | 23 ++++++++++++++----- .../concrete/SmartArrayBasedNodeFactory.java | 4 ++-- .../bytearray/ByteArrayCharSequence.java | 20 +++++++++++++++- .../bytearray/ByteArrayNodeDefault.java | 6 ++++- .../bytearray/ByteArrayNodeLeafNullValue.java | 6 ++++- .../bytearray/ByteArrayNodeLeafVoidValue.java | 6 ++++- .../bytearray/ByteArrayNodeLeafWithValue.java | 6 ++++- .../ByteArrayNodeNonLeafNullValue.java | 6 ++++- .../ByteArrayNodeNonLeafVoidValue.java | 6 ++++- 9 files changed, 68 insertions(+), 15 deletions(-) diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultByteArrayNodeFactory.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultByteArrayNodeFactory.java index 80342d5..a7a6ea6 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultByteArrayNodeFactory.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultByteArrayNodeFactory.java @@ -39,34 +39,45 @@ public class DefaultByteArrayNodeFactory implements NodeFactory { private static final long serialVersionUID = 1L; + private final boolean fast; + + public DefaultByteArrayNodeFactory() { + fast = false; + } + + DefaultByteArrayNodeFactory(boolean fast) { + this.fast = fast; + } + @Override public Node createNode(CharSequence edgeCharacters, Object value, List childNodes, boolean isRoot) { assert edgeCharacters != null : "The edgeCharacters argument was null"; assert isRoot || edgeCharacters.length() > 0 : "Invalid edge characters for non-root node: " + CharSequences.toString(edgeCharacters); assert childNodes != null : "The edgeCharacters argument was null"; assert NodeUtil.hasNoDuplicateEdges(childNodes) : "Duplicate edge detected in list of nodes supplied: " + childNodes; + byte[] incomingEdgeCharArray = ByteArrayCharSequence.toSingleByteUtf8Encoding(edgeCharacters, true); if (childNodes.isEmpty()) { // Leaf node... if (value instanceof VoidValue) { - return new ByteArrayNodeLeafVoidValue(edgeCharacters); + return new ByteArrayNodeLeafVoidValue(incomingEdgeCharArray); } else if (value != null) { - return new ByteArrayNodeLeafWithValue(edgeCharacters, value); + return new ByteArrayNodeLeafWithValue(incomingEdgeCharArray, value); } else { - return new ByteArrayNodeLeafNullValue(edgeCharacters); + return new ByteArrayNodeLeafNullValue(incomingEdgeCharArray); } } else { // Non-leaf node... if (value instanceof VoidValue) { - return new ByteArrayNodeNonLeafVoidValue(edgeCharacters, childNodes); + return new ByteArrayNodeNonLeafVoidValue(incomingEdgeCharArray, childNodes); } else if (value == null) { - return new ByteArrayNodeNonLeafNullValue(edgeCharacters, childNodes); + return new ByteArrayNodeNonLeafNullValue(incomingEdgeCharArray, childNodes); } else { - return new ByteArrayNodeDefault(edgeCharacters, value, childNodes); + return new ByteArrayNodeDefault(incomingEdgeCharArray, value, childNodes); } } } diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/SmartArrayBasedNodeFactory.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/SmartArrayBasedNodeFactory.java index ebad1f6..c3eb3fd 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/SmartArrayBasedNodeFactory.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/SmartArrayBasedNodeFactory.java @@ -33,14 +33,14 @@ public class SmartArrayBasedNodeFactory implements NodeFactory { private static final long serialVersionUID = 1L; final NodeFactory charArrayNodeFactory = new DefaultCharArrayNodeFactory(); - final NodeFactory byteArrayNodeFactory = new DefaultByteArrayNodeFactory(); + final NodeFactory byteArrayNodeFactory = new DefaultByteArrayNodeFactory(true); @Override public Node createNode(CharSequence edgeCharacters, Object value, List childNodes, boolean isRoot) { try { return byteArrayNodeFactory.createNode(edgeCharacters, value, childNodes, isRoot); } - catch (ByteArrayCharSequence.IncompatibleCharacterException e) { + catch (ByteArrayCharSequence.IncompatibleCharacterException.FastThrow ignored) { return charArrayNodeFactory.createNode(edgeCharacters, value, childNodes, isRoot); } } diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayCharSequence.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayCharSequence.java index 7022cbd..f404752 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayCharSequence.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayCharSequence.java @@ -71,12 +71,20 @@ public String toString() { * @throws IllegalStateException If the characters cannot be encoded as described */ public static byte[] toSingleByteUtf8Encoding(CharSequence charSequence) { + return toSingleByteUtf8Encoding(charSequence, false); + } + + public static byte[] toSingleByteUtf8Encoding(CharSequence charSequence, boolean fast) { final int length = charSequence.length(); byte[] bytes = new byte[length]; for (int i = 0; i < length; i++) { char inputChar = charSequence.charAt(i); if (inputChar > 255) { - throw new IncompatibleCharacterException("Input contains a character which cannot be represented as a single byte in UTF-8: " + inputChar); + if (fast) { + throw new IncompatibleCharacterException.FastThrow(); + } else { + throw new IncompatibleCharacterException("Input contains a character which cannot be represented as a single byte in UTF-8: " + inputChar); + } } bytes[i] = (byte)inputChar; } @@ -90,5 +98,15 @@ public static class IncompatibleCharacterException extends IllegalStateException public IncompatibleCharacterException(String s) { super(s); } + + public static class FastThrow extends IllegalStateException { + + private static final long serialVersionUID = 1L; + + @Override + public Throwable fillInStackTrace() { + return this; + } + } } } diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeDefault.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeDefault.java index 6ab085e..c59df6c 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeDefault.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeDefault.java @@ -54,11 +54,15 @@ public class ByteArrayNodeDefault implements Node { private final Object value; public ByteArrayNodeDefault(CharSequence edgeCharSequence, Object value, List outgoingEdges) { + this(ByteArrayCharSequence.toSingleByteUtf8Encoding(edgeCharSequence), value, outgoingEdges); + } + + public ByteArrayNodeDefault(byte[] incomingEdgeCharArray, Object value, List outgoingEdges) { Node[] childNodeArray = outgoingEdges.toArray(new Node[0]); // Sort the child nodes... Arrays.sort(childNodeArray, NodeCharacterComparator.SINGLETON); this.outgoingEdges = new AtomicReferenceArray(childNodeArray); - this.incomingEdgeCharArray = ByteArrayCharSequence.toSingleByteUtf8Encoding(edgeCharSequence); + this.incomingEdgeCharArray = incomingEdgeCharArray; this.value = value; this.outgoingEdgesAsList = new AtomicReferenceArrayListAdapter(this.outgoingEdges); } diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafNullValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafNullValue.java index af1fb1a..b3c6332 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafNullValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafNullValue.java @@ -38,7 +38,11 @@ public class ByteArrayNodeLeafNullValue implements Node { private final byte[] incomingEdgeCharArray; public ByteArrayNodeLeafNullValue(CharSequence edgeCharSequence) { - this.incomingEdgeCharArray = ByteArrayCharSequence.toSingleByteUtf8Encoding(edgeCharSequence); + this(ByteArrayCharSequence.toSingleByteUtf8Encoding(edgeCharSequence)); + } + + public ByteArrayNodeLeafNullValue(byte[] incomingEdgeCharArray) { + this.incomingEdgeCharArray = incomingEdgeCharArray; } @Override diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafVoidValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafVoidValue.java index 359397f..b5329bb 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafVoidValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafVoidValue.java @@ -39,7 +39,11 @@ public class ByteArrayNodeLeafVoidValue implements Node { private final byte[] incomingEdgeCharArray; public ByteArrayNodeLeafVoidValue(CharSequence edgeCharSequence) { - this.incomingEdgeCharArray = ByteArrayCharSequence.toSingleByteUtf8Encoding(edgeCharSequence); + this(ByteArrayCharSequence.toSingleByteUtf8Encoding(edgeCharSequence)); + } + + public ByteArrayNodeLeafVoidValue(byte[] incomingEdgeCharArray) { + this.incomingEdgeCharArray = incomingEdgeCharArray; } @Override diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafWithValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafWithValue.java index 42d6b2a..cebe2b9 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafWithValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafWithValue.java @@ -42,7 +42,11 @@ public class ByteArrayNodeLeafWithValue implements Node { private final Object value; public ByteArrayNodeLeafWithValue(CharSequence edgeCharSequence, Object value) { - this.incomingEdgeCharArray = ByteArrayCharSequence.toSingleByteUtf8Encoding(edgeCharSequence); + this(ByteArrayCharSequence.toSingleByteUtf8Encoding(edgeCharSequence), value); + } + + public ByteArrayNodeLeafWithValue(byte[] incomingEdgeCharArray, Object value) { + this.incomingEdgeCharArray = incomingEdgeCharArray; this.value = value; } diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafNullValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafNullValue.java index 5195b74..02ab396 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafNullValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafNullValue.java @@ -50,11 +50,15 @@ public class ByteArrayNodeNonLeafNullValue implements Node { private final List outgoingEdgesAsList; public ByteArrayNodeNonLeafNullValue(CharSequence edgeCharSequence, List outgoingEdges) { + this(ByteArrayCharSequence.toSingleByteUtf8Encoding(edgeCharSequence), outgoingEdges); + } + + public ByteArrayNodeNonLeafNullValue(byte[] incomingEdgeCharArray, List outgoingEdges) { Node[] childNodeArray = outgoingEdges.toArray(new Node[0]); // Sort the child nodes... Arrays.sort(childNodeArray, NodeCharacterComparator.SINGLETON); this.outgoingEdges = new AtomicReferenceArray(childNodeArray); - this.incomingEdgeCharArray = ByteArrayCharSequence.toSingleByteUtf8Encoding(edgeCharSequence); + this.incomingEdgeCharArray = incomingEdgeCharArray; this.outgoingEdgesAsList = new AtomicReferenceArrayListAdapter(this.outgoingEdges); } diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafVoidValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafVoidValue.java index eefa41e..aaf0b06 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafVoidValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafVoidValue.java @@ -51,11 +51,15 @@ public class ByteArrayNodeNonLeafVoidValue implements Node { private final List outgoingEdgesAsList; public ByteArrayNodeNonLeafVoidValue(CharSequence edgeCharSequence, List outgoingEdges) { + this(ByteArrayCharSequence.toSingleByteUtf8Encoding(edgeCharSequence), outgoingEdges); + } + + public ByteArrayNodeNonLeafVoidValue(byte[] incomingEdgeCharArray, List outgoingEdges) { Node[] childNodeArray = outgoingEdges.toArray(new Node[0]); // Sort the child nodes... Arrays.sort(childNodeArray, NodeCharacterComparator.SINGLETON); this.outgoingEdges = new AtomicReferenceArray(childNodeArray); - this.incomingEdgeCharArray = ByteArrayCharSequence.toSingleByteUtf8Encoding(edgeCharSequence); + this.incomingEdgeCharArray = incomingEdgeCharArray; this.outgoingEdgesAsList = new AtomicReferenceArrayListAdapter(this.outgoingEdges); } From 238270e42fb3415a38770194f4f563eb95ee4a25 Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Sun, 25 Jul 2021 23:01:42 +0200 Subject: [PATCH 10/15] Add missing javadoc to interface. --- .../concurrenttrees/radix/node/Node.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/Node.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/Node.java index d78c5f3..80b4ee1 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/Node.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/Node.java @@ -98,8 +98,23 @@ public interface Node extends NodeCharacterProvider, Serializable { */ char getIncomingEdgeFirstCharacter(); + /** + * Returns the length of the "edge" encoded in this node, belonging to the connection from a parent node to this + * node. + *

+ * + * @return The length of the "edge" encoded in this node + */ int getIncomingEdgeLength(); + /** + * Returns the character at a given index of the "edge" encoded in this node, belonging to the connection from a + * parent node to this node. + *

+ * + * @param index The index of the character to resolve of the "edge" encoded in this node + * @return The character at the index of the "edge" encoded in this node + */ char getIncomingEdgeCharacterAt(int index); /** From 9c39328b92b5864d35efa9f8c4983244c78b577a Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Mon, 26 Jul 2021 23:29:53 +0200 Subject: [PATCH 11/15] Introduce NodeList abstraction to avoid list allocation when reading decendent nodes. Unfortunately, the AbstractReferenceArray API and List API are incompatible due to the conflicting signatures of set(int,Object) where one returns a boolean and another declares void. To avoid this conflict, an API is introduced that implements the minimal required functionality but allows a single object to represent any interaction with child nodes. This way, non-leaf nodes do no longer require an additional field to carry the list wrapper, reducing the memory consumption of a tree with many non-leaf nodes. --- .../concurrenttrees/common/PrettyPrinter.java | 3 +- .../radix/ConcurrentRadixTree.java | 26 +++--- .../concurrenttrees/radix/node/Node.java | 2 +- .../radix/node/NodeFactory.java | 2 +- .../concurrenttrees/radix/node/NodeList.java | 20 +++++ .../radix/node/SimpleNodeList.java | 69 ++++++++++++++++ .../concrete/DefaultByteArrayNodeFactory.java | 5 +- .../concrete/DefaultCharArrayNodeFactory.java | 7 +- .../DefaultCharSequenceNodeFactory.java | 5 +- .../concrete/SmartArrayBasedNodeFactory.java | 5 +- .../bytearray/ByteArrayNodeDefault.java | 23 +++--- .../bytearray/ByteArrayNodeLeafNullValue.java | 9 +-- .../bytearray/ByteArrayNodeLeafVoidValue.java | 9 +-- .../bytearray/ByteArrayNodeLeafWithValue.java | 9 +-- .../ByteArrayNodeNonLeafNullValue.java | 23 +++--- .../ByteArrayNodeNonLeafVoidValue.java | 23 +++--- .../chararray/CharArrayNodeDefault.java | 22 +++-- .../chararray/CharArrayNodeLeafNullValue.java | 9 +-- .../chararray/CharArrayNodeLeafVoidValue.java | 9 +-- .../chararray/CharArrayNodeLeafWithValue.java | 9 +-- .../CharArrayNodeNonLeafNullValue.java | 20 ++--- .../CharArrayNodeNonLeafVoidValue.java | 20 ++--- .../charsequence/CharSequenceNodeDefault.java | 20 ++--- .../CharSequenceNodeLeafNullValue.java | 9 +-- .../CharSequenceNodeLeafVoidValue.java | 14 +--- .../CharSequenceNodeLeafWithValue.java | 9 +-- .../CharSequenceNodeNonLeafNullValue.java | 20 ++--- .../CharSequenceNodeNonLeafVoidValue.java | 20 ++--- .../node/util/AtomicNodeReferenceArray.java | 81 +++++++++++++++++++ .../util/AtomicReferenceArrayListAdapter.java | 49 ----------- .../radix/node/util/NodeUtil.java | 7 +- .../common/PrettyPrinterTest.java | 16 ++-- .../radix/ConcurrentRadixTreeTest.java | 33 ++++---- .../DefaultByteArrayNodeFactoryTest.java | 5 +- .../DefaultCharArrayNodeFactoryTest.java | 5 +- .../DefaultCharSequenceNodeFactoryTest.java | 5 +- .../SmartArrayBasedNodeFactoryTest.java | 5 +- .../bytearray/ByteArrayNodeDefaultTest.java | 5 +- .../ByteArrayNodeLeafNullValueTest.java | 3 +- .../ByteArrayNodeLeafVoidValueTest.java | 3 +- .../ByteArrayNodeLeafWithValueTest.java | 3 +- .../ByteArrayNodeNonLeafNullValueTest.java | 11 +-- .../ByteArrayNodeNonLeafVoidValueTest.java | 15 ++-- .../chararray/CharArrayNodeDefaultTest.java | 5 +- .../CharArrayNodeLeafNullValueTest.java | 3 +- .../CharArrayNodeLeafVoidValueTest.java | 3 +- .../CharArrayNodeLeafWithValueTest.java | 3 +- .../CharArrayNodeNonLeafNullValueTest.java | 11 +-- .../CharArrayNodeNonLeafVoidValueTest.java | 15 ++-- .../CharSequenceNodeLeafNullValueTest.java | 3 +- .../CharSequenceNodeLeafVoidValueTest.java | 3 +- .../CharSequenceNodeLeafWithValueTest.java | 3 +- .../CharSequenceNodeNonLeafNullValueTest.java | 11 +-- .../CharSequenceNodeNonLeafVoidValueTest.java | 15 ++-- .../DefaultCharSequenceNodeTest.java | 7 +- .../radix/node/util/NodeUtilTest.java | 23 +++--- 56 files changed, 433 insertions(+), 339 deletions(-) create mode 100644 code/src/main/java/com/googlecode/concurrenttrees/radix/node/NodeList.java create mode 100644 code/src/main/java/com/googlecode/concurrenttrees/radix/node/SimpleNodeList.java create mode 100644 code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/AtomicNodeReferenceArray.java delete mode 100644 code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/AtomicReferenceArrayListAdapter.java diff --git a/code/src/main/java/com/googlecode/concurrenttrees/common/PrettyPrinter.java b/code/src/main/java/com/googlecode/concurrenttrees/common/PrettyPrinter.java index 7c6ad06..46dbd07 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/common/PrettyPrinter.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/common/PrettyPrinter.java @@ -16,6 +16,7 @@ package com.googlecode.concurrenttrees.common; import com.googlecode.concurrenttrees.radix.node.Node; +import com.googlecode.concurrenttrees.radix.node.NodeList; import com.googlecode.concurrenttrees.radix.node.util.PrettyPrintable; import java.io.IOException; @@ -92,7 +93,7 @@ static void prettyPrint(Node node, Appendable sb, String prefix, boolean isTail, label.append(" (").append(node.getValue()).append(")"); } sb.append(prefix).append(isTail ? isRoot ? "" : "└── ○ " : "├── ○ ").append(label).append("\n"); - List children = node.getOutgoingEdges(); + NodeList children = node.getOutgoingEdges(); for (int i = 0; i < children.size() - 1; i++) { prettyPrint(children.get(i), sb, prefix + (isTail ? isRoot ? "" : " " : "│ "), false, false); } diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/ConcurrentRadixTree.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/ConcurrentRadixTree.java index 74fbdb9..2cd0229 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/ConcurrentRadixTree.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/ConcurrentRadixTree.java @@ -20,6 +20,8 @@ import com.googlecode.concurrenttrees.common.LazyIterator; import com.googlecode.concurrenttrees.radix.node.Node; import com.googlecode.concurrenttrees.radix.node.NodeFactory; +import com.googlecode.concurrenttrees.radix.node.NodeList; +import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; import com.googlecode.concurrenttrees.radix.node.util.PrettyPrintable; import java.io.Serializable; @@ -59,7 +61,7 @@ public class ConcurrentRadixTree implements RadixTree, PrettyPrintable, Se public ConcurrentRadixTree(NodeFactory nodeFactory) { this.nodeFactory = nodeFactory; @SuppressWarnings({"NullableProblems", "UnnecessaryLocalVariable"}) - Node rootNode = nodeFactory.createNode("", null, Collections.emptyList(), true); + Node rootNode = nodeFactory.createNode("", null, new SimpleNodeList(), true); this.root = rootNode; } @@ -209,7 +211,7 @@ public boolean remove(CharSequence key) { } // Proceed with deleting the node... - List childEdges = searchResult.nodeFound.getOutgoingEdges(); + NodeList childEdges = searchResult.nodeFound.getOutgoingEdges(); if (childEdges.size() > 1) { // This node has more than one child, so if we delete the value from this node, we still need // to leave a similar node in place to act as the split between the child edges. @@ -239,11 +241,11 @@ else if (childEdges.size() == 1) { // (a special case which we never merge), then we also need to merge the parent with its // remaining child. - List currentEdgesFromParent = searchResult.parentNode.getOutgoingEdges(); + NodeList currentEdgesFromParent = searchResult.parentNode.getOutgoingEdges(); // Create a list of the outgoing edges of the parent which will remain // if we remove this child... // Use a non-resizable list, as a sanity check to force ArrayIndexOutOfBounds... - List newEdgesOfParent = Arrays.asList(new Node[searchResult.parentNode.getOutgoingEdges().size() - 1]); + NodeList newEdgesOfParent = new SimpleNodeList(new Node[searchResult.parentNode.getOutgoingEdges().size() - 1]); for (int i = 0, added = 0, numParentEdges = currentEdgesFromParent.size(); i < numParentEdges; i++) { Node node = currentEdgesFromParent.get(i); if (node != searchResult.nodeFound) { @@ -423,7 +425,7 @@ public int size() { return count; } Node current = stack.removeFirst(); - stack.addAll(current.getOutgoingEdges()); + current.getOutgoingEdges().addTo(stack); if (current.getValue() != null) { count++; } @@ -486,7 +488,7 @@ Object putInternal(CharSequence key, Object value, boolean overwrite) { // Create new nodes... Node newChild = nodeFactory.createNode(suffixFromExistingEdge, searchResult.nodeFound.getValue(), searchResult.nodeFound.getOutgoingEdges(), false); - Node newParent = nodeFactory.createNode(commonPrefix, value, Arrays.asList(newChild), false); + Node newParent = nodeFactory.createNode(commonPrefix, value, new SimpleNodeList(newChild), false); // Add the new parent to the parent of the node being replaced (replacing the existing node)... searchResult.parentNode.updateOutgoingEdge(newParent); @@ -504,13 +506,13 @@ Object putInternal(CharSequence key, Object value, boolean overwrite) { // Create a new child node containing the trailing characters... CharSequence keySuffix = key.subSequence(searchResult.charsMatched, key.length()); - Node newChild = nodeFactory.createNode(keySuffix, value, Collections.emptyList(), false); + Node newChild = nodeFactory.createNode(keySuffix, value, new SimpleNodeList(), false); // Clone the current node adding the new child... List edges = new ArrayList(searchResult.nodeFound.getOutgoingEdges().size() + 1); - edges.addAll(searchResult.nodeFound.getOutgoingEdges()); + searchResult.nodeFound.getOutgoingEdges().addTo(edges); edges.add(newChild); - Node clonedNode = nodeFactory.createNode(searchResult.nodeFound.getIncomingEdge(), searchResult.nodeFound.getValue(), edges, searchResult.nodeFound == root); + Node clonedNode = nodeFactory.createNode(searchResult.nodeFound.getIncomingEdge(), searchResult.nodeFound.getValue(), new SimpleNodeList(edges), searchResult.nodeFound == root); // Re-add the cloned node to its parent node... if (searchResult.nodeFound == root) { @@ -542,10 +544,10 @@ Object putInternal(CharSequence key, Object value, boolean overwrite) { CharSequence suffixFromKey = key.subSequence(searchResult.charsMatched, key.length()); // Create new nodes... - Node n1 = nodeFactory.createNode(suffixFromKey, value, Collections.emptyList(), false); + Node n1 = nodeFactory.createNode(suffixFromKey, value, new SimpleNodeList(), false); Node n2 = nodeFactory.createNode(suffixFromExistingEdge, searchResult.nodeFound.getValue(), searchResult.nodeFound.getOutgoingEdges(), false); @SuppressWarnings({"NullableProblems"}) - Node n3 = nodeFactory.createNode(commonPrefix, null, Arrays.asList(n1, n2), false); + Node n3 = nodeFactory.createNode(commonPrefix, null, new SimpleNodeList(n1, n2), false); searchResult.parentNode.updateOutgoingEdge(n3); @@ -795,7 +797,7 @@ protected NodeKeyPair computeNext() { return endOfData(); } NodeKeyPair current = stack.removeFirst(); - List childNodes = current.node.getOutgoingEdges(); + NodeList childNodes = current.node.getOutgoingEdges(); // -> Iterate child nodes in reverse order and so push them onto the stack in reverse order, // to counteract that pushing them onto the stack alone would otherwise reverse their processing order. diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/Node.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/Node.java index 80b4ee1..9a4df53 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/Node.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/Node.java @@ -168,5 +168,5 @@ public interface Node extends NodeCharacterProvider, Serializable { * * @return A read-only list of the child nodes to which this node has outgoing edges */ - List getOutgoingEdges(); + NodeList getOutgoingEdges(); } diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/NodeFactory.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/NodeFactory.java index f4bdcc2..96c3b71 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/NodeFactory.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/NodeFactory.java @@ -47,6 +47,6 @@ public interface NodeFactory extends Serializable { * * @return An object implementing the {@link Node} interface which stores the given variables */ - Node createNode(CharSequence edgeCharacters, Object value, List childNodes, boolean isRoot); + Node createNode(CharSequence edgeCharacters, Object value, NodeList childNodes, boolean isRoot); } diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/NodeList.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/NodeList.java new file mode 100644 index 0000000..651b0af --- /dev/null +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/NodeList.java @@ -0,0 +1,20 @@ +package com.googlecode.concurrenttrees.radix.node; + +import java.util.Collection; + +public interface NodeList { + + int size(); + + Node get(int index); + + boolean isEmpty(); + + void set(int index, Node node); + + boolean contains(Node node); + + void addTo(Collection nodes); + + Node[] toArray(); +} diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/SimpleNodeList.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/SimpleNodeList.java new file mode 100644 index 0000000..bfcd90d --- /dev/null +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/SimpleNodeList.java @@ -0,0 +1,69 @@ +package com.googlecode.concurrenttrees.radix.node; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +public class SimpleNodeList implements NodeList { + + private final List nodes; + + public static final NodeList EMPTY = new SimpleNodeList(); + + SimpleNodeList() { + this.nodes = Collections.emptyList(); + } + + public SimpleNodeList(Node node) { + this.nodes = Collections.singletonList(node); + } + + public SimpleNodeList(Node... nodes) { + this.nodes = Arrays.asList(nodes); + } + + public SimpleNodeList(List nodes) { + this.nodes = nodes; + } + + @Override + public int size() { + return nodes.size(); + } + + @Override + public Node get(int index) { + return nodes.get(index); + } + + @Override + public boolean contains(Node node) { + return nodes.contains(node); + } + + @Override + public boolean isEmpty() { + return nodes.isEmpty(); + } + + @Override + public void set(int index, Node node) { + nodes.set(index, node); + } + + @Override + public void addTo(Collection nodes) { + nodes.addAll(this.nodes); + } + + @Override + public Node[] toArray() { + return nodes.toArray(new Node[0]); + } + + @Override + public String toString() { + return nodes.toString(); + } +} diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultByteArrayNodeFactory.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultByteArrayNodeFactory.java index a7a6ea6..4abcf97 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultByteArrayNodeFactory.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultByteArrayNodeFactory.java @@ -18,12 +18,11 @@ import com.googlecode.concurrenttrees.common.CharSequences; import com.googlecode.concurrenttrees.radix.node.Node; import com.googlecode.concurrenttrees.radix.node.NodeFactory; +import com.googlecode.concurrenttrees.radix.node.NodeList; import com.googlecode.concurrenttrees.radix.node.concrete.bytearray.*; import com.googlecode.concurrenttrees.radix.node.concrete.voidvalue.VoidValue; import com.googlecode.concurrenttrees.radix.node.util.NodeUtil; -import java.util.List; - /** * A {@link NodeFactory} which creates {@link Node} objects which store incoming edge characters as a byte array inside * the node. This is similar to {@link DefaultCharArrayNodeFactory}, except nodes use a single byte to represent each @@ -50,7 +49,7 @@ public DefaultByteArrayNodeFactory() { } @Override - public Node createNode(CharSequence edgeCharacters, Object value, List childNodes, boolean isRoot) { + public Node createNode(CharSequence edgeCharacters, Object value, NodeList childNodes, boolean isRoot) { assert edgeCharacters != null : "The edgeCharacters argument was null"; assert isRoot || edgeCharacters.length() > 0 : "Invalid edge characters for non-root node: " + CharSequences.toString(edgeCharacters); assert childNodes != null : "The edgeCharacters argument was null"; diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharArrayNodeFactory.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharArrayNodeFactory.java index fa96b66..3c9fca9 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharArrayNodeFactory.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharArrayNodeFactory.java @@ -15,14 +15,13 @@ */ package com.googlecode.concurrenttrees.radix.node.concrete; +import com.googlecode.concurrenttrees.common.CharSequences; import com.googlecode.concurrenttrees.radix.node.Node; import com.googlecode.concurrenttrees.radix.node.NodeFactory; +import com.googlecode.concurrenttrees.radix.node.NodeList; import com.googlecode.concurrenttrees.radix.node.concrete.chararray.*; import com.googlecode.concurrenttrees.radix.node.concrete.voidvalue.VoidValue; import com.googlecode.concurrenttrees.radix.node.util.NodeUtil; -import com.googlecode.concurrenttrees.common.CharSequences; - -import java.util.List; /** * A {@link NodeFactory} which creates various implementations of {@link Node} objects all of which store incoming @@ -47,7 +46,7 @@ public class DefaultCharArrayNodeFactory implements NodeFactory { private static final long serialVersionUID = 1L; @Override - public Node createNode(CharSequence edgeCharacters, Object value, List childNodes, boolean isRoot) { + public Node createNode(CharSequence edgeCharacters, Object value, NodeList childNodes, boolean isRoot) { assert edgeCharacters != null : "The edgeCharacters argument was null"; assert isRoot || edgeCharacters.length() > 0 : "Invalid edge characters for non-root node: " + CharSequences.toString(edgeCharacters); assert childNodes != null : "The edgeCharacters argument was null"; diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharSequenceNodeFactory.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharSequenceNodeFactory.java index c9fc701..347ec88 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharSequenceNodeFactory.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharSequenceNodeFactory.java @@ -18,12 +18,11 @@ import com.googlecode.concurrenttrees.common.CharSequences; import com.googlecode.concurrenttrees.radix.node.Node; import com.googlecode.concurrenttrees.radix.node.NodeFactory; +import com.googlecode.concurrenttrees.radix.node.NodeList; import com.googlecode.concurrenttrees.radix.node.concrete.charsequence.*; import com.googlecode.concurrenttrees.radix.node.concrete.voidvalue.VoidValue; import com.googlecode.concurrenttrees.radix.node.util.NodeUtil; -import java.util.List; - /** * A {@link NodeFactory} which creates various implementations of {@link Node} objects all of which store incoming * edge characters as a {@link CharSequence} (a view onto the original key) rather than copying the edge into a @@ -48,7 +47,7 @@ public class DefaultCharSequenceNodeFactory implements NodeFactory { private static final long serialVersionUID = 1L; @Override - public Node createNode(CharSequence edgeCharacters, Object value, List childNodes, boolean isRoot) { + public Node createNode(CharSequence edgeCharacters, Object value, NodeList childNodes, boolean isRoot) { assert edgeCharacters != null : "The edgeCharacters argument was null"; assert isRoot || edgeCharacters.length() > 0 : "Invalid edge characters for non-root node: " + CharSequences.toString(edgeCharacters); assert childNodes != null : "The edgeCharacters argument was null"; diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/SmartArrayBasedNodeFactory.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/SmartArrayBasedNodeFactory.java index c3eb3fd..929ae24 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/SmartArrayBasedNodeFactory.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/SmartArrayBasedNodeFactory.java @@ -17,10 +17,9 @@ import com.googlecode.concurrenttrees.radix.node.Node; import com.googlecode.concurrenttrees.radix.node.NodeFactory; +import com.googlecode.concurrenttrees.radix.node.NodeList; import com.googlecode.concurrenttrees.radix.node.concrete.bytearray.ByteArrayCharSequence; -import java.util.List; - /** * A {@link NodeFactory} which internally uses {@link DefaultByteArrayNodeFactory} to create nodes by default (which * can reduce memory overhead), but falls back to {@link DefaultCharArrayNodeFactory} if characters are detected which @@ -36,7 +35,7 @@ public class SmartArrayBasedNodeFactory implements NodeFactory { final NodeFactory byteArrayNodeFactory = new DefaultByteArrayNodeFactory(true); @Override - public Node createNode(CharSequence edgeCharacters, Object value, List childNodes, boolean isRoot) { + public Node createNode(CharSequence edgeCharacters, Object value, NodeList childNodes, boolean isRoot) { try { return byteArrayNodeFactory.createNode(edgeCharacters, value, childNodes, isRoot); } diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeDefault.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeDefault.java index c59df6c..12ced1a 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeDefault.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeDefault.java @@ -16,13 +16,12 @@ package com.googlecode.concurrenttrees.radix.node.concrete.bytearray; import com.googlecode.concurrenttrees.radix.node.Node; -import com.googlecode.concurrenttrees.radix.node.util.AtomicReferenceArrayListAdapter; +import com.googlecode.concurrenttrees.radix.node.NodeList; +import com.googlecode.concurrenttrees.radix.node.util.AtomicNodeReferenceArray; import com.googlecode.concurrenttrees.radix.node.util.NodeCharacterComparator; import com.googlecode.concurrenttrees.radix.node.util.NodeUtil; import java.util.Arrays; -import java.util.List; -import java.util.concurrent.atomic.AtomicReferenceArray; /** * Similar to {@link com.googlecode.concurrenttrees.radix.node.concrete.chararray.CharArrayNodeDefault} but represents @@ -44,27 +43,23 @@ public class ByteArrayNodeDefault implements Node { // References to child nodes representing outgoing edges from this node. // Once assigned we never add or remove references, but we do update existing references to point to new child // nodes provided new edges start with the same first character... - private final AtomicReferenceArray outgoingEdges; - - // A read-only List wrapper around the outgoingEdges AtomicReferenceArray... - private final List outgoingEdgesAsList; + private final AtomicNodeReferenceArray outgoingEdges; // An arbitrary value which the application associates with a key matching the path to this node in the tree. // This value can be null... private final Object value; - public ByteArrayNodeDefault(CharSequence edgeCharSequence, Object value, List outgoingEdges) { + public ByteArrayNodeDefault(CharSequence edgeCharSequence, Object value, NodeList outgoingEdges) { this(ByteArrayCharSequence.toSingleByteUtf8Encoding(edgeCharSequence), value, outgoingEdges); } - public ByteArrayNodeDefault(byte[] incomingEdgeCharArray, Object value, List outgoingEdges) { - Node[] childNodeArray = outgoingEdges.toArray(new Node[0]); + public ByteArrayNodeDefault(byte[] incomingEdgeCharArray, Object value, NodeList outgoingEdges) { + Node[] childNodeArray = outgoingEdges.toArray(); // Sort the child nodes... Arrays.sort(childNodeArray, NodeCharacterComparator.SINGLETON); - this.outgoingEdges = new AtomicReferenceArray(childNodeArray); + this.outgoingEdges = new AtomicNodeReferenceArray(childNodeArray); this.incomingEdgeCharArray = incomingEdgeCharArray; this.value = value; - this.outgoingEdgesAsList = new AtomicReferenceArrayListAdapter(this.outgoingEdges); } @Override @@ -120,8 +115,8 @@ public void updateOutgoingEdge(Node childNode) { } @Override - public List getOutgoingEdges() { - return outgoingEdgesAsList; + public NodeList getOutgoingEdges() { + return outgoingEdges; } @Override diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafNullValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafNullValue.java index b3c6332..79256d7 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafNullValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafNullValue.java @@ -16,9 +16,8 @@ package com.googlecode.concurrenttrees.radix.node.concrete.bytearray; import com.googlecode.concurrenttrees.radix.node.Node; - -import java.util.Collections; -import java.util.List; +import com.googlecode.concurrenttrees.radix.node.NodeList; +import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; /** * Similar to {@link com.googlecode.concurrenttrees.radix.node.concrete.chararray.CharArrayNodeLeafNullValue} but represents @@ -81,8 +80,8 @@ public void updateOutgoingEdge(Node childNode) { } @Override - public List getOutgoingEdges() { - return Collections.emptyList(); + public NodeList getOutgoingEdges() { + return SimpleNodeList.EMPTY; } @Override diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafVoidValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafVoidValue.java index b5329bb..6dc9266 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafVoidValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafVoidValue.java @@ -16,11 +16,10 @@ package com.googlecode.concurrenttrees.radix.node.concrete.bytearray; import com.googlecode.concurrenttrees.radix.node.Node; +import com.googlecode.concurrenttrees.radix.node.NodeList; +import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; import com.googlecode.concurrenttrees.radix.node.concrete.voidvalue.VoidValue; -import java.util.Collections; -import java.util.List; - /** * Similar to {@link com.googlecode.concurrenttrees.radix.node.concrete.chararray.CharArrayNodeLeafVoidValue} but represents * each character in UTF-8, instead of Java's default 2-byte UFT-16 encoding. @@ -82,8 +81,8 @@ public void updateOutgoingEdge(Node childNode) { } @Override - public List getOutgoingEdges() { - return Collections.emptyList(); + public NodeList getOutgoingEdges() { + return SimpleNodeList.EMPTY; } @Override diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafWithValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafWithValue.java index cebe2b9..8e4306c 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafWithValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafWithValue.java @@ -16,9 +16,8 @@ package com.googlecode.concurrenttrees.radix.node.concrete.bytearray; import com.googlecode.concurrenttrees.radix.node.Node; - -import java.util.Collections; -import java.util.List; +import com.googlecode.concurrenttrees.radix.node.NodeList; +import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; /** * Similar to {@link com.googlecode.concurrenttrees.radix.node.concrete.chararray.CharArrayNodeLeafWithValue} but represents @@ -86,8 +85,8 @@ public void updateOutgoingEdge(Node childNode) { } @Override - public List getOutgoingEdges() { - return Collections.emptyList(); + public NodeList getOutgoingEdges() { + return SimpleNodeList.EMPTY; } @Override diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafNullValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafNullValue.java index 02ab396..6959d51 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafNullValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafNullValue.java @@ -16,13 +16,12 @@ package com.googlecode.concurrenttrees.radix.node.concrete.bytearray; import com.googlecode.concurrenttrees.radix.node.Node; -import com.googlecode.concurrenttrees.radix.node.util.AtomicReferenceArrayListAdapter; +import com.googlecode.concurrenttrees.radix.node.NodeList; +import com.googlecode.concurrenttrees.radix.node.util.AtomicNodeReferenceArray; import com.googlecode.concurrenttrees.radix.node.util.NodeCharacterComparator; import com.googlecode.concurrenttrees.radix.node.util.NodeUtil; import java.util.Arrays; -import java.util.List; -import java.util.concurrent.atomic.AtomicReferenceArray; /** * Similar to {@link com.googlecode.concurrenttrees.radix.node.concrete.chararray.CharArrayNodeNonLeafNullValue} but represents @@ -44,22 +43,18 @@ public class ByteArrayNodeNonLeafNullValue implements Node { // References to child nodes representing outgoing edges from this node. // Once assigned we never add or remove references, but we do update existing references to point to new child // nodes provided new edges start with the same first character... - private final AtomicReferenceArray outgoingEdges; + private final AtomicNodeReferenceArray outgoingEdges; - // A read-only List wrapper around the outgoingEdges AtomicReferenceArray... - private final List outgoingEdgesAsList; - - public ByteArrayNodeNonLeafNullValue(CharSequence edgeCharSequence, List outgoingEdges) { + public ByteArrayNodeNonLeafNullValue(CharSequence edgeCharSequence, NodeList outgoingEdges) { this(ByteArrayCharSequence.toSingleByteUtf8Encoding(edgeCharSequence), outgoingEdges); } - public ByteArrayNodeNonLeafNullValue(byte[] incomingEdgeCharArray, List outgoingEdges) { - Node[] childNodeArray = outgoingEdges.toArray(new Node[0]); + public ByteArrayNodeNonLeafNullValue(byte[] incomingEdgeCharArray, NodeList outgoingEdges) { + Node[] childNodeArray = outgoingEdges.toArray(); // Sort the child nodes... Arrays.sort(childNodeArray, NodeCharacterComparator.SINGLETON); - this.outgoingEdges = new AtomicReferenceArray(childNodeArray); + this.outgoingEdges = new AtomicNodeReferenceArray(childNodeArray); this.incomingEdgeCharArray = incomingEdgeCharArray; - this.outgoingEdgesAsList = new AtomicReferenceArrayListAdapter(this.outgoingEdges); } @Override @@ -115,8 +110,8 @@ public void updateOutgoingEdge(Node childNode) { } @Override - public List getOutgoingEdges() { - return outgoingEdgesAsList; + public NodeList getOutgoingEdges() { + return outgoingEdges; } @Override diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafVoidValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafVoidValue.java index aaf0b06..4fa907d 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafVoidValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafVoidValue.java @@ -16,14 +16,13 @@ package com.googlecode.concurrenttrees.radix.node.concrete.bytearray; import com.googlecode.concurrenttrees.radix.node.Node; +import com.googlecode.concurrenttrees.radix.node.NodeList; import com.googlecode.concurrenttrees.radix.node.concrete.voidvalue.VoidValue; -import com.googlecode.concurrenttrees.radix.node.util.AtomicReferenceArrayListAdapter; +import com.googlecode.concurrenttrees.radix.node.util.AtomicNodeReferenceArray; import com.googlecode.concurrenttrees.radix.node.util.NodeCharacterComparator; import com.googlecode.concurrenttrees.radix.node.util.NodeUtil; import java.util.Arrays; -import java.util.List; -import java.util.concurrent.atomic.AtomicReferenceArray; /** * Similar to {@link com.googlecode.concurrenttrees.radix.node.concrete.chararray.CharArrayNodeNonLeafVoidValue} but represents @@ -45,22 +44,18 @@ public class ByteArrayNodeNonLeafVoidValue implements Node { // References to child nodes representing outgoing edges from this node. // Once assigned we never add or remove references, but we do update existing references to point to new child // nodes provided new edges start with the same first character... - private final AtomicReferenceArray outgoingEdges; + private final AtomicNodeReferenceArray outgoingEdges; - // A read-only List wrapper around the outgoingEdges AtomicReferenceArray... - private final List outgoingEdgesAsList; - - public ByteArrayNodeNonLeafVoidValue(CharSequence edgeCharSequence, List outgoingEdges) { + public ByteArrayNodeNonLeafVoidValue(CharSequence edgeCharSequence, NodeList outgoingEdges) { this(ByteArrayCharSequence.toSingleByteUtf8Encoding(edgeCharSequence), outgoingEdges); } - public ByteArrayNodeNonLeafVoidValue(byte[] incomingEdgeCharArray, List outgoingEdges) { - Node[] childNodeArray = outgoingEdges.toArray(new Node[0]); + public ByteArrayNodeNonLeafVoidValue(byte[] incomingEdgeCharArray, NodeList outgoingEdges) { + Node[] childNodeArray = outgoingEdges.toArray(); // Sort the child nodes... Arrays.sort(childNodeArray, NodeCharacterComparator.SINGLETON); - this.outgoingEdges = new AtomicReferenceArray(childNodeArray); + this.outgoingEdges = new AtomicNodeReferenceArray(childNodeArray); this.incomingEdgeCharArray = incomingEdgeCharArray; - this.outgoingEdgesAsList = new AtomicReferenceArrayListAdapter(this.outgoingEdges); } @Override @@ -116,8 +111,8 @@ public void updateOutgoingEdge(Node childNode) { } @Override - public List getOutgoingEdges() { - return outgoingEdgesAsList; + public NodeList getOutgoingEdges() { + return outgoingEdges; } @Override diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeDefault.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeDefault.java index c112949..f6bb728 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeDefault.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeDefault.java @@ -15,14 +15,14 @@ */ package com.googlecode.concurrenttrees.radix.node.concrete.chararray; +import com.googlecode.concurrenttrees.common.CharSequences; import com.googlecode.concurrenttrees.radix.node.Node; +import com.googlecode.concurrenttrees.radix.node.NodeList; +import com.googlecode.concurrenttrees.radix.node.util.AtomicNodeReferenceArray; import com.googlecode.concurrenttrees.radix.node.util.NodeCharacterComparator; import com.googlecode.concurrenttrees.radix.node.util.NodeUtil; -import com.googlecode.concurrenttrees.radix.node.util.AtomicReferenceArrayListAdapter; -import com.googlecode.concurrenttrees.common.CharSequences; import java.util.Arrays; -import java.util.List; import java.util.concurrent.atomic.AtomicReferenceArray; /** @@ -60,23 +60,19 @@ public class CharArrayNodeDefault implements Node { // References to child nodes representing outgoing edges from this node. // Once assigned we never add or remove references, but we do update existing references to point to new child // nodes provided new edges start with the same first character... - private final AtomicReferenceArray outgoingEdges; - - // A read-only List wrapper around the outgoingEdges AtomicReferenceArray... - private final List outgoingEdgesAsList; + private final AtomicNodeReferenceArray outgoingEdges; // An arbitrary value which the application associates with a key matching the path to this node in the tree. // This value can be null... private final Object value; - public CharArrayNodeDefault(CharSequence edgeCharSequence, Object value, List outgoingEdges) { - Node[] childNodeArray = outgoingEdges.toArray(new Node[0]); + public CharArrayNodeDefault(CharSequence edgeCharSequence, Object value, NodeList outgoingEdges) { + Node[] childNodeArray = outgoingEdges.toArray(); // Sort the child nodes... Arrays.sort(childNodeArray, NodeCharacterComparator.SINGLETON); - this.outgoingEdges = new AtomicReferenceArray(childNodeArray); + this.outgoingEdges = new AtomicNodeReferenceArray(childNodeArray); this.incomingEdgeCharArray = CharSequences.toCharArray(edgeCharSequence); this.value = value; - this.outgoingEdgesAsList = new AtomicReferenceArrayListAdapter(this.outgoingEdges); } @Override @@ -132,8 +128,8 @@ public void updateOutgoingEdge(Node childNode) { } @Override - public List getOutgoingEdges() { - return outgoingEdgesAsList; + public NodeList getOutgoingEdges() { + return outgoingEdges; } @Override diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafNullValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafNullValue.java index 8e91855..6e37ee8 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafNullValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafNullValue.java @@ -17,9 +17,8 @@ import com.googlecode.concurrenttrees.common.CharSequences; import com.googlecode.concurrenttrees.radix.node.Node; - -import java.util.Collections; -import java.util.List; +import com.googlecode.concurrenttrees.radix.node.NodeList; +import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; /** * Stores only incoming edge as a {@code char[]}. @@ -75,8 +74,8 @@ public void updateOutgoingEdge(Node childNode) { } @Override - public List getOutgoingEdges() { - return Collections.emptyList(); + public NodeList getOutgoingEdges() { + return SimpleNodeList.EMPTY; } @Override diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafVoidValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafVoidValue.java index 7f909df..7a5e7e7 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafVoidValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafVoidValue.java @@ -17,11 +17,10 @@ import com.googlecode.concurrenttrees.common.CharSequences; import com.googlecode.concurrenttrees.radix.node.Node; +import com.googlecode.concurrenttrees.radix.node.NodeList; +import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; import com.googlecode.concurrenttrees.radix.node.concrete.voidvalue.VoidValue; -import java.util.Collections; -import java.util.List; - /** * Stores only incoming edge as a {@code char[]}. * Returns {@link VoidValue} for the value. Does not store any outgoing edges. @@ -76,8 +75,8 @@ public void updateOutgoingEdge(Node childNode) { } @Override - public List getOutgoingEdges() { - return Collections.emptyList(); + public NodeList getOutgoingEdges() { + return SimpleNodeList.EMPTY; } @Override diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafWithValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafWithValue.java index 069cdf5..c392ab0 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafWithValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafWithValue.java @@ -17,9 +17,8 @@ import com.googlecode.concurrenttrees.common.CharSequences; import com.googlecode.concurrenttrees.radix.node.Node; - -import java.util.Collections; -import java.util.List; +import com.googlecode.concurrenttrees.radix.node.NodeList; +import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; /** * Stores only incoming edge as a {@code char[]}, and a reference to a value. Does not store any outgoing @@ -80,8 +79,8 @@ public void updateOutgoingEdge(Node childNode) { } @Override - public List getOutgoingEdges() { - return Collections.emptyList(); + public NodeList getOutgoingEdges() { + return SimpleNodeList.EMPTY; } @Override diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafNullValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafNullValue.java index 3fc0a9e..3e906c4 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafNullValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafNullValue.java @@ -17,12 +17,12 @@ import com.googlecode.concurrenttrees.common.CharSequences; import com.googlecode.concurrenttrees.radix.node.Node; -import com.googlecode.concurrenttrees.radix.node.util.AtomicReferenceArrayListAdapter; +import com.googlecode.concurrenttrees.radix.node.NodeList; +import com.googlecode.concurrenttrees.radix.node.util.AtomicNodeReferenceArray; import com.googlecode.concurrenttrees.radix.node.util.NodeCharacterComparator; import com.googlecode.concurrenttrees.radix.node.util.NodeUtil; import java.util.Arrays; -import java.util.List; import java.util.concurrent.atomic.AtomicReferenceArray; /** @@ -42,18 +42,14 @@ public class CharArrayNodeNonLeafNullValue implements Node { // References to child nodes representing outgoing edges from this node. // Once assigned we never add or remove references, but we do update existing references to point to new child // nodes provided new edges start with the same first character... - private final AtomicReferenceArray outgoingEdges; + private final AtomicNodeReferenceArray outgoingEdges; - // A read-only List wrapper around the outgoingEdges AtomicReferenceArray... - private final List outgoingEdgesAsList; - - public CharArrayNodeNonLeafNullValue(CharSequence edgeCharSequence, List outgoingEdges) { - Node[] childNodeArray = outgoingEdges.toArray(new Node[0]); + public CharArrayNodeNonLeafNullValue(CharSequence edgeCharSequence, NodeList outgoingEdges) { + Node[] childNodeArray = outgoingEdges.toArray(); // Sort the child nodes... Arrays.sort(childNodeArray, NodeCharacterComparator.SINGLETON); - this.outgoingEdges = new AtomicReferenceArray(childNodeArray); + this.outgoingEdges = new AtomicNodeReferenceArray(childNodeArray); this.incomingEdgeCharArray = CharSequences.toCharArray(edgeCharSequence); - this.outgoingEdgesAsList = new AtomicReferenceArrayListAdapter(this.outgoingEdges); } @Override @@ -109,8 +105,8 @@ public void updateOutgoingEdge(Node childNode) { } @Override - public List getOutgoingEdges() { - return outgoingEdgesAsList; + public NodeList getOutgoingEdges() { + return outgoingEdges; } @Override diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafVoidValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafVoidValue.java index a681fdd..f5be6c9 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafVoidValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafVoidValue.java @@ -17,13 +17,13 @@ import com.googlecode.concurrenttrees.common.CharSequences; import com.googlecode.concurrenttrees.radix.node.Node; +import com.googlecode.concurrenttrees.radix.node.NodeList; import com.googlecode.concurrenttrees.radix.node.concrete.voidvalue.VoidValue; -import com.googlecode.concurrenttrees.radix.node.util.AtomicReferenceArrayListAdapter; +import com.googlecode.concurrenttrees.radix.node.util.AtomicNodeReferenceArray; import com.googlecode.concurrenttrees.radix.node.util.NodeCharacterComparator; import com.googlecode.concurrenttrees.radix.node.util.NodeUtil; import java.util.Arrays; -import java.util.List; import java.util.concurrent.atomic.AtomicReferenceArray; /** @@ -43,18 +43,14 @@ public class CharArrayNodeNonLeafVoidValue implements Node { // References to child nodes representing outgoing edges from this node. // Once assigned we never add or remove references, but we do update existing references to point to new child // nodes provided new edges start with the same first character... - private final AtomicReferenceArray outgoingEdges; + private final AtomicNodeReferenceArray outgoingEdges; - // A read-only List wrapper around the outgoingEdges AtomicReferenceArray... - private final List outgoingEdgesAsList; - - public CharArrayNodeNonLeafVoidValue(CharSequence edgeCharSequence, List outgoingEdges) { - Node[] childNodeArray = outgoingEdges.toArray(new Node[0]); + public CharArrayNodeNonLeafVoidValue(CharSequence edgeCharSequence, NodeList outgoingEdges) { + Node[] childNodeArray = outgoingEdges.toArray(); // Sort the child nodes... Arrays.sort(childNodeArray, NodeCharacterComparator.SINGLETON); - this.outgoingEdges = new AtomicReferenceArray(childNodeArray); + this.outgoingEdges = new AtomicNodeReferenceArray(childNodeArray); this.incomingEdgeCharArray = CharSequences.toCharArray(edgeCharSequence); - this.outgoingEdgesAsList = new AtomicReferenceArrayListAdapter(this.outgoingEdges); } @Override @@ -110,8 +106,8 @@ public void updateOutgoingEdge(Node childNode) { } @Override - public List getOutgoingEdges() { - return outgoingEdgesAsList; + public NodeList getOutgoingEdges() { + return outgoingEdges; } @Override diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeDefault.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeDefault.java index 5edf4fc..627c03d 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeDefault.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeDefault.java @@ -16,12 +16,12 @@ package com.googlecode.concurrenttrees.radix.node.concrete.charsequence; import com.googlecode.concurrenttrees.radix.node.Node; -import com.googlecode.concurrenttrees.radix.node.util.AtomicReferenceArrayListAdapter; +import com.googlecode.concurrenttrees.radix.node.NodeList; +import com.googlecode.concurrenttrees.radix.node.util.AtomicNodeReferenceArray; import com.googlecode.concurrenttrees.radix.node.util.NodeCharacterComparator; import com.googlecode.concurrenttrees.radix.node.util.NodeUtil; import java.util.Arrays; -import java.util.List; import java.util.concurrent.atomic.AtomicReferenceArray; /** @@ -60,23 +60,19 @@ public class CharSequenceNodeDefault implements Node { // References to child nodes representing outgoing edges from this node. // Once assigned we never add or remove references, but we do update existing references to point to new child // nodes provided new edges start with the same first character... - private final AtomicReferenceArray outgoingEdges; - - // A read-only List wrapper around the outgoingEdges AtomicReferenceArray... - private final List outgoingEdgesAsList; + private final AtomicNodeReferenceArray outgoingEdges; // An arbitrary value which the application associates with a key matching the path to this node in the tree. // This value can be null... private final Object value; - public CharSequenceNodeDefault(CharSequence edgeCharSequence, Object value, List outgoingEdges) { - Node[] childNodeArray = outgoingEdges.toArray(new Node[0]); + public CharSequenceNodeDefault(CharSequence edgeCharSequence, Object value, NodeList outgoingEdges) { + Node[] childNodeArray = outgoingEdges.toArray(); // Sort the child nodes... Arrays.sort(childNodeArray, NodeCharacterComparator.SINGLETON); - this.outgoingEdges = new AtomicReferenceArray(childNodeArray); + this.outgoingEdges = new AtomicNodeReferenceArray(childNodeArray); this.incomingEdgeCharSequence = edgeCharSequence; this.value = value; - this.outgoingEdgesAsList = new AtomicReferenceArrayListAdapter(this.outgoingEdges); } @Override @@ -132,8 +128,8 @@ public void updateOutgoingEdge(Node childNode) { } @Override - public List getOutgoingEdges() { - return outgoingEdgesAsList; + public NodeList getOutgoingEdges() { + return outgoingEdges; } @Override diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafNullValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafNullValue.java index 281220c..c428ccd 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafNullValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafNullValue.java @@ -16,9 +16,8 @@ package com.googlecode.concurrenttrees.radix.node.concrete.charsequence; import com.googlecode.concurrenttrees.radix.node.Node; - -import java.util.Collections; -import java.util.List; +import com.googlecode.concurrenttrees.radix.node.NodeList; +import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; /** * Stores only incoming edge as a {@link CharSequence} (a view onto the original key) rather than copying the @@ -74,8 +73,8 @@ public void updateOutgoingEdge(Node childNode) { } @Override - public List getOutgoingEdges() { - return Collections.emptyList(); + public NodeList getOutgoingEdges() { + return SimpleNodeList.EMPTY; } @Override diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafVoidValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafVoidValue.java index d57dcf4..a880378 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafVoidValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafVoidValue.java @@ -16,15 +16,9 @@ package com.googlecode.concurrenttrees.radix.node.concrete.charsequence; import com.googlecode.concurrenttrees.radix.node.Node; +import com.googlecode.concurrenttrees.radix.node.NodeList; +import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; import com.googlecode.concurrenttrees.radix.node.concrete.voidvalue.VoidValue; -import com.googlecode.concurrenttrees.radix.node.util.AtomicReferenceArrayListAdapter; -import com.googlecode.concurrenttrees.radix.node.util.NodeCharacterComparator; -import com.googlecode.concurrenttrees.radix.node.util.NodeUtil; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.atomic.AtomicReferenceArray; /** * Stores only incoming edge as a {@link CharSequence} (a view onto the original key) rather than copying the @@ -80,8 +74,8 @@ public void updateOutgoingEdge(Node childNode) { } @Override - public List getOutgoingEdges() { - return Collections.emptyList(); + public NodeList getOutgoingEdges() { + return SimpleNodeList.EMPTY; } @Override diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafWithValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafWithValue.java index 2ec6f07..f11eef4 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafWithValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafWithValue.java @@ -16,9 +16,8 @@ package com.googlecode.concurrenttrees.radix.node.concrete.charsequence; import com.googlecode.concurrenttrees.radix.node.Node; - -import java.util.Collections; -import java.util.List; +import com.googlecode.concurrenttrees.radix.node.NodeList; +import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; /** * Stores incoming edge as a {@link CharSequence} (a view onto the original key) rather than copying the @@ -80,8 +79,8 @@ public void updateOutgoingEdge(Node childNode) { } @Override - public List getOutgoingEdges() { - return Collections.emptyList(); + public NodeList getOutgoingEdges() { + return SimpleNodeList.EMPTY; } @Override diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafNullValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafNullValue.java index 12bde24..cdeb351 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafNullValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafNullValue.java @@ -16,12 +16,12 @@ package com.googlecode.concurrenttrees.radix.node.concrete.charsequence; import com.googlecode.concurrenttrees.radix.node.Node; -import com.googlecode.concurrenttrees.radix.node.util.AtomicReferenceArrayListAdapter; +import com.googlecode.concurrenttrees.radix.node.NodeList; +import com.googlecode.concurrenttrees.radix.node.util.AtomicNodeReferenceArray; import com.googlecode.concurrenttrees.radix.node.util.NodeCharacterComparator; import com.googlecode.concurrenttrees.radix.node.util.NodeUtil; import java.util.Arrays; -import java.util.List; import java.util.concurrent.atomic.AtomicReferenceArray; /** @@ -42,18 +42,14 @@ public class CharSequenceNodeNonLeafNullValue implements Node { // References to child nodes representing outgoing edges from this node. // Once assigned we never add or remove references, but we do update existing references to point to new child // nodes provided new edges start with the same first character... - private final AtomicReferenceArray outgoingEdges; + private final AtomicNodeReferenceArray outgoingEdges; - // A read-only List wrapper around the outgoingEdges AtomicReferenceArray... - private final List outgoingEdgesAsList; - - public CharSequenceNodeNonLeafNullValue(CharSequence edgeCharSequence, List outgoingEdges) { - Node[] childNodeArray = outgoingEdges.toArray(new Node[0]); + public CharSequenceNodeNonLeafNullValue(CharSequence edgeCharSequence, NodeList outgoingEdges) { + Node[] childNodeArray = outgoingEdges.toArray(); // Sort the child nodes... Arrays.sort(childNodeArray, NodeCharacterComparator.SINGLETON); - this.outgoingEdges = new AtomicReferenceArray(childNodeArray); + this.outgoingEdges = new AtomicNodeReferenceArray(childNodeArray); this.incomingEdgeCharSequence = edgeCharSequence; - this.outgoingEdgesAsList = new AtomicReferenceArrayListAdapter(this.outgoingEdges); } @Override @@ -109,8 +105,8 @@ public void updateOutgoingEdge(Node childNode) { } @Override - public List getOutgoingEdges() { - return outgoingEdgesAsList; + public NodeList getOutgoingEdges() { + return outgoingEdges; } @Override diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafVoidValue.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafVoidValue.java index de78a04..51c97a8 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafVoidValue.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafVoidValue.java @@ -16,13 +16,13 @@ package com.googlecode.concurrenttrees.radix.node.concrete.charsequence; import com.googlecode.concurrenttrees.radix.node.Node; +import com.googlecode.concurrenttrees.radix.node.NodeList; import com.googlecode.concurrenttrees.radix.node.concrete.voidvalue.VoidValue; -import com.googlecode.concurrenttrees.radix.node.util.AtomicReferenceArrayListAdapter; +import com.googlecode.concurrenttrees.radix.node.util.AtomicNodeReferenceArray; import com.googlecode.concurrenttrees.radix.node.util.NodeCharacterComparator; import com.googlecode.concurrenttrees.radix.node.util.NodeUtil; import java.util.Arrays; -import java.util.List; import java.util.concurrent.atomic.AtomicReferenceArray; /** @@ -43,18 +43,14 @@ public class CharSequenceNodeNonLeafVoidValue implements Node { // References to child nodes representing outgoing edges from this node. // Once assigned we never add or remove references, but we do update existing references to point to new child // nodes provided new edges start with the same first character... - private final AtomicReferenceArray outgoingEdges; + private final AtomicNodeReferenceArray outgoingEdges; - // A read-only List wrapper around the outgoingEdges AtomicReferenceArray... - private final List outgoingEdgesAsList; - - public CharSequenceNodeNonLeafVoidValue(CharSequence edgeCharSequence, List outgoingEdges) { - Node[] childNodeArray = outgoingEdges.toArray(new Node[0]); + public CharSequenceNodeNonLeafVoidValue(CharSequence edgeCharSequence, NodeList outgoingEdges) { + Node[] childNodeArray = outgoingEdges.toArray(); // Sort the child nodes... Arrays.sort(childNodeArray, NodeCharacterComparator.SINGLETON); - this.outgoingEdges = new AtomicReferenceArray(childNodeArray); + this.outgoingEdges = new AtomicNodeReferenceArray(childNodeArray); this.incomingEdgeCharSequence = edgeCharSequence; - this.outgoingEdgesAsList = new AtomicReferenceArrayListAdapter(this.outgoingEdges); } @Override @@ -110,8 +106,8 @@ public void updateOutgoingEdge(Node childNode) { } @Override - public List getOutgoingEdges() { - return outgoingEdgesAsList; + public NodeList getOutgoingEdges() { + return outgoingEdges; } @Override diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/AtomicNodeReferenceArray.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/AtomicNodeReferenceArray.java new file mode 100644 index 0000000..e1ade3e --- /dev/null +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/AtomicNodeReferenceArray.java @@ -0,0 +1,81 @@ +/* + * Copyright 2012-2013 Niall Gallagher + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.googlecode.concurrenttrees.radix.node.util; + +import com.googlecode.concurrenttrees.radix.node.Node; +import com.googlecode.concurrenttrees.radix.node.NodeList; + +import java.util.Collection; +import java.util.concurrent.atomic.AtomicReferenceArray; + +public class AtomicNodeReferenceArray extends AtomicReferenceArray implements NodeList { + + private static final long serialVersionUID = 1L; + + public AtomicNodeReferenceArray(Node[] array) { + super(array); + } + + @Override + public int size() { + return length(); + } + + @Override + public boolean isEmpty() { + return length() == 0; + } + + @Override + public boolean contains(Node node) { + for (int index = 0; index < length(); index++) { + if (node == null && get(index) == null || node != null && node.equals(get(index))) { + return true; + } + } + return false; + } + + @Override + public void addTo(Collection nodes) { + for (int index = 0; index < length(); index++) { + nodes.add(get(index)); + } + } + + @Override + public Node[] toArray() { + Node[] nodes = new Node[length()]; + for (int index = 0; index < nodes.length; index++) { + nodes[index] = get(index); + } + return nodes; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append('['); + for (int index = 0; index < length(); index++) { + if (index > 0) { + sb.append(", "); + } + sb.append(get(index)); + } + sb.append(']'); + return sb.toString(); + } +} diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/AtomicReferenceArrayListAdapter.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/AtomicReferenceArrayListAdapter.java deleted file mode 100644 index 93cdbfa..0000000 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/AtomicReferenceArrayListAdapter.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2012-2013 Niall Gallagher - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.googlecode.concurrenttrees.radix.node.util; - -import java.io.Serializable; -import java.util.AbstractList; -import java.util.concurrent.atomic.AtomicReferenceArray; - -/** - * Wraps an {@link AtomicReferenceArray} to implement read-only methods of the {@link java.util.List} interface. - *

- * This enables binary search of an {@link AtomicReferenceArray}, using - * {@link java.util.Collections#binarySearch(java.util.List, Object)}. - * - * @author Niall Gallagher - */ -public class AtomicReferenceArrayListAdapter extends AbstractList implements Serializable { - - private static final long serialVersionUID = 1L; - - private final AtomicReferenceArray atomicReferenceArray; - - public AtomicReferenceArrayListAdapter(AtomicReferenceArray atomicReferenceArray) { - this.atomicReferenceArray = atomicReferenceArray; - } - - @Override - public T get(int index) { - return atomicReferenceArray.get(index); - } - - @Override - public int size() { - return atomicReferenceArray.length(); - } -} diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/NodeUtil.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/NodeUtil.java index c1ca2af..7e26e60 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/NodeUtil.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/util/NodeUtil.java @@ -16,6 +16,7 @@ package com.googlecode.concurrenttrees.radix.node.util; import com.googlecode.concurrenttrees.radix.node.Node; +import com.googlecode.concurrenttrees.radix.node.NodeList; import java.util.*; import java.util.concurrent.atomic.AtomicReferenceArray; @@ -86,11 +87,11 @@ else if (cmp > 0) * @param nodes The list of nodes to validate * @return {@code true} if the supplied edges are free of duplicates. */ - public static boolean hasNoDuplicateEdges(List nodes) { + public static boolean hasNoDuplicateEdges(NodeList nodes) { // Sanity check that no two nodes specify an edge with the same first character... Set uniqueChars = new HashSet(nodes.size()); - for (Node node : nodes) { - uniqueChars.add(node.getIncomingEdgeFirstCharacter()); + for (int index = 0; index < nodes.size(); index++) { + uniqueChars.add(nodes.get(index).getIncomingEdgeFirstCharacter()); } return nodes.size() == uniqueChars.size(); } diff --git a/code/src/test/java/com/googlecode/concurrenttrees/common/PrettyPrinterTest.java b/code/src/test/java/com/googlecode/concurrenttrees/common/PrettyPrinterTest.java index c287e24..a467fc8 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/common/PrettyPrinterTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/common/PrettyPrinterTest.java @@ -17,6 +17,8 @@ import com.googlecode.concurrenttrees.radix.node.Node; import com.googlecode.concurrenttrees.radix.node.NodeFactory; +import com.googlecode.concurrenttrees.radix.node.NodeList; +import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; import com.googlecode.concurrenttrees.radix.node.concrete.DefaultCharArrayNodeFactory; import com.googlecode.concurrenttrees.radix.node.util.PrettyPrintable; import org.junit.Assert; @@ -110,14 +112,14 @@ static Node getHandBuiltTestTree() { // └── ○ DANA (4) final Node n1, n2, n3, n4, n5, n6; - n6 = nodeFactory.createNode("A", 6, Collections.emptyList(), false); - n5 = nodeFactory.createNode("AN", 5, Arrays.asList(n6), false); - n4 = nodeFactory.createNode("DANA", 4, Collections.emptyList(), false); - n3 = nodeFactory.createNode("N", 3, Arrays.asList(n4, n5), false); // note: it should sort these such that n5 is first - n2 = nodeFactory.createNode("A", 2, Arrays.asList(n3), false); - n1 = nodeFactory.createNode("B", 1, Arrays.asList(n2), false); + n6 = nodeFactory.createNode("A", 6, SimpleNodeList.EMPTY, false); + n5 = nodeFactory.createNode("AN", 5, new SimpleNodeList(n6), false); + n4 = nodeFactory.createNode("DANA", 4, SimpleNodeList.EMPTY, false); + n3 = nodeFactory.createNode("N", 3, new SimpleNodeList(n4, n5), false); // note: it should sort these such that n5 is first + n2 = nodeFactory.createNode("A", 2, new SimpleNodeList(n3), false); + n1 = nodeFactory.createNode("B", 1, new SimpleNodeList(n2), false); //noinspection NullableProblems - return nodeFactory.createNode("", null, Arrays.asList(n1), true); // root + return nodeFactory.createNode("", null, new SimpleNodeList(n1), true); // root } PrettyPrintable wrapNodeForPrinting(final Node node) { diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/ConcurrentRadixTreeTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/ConcurrentRadixTreeTest.java index e0983f6..f194f71 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/ConcurrentRadixTreeTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/ConcurrentRadixTreeTest.java @@ -21,6 +21,7 @@ import com.googlecode.concurrenttrees.common.PrettyPrinter; import com.googlecode.concurrenttrees.radix.node.Node; import com.googlecode.concurrenttrees.radix.node.NodeFactory; +import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; import com.googlecode.concurrenttrees.radix.node.concrete.DefaultCharArrayNodeFactory; import com.googlecode.concurrenttrees.radix.node.concrete.DefaultCharSequenceNodeFactory; import com.googlecode.concurrenttrees.radix.node.concrete.voidvalue.VoidValue; @@ -59,14 +60,14 @@ public void testBuildTreeByHand() { // └── ○ DANA (4) final Node root, n1, n2, n3, n4, n5, n6; - n6 = getNodeFactory().createNode("A", 6, Collections.emptyList(), false); - n5 = getNodeFactory().createNode("AN", 5, Arrays.asList(n6), false); - n4 = getNodeFactory().createNode("DANA", 4, Collections.emptyList(), false); - n3 = getNodeFactory().createNode("N", 3, Arrays.asList(n4, n5), false); // note: it should sort alphabetically such that n5 is first - n2 = getNodeFactory().createNode("A", 2, Arrays.asList(n3), false); - n1 = getNodeFactory().createNode("B", 1, Arrays.asList(n2), false); + n6 = getNodeFactory().createNode("A", 6, SimpleNodeList.EMPTY, false); + n5 = getNodeFactory().createNode("AN", 5, new SimpleNodeList(n6), false); + n4 = getNodeFactory().createNode("DANA", 4, SimpleNodeList.EMPTY, false); + n3 = getNodeFactory().createNode("N", 3, new SimpleNodeList(n4, n5), false); // note: it should sort alphabetically such that n5 is first + n2 = getNodeFactory().createNode("A", 2, new SimpleNodeList(n3), false); + n1 = getNodeFactory().createNode("B", 1, new SimpleNodeList(n2), false); //noinspection NullableProblems - root = getNodeFactory().createNode("", null, Arrays.asList(n1), true); + root = getNodeFactory().createNode("", null, new SimpleNodeList(n1), true); String expected = "○\n" + @@ -853,14 +854,14 @@ public void testSearchTree() { // └── ○ DANA (4) final Node root, n1, n2, n3, n4, n5, n6; - n6 = getNodeFactory().createNode("A", 6, Collections.emptyList(), false); - n5 = getNodeFactory().createNode("AN", 5, Arrays.asList(n6), false); - n4 = getNodeFactory().createNode("DANA", 4, Collections.emptyList(), false); - n3 = getNodeFactory().createNode("N", 3, Arrays.asList(n4, n5), false); // note: it should sort these such that n5 is first - n2 = getNodeFactory().createNode("A", 2, Arrays.asList(n3), false); - n1 = getNodeFactory().createNode("B", 1, Arrays.asList(n2), false); + n6 = getNodeFactory().createNode("A", 6, SimpleNodeList.EMPTY, false); + n5 = getNodeFactory().createNode("AN", 5, new SimpleNodeList(n6), false); + n4 = getNodeFactory().createNode("DANA", 4, SimpleNodeList.EMPTY, false); + n3 = getNodeFactory().createNode("N", 3, new SimpleNodeList(n4, n5), false); // note: it should sort these such that n5 is first + n2 = getNodeFactory().createNode("A", 2, new SimpleNodeList(n3), false); + n1 = getNodeFactory().createNode("B", 1, new SimpleNodeList(n2), false); //noinspection NullableProblems - root = getNodeFactory().createNode("", null, Arrays.asList(n1), true); + root = getNodeFactory().createNode("", null, new SimpleNodeList(n1), true); // Overwrite the tree's default root with the one built by hand... tree.root = root; @@ -954,7 +955,7 @@ public void testSearchResult_FailureToClassify1() { @Test(expected = IllegalStateException.class) public void testSearchResult_FailureToClassify2() { // Testing the various (unlikely) ways to fall through classification to have the exception thrown... - Node dummyNodeFound = getNodeFactory().createNode("DUMMY", 1, Collections.emptyList(), false); + Node dummyNodeFound = getNodeFactory().createNode("DUMMY", 1, SimpleNodeList.EMPTY, false); new ConcurrentRadixTree.SearchResult("DUMMY", dummyNodeFound, 5, 70, null, null); } @@ -962,7 +963,7 @@ public void testSearchResult_FailureToClassify2() { @Test(expected = IllegalStateException.class) public void testSearchResult_FailureToClassify3() { // Testing the various (unlikely) ways to fall through classification to have the exception thrown... - Node dummyNodeFound = getNodeFactory().createNode("DUMMY", 1, Collections.emptyList(), false); + Node dummyNodeFound = getNodeFactory().createNode("DUMMY", 1, SimpleNodeList.EMPTY, false); new ConcurrentRadixTree.SearchResult("DUMMY", dummyNodeFound, 4, 70, null, null); } diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultByteArrayNodeFactoryTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultByteArrayNodeFactoryTest.java index 24bb7b6..e5b7ac5 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultByteArrayNodeFactoryTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultByteArrayNodeFactoryTest.java @@ -16,6 +16,7 @@ package com.googlecode.concurrenttrees.radix.node.concrete; import com.googlecode.concurrenttrees.radix.node.Node; +import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; import org.junit.Before; import org.junit.Test; @@ -39,14 +40,14 @@ public void setUp() { public void testCreateNode_NullEdge() throws Exception { assertTrue(assertions); //noinspection NullableProblems - new DefaultByteArrayNodeFactory().createNode(null, 1, Collections.emptyList(), false); + new DefaultByteArrayNodeFactory().createNode(null, 1, SimpleNodeList.EMPTY, false); } @Test(expected = AssertionError.class) public void testCreateNode_EmptyEdgeNonRoot() throws Exception { assertTrue(assertions); //noinspection NullableProblems - new DefaultByteArrayNodeFactory().createNode("", 1, Collections.emptyList(), false); + new DefaultByteArrayNodeFactory().createNode("", 1, SimpleNodeList.EMPTY, false); } @Test(expected = AssertionError.class) diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharArrayNodeFactoryTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharArrayNodeFactoryTest.java index 83c343a..dedb905 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharArrayNodeFactoryTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharArrayNodeFactoryTest.java @@ -16,6 +16,7 @@ package com.googlecode.concurrenttrees.radix.node.concrete; import com.googlecode.concurrenttrees.radix.node.Node; +import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; import org.junit.Before; import org.junit.Test; @@ -39,14 +40,14 @@ public void setUp() { public void testCreateNode_NullEdge() throws Exception { assertTrue(assertions); //noinspection NullableProblems - new DefaultCharArrayNodeFactory().createNode(null, 1, Collections.emptyList(), false); + new DefaultCharArrayNodeFactory().createNode(null, 1, SimpleNodeList.EMPTY, false); } @Test(expected = AssertionError.class) public void testCreateNode_EmptyEdgeNonRoot() throws Exception { assertTrue(assertions); //noinspection NullableProblems - new DefaultCharArrayNodeFactory().createNode("", 1, Collections.emptyList(), false); + new DefaultCharArrayNodeFactory().createNode("", 1, SimpleNodeList.EMPTY, false); } @Test(expected = AssertionError.class) diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharSequenceNodeFactoryTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharSequenceNodeFactoryTest.java index aeab776..fc718a2 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharSequenceNodeFactoryTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharSequenceNodeFactoryTest.java @@ -16,6 +16,7 @@ package com.googlecode.concurrenttrees.radix.node.concrete; import com.googlecode.concurrenttrees.radix.node.Node; +import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; import org.junit.Before; import org.junit.Test; @@ -39,14 +40,14 @@ public void setUp() { public void testCreateNode_NullEdge() throws Exception { assertTrue(assertions); //noinspection NullableProblems - new DefaultCharSequenceNodeFactory().createNode(null, 1, Collections.emptyList(), false); + new DefaultCharSequenceNodeFactory().createNode(null, 1, SimpleNodeList.EMPTY, false); } @Test(expected = AssertionError.class) public void testCreateNode_EmptyEdgeNonRoot() throws Exception { assertTrue(assertions); //noinspection NullableProblems - new DefaultCharSequenceNodeFactory().createNode("", 1, Collections.emptyList(), false); + new DefaultCharSequenceNodeFactory().createNode("", 1, SimpleNodeList.EMPTY, false); } @Test(expected = AssertionError.class) diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/SmartArrayBasedNodeFactoryTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/SmartArrayBasedNodeFactoryTest.java index b2eef36..edf17d7 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/SmartArrayBasedNodeFactoryTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/SmartArrayBasedNodeFactoryTest.java @@ -16,6 +16,7 @@ package com.googlecode.concurrenttrees.radix.node.concrete; import com.googlecode.concurrenttrees.radix.node.Node; +import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; import com.googlecode.concurrenttrees.radix.node.concrete.bytearray.ByteArrayNodeLeafVoidValue; import com.googlecode.concurrenttrees.radix.node.concrete.chararray.CharArrayNodeLeafVoidValue; import com.googlecode.concurrenttrees.radix.node.concrete.voidvalue.VoidValue; @@ -33,13 +34,13 @@ public class SmartArrayBasedNodeFactoryTest { @Test public void testCreateNode_CompatibleCharacters() throws Exception { - Node node = smartNodeFactory.createNode("FOOBAR", VoidValue.SINGLETON, Collections.emptyList(), false); + Node node = smartNodeFactory.createNode("FOOBAR", VoidValue.SINGLETON, SimpleNodeList.EMPTY, false); Assert.assertEquals(ByteArrayNodeLeafVoidValue.class, node.getClass()); } @Test public void testCreateNode_IncompatibleCharacters() throws Exception { - Node node = smartNodeFactory.createNode("FOOBAR○", VoidValue.SINGLETON, Collections.emptyList(), false); + Node node = smartNodeFactory.createNode("FOOBAR○", VoidValue.SINGLETON, SimpleNodeList.EMPTY, false); Assert.assertEquals(CharArrayNodeLeafVoidValue.class, node.getClass()); } } diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeDefaultTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeDefaultTest.java index 70eebd9..28930dd 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeDefaultTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeDefaultTest.java @@ -16,6 +16,7 @@ package com.googlecode.concurrenttrees.radix.node.concrete.bytearray; import com.googlecode.concurrenttrees.radix.node.Node; +import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; import org.junit.Test; import java.util.Collections; @@ -27,7 +28,7 @@ public class ByteArrayNodeDefaultTest { @Test(expected = IllegalStateException.class) public void testUpdateOutgoingEdge_NonExistentEdge() throws Exception { - Node node = new ByteArrayNodeDefault("FOO", null, Collections.emptyList()); - node.updateOutgoingEdge(new ByteArrayNodeDefault("BAR", null, Collections.emptyList())); + Node node = new ByteArrayNodeDefault("FOO", null, SimpleNodeList.EMPTY); + node.updateOutgoingEdge(new ByteArrayNodeDefault("BAR", null, SimpleNodeList.EMPTY)); } } diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafNullValueTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafNullValueTest.java index b74ff2b..fe78109 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafNullValueTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafNullValueTest.java @@ -16,6 +16,7 @@ package com.googlecode.concurrenttrees.radix.node.concrete.bytearray; import com.googlecode.concurrenttrees.radix.node.Node; +import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; import org.junit.Assert; import org.junit.Test; @@ -29,7 +30,7 @@ public class ByteArrayNodeLeafNullValueTest { @Test(expected = IllegalStateException.class) public void testUpdateOutgoingEdge() throws Exception { Node node = new ByteArrayNodeLeafNullValue("FOO"); - node.updateOutgoingEdge(new ByteArrayNodeDefault("BAR", null, Collections.emptyList())); + node.updateOutgoingEdge(new ByteArrayNodeDefault("BAR", null, SimpleNodeList.EMPTY)); } @Test diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafVoidValueTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafVoidValueTest.java index 1da516b..f976ae2 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafVoidValueTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafVoidValueTest.java @@ -16,6 +16,7 @@ package com.googlecode.concurrenttrees.radix.node.concrete.bytearray; import com.googlecode.concurrenttrees.radix.node.Node; +import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; import org.junit.Assert; import org.junit.Test; @@ -29,7 +30,7 @@ public class ByteArrayNodeLeafVoidValueTest { @Test(expected = IllegalStateException.class) public void testUpdateOutgoingEdge() throws Exception { Node node = new ByteArrayNodeLeafVoidValue("FOO"); - node.updateOutgoingEdge(new ByteArrayNodeDefault("BAR", null, Collections.emptyList())); + node.updateOutgoingEdge(new ByteArrayNodeDefault("BAR", null, SimpleNodeList.EMPTY)); } @Test diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafWithValueTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafWithValueTest.java index abe35f0..adfccc3 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafWithValueTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafWithValueTest.java @@ -16,6 +16,7 @@ package com.googlecode.concurrenttrees.radix.node.concrete.bytearray; import com.googlecode.concurrenttrees.radix.node.Node; +import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; import org.junit.Assert; import org.junit.Test; @@ -29,7 +30,7 @@ public class ByteArrayNodeLeafWithValueTest { @Test(expected = IllegalStateException.class) public void testUpdateOutgoingEdge() throws Exception { Node node = new ByteArrayNodeLeafWithValue("FOO", 1); - node.updateOutgoingEdge(new ByteArrayNodeDefault("BAR", null, Collections.emptyList())); + node.updateOutgoingEdge(new ByteArrayNodeDefault("BAR", null, SimpleNodeList.EMPTY)); } @Test diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafNullValueTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafNullValueTest.java index 7289d90..6ad9220 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafNullValueTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafNullValueTest.java @@ -16,6 +16,7 @@ package com.googlecode.concurrenttrees.radix.node.concrete.bytearray; import com.googlecode.concurrenttrees.radix.node.Node; +import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; import org.junit.Assert; import org.junit.Test; @@ -29,19 +30,19 @@ public class ByteArrayNodeNonLeafNullValueTest { @Test public void testUpdateOutgoingEdge() throws Exception { - Node node = new ByteArrayNodeNonLeafNullValue("FOO", Arrays.asList((Node)new ByteArrayNodeDefault("BAR1", 1, Collections.emptyList()))); - node.updateOutgoingEdge(new ByteArrayNodeDefault("BAR2", null, Collections.emptyList())); + Node node = new ByteArrayNodeNonLeafNullValue("FOO", new SimpleNodeList(new ByteArrayNodeDefault("BAR1", 1, SimpleNodeList.EMPTY))); + node.updateOutgoingEdge(new ByteArrayNodeDefault("BAR2", null, SimpleNodeList.EMPTY)); } @Test(expected = IllegalStateException.class) public void testUpdateOutgoingEdge_NonExistentEdge() throws Exception { - Node node = new ByteArrayNodeNonLeafNullValue("FOO", Arrays.asList((Node)new ByteArrayNodeDefault("BAR", 1, Collections.emptyList()))); - node.updateOutgoingEdge(new ByteArrayNodeDefault("CAR", null, Collections.emptyList())); + Node node = new ByteArrayNodeNonLeafNullValue("FOO", new SimpleNodeList(new ByteArrayNodeDefault("BAR", 1, SimpleNodeList.EMPTY))); + node.updateOutgoingEdge(new ByteArrayNodeDefault("CAR", null, SimpleNodeList.EMPTY)); } @Test public void testToString() throws Exception { - Node node = new ByteArrayNodeNonLeafNullValue("FOO", Collections.emptyList()); + Node node = new ByteArrayNodeNonLeafNullValue("FOO", SimpleNodeList.EMPTY); Assert.assertEquals("Node{edge=FOO, value=null, edges=[]}", node.toString()); } } diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafVoidValueTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafVoidValueTest.java index 00b2b7c..6ca20c2 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafVoidValueTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafVoidValueTest.java @@ -16,6 +16,7 @@ package com.googlecode.concurrenttrees.radix.node.concrete.bytearray; import com.googlecode.concurrenttrees.radix.node.Node; +import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; import org.junit.Assert; import org.junit.Test; @@ -29,32 +30,32 @@ public class ByteArrayNodeNonLeafVoidValueTest { @Test public void testUpdateOutgoingEdge() throws Exception { - Node node = new ByteArrayNodeNonLeafVoidValue("FOO", Arrays.asList((Node) new ByteArrayNodeDefault("BAR1", 1, Collections.emptyList()))); - node.updateOutgoingEdge(new ByteArrayNodeDefault("BAR2", null, Collections.emptyList())); + Node node = new ByteArrayNodeNonLeafVoidValue("FOO", new SimpleNodeList(new ByteArrayNodeDefault("BAR1", 1, SimpleNodeList.EMPTY))); + node.updateOutgoingEdge(new ByteArrayNodeDefault("BAR2", null, SimpleNodeList.EMPTY)); } @Test(expected = IllegalStateException.class) public void testUpdateOutgoingEdge_NonExistentEdge() throws Exception { - Node node = new ByteArrayNodeNonLeafVoidValue("FOO", Arrays.asList((Node)new ByteArrayNodeDefault("BAR", 1, Collections.emptyList()))); - node.updateOutgoingEdge(new ByteArrayNodeDefault("CAR", null, Collections.emptyList())); + Node node = new ByteArrayNodeNonLeafVoidValue("FOO", new SimpleNodeList(new ByteArrayNodeDefault("BAR", 1, SimpleNodeList.EMPTY))); + node.updateOutgoingEdge(new ByteArrayNodeDefault("CAR", null, SimpleNodeList.EMPTY)); } @Test public void testToString() throws Exception { - Node node = new ByteArrayNodeNonLeafVoidValue("FOO", Collections.emptyList()); + Node node = new ByteArrayNodeNonLeafVoidValue("FOO", SimpleNodeList.EMPTY); Assert.assertEquals("Node{edge=FOO, value=-, edges=[]}", node.toString()); } @Test public void testGetOutgoingEdge() throws Exception { - Node node = new ByteArrayNodeNonLeafVoidValue("FOO", Arrays.asList((Node) new ByteArrayNodeDefault("BAR1", 1, Collections.emptyList()))); + Node node = new ByteArrayNodeNonLeafVoidValue("FOO", new SimpleNodeList(new ByteArrayNodeDefault("BAR1", 1, SimpleNodeList.EMPTY))); Assert.assertNotNull(node.getOutgoingEdge('B')); Assert.assertEquals(1, node.getOutgoingEdge('B').getValue()); } @Test public void testGetOutgoingEdge_NonExistent() throws Exception { - Node node = new ByteArrayNodeNonLeafVoidValue("FOO", Arrays.asList((Node) new ByteArrayNodeDefault("BAR1", 1, Collections.emptyList()))); + Node node = new ByteArrayNodeNonLeafVoidValue("FOO", new SimpleNodeList(new ByteArrayNodeDefault("BAR1", 1, SimpleNodeList.EMPTY))); Assert.assertNull(node.getOutgoingEdge('C')); } } diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeDefaultTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeDefaultTest.java index 1f9710d..8bc74b1 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeDefaultTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeDefaultTest.java @@ -16,6 +16,7 @@ package com.googlecode.concurrenttrees.radix.node.concrete.chararray; import com.googlecode.concurrenttrees.radix.node.Node; +import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; import com.googlecode.concurrenttrees.radix.node.concrete.chararray.CharArrayNodeDefault; import org.junit.Test; @@ -28,7 +29,7 @@ public class CharArrayNodeDefaultTest { @Test(expected = IllegalStateException.class) public void testUpdateOutgoingEdge_NonExistentEdge() throws Exception { - Node node = new CharArrayNodeDefault("FOO", null, Collections.emptyList()); - node.updateOutgoingEdge(new CharArrayNodeDefault("BAR", null, Collections.emptyList())); + Node node = new CharArrayNodeDefault("FOO", null, SimpleNodeList.EMPTY); + node.updateOutgoingEdge(new CharArrayNodeDefault("BAR", null, SimpleNodeList.EMPTY)); } } diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafNullValueTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafNullValueTest.java index d98b8d9..a34c4a0 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafNullValueTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafNullValueTest.java @@ -16,6 +16,7 @@ package com.googlecode.concurrenttrees.radix.node.concrete.chararray; import com.googlecode.concurrenttrees.radix.node.Node; +import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; import org.junit.Assert; import org.junit.Test; @@ -29,7 +30,7 @@ public class CharArrayNodeLeafNullValueTest { @Test(expected = IllegalStateException.class) public void testUpdateOutgoingEdge() throws Exception { Node node = new CharArrayNodeLeafNullValue("FOO"); - node.updateOutgoingEdge(new CharArrayNodeDefault("BAR", null, Collections.emptyList())); + node.updateOutgoingEdge(new CharArrayNodeDefault("BAR", null, SimpleNodeList.EMPTY)); } @Test diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafVoidValueTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafVoidValueTest.java index 258c7ff..e0d5319 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafVoidValueTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafVoidValueTest.java @@ -16,6 +16,7 @@ package com.googlecode.concurrenttrees.radix.node.concrete.chararray; import com.googlecode.concurrenttrees.radix.node.Node; +import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; import org.junit.Assert; import org.junit.Test; @@ -29,7 +30,7 @@ public class CharArrayNodeLeafVoidValueTest { @Test(expected = IllegalStateException.class) public void testUpdateOutgoingEdge() throws Exception { Node node = new CharArrayNodeLeafVoidValue("FOO"); - node.updateOutgoingEdge(new CharArrayNodeDefault("BAR", null, Collections.emptyList())); + node.updateOutgoingEdge(new CharArrayNodeDefault("BAR", null, SimpleNodeList.EMPTY)); } @Test diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafWithValueTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafWithValueTest.java index dce199a..790558c 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafWithValueTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafWithValueTest.java @@ -16,6 +16,7 @@ package com.googlecode.concurrenttrees.radix.node.concrete.chararray; import com.googlecode.concurrenttrees.radix.node.Node; +import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; import org.junit.Assert; import org.junit.Test; @@ -29,7 +30,7 @@ public class CharArrayNodeLeafWithValueTest { @Test(expected = IllegalStateException.class) public void testUpdateOutgoingEdge() throws Exception { Node node = new CharArrayNodeLeafWithValue("FOO", 1); - node.updateOutgoingEdge(new CharArrayNodeDefault("BAR", null, Collections.emptyList())); + node.updateOutgoingEdge(new CharArrayNodeDefault("BAR", null, SimpleNodeList.EMPTY)); } @Test diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafNullValueTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafNullValueTest.java index 9810914..7ffb113 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafNullValueTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafNullValueTest.java @@ -16,6 +16,7 @@ package com.googlecode.concurrenttrees.radix.node.concrete.chararray; import com.googlecode.concurrenttrees.radix.node.Node; +import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; import org.junit.Assert; import org.junit.Test; @@ -29,19 +30,19 @@ public class CharArrayNodeNonLeafNullValueTest { @Test public void testUpdateOutgoingEdge() throws Exception { - Node node = new CharArrayNodeNonLeafNullValue("FOO", Arrays.asList((Node)new CharArrayNodeDefault("BAR1", 1, Collections.emptyList()))); - node.updateOutgoingEdge(new CharArrayNodeDefault("BAR2", null, Collections.emptyList())); + Node node = new CharArrayNodeNonLeafNullValue("FOO", new SimpleNodeList(new CharArrayNodeDefault("BAR1", 1, SimpleNodeList.EMPTY))); + node.updateOutgoingEdge(new CharArrayNodeDefault("BAR2", null, SimpleNodeList.EMPTY)); } @Test(expected = IllegalStateException.class) public void testUpdateOutgoingEdge_NonExistentEdge() throws Exception { - Node node = new CharArrayNodeNonLeafNullValue("FOO", Arrays.asList((Node)new CharArrayNodeDefault("BAR", 1, Collections.emptyList()))); - node.updateOutgoingEdge(new CharArrayNodeDefault("CAR", null, Collections.emptyList())); + Node node = new CharArrayNodeNonLeafNullValue("FOO", new SimpleNodeList(new CharArrayNodeDefault("BAR", 1, SimpleNodeList.EMPTY))); + node.updateOutgoingEdge(new CharArrayNodeDefault("CAR", null, SimpleNodeList.EMPTY)); } @Test public void testToString() throws Exception { - Node node = new CharArrayNodeNonLeafNullValue("FOO", Collections.emptyList()); + Node node = new CharArrayNodeNonLeafNullValue("FOO", SimpleNodeList.EMPTY); Assert.assertEquals("Node{edge=FOO, value=null, edges=[]}", node.toString()); } } diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafVoidValueTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafVoidValueTest.java index 71720dc..aeffd5a 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafVoidValueTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafVoidValueTest.java @@ -16,6 +16,7 @@ package com.googlecode.concurrenttrees.radix.node.concrete.chararray; import com.googlecode.concurrenttrees.radix.node.Node; +import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; import org.junit.Assert; import org.junit.Test; @@ -29,32 +30,32 @@ public class CharArrayNodeNonLeafVoidValueTest { @Test public void testUpdateOutgoingEdge() throws Exception { - Node node = new CharArrayNodeNonLeafVoidValue("FOO", Arrays.asList((Node) new CharArrayNodeDefault("BAR1", 1, Collections.emptyList()))); - node.updateOutgoingEdge(new CharArrayNodeDefault("BAR2", null, Collections.emptyList())); + Node node = new CharArrayNodeNonLeafVoidValue("FOO", new SimpleNodeList(new CharArrayNodeDefault("BAR1", 1, SimpleNodeList.EMPTY))); + node.updateOutgoingEdge(new CharArrayNodeDefault("BAR2", null, SimpleNodeList.EMPTY)); } @Test(expected = IllegalStateException.class) public void testUpdateOutgoingEdge_NonExistentEdge() throws Exception { - Node node = new CharArrayNodeNonLeafVoidValue("FOO", Arrays.asList((Node)new CharArrayNodeDefault("BAR", 1, Collections.emptyList()))); - node.updateOutgoingEdge(new CharArrayNodeDefault("CAR", null, Collections.emptyList())); + Node node = new CharArrayNodeNonLeafVoidValue("FOO", new SimpleNodeList(new CharArrayNodeDefault("BAR", 1, SimpleNodeList.EMPTY))); + node.updateOutgoingEdge(new CharArrayNodeDefault("CAR", null, SimpleNodeList.EMPTY)); } @Test public void testToString() throws Exception { - Node node = new CharArrayNodeNonLeafVoidValue("FOO", Collections.emptyList()); + Node node = new CharArrayNodeNonLeafVoidValue("FOO", SimpleNodeList.EMPTY); Assert.assertEquals("Node{edge=FOO, value=-, edges=[]}", node.toString()); } @Test public void testGetOutgoingEdge() throws Exception { - Node node = new CharArrayNodeNonLeafVoidValue("FOO", Arrays.asList((Node) new CharArrayNodeDefault("BAR1", 1, Collections.emptyList()))); + Node node = new CharArrayNodeNonLeafVoidValue("FOO", new SimpleNodeList(new CharArrayNodeDefault("BAR1", 1, SimpleNodeList.EMPTY))); Assert.assertNotNull(node.getOutgoingEdge('B')); Assert.assertEquals(1, node.getOutgoingEdge('B').getValue()); } @Test public void testGetOutgoingEdge_NonExistent() throws Exception { - Node node = new CharArrayNodeNonLeafVoidValue("FOO", Arrays.asList((Node) new CharArrayNodeDefault("BAR1", 1, Collections.emptyList()))); + Node node = new CharArrayNodeNonLeafVoidValue("FOO", new SimpleNodeList(new CharArrayNodeDefault("BAR1", 1, SimpleNodeList.EMPTY))); Assert.assertNull(node.getOutgoingEdge('C')); } } diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafNullValueTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafNullValueTest.java index 61b3f37..b2ff8bc 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafNullValueTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafNullValueTest.java @@ -16,6 +16,7 @@ package com.googlecode.concurrenttrees.radix.node.concrete.charsequence; import com.googlecode.concurrenttrees.radix.node.Node; +import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; import org.junit.Assert; import org.junit.Test; @@ -29,7 +30,7 @@ public class CharSequenceNodeLeafNullValueTest { @Test(expected = IllegalStateException.class) public void testUpdateOutgoingEdge() throws Exception { Node node = new CharSequenceNodeLeafNullValue("FOO"); - node.updateOutgoingEdge(new CharSequenceNodeDefault("BAR", null, Collections.emptyList())); + node.updateOutgoingEdge(new CharSequenceNodeDefault("BAR", null, SimpleNodeList.EMPTY)); } @Test diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafVoidValueTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafVoidValueTest.java index 32db579..03431c6 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafVoidValueTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafVoidValueTest.java @@ -16,6 +16,7 @@ package com.googlecode.concurrenttrees.radix.node.concrete.charsequence; import com.googlecode.concurrenttrees.radix.node.Node; +import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; import org.junit.Assert; import org.junit.Test; @@ -29,7 +30,7 @@ public class CharSequenceNodeLeafVoidValueTest { @Test(expected = IllegalStateException.class) public void testUpdateOutgoingEdge() throws Exception { Node node = new CharSequenceNodeLeafVoidValue("FOO"); - node.updateOutgoingEdge(new CharSequenceNodeDefault("BAR", null, Collections.emptyList())); + node.updateOutgoingEdge(new CharSequenceNodeDefault("BAR", null, SimpleNodeList.EMPTY)); } @Test diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafWithValueTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafWithValueTest.java index e5c1aaf..c2ec6f5 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafWithValueTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafWithValueTest.java @@ -16,6 +16,7 @@ package com.googlecode.concurrenttrees.radix.node.concrete.charsequence; import com.googlecode.concurrenttrees.radix.node.Node; +import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; import org.junit.Assert; import org.junit.Test; @@ -29,7 +30,7 @@ public class CharSequenceNodeLeafWithValueTest { @Test(expected = IllegalStateException.class) public void testUpdateOutgoingEdge() throws Exception { Node node = new CharSequenceNodeLeafWithValue("FOO", 1); - node.updateOutgoingEdge(new CharSequenceNodeDefault("BAR", null, Collections.emptyList())); + node.updateOutgoingEdge(new CharSequenceNodeDefault("BAR", null, SimpleNodeList.EMPTY)); } @Test diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafNullValueTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafNullValueTest.java index 6476135..bf664fb 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafNullValueTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafNullValueTest.java @@ -16,6 +16,7 @@ package com.googlecode.concurrenttrees.radix.node.concrete.charsequence; import com.googlecode.concurrenttrees.radix.node.Node; +import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; import org.junit.Assert; import org.junit.Test; @@ -29,19 +30,19 @@ public class CharSequenceNodeNonLeafNullValueTest { @Test public void testUpdateOutgoingEdge() throws Exception { - Node node = new CharSequenceNodeNonLeafNullValue("FOO", Arrays.asList((Node)new CharSequenceNodeDefault("BAR1", 1, Collections.emptyList()))); - node.updateOutgoingEdge(new CharSequenceNodeDefault("BAR2", null, Collections.emptyList())); + Node node = new CharSequenceNodeNonLeafNullValue("FOO", new SimpleNodeList(new CharSequenceNodeDefault("BAR1", 1, SimpleNodeList.EMPTY))); + node.updateOutgoingEdge(new CharSequenceNodeDefault("BAR2", null, SimpleNodeList.EMPTY)); } @Test(expected = IllegalStateException.class) public void testUpdateOutgoingEdge_NonExistentEdge() throws Exception { - Node node = new CharSequenceNodeNonLeafNullValue("FOO", Arrays.asList((Node)new CharSequenceNodeDefault("BAR", 1, Collections.emptyList()))); - node.updateOutgoingEdge(new CharSequenceNodeDefault("CAR", null, Collections.emptyList())); + Node node = new CharSequenceNodeNonLeafNullValue("FOO", new SimpleNodeList(new CharSequenceNodeDefault("BAR", 1, SimpleNodeList.EMPTY))); + node.updateOutgoingEdge(new CharSequenceNodeDefault("CAR", null, SimpleNodeList.EMPTY)); } @Test public void testToString() throws Exception { - Node node = new CharSequenceNodeNonLeafNullValue("FOO", Collections.emptyList()); + Node node = new CharSequenceNodeNonLeafNullValue("FOO", SimpleNodeList.EMPTY); Assert.assertEquals("Node{edge=FOO, value=null, edges=[]}", node.toString()); } } diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafVoidValueTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafVoidValueTest.java index da0b1c3..38dfd55 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafVoidValueTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafVoidValueTest.java @@ -16,6 +16,7 @@ package com.googlecode.concurrenttrees.radix.node.concrete.charsequence; import com.googlecode.concurrenttrees.radix.node.Node; +import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; import org.junit.Assert; import org.junit.Test; @@ -29,32 +30,32 @@ public class CharSequenceNodeNonLeafVoidValueTest { @Test public void testUpdateOutgoingEdge() throws Exception { - Node node = new CharSequenceNodeNonLeafVoidValue("FOO", Arrays.asList((Node) new CharSequenceNodeDefault("BAR1", 1, Collections.emptyList()))); - node.updateOutgoingEdge(new CharSequenceNodeDefault("BAR2", null, Collections.emptyList())); + Node node = new CharSequenceNodeNonLeafVoidValue("FOO", new SimpleNodeList(new CharSequenceNodeDefault("BAR1", 1, SimpleNodeList.EMPTY))); + node.updateOutgoingEdge(new CharSequenceNodeDefault("BAR2", null, SimpleNodeList.EMPTY)); } @Test(expected = IllegalStateException.class) public void testUpdateOutgoingEdge_NonExistentEdge() throws Exception { - Node node = new CharSequenceNodeNonLeafVoidValue("FOO", Arrays.asList((Node)new CharSequenceNodeDefault("BAR", 1, Collections.emptyList()))); - node.updateOutgoingEdge(new CharSequenceNodeDefault("CAR", null, Collections.emptyList())); + Node node = new CharSequenceNodeNonLeafVoidValue("FOO", new SimpleNodeList(new CharSequenceNodeDefault("BAR", 1, SimpleNodeList.EMPTY))); + node.updateOutgoingEdge(new CharSequenceNodeDefault("CAR", null, SimpleNodeList.EMPTY)); } @Test public void testToString() throws Exception { - Node node = new CharSequenceNodeNonLeafVoidValue("FOO", Collections.emptyList()); + Node node = new CharSequenceNodeNonLeafVoidValue("FOO", SimpleNodeList.EMPTY); Assert.assertEquals("Node{edge=FOO, value=-, edges=[]}", node.toString()); } @Test public void testGetOutgoingEdge() throws Exception { - Node node = new CharSequenceNodeNonLeafVoidValue("FOO", Arrays.asList((Node) new CharSequenceNodeDefault("BAR1", 1, Collections.emptyList()))); + Node node = new CharSequenceNodeNonLeafVoidValue("FOO", new SimpleNodeList(new CharSequenceNodeDefault("BAR1", 1, SimpleNodeList.EMPTY))); Assert.assertNotNull(node.getOutgoingEdge('B')); Assert.assertEquals(1, node.getOutgoingEdge('B').getValue()); } @Test public void testGetOutgoingEdge_NonExistent() throws Exception { - Node node = new CharSequenceNodeNonLeafVoidValue("FOO", Arrays.asList((Node) new CharSequenceNodeDefault("BAR1", 1, Collections.emptyList()))); + Node node = new CharSequenceNodeNonLeafVoidValue("FOO", new SimpleNodeList(new CharSequenceNodeDefault("BAR1", 1, SimpleNodeList.EMPTY))); Assert.assertNull(node.getOutgoingEdge('C')); } } diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/DefaultCharSequenceNodeTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/DefaultCharSequenceNodeTest.java index 87620a9..e7ba794 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/DefaultCharSequenceNodeTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/DefaultCharSequenceNodeTest.java @@ -16,6 +16,7 @@ package com.googlecode.concurrenttrees.radix.node.concrete.charsequence; import com.googlecode.concurrenttrees.radix.node.Node; +import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; import com.googlecode.concurrenttrees.radix.node.concrete.charsequence.CharSequenceNodeDefault; import org.junit.Assert; import org.junit.Test; @@ -29,14 +30,14 @@ public class DefaultCharSequenceNodeTest { @Test public void testToString() throws Exception { - Node node = new CharSequenceNodeDefault("FOO", null, Collections.emptyList()); + Node node = new CharSequenceNodeDefault("FOO", null, SimpleNodeList.EMPTY); Assert.assertEquals("Node{edge=FOO, value=null, edges=[]}", node.toString()); } @Test(expected = IllegalStateException.class) public void testUpdateOutgoingEdge_NonExistentEdge() throws Exception { - Node node = new CharSequenceNodeDefault("FOO", null, Collections.emptyList()); - node.updateOutgoingEdge(new CharSequenceNodeDefault("BAR", null, Collections.emptyList())); + Node node = new CharSequenceNodeDefault("FOO", null, SimpleNodeList.EMPTY); + node.updateOutgoingEdge(new CharSequenceNodeDefault("BAR", null, SimpleNodeList.EMPTY)); } } diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/util/NodeUtilTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/util/NodeUtilTest.java index 2714590..66ef14d 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/util/NodeUtilTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/util/NodeUtilTest.java @@ -17,6 +17,7 @@ import com.googlecode.concurrenttrees.radix.node.Node; import com.googlecode.concurrenttrees.radix.node.NodeFactory; +import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; import com.googlecode.concurrenttrees.radix.node.concrete.DefaultCharArrayNodeFactory; import org.junit.Assert; import org.junit.Test; @@ -38,9 +39,9 @@ public class NodeUtilTest { public void testBinarySearchForEdge() throws Exception { NodeFactory nodeFactory = new DefaultCharArrayNodeFactory(); Node[] nodes = new Node[] { - nodeFactory.createNode("A", null, Collections.emptyList(), false), - nodeFactory.createNode("B", null, Collections.emptyList(), false), - nodeFactory.createNode("C", null, Collections.emptyList(), false) + nodeFactory.createNode("A", null, SimpleNodeList.EMPTY, false), + nodeFactory.createNode("B", null, SimpleNodeList.EMPTY, false), + nodeFactory.createNode("C", null, SimpleNodeList.EMPTY, false) }; AtomicReferenceArray atomicReferenceArray = new AtomicReferenceArray(nodes); Assert.assertEquals(0, NodeUtil.binarySearchForEdge(atomicReferenceArray, 'A')); @@ -54,9 +55,9 @@ public void testBinarySearchForEdge() throws Exception { public void testEnsureNoDuplicateEdges_Positive() throws Exception { NodeFactory nodeFactory = new DefaultCharArrayNodeFactory(); List nodes = Arrays.asList( - nodeFactory.createNode("A", null, Collections.emptyList(), false), - nodeFactory.createNode("B", null, Collections.emptyList(), false), - nodeFactory.createNode("C", null, Collections.emptyList(), false) + nodeFactory.createNode("A", null, SimpleNodeList.EMPTY, false), + nodeFactory.createNode("B", null, SimpleNodeList.EMPTY, false), + nodeFactory.createNode("C", null, SimpleNodeList.EMPTY, false) ); } @@ -64,11 +65,11 @@ public void testEnsureNoDuplicateEdges_Positive() throws Exception { @SuppressWarnings({"NullableProblems"}) public void testEnsureNoDuplicateEdges_Negative() throws Exception { NodeFactory nodeFactory = new DefaultCharArrayNodeFactory(); - List nodes = Arrays.asList( - nodeFactory.createNode("A", null, Collections.emptyList(), false), - nodeFactory.createNode("B", null, Collections.emptyList(), false), - nodeFactory.createNode("B", null, Collections.emptyList(), false), - nodeFactory.createNode("C", null, Collections.emptyList(), false) + SimpleNodeList nodes = new SimpleNodeList( + nodeFactory.createNode("A", null, SimpleNodeList.EMPTY, false), + nodeFactory.createNode("B", null, SimpleNodeList.EMPTY, false), + nodeFactory.createNode("B", null, SimpleNodeList.EMPTY, false), + nodeFactory.createNode("C", null, SimpleNodeList.EMPTY, false) ); assertFalse(NodeUtil.hasNoDuplicateEdges(nodes)); } From dddccfb9e6f97ee61948d93b56637366fe5d4752 Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Mon, 26 Jul 2021 23:36:58 +0200 Subject: [PATCH 12/15] Remove dangling javadoc from tests. --- .../concurrenttrees/common/CharSequencesTest.java | 2 +- .../googlecode/concurrenttrees/common/IterablesTest.java | 2 +- .../concurrenttrees/common/LazyIteratorTest.java | 2 +- .../concurrenttrees/common/PrettyPrinterTest.java | 5 +---- .../ConcurrentRadixTreeInMemoryFileSystem.java | 2 +- .../examples/filesystem/InMemoryFileSystem.java | 2 +- .../examples/filesystem/InMemoryFileSystemUsage.java | 2 +- .../BuildShakespeareSinglePlaySuffixTree.java | 2 +- .../shakespeare/BuildShakespeareTragediesSuffixTree.java | 2 +- .../shakespeare/BuildShakespeareWordRadixTree.java | 2 +- .../shakespeare/BuildShakespeareWordSuffixTree.java | 2 +- .../examples/shakespeare/FindLongestCommonSubstring.java | 2 +- .../examples/shakespeare/util/IOUtil.java | 2 +- .../examples/usage/InvertedRadixTreeUsage.java | 2 +- .../concurrenttrees/examples/usage/IterablesUsage.java | 2 +- .../examples/usage/LCSubstringSolverUsage.java | 2 +- .../concurrenttrees/examples/usage/RadixTreeUsage.java | 2 +- .../examples/usage/ReversedRadixTreeUsage.java | 2 +- .../concurrenttrees/examples/usage/SuffixTreeUsage.java | 2 +- .../concurrenttrees/radix/ConcurrentRadixTreeTest.java | 9 +-------- .../node/concrete/DefaultByteArrayNodeFactoryTest.java | 2 +- .../node/concrete/DefaultCharArrayNodeFactoryTest.java | 2 +- .../concrete/DefaultCharSequenceNodeFactoryTest.java | 2 +- .../node/concrete/SmartArrayBasedNodeFactoryTest.java | 4 +--- .../concrete/bytearray/ByteArrayCharSequenceTest.java | 2 +- .../concrete/bytearray/ByteArrayNodeDefaultTest.java | 4 +--- .../bytearray/ByteArrayNodeLeafNullValueTest.java | 4 +--- .../bytearray/ByteArrayNodeLeafVoidValueTest.java | 4 +--- .../bytearray/ByteArrayNodeLeafWithValueTest.java | 4 +--- .../bytearray/ByteArrayNodeNonLeafNullValueTest.java | 5 +---- .../bytearray/ByteArrayNodeNonLeafVoidValueTest.java | 5 +---- .../ByteArrayNodeFactory_InvertedRadixTreeTest.java | 2 +- .../functional/ByteArrayNodeFactory_RadixTreeTest.java | 2 +- .../ByteArrayNodeFactory_ReversedRadixTreeTest.java | 2 +- .../functional/ByteArrayNodeFactory_SuffixTreeTest.java | 2 +- .../concrete/chararray/CharArrayNodeDefaultTest.java | 5 +---- .../chararray/CharArrayNodeLeafNullValueTest.java | 4 +--- .../chararray/CharArrayNodeLeafVoidValueTest.java | 4 +--- .../chararray/CharArrayNodeLeafWithValueTest.java | 4 +--- .../chararray/CharArrayNodeNonLeafNullValueTest.java | 5 +---- .../chararray/CharArrayNodeNonLeafVoidValueTest.java | 5 +---- .../charsequence/CharSequenceNodeLeafNullValueTest.java | 4 +--- .../charsequence/CharSequenceNodeLeafVoidValueTest.java | 4 +--- .../charsequence/CharSequenceNodeLeafWithValueTest.java | 4 +--- .../CharSequenceNodeNonLeafNullValueTest.java | 5 +---- .../CharSequenceNodeNonLeafVoidValueTest.java | 5 +---- .../charsequence/DefaultCharSequenceNodeTest.java | 5 +---- .../radix/node/concrete/voidvalue/VoidValueTest.java | 2 +- .../concurrenttrees/radix/node/util/NodeUtilTest.java | 2 +- .../radixinverted/ConcurrentInvertedRadixTreeTest.java | 2 +- .../radixreversed/ConcurrentReversedRadixTreeTest.java | 2 +- .../concurrenttrees/solver/LCSubstringSolverTest.java | 2 +- .../concurrenttrees/suffix/ConcurrentSuffixTreeTest.java | 2 +- .../googlecode/concurrenttrees/testutil/TestUtility.java | 2 +- 54 files changed, 54 insertions(+), 110 deletions(-) diff --git a/code/src/test/java/com/googlecode/concurrenttrees/common/CharSequencesTest.java b/code/src/test/java/com/googlecode/concurrenttrees/common/CharSequencesTest.java index 1dc4241..6d2d088 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/common/CharSequencesTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/common/CharSequencesTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/code/src/test/java/com/googlecode/concurrenttrees/common/IterablesTest.java b/code/src/test/java/com/googlecode/concurrenttrees/common/IterablesTest.java index 87386e6..9744015 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/common/IterablesTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/common/IterablesTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/code/src/test/java/com/googlecode/concurrenttrees/common/LazyIteratorTest.java b/code/src/test/java/com/googlecode/concurrenttrees/common/LazyIteratorTest.java index 4b43bba..2d02be9 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/common/LazyIteratorTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/common/LazyIteratorTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/code/src/test/java/com/googlecode/concurrenttrees/common/PrettyPrinterTest.java b/code/src/test/java/com/googlecode/concurrenttrees/common/PrettyPrinterTest.java index a467fc8..9030258 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/common/PrettyPrinterTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/common/PrettyPrinterTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,7 +17,6 @@ import com.googlecode.concurrenttrees.radix.node.Node; import com.googlecode.concurrenttrees.radix.node.NodeFactory; -import com.googlecode.concurrenttrees.radix.node.NodeList; import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; import com.googlecode.concurrenttrees.radix.node.concrete.DefaultCharArrayNodeFactory; import com.googlecode.concurrenttrees.radix.node.util.PrettyPrintable; @@ -25,8 +24,6 @@ import org.junit.Test; import java.io.IOException; -import java.util.Arrays; -import java.util.Collections; /** * @author Niall Gallagher diff --git a/code/src/test/java/com/googlecode/concurrenttrees/examples/filesystem/ConcurrentRadixTreeInMemoryFileSystem.java b/code/src/test/java/com/googlecode/concurrenttrees/examples/filesystem/ConcurrentRadixTreeInMemoryFileSystem.java index 592cbbf..9448064 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/examples/filesystem/ConcurrentRadixTreeInMemoryFileSystem.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/examples/filesystem/ConcurrentRadixTreeInMemoryFileSystem.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/code/src/test/java/com/googlecode/concurrenttrees/examples/filesystem/InMemoryFileSystem.java b/code/src/test/java/com/googlecode/concurrenttrees/examples/filesystem/InMemoryFileSystem.java index 6684ef2..3696445 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/examples/filesystem/InMemoryFileSystem.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/examples/filesystem/InMemoryFileSystem.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/code/src/test/java/com/googlecode/concurrenttrees/examples/filesystem/InMemoryFileSystemUsage.java b/code/src/test/java/com/googlecode/concurrenttrees/examples/filesystem/InMemoryFileSystemUsage.java index 1c50265..c406706 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/examples/filesystem/InMemoryFileSystemUsage.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/examples/filesystem/InMemoryFileSystemUsage.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/code/src/test/java/com/googlecode/concurrenttrees/examples/shakespeare/BuildShakespeareSinglePlaySuffixTree.java b/code/src/test/java/com/googlecode/concurrenttrees/examples/shakespeare/BuildShakespeareSinglePlaySuffixTree.java index daff253..c2af06c 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/examples/shakespeare/BuildShakespeareSinglePlaySuffixTree.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/examples/shakespeare/BuildShakespeareSinglePlaySuffixTree.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/code/src/test/java/com/googlecode/concurrenttrees/examples/shakespeare/BuildShakespeareTragediesSuffixTree.java b/code/src/test/java/com/googlecode/concurrenttrees/examples/shakespeare/BuildShakespeareTragediesSuffixTree.java index e080369..9511cf7 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/examples/shakespeare/BuildShakespeareTragediesSuffixTree.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/examples/shakespeare/BuildShakespeareTragediesSuffixTree.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/code/src/test/java/com/googlecode/concurrenttrees/examples/shakespeare/BuildShakespeareWordRadixTree.java b/code/src/test/java/com/googlecode/concurrenttrees/examples/shakespeare/BuildShakespeareWordRadixTree.java index 93a95d7..c4f9d3c 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/examples/shakespeare/BuildShakespeareWordRadixTree.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/examples/shakespeare/BuildShakespeareWordRadixTree.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/code/src/test/java/com/googlecode/concurrenttrees/examples/shakespeare/BuildShakespeareWordSuffixTree.java b/code/src/test/java/com/googlecode/concurrenttrees/examples/shakespeare/BuildShakespeareWordSuffixTree.java index e269c31..54454d3 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/examples/shakespeare/BuildShakespeareWordSuffixTree.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/examples/shakespeare/BuildShakespeareWordSuffixTree.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/code/src/test/java/com/googlecode/concurrenttrees/examples/shakespeare/FindLongestCommonSubstring.java b/code/src/test/java/com/googlecode/concurrenttrees/examples/shakespeare/FindLongestCommonSubstring.java index adeba2a..7c2d8ea 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/examples/shakespeare/FindLongestCommonSubstring.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/examples/shakespeare/FindLongestCommonSubstring.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/code/src/test/java/com/googlecode/concurrenttrees/examples/shakespeare/util/IOUtil.java b/code/src/test/java/com/googlecode/concurrenttrees/examples/shakespeare/util/IOUtil.java index 60e215d..771ec8c 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/examples/shakespeare/util/IOUtil.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/examples/shakespeare/util/IOUtil.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/code/src/test/java/com/googlecode/concurrenttrees/examples/usage/InvertedRadixTreeUsage.java b/code/src/test/java/com/googlecode/concurrenttrees/examples/usage/InvertedRadixTreeUsage.java index 70f9c11..3f5e5c8 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/examples/usage/InvertedRadixTreeUsage.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/examples/usage/InvertedRadixTreeUsage.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/code/src/test/java/com/googlecode/concurrenttrees/examples/usage/IterablesUsage.java b/code/src/test/java/com/googlecode/concurrenttrees/examples/usage/IterablesUsage.java index 0fca12c..23b89a5 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/examples/usage/IterablesUsage.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/examples/usage/IterablesUsage.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/code/src/test/java/com/googlecode/concurrenttrees/examples/usage/LCSubstringSolverUsage.java b/code/src/test/java/com/googlecode/concurrenttrees/examples/usage/LCSubstringSolverUsage.java index b094fe2..117ddec 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/examples/usage/LCSubstringSolverUsage.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/examples/usage/LCSubstringSolverUsage.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/code/src/test/java/com/googlecode/concurrenttrees/examples/usage/RadixTreeUsage.java b/code/src/test/java/com/googlecode/concurrenttrees/examples/usage/RadixTreeUsage.java index 33e7448..4404d4c 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/examples/usage/RadixTreeUsage.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/examples/usage/RadixTreeUsage.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/code/src/test/java/com/googlecode/concurrenttrees/examples/usage/ReversedRadixTreeUsage.java b/code/src/test/java/com/googlecode/concurrenttrees/examples/usage/ReversedRadixTreeUsage.java index 5314656..e51ae9d 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/examples/usage/ReversedRadixTreeUsage.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/examples/usage/ReversedRadixTreeUsage.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/code/src/test/java/com/googlecode/concurrenttrees/examples/usage/SuffixTreeUsage.java b/code/src/test/java/com/googlecode/concurrenttrees/examples/usage/SuffixTreeUsage.java index 3891a0c..69c9701 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/examples/usage/SuffixTreeUsage.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/examples/usage/SuffixTreeUsage.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/ConcurrentRadixTreeTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/ConcurrentRadixTreeTest.java index f194f71..82f4cf4 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/ConcurrentRadixTreeTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/ConcurrentRadixTreeTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,7 +15,6 @@ */ package com.googlecode.concurrenttrees.radix; -import com.googlecode.concurrenttrees.common.CharSequences; import com.googlecode.concurrenttrees.common.Iterables; import com.googlecode.concurrenttrees.common.KeyValuePair; import com.googlecode.concurrenttrees.common.PrettyPrinter; @@ -27,14 +26,8 @@ import com.googlecode.concurrenttrees.radix.node.concrete.voidvalue.VoidValue; import com.googlecode.concurrenttrees.radix.node.util.PrettyPrintable; import com.googlecode.concurrenttrees.testutil.TestUtility; -import junit.framework.Assert; import org.junit.Test; -import java.io.*; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - import static org.junit.Assert.*; /** * @author Niall Gallagher diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultByteArrayNodeFactoryTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultByteArrayNodeFactoryTest.java index e5b7ac5..a703cff 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultByteArrayNodeFactoryTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultByteArrayNodeFactoryTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharArrayNodeFactoryTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharArrayNodeFactoryTest.java index dedb905..50030b7 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharArrayNodeFactoryTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharArrayNodeFactoryTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharSequenceNodeFactoryTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharSequenceNodeFactoryTest.java index fc718a2..072c77e 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharSequenceNodeFactoryTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultCharSequenceNodeFactoryTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/SmartArrayBasedNodeFactoryTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/SmartArrayBasedNodeFactoryTest.java index edf17d7..bb7151c 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/SmartArrayBasedNodeFactoryTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/SmartArrayBasedNodeFactoryTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,8 +23,6 @@ import org.junit.Assert; import org.junit.Test; -import java.util.Collections; - /** * @author Niall Gallagher */ diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayCharSequenceTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayCharSequenceTest.java index 964ac7b..2b1b6ef 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayCharSequenceTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayCharSequenceTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeDefaultTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeDefaultTest.java index 28930dd..e529bed 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeDefaultTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeDefaultTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,8 +19,6 @@ import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; import org.junit.Test; -import java.util.Collections; - /** * @author Niall Gallagher */ diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafNullValueTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafNullValueTest.java index fe78109..2eaf397 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafNullValueTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafNullValueTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,8 +20,6 @@ import org.junit.Assert; import org.junit.Test; -import java.util.Collections; - /** * @author Niall Gallagher */ diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafVoidValueTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafVoidValueTest.java index f976ae2..923e893 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafVoidValueTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafVoidValueTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,8 +20,6 @@ import org.junit.Assert; import org.junit.Test; -import java.util.Collections; - /** * @author Niall Gallagher */ diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafWithValueTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafWithValueTest.java index adfccc3..79dc507 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafWithValueTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeLeafWithValueTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,8 +20,6 @@ import org.junit.Assert; import org.junit.Test; -import java.util.Collections; - /** * @author Niall Gallagher */ diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafNullValueTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafNullValueTest.java index 6ad9220..453ddc3 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafNullValueTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafNullValueTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,9 +20,6 @@ import org.junit.Assert; import org.junit.Test; -import java.util.Arrays; -import java.util.Collections; - /** * @author Niall Gallagher */ diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafVoidValueTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafVoidValueTest.java index 6ca20c2..7de33ae 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafVoidValueTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayNodeNonLeafVoidValueTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,9 +20,6 @@ import org.junit.Assert; import org.junit.Test; -import java.util.Arrays; -import java.util.Collections; - /** * @author Niall Gallagher */ diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/functional/ByteArrayNodeFactory_InvertedRadixTreeTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/functional/ByteArrayNodeFactory_InvertedRadixTreeTest.java index d510d8d..b8a62ad 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/functional/ByteArrayNodeFactory_InvertedRadixTreeTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/functional/ByteArrayNodeFactory_InvertedRadixTreeTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/functional/ByteArrayNodeFactory_RadixTreeTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/functional/ByteArrayNodeFactory_RadixTreeTest.java index 76cd67d..00ad050 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/functional/ByteArrayNodeFactory_RadixTreeTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/functional/ByteArrayNodeFactory_RadixTreeTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/functional/ByteArrayNodeFactory_ReversedRadixTreeTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/functional/ByteArrayNodeFactory_ReversedRadixTreeTest.java index c538c09..b15cc8c 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/functional/ByteArrayNodeFactory_ReversedRadixTreeTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/functional/ByteArrayNodeFactory_ReversedRadixTreeTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/functional/ByteArrayNodeFactory_SuffixTreeTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/functional/ByteArrayNodeFactory_SuffixTreeTest.java index 7cc0669..c31eb4a 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/functional/ByteArrayNodeFactory_SuffixTreeTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/functional/ByteArrayNodeFactory_SuffixTreeTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeDefaultTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeDefaultTest.java index 8bc74b1..c57f847 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeDefaultTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeDefaultTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,11 +17,8 @@ import com.googlecode.concurrenttrees.radix.node.Node; import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; -import com.googlecode.concurrenttrees.radix.node.concrete.chararray.CharArrayNodeDefault; import org.junit.Test; -import java.util.Collections; - /** * @author Niall Gallagher */ diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafNullValueTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafNullValueTest.java index a34c4a0..0cd57e9 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafNullValueTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafNullValueTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,8 +20,6 @@ import org.junit.Assert; import org.junit.Test; -import java.util.Collections; - /** * @author Niall Gallagher */ diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafVoidValueTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafVoidValueTest.java index e0d5319..62ce0ff 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafVoidValueTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafVoidValueTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,8 +20,6 @@ import org.junit.Assert; import org.junit.Test; -import java.util.Collections; - /** * @author Niall Gallagher */ diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafWithValueTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafWithValueTest.java index 790558c..011f348 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafWithValueTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeLeafWithValueTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,8 +20,6 @@ import org.junit.Assert; import org.junit.Test; -import java.util.Collections; - /** * @author Niall Gallagher */ diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafNullValueTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafNullValueTest.java index 7ffb113..27eb9b9 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafNullValueTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafNullValueTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,9 +20,6 @@ import org.junit.Assert; import org.junit.Test; -import java.util.Arrays; -import java.util.Collections; - /** * @author Niall Gallagher */ diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafVoidValueTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafVoidValueTest.java index aeffd5a..213e828 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafVoidValueTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/chararray/CharArrayNodeNonLeafVoidValueTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,9 +20,6 @@ import org.junit.Assert; import org.junit.Test; -import java.util.Arrays; -import java.util.Collections; - /** * @author Niall Gallagher */ diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafNullValueTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafNullValueTest.java index b2ff8bc..ebac4fa 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafNullValueTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafNullValueTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,8 +20,6 @@ import org.junit.Assert; import org.junit.Test; -import java.util.Collections; - /** * @author Niall Gallagher */ diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafVoidValueTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafVoidValueTest.java index 03431c6..d4d01e1 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafVoidValueTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafVoidValueTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,8 +20,6 @@ import org.junit.Assert; import org.junit.Test; -import java.util.Collections; - /** * @author Niall Gallagher */ diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafWithValueTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafWithValueTest.java index c2ec6f5..2c0b8cc 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafWithValueTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeLeafWithValueTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,8 +20,6 @@ import org.junit.Assert; import org.junit.Test; -import java.util.Collections; - /** * @author Niall Gallagher */ diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafNullValueTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafNullValueTest.java index bf664fb..3782b36 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafNullValueTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafNullValueTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,9 +20,6 @@ import org.junit.Assert; import org.junit.Test; -import java.util.Arrays; -import java.util.Collections; - /** * @author Niall Gallagher */ diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafVoidValueTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafVoidValueTest.java index 38dfd55..67a0603 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafVoidValueTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/CharSequenceNodeNonLeafVoidValueTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,9 +20,6 @@ import org.junit.Assert; import org.junit.Test; -import java.util.Arrays; -import java.util.Collections; - /** * @author Niall Gallagher */ diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/DefaultCharSequenceNodeTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/DefaultCharSequenceNodeTest.java index e7ba794..b5baeed 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/DefaultCharSequenceNodeTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/charsequence/DefaultCharSequenceNodeTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,12 +17,9 @@ import com.googlecode.concurrenttrees.radix.node.Node; import com.googlecode.concurrenttrees.radix.node.SimpleNodeList; -import com.googlecode.concurrenttrees.radix.node.concrete.charsequence.CharSequenceNodeDefault; import org.junit.Assert; import org.junit.Test; -import java.util.Collections; - /** * @author Niall Gallagher */ diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/voidvalue/VoidValueTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/voidvalue/VoidValueTest.java index 72ea803..c8a896b 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/voidvalue/VoidValueTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/concrete/voidvalue/VoidValueTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/util/NodeUtilTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/util/NodeUtilTest.java index 66ef14d..808d78f 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radix/node/util/NodeUtilTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radix/node/util/NodeUtilTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radixinverted/ConcurrentInvertedRadixTreeTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radixinverted/ConcurrentInvertedRadixTreeTest.java index 155a9b8..ee53de5 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radixinverted/ConcurrentInvertedRadixTreeTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radixinverted/ConcurrentInvertedRadixTreeTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/code/src/test/java/com/googlecode/concurrenttrees/radixreversed/ConcurrentReversedRadixTreeTest.java b/code/src/test/java/com/googlecode/concurrenttrees/radixreversed/ConcurrentReversedRadixTreeTest.java index 5bbcb2f..7f4469b 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/radixreversed/ConcurrentReversedRadixTreeTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/radixreversed/ConcurrentReversedRadixTreeTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/code/src/test/java/com/googlecode/concurrenttrees/solver/LCSubstringSolverTest.java b/code/src/test/java/com/googlecode/concurrenttrees/solver/LCSubstringSolverTest.java index b0cc40c..4367185 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/solver/LCSubstringSolverTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/solver/LCSubstringSolverTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/code/src/test/java/com/googlecode/concurrenttrees/suffix/ConcurrentSuffixTreeTest.java b/code/src/test/java/com/googlecode/concurrenttrees/suffix/ConcurrentSuffixTreeTest.java index 5b9645b..8bc7268 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/suffix/ConcurrentSuffixTreeTest.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/suffix/ConcurrentSuffixTreeTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/code/src/test/java/com/googlecode/concurrenttrees/testutil/TestUtility.java b/code/src/test/java/com/googlecode/concurrenttrees/testutil/TestUtility.java index f05173f..44e6b7a 100644 --- a/code/src/test/java/com/googlecode/concurrenttrees/testutil/TestUtility.java +++ b/code/src/test/java/com/googlecode/concurrenttrees/testutil/TestUtility.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2012-2013 Niall Gallagher * * Licensed under the Apache License, Version 2.0 (the "License"); From 2925f825fc09198421b423df9e6bc572fe6a4253 Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Tue, 27 Jul 2021 23:12:46 +0200 Subject: [PATCH 13/15] Remove fast exception in favor of nullcheck. --- .../concrete/DefaultByteArrayNodeFactory.java | 5 ++++- .../concrete/SmartArrayBasedNodeFactory.java | 8 ++++---- .../bytearray/ByteArrayCharSequence.java | 16 +++------------- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultByteArrayNodeFactory.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultByteArrayNodeFactory.java index 4abcf97..e4b478d 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultByteArrayNodeFactory.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/DefaultByteArrayNodeFactory.java @@ -54,7 +54,10 @@ public Node createNode(CharSequence edgeCharacters, Object value, NodeList child assert isRoot || edgeCharacters.length() > 0 : "Invalid edge characters for non-root node: " + CharSequences.toString(edgeCharacters); assert childNodes != null : "The edgeCharacters argument was null"; assert NodeUtil.hasNoDuplicateEdges(childNodes) : "Duplicate edge detected in list of nodes supplied: " + childNodes; - byte[] incomingEdgeCharArray = ByteArrayCharSequence.toSingleByteUtf8Encoding(edgeCharacters, true); + byte[] incomingEdgeCharArray = ByteArrayCharSequence.toSingleByteUtf8Encoding(edgeCharacters, fast); + if (incomingEdgeCharArray == null) { + return null; + } if (childNodes.isEmpty()) { // Leaf node... if (value instanceof VoidValue) { diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/SmartArrayBasedNodeFactory.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/SmartArrayBasedNodeFactory.java index 929ae24..582664b 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/SmartArrayBasedNodeFactory.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/SmartArrayBasedNodeFactory.java @@ -36,11 +36,11 @@ public class SmartArrayBasedNodeFactory implements NodeFactory { @Override public Node createNode(CharSequence edgeCharacters, Object value, NodeList childNodes, boolean isRoot) { - try { - return byteArrayNodeFactory.createNode(edgeCharacters, value, childNodes, isRoot); - } - catch (ByteArrayCharSequence.IncompatibleCharacterException.FastThrow ignored) { + Node node = byteArrayNodeFactory.createNode(edgeCharacters, value, childNodes, isRoot); + if (node == null) { return charArrayNodeFactory.createNode(edgeCharacters, value, childNodes, isRoot); + } else { + return node; } } } diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayCharSequence.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayCharSequence.java index f404752..06f5fa1 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayCharSequence.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/concrete/bytearray/ByteArrayCharSequence.java @@ -74,14 +74,14 @@ public static byte[] toSingleByteUtf8Encoding(CharSequence charSequence) { return toSingleByteUtf8Encoding(charSequence, false); } - public static byte[] toSingleByteUtf8Encoding(CharSequence charSequence, boolean fast) { + public static byte[] toSingleByteUtf8Encoding(CharSequence charSequence, boolean nullIfIncompatible) { final int length = charSequence.length(); byte[] bytes = new byte[length]; for (int i = 0; i < length; i++) { char inputChar = charSequence.charAt(i); if (inputChar > 255) { - if (fast) { - throw new IncompatibleCharacterException.FastThrow(); + if (nullIfIncompatible) { + return null; } else { throw new IncompatibleCharacterException("Input contains a character which cannot be represented as a single byte in UTF-8: " + inputChar); } @@ -98,15 +98,5 @@ public static class IncompatibleCharacterException extends IllegalStateException public IncompatibleCharacterException(String s) { super(s); } - - public static class FastThrow extends IllegalStateException { - - private static final long serialVersionUID = 1L; - - @Override - public Throwable fillInStackTrace() { - return this; - } - } } } From 11a3677f22ac7fbbb21f2397ea5629e25f78195b Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Tue, 27 Jul 2021 23:17:58 +0200 Subject: [PATCH 14/15] Add missing javadoc and header. --- .../concurrenttrees/radix/node/NodeList.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/NodeList.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/NodeList.java index 651b0af..3bea2cd 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/NodeList.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/NodeList.java @@ -1,9 +1,28 @@ +/* + * Copyright 2012-2013 Niall Gallagher + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.googlecode.concurrenttrees.radix.node; import java.util.Collection; +/** + * A list of {@link Node}s represented by a tree. This interface is used rather then a Java list, + * to allow representing concurrent arrays as such lists and to avoid allocating wrapper instances. + */ public interface NodeList { - + int size(); Node get(int index); From f4263739bbdcf2c690dbf6ce2b94e508c4e7f565 Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Tue, 27 Jul 2021 23:19:24 +0200 Subject: [PATCH 15/15] Add additional license header and javadoc. --- .../radix/node/SimpleNodeList.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/SimpleNodeList.java b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/SimpleNodeList.java index bfcd90d..cfd4b58 100644 --- a/code/src/main/java/com/googlecode/concurrenttrees/radix/node/SimpleNodeList.java +++ b/code/src/main/java/com/googlecode/concurrenttrees/radix/node/SimpleNodeList.java @@ -1,3 +1,18 @@ +/* + * Copyright 2012-2013 Niall Gallagher + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.googlecode.concurrenttrees.radix.node; import java.util.Arrays; @@ -5,6 +20,9 @@ import java.util.Collections; import java.util.List; +/** + * A simple implementation of a {@link NodeList} backed by a {@link List}. + */ public class SimpleNodeList implements NodeList { private final List nodes;