OpenJDK / lambda / lambda / jdk
changeset 8091:d9902df08138
Cleanup pass on Node
author | briangoetz |
---|---|
date | Thu, 11 Apr 2013 23:01:10 -0400 |
parents | e8eea7e26b32 |
children | ef1694af47a2 |
files | src/share/classes/java/util/stream/Nodes.java src/share/classes/java/util/stream/SliceOps.java test-ng/boottests/java/util/stream/DoubleNodeTest.java test-ng/boottests/java/util/stream/IntNodeTest.java test-ng/boottests/java/util/stream/LongNodeTest.java test-ng/boottests/java/util/stream/NodeBuilderTest.java test-ng/boottests/java/util/stream/NodeTest.java |
diffstat | 7 files changed, 440 insertions(+), 606 deletions(-) [+] |
line wrap: on
line diff
--- a/src/share/classes/java/util/stream/Nodes.java Thu Apr 11 20:37:23 2013 -0400 +++ b/src/share/classes/java/util/stream/Nodes.java Thu Apr 11 23:01:10 2013 -0400 @@ -35,8 +35,8 @@ import static java.util.stream.Collectors.toStringJoiner; /** - * Factory methods for constructing implementations of {@link Node} and {@link Node.Builder} - * and primitive specializations of. + * Factory methods for constructing implementations of {@link Node} and + * {@link Node.Builder} and their primitive specializations. * * @since 1.8 */ @@ -46,210 +46,134 @@ throw new Error("no instances"); } + private static final Node EMPTY_NODE = new EmptyNode.OfRef(); + private static final Node.OfInt EMPTY_INT_NODE = new EmptyNode.OfInt(); + private static final Node.OfLong EMPTY_LONG_NODE = new EmptyNode.OfLong(); + private static final Node.OfDouble EMPTY_DOUBLE_NODE = new EmptyNode.OfDouble(); + // General shape-based node creation methods /** - * Create an empty node whose count is zero, has no children and no content. + * Produces an empty node whose count is zero, has no children and no content. * * @param shape the shape of the node to be created. * @param <T> the type of elements of the created node. * @return an empty node. */ @SuppressWarnings("unchecked") - public static <T> Node<T> createEmptyNode(StreamShape shape) { + static <T> Node<T> emptyNode(StreamShape shape) { switch (shape) { - case REFERENCE: - return emptyNode(); - case INT_VALUE: - return (Node<T>) emptyIntNode(); - case LONG_VALUE: - return (Node<T>) emptyLongNode(); - case DOUBLE_VALUE: - return (Node<T>) emptyDoubleNode(); + case REFERENCE: return (Node<T>) EMPTY_NODE; + case INT_VALUE: return (Node<T>) EMPTY_INT_NODE; + case LONG_VALUE: return (Node<T>) EMPTY_LONG_NODE; + case DOUBLE_VALUE: return (Node<T>) EMPTY_DOUBLE_NODE; default: throw new IllegalStateException("Unknown shape " + shape); } } /** - * Create a concatenated {@link Node} that has two or more children. - * <p>The count of the concatenated node is equal to the sum - * of the count of each child. Traversal of the concatenated node - * traverses the content of each child in encounter order of the list of children. - * Splitting a spliterator obtained from the concatenated node preserves - * the encounter order of the list of children. + * Produces a concatenated {@link Node} that has two or more children. + * <p>The count of the concatenated node is equal to the sum of the count + * of each child. Traversal of the concatenated node traverses the content + * of each child in encounter order of the list of children. Splitting a + * spliterator obtained from the concatenated node preserves the encounter + * order of the list of children. + * + * <p>The result may be a concatenated node, the input sole node if the size + * of the list is 1, or an empty node. * * @param shape the shape of the concatenated node to be created - * @param nodes the list of child nodes. - * @param <T> the type of elements of the concatenated node. - * @return a concatenated node if the size of the list is > 1. If the size is 0 then an - * empty node is returned (see {@link #emptyNode()}). If the size is 1 then the single - * node contained in the list is returned. - * @throws IllegalStateException if all {@link Node} elements of the list are an not instance of type - * supported by this factory. + * @param nodes the input nodes + * @param <T> the type of elements of the concatenated node + * @return a {@code Node} covering the elements of the input nodes + * @throws IllegalStateException if all {@link Node} elements of the list + * are an not instance of type supported by this factory. */ @SuppressWarnings("unchecked") - public static <T> Node<T> createConcNode(StreamShape shape, List<Node<T>> nodes) { + static <T> Node<T> createConcNode(StreamShape shape, List<Node<T>> nodes) { + try { + switch (shape) { + case REFERENCE: + return node(nodes.toArray(new Node[nodes.size()])); + case INT_VALUE: + return (Node<T>) intNode(nodes.toArray(new Node.OfInt[nodes.size()])); + case LONG_VALUE: + return (Node<T>) longNode(nodes.toArray(new Node.OfLong[nodes.size()])); + case DOUBLE_VALUE: + return (Node<T>) doubleNode(nodes.toArray(new Node.OfDouble[nodes.size()])); + default: + throw new IllegalStateException("Unknown shape " + shape); + } + } + catch (ArrayStoreException e) { + throw new IllegalStateException("Error creating Conc node for shape " + shape + + "; the input contained at least one Node instance of the wrong shape", e); + } + } + + /** + * Truncate a {@link Node}, returning a node describing a subsequence of + * the contents of the input node. + * + * @param input the input node + * @param from the starting offset to include in the truncated node (inclusive) + * @param to the ending offset ot include in the truncated node (exclusive) + * @param generator the array factory (only used for reference nodes) + * @param <T> the type of elements of the input node and truncated node + * @return the truncated node + */ + @SuppressWarnings("unchecked") + static <T> Node<T> truncateNode(Node<T> input, long from, long to, IntFunction<T[]> generator) { + StreamShape shape = input.getShape(); + long size = truncatedSize(input.count(), from, to); + if (size == 0) + return emptyNode(shape); + else if (from == 0 && to >= input.count()) + return input; + switch (shape) { - case REFERENCE: - return node(nodes.toArray(new Node[nodes.size()])); + case REFERENCE: { + Spliterator<T> spliterator = input.spliterator(); + Node.Builder<T> nodeBuilder = Nodes.makeBuilder(size, generator); + nodeBuilder.begin(size); + for (int i = 0; i < from && spliterator.tryAdvance(e -> { }); i++) { } + for (int i = 0; (i < size) && spliterator.tryAdvance(nodeBuilder); i++) { } + nodeBuilder.end(); + return nodeBuilder.build(); + } case INT_VALUE: { - Node.OfInt[] array; - try { - array = nodes.toArray(new Node.OfInt[nodes.size()]); - } catch (ArrayStoreException e) { - throw new IllegalStateException("Error creating conc Node.OfInt. " + - "The List<Node<Integer>> contains at least one Node instance " + - "that is not an instance of Node.OfInt", e); - } - return (Node<T>) intNode(array); + Spliterator.OfInt spliterator = ((Node.OfInt) input).spliterator(); + Node.Builder.OfInt nodeBuilder = Nodes.intMakeBuilder(size); + nodeBuilder.begin(size); + for (int i = 0; i < from && spliterator.tryAdvance((IntConsumer) e -> { }); i++) { } + for (int i = 0; (i < size) && spliterator.tryAdvance((IntConsumer) nodeBuilder); i++) { } + nodeBuilder.end(); + return (Node<T>) nodeBuilder.build(); } case LONG_VALUE: { - Node.OfLong[] array; - try { - array = nodes.toArray(new Node.OfLong[nodes.size()]); - } catch (ArrayStoreException e) { - throw new IllegalStateException("Error creating conc Node.OfLong. " + - "The List<Node<Long>> contains at least one Node instance " + - "that is not an instance of Node.OfLong", e); - } - return (Node<T>) longNode(array); - } + Spliterator.OfLong spliterator = ((Node.OfLong) input).spliterator(); + Node.Builder.OfLong nodeBuilder = Nodes.longMakeBuilder(size); + nodeBuilder.begin(size); + for (int i = 0; i < from && spliterator.tryAdvance((LongConsumer) e -> { }); i++) { } + for (int i = 0; (i < size) && spliterator.tryAdvance((LongConsumer) nodeBuilder); i++) { } + nodeBuilder.end(); + return (Node<T>) nodeBuilder.build(); + } case DOUBLE_VALUE: { - Node.OfDouble[] array; - try { - array = nodes.toArray(new Node.OfDouble[nodes.size()]); - } catch (ArrayStoreException e) { - throw new IllegalStateException("Error creating conc Node.OfDouble. " + - "The List<Node<Double>> contains at least one Node instance " + - "that is not an instance of Node.OfDouble", e); - } - return (Node<T>) doubleNode(array); + Spliterator.OfDouble spliterator = ((Node.OfDouble) input).spliterator(); + Node.Builder.OfDouble nodeBuilder = Nodes.doubleMakeBuilder(size); + nodeBuilder.begin(size); + for (int i = 0; i < from && spliterator.tryAdvance((DoubleConsumer) e -> { }); i++) { } + for (int i = 0; (i < size) && spliterator.tryAdvance((DoubleConsumer) nodeBuilder); i++) { } + nodeBuilder.end(); + return (Node<T>) nodeBuilder.build(); } default: throw new IllegalStateException("Unknown shape " + shape); } } - /** - * Created a truncated {@link Node} from an input {@link Node}. - * - * @param input the input node. - * @param from the offset from which to truncate from - * @param to the offset form which to truncate up to (but not including) - * @param generator the array factory - * @param <T> the type of elements of the input node and truncated node. - * @return the truncated node. - */ - @SuppressWarnings("unchecked") - public static <T> Node<T> createTruncatedNode(Node<T> input, long from, long to, IntFunction<T[]> generator) { - switch (input.getShape()) { - case REFERENCE: - return Nodes.truncateNode(input, from, to, generator); - case INT_VALUE: - return (Node<T>) Nodes.truncateIntNode((Node.OfInt) input, from, to); - case LONG_VALUE: - return (Node<T>) Nodes.truncateLongNode((Node.OfLong) input, from, to); - case DOUBLE_VALUE: - return (Node<T>) Nodes.truncateDoubleNode((Node.OfDouble) input, from, to); - default: - throw new IllegalStateException("Unknown shape " + input.getShape()); - } - } - - // Reference-based node methods - - /** - * Create an empty (reference) {@link Node}. - * - * @param <T> the type of elements held by the node. - * @return an empty node. - */ - @SuppressWarnings("unchecked") - public static<T> Node<T> emptyNode() { - return (Node<T>) EMPTY_NODE; - } - - /** - * Create a (reference) {@link Node} whose contents is an array. - * <p> - * The created node will hold the reference to the array and will not make - * a copy. - * - * @param array the array. - * @param <T> the type of elements held by the node. - * @return a node holding an array. - */ - public static<T> Node<T> node(T[] array) { - return new ArrayNode<>(array); - } - - /** - * Create a (reference) {@link Node} whose contents is a {@link Collection}. - * <p> - * The created node will hold the reference to the collection and will not make - * a copy. - * - * @param c the collection. - * @param <T> the type of elements held by the node. - * @return a node holding a collection. - */ - public static<T> Node<T> node(Collection<T> c) { - return new CollectionNode<>(c); - } - - /** - * Create a concatenated (reference) {@link Node} that has two or more children. - * <p>The count of the concatenated node is equal to the sum - * of the count of each child. Traversal of the concatenated node - * traverses the content of each child in encounter order of the list of children. - * Splitting a spliterator obtained from the concatenated node preserves - * the encounter order of the list of children. - * - * @param nodes the list of child nodes. - * @param <T> the type of elements of the concatenated node. - * @return a concatenated node if the size of the list is > 1. If the size is 0 then an - * empty node is returned (see {@link #emptyNode()}). If the size is 1 then the single - * node contained in the list is returned. - */ - @SafeVarargs - public static<T> Node<T> node(Node<T>... nodes) { - Objects.requireNonNull(nodes); - if (nodes.length > 1) { - return new ConcNode<>(nodes); - } - else if (nodes.length == 1) { - return nodes[0]; - } - else { - return emptyNode(); - } - } - - /** - * Created a truncated (reference ){@link Node} from an input {@link Node}. - * - * @param n the input node. - * @param from the offset from which to truncate from - * @param to the offset form which to truncate up to (but not including) - * @param generator the array factory - * @param <T> the type of elements of the input node and truncated node. - * @return a truncated node. - */ - public static<T> Node<T> truncateNode(Node<T> n, long from, long to, IntFunction<T[]> generator) { - long size = truncatedSize(n.count(), from, to); - if (size == 0) - return emptyNode(); - - Spliterator<T> spliterator = n.spliterator(); - Node.Builder<T> nodeBuilder = Nodes.makeBuilder(size, generator); - nodeBuilder.begin(size); - for (int i = 0; i < from && spliterator.tryAdvance(e -> { }); i++) { } - for (int i = 0; (i < size) && spliterator.tryAdvance(nodeBuilder); i++) { } - nodeBuilder.end(); - return nodeBuilder.build(); - } - private static long truncatedSize(long size, long from, long to) { if (from >= 0) size = Math.max(0, size - from); @@ -259,84 +183,119 @@ return size; } + // Reference-based node methods + /** - * Create a (reference) {@link Node.Builder}. + * Produces a {@link Node} describing an array. + * <p> + * The node will hold a reference to the array and will not make a copy. * - * @param exactSizeIfKnown if >=0 then a builder will be created that has a fixed capacity of exactly - * exactSizeIfKnown elements; if < 0 then the builder has variable capacity. - * A fixed capacity builder will fail if an element is added and the builder has reached - * capacity. - * @param generator the array factory. - * @param <T> the type of elements of the node builder. - * @return a {@code Node.Builder} + * @param array the array. + * @param <T> the type of elements held by the node + * @return a node holding an array */ - public static <T> Node.Builder<T> makeBuilder(long exactSizeIfKnown, IntFunction<T[]> generator) { - return (exactSizeIfKnown >= 0 && exactSizeIfKnown < Streams.MAX_ARRAY_SIZE) - ? makeFixedSizeBuilder(exactSizeIfKnown, generator) - : makeVariableSizeBuilder(); + static<T> Node<T> node(T[] array) { + return new ArrayNode<>(array); } /** - * Create a fixed size (reference) {@link Node.Builder}. + * Produces a {@link Node} describing a {@link Collection}. + * <p> + * The node will hold a reference to the collection and will not make a copy. * - * @param size the fixed size of the builder. - * @param <T> the type of elements of the node builder. - * @return a {@code Node.Builder} + * @param c the collection. + * @param <T> the type of elements held by the node. + * @return a node holding a collection. */ - public static <T> Node.Builder<T> makeFixedSizeBuilder(long size, IntFunction<T[]> generator) { - assert size < Streams.MAX_ARRAY_SIZE; - return new FixedNodeBuilder<>(size, generator); + static<T> Node<T> node(Collection<T> c) { + return new CollectionNode<>(c); } /** - * Create a variable size (reference) @{link Node.Builder}. + * Produces a concatenated {@link Node} that has two or more children. + * <p>The count of the concatenated node is equal to the sum of the count + * of each child. Traversal of the concatenated node traverses the content + * of each child in encounter order of the list of children. Splitting a + * spliterator obtained from the concatenated node preserves the encounter + * order of the list of children. * - * @param <T> the type of elements of the node builder. + * <p>The result may be a concatenated node, the input sole node if the size + * of the list is 1, or an empty node. + * + * @param nodes the input nodes + * @param <T> the type of elements of the concatenated node + * @return a {@code Node} covering the elements of the input nodes + */ + @SafeVarargs + static<T> Node<T> node(Node<T>... nodes) { + Objects.requireNonNull(nodes); + if (nodes.length > 1) { + return new ConcNode<>(nodes); + } + else if (nodes.length == 1) { + return nodes[0]; + } + else { + return (Node<T>) EMPTY_NODE; + } + } + + /** + * Produces a {@link Node.Builder}. + * + * @param exactSizeIfKnown -1 if a variable size builder is requested, + * otherwise the exact capacity desired. A fixed capacity builder will + * fail if the wrong number of elements are added to the builder. + * @param generator the array factory + * @param <T> the type of elements of the node builder * @return a {@code Node.Builder} */ - public static <T> Node.Builder<T> makeVariableSizeBuilder() { + static <T> Node.Builder<T> makeBuilder(long exactSizeIfKnown, IntFunction<T[]> generator) { + return (exactSizeIfKnown >= 0 && exactSizeIfKnown < Streams.MAX_ARRAY_SIZE) + ? new FixedNodeBuilder<>(exactSizeIfKnown, generator) + : makeBuilder(); + } + + /** + * Produces a variable size @{link Node.Builder}. + * + * @param <T> the type of elements of the node builder + * @return a {@code Node.Builder} + */ + static <T> Node.Builder<T> makeBuilder() { return new SpinedNodeBuilder<>(); } // Int nodes /** - * Create an empty {@link Node.OfInt}. + * Produces a {@link Node.OfInt} describing an int[] array. + * <p> + * The node will hold a reference to the array and will not make a copy. * - * @return an empty node. + * @param array the array + * @return a node holding an array */ - public static Node.OfInt emptyIntNode() { - return EMPTY_INT_NODE; - } - - /** - * Create a {@link Node.OfInt} whose contents is an int[] array. - * <p> - * The created node will hold the reference to the array and will not make - * a copy. - * - * @param array the array. - * @return a node holding an array. - */ - public static Node.OfInt intNode(int[] array) { + static Node.OfInt intNode(int[] array) { return new IntArrayNode(array); } /** - * Create a concatenated {@link Node.OfInt} that has two or more children. - * <p>The count of the concatenated node is equal to the sum - * of the count of each child. Traversal of the concatenated node - * traverses the content of each child in encounter order of the list of children. - * Splitting a spliterator obtained from the concatenated node preserves - * the encounter order of the list of children. + * Produces a concatenated {@link Node.OfInt} that has two or more children. + * <p>The count of the concatenated node is equal to the sum of the count + * of each child. Traversal of the concatenated node traverses the content + * of each child in encounter order of the list of children. Splitting a + * spliterator obtained from the concatenated node preserves the encounter + * order of the list of children. * - * @param nodes the list of child nodes. - * @return a concatenated node if the size of the list is > 1. If the size is 0 then an - * empty node is returned (see {@link #emptyNode()}). If the size is 1 then the single - * node contained in the list is returned. + * <p>The result may be a concatenated node, the input sole node if the size + * of the list is 1, or an empty node. + * + * @param nodes the input nodes + * @return a {@code Node.OfInt} covering the elements of the input nodes */ @SafeVarargs - public static Node.OfInt intNode(Node.OfInt... nodes) { + static Node.OfInt intNode(Node.OfInt... nodes) { Objects.requireNonNull(nodes); if (nodes.length > 1) { return new IntConcNode(nodes); @@ -345,106 +304,63 @@ return nodes[0]; } else { - return emptyIntNode(); + return EMPTY_INT_NODE; } } /** - * Created a truncated {@link Node.OfInt} from an input {@link Node.OfInt}. + * Produces a {@link Node.Builder.OfInt}. * - * @param n the input node. - * @param from the offset from which to truncate from - * @param to the offset form which to truncate up to (but not including) - * @return a truncated node. + * @param exactSizeIfKnown -1 if a variable size builder is requested, + * otherwise the exact capacity desired. A fixed capacity builder will + * fail if the wrong number of elements are added to the builder. + * @return a {@code Node.Builder.OfInt} */ - public static Node.OfInt truncateIntNode(Node.OfInt n, long from, long to) { - long size = truncatedSize(n.count(), from, to); - if (size == 0) - return emptyIntNode(); - - Spliterator.OfInt spliterator = n.spliterator(); - Node.Builder.OfInt nodeBuilder = Nodes.intMakeBuilder(size); - nodeBuilder.begin(size); - for (int i = 0; i < from && spliterator.tryAdvance((IntConsumer) e -> { }); i++) { } - for (int i = 0; (i < size) && spliterator.tryAdvance((IntConsumer) nodeBuilder); i++) { } - nodeBuilder.end(); - return nodeBuilder.build(); + static Node.Builder.OfInt intMakeBuilder(long exactSizeIfKnown) { + return (exactSizeIfKnown >= 0 && exactSizeIfKnown < Streams.MAX_ARRAY_SIZE) + ? new IntFixedNodeBuilder(exactSizeIfKnown) + : intMakeBuilder(); } /** - * Create a (reference) {@link Node.Builder.OfInt}. - * - * @param exactSizeIfKnown if >=0 then a builder will be created that has a fixed capacity of exactly - * exactSizeIfKnown elements; if < 0 then the builder has variable capacity. - * A fixed capacity builder will fail if an element is added and the builder has reached - * capacity. - * @return a {@code Node.Builder.OfInt} - */ - public static Node.Builder.OfInt intMakeBuilder(long exactSizeIfKnown) { - return (exactSizeIfKnown >= 0 && exactSizeIfKnown < Streams.MAX_ARRAY_SIZE) - ? intMakeFixedSizeBuilder(exactSizeIfKnown) - : intMakeVariableSizeBuilder(); - } - - /** - * Create a fixed size {@link Node.Builder.OfInt}. - * - * @param size the fixed size of the builder. - * @return a {@code Node.Builder.OfInt} - */ - public static Node.Builder.OfInt intMakeFixedSizeBuilder(long size) { - assert size < Streams.MAX_ARRAY_SIZE; - return new IntFixedNodeBuilder(size); - } - - /** - * Create a variable size @{link Node.Builder.OfInt}. + * Produces a variable size @{link Node.Builder.OfInt}. * * @return a {@code Node.Builder.OfInt} */ - public static Node.Builder.OfInt intMakeVariableSizeBuilder() { + static Node.Builder.OfInt intMakeBuilder() { return new IntSpinedNodeBuilder(); } // Long nodes /** - * Create an empty {@link Node.OfLong}. + * Produces a {@link Node.OfLong} describing a long[] array. + * <p> + * The node will hold a reference to the array and will not make a copy. * - * @return an empty node. + * @param array the array + * @return a node holding an array */ - public static Node.OfLong emptyLongNode() { - return EMPTY_LONG_NODE; - } - - /** - * Create a {@link Node.OfLong} whose contents is a long[] array. - * <p> - * The created node will hold the reference to the array and will not make - * a copy. - * - * @param array the array. - * @return a node holding an array. - */ - public static Node.OfLong longNode(final long[] array) { + static Node.OfLong longNode(final long[] array) { return new LongArrayNode(array); } /** - * Create a concatenated {@link Node.OfLong} that has two or more children. - * <p>The count of the concatenated node is equal to the sum - * of the count of each child. Traversal of the concatenated node - * traverses the content of each child in encounter order of the list of children. - * Splitting a spliterator obtained from the concatenated node preserves - * the encounter order of the list of children. + * Produces a concatenated {@link Node.OfLong} that has two or more children. + * <p>The count of the concatenated node is equal to the sum of the count + * of each child. Traversal of the concatenated node traverses the content + * of each child in encounter order of the list of children. Splitting a + * spliterator obtained from the concatenated node preserves the encounter + * order of the list of children. * - * @param nodes the list of child nodes. - * @return a concatenated node if the size of the list is > 1. If the size is 0 then an - * empty node is returned (see {@link #emptyNode()}). If the size is 1 then the single - * node contained in the list is returned. + * <p>The result may be a concatenated node, the input sole node if the size + * of the list is 1, or an empty node. + * + * @param nodes the input nodes + * @return a {@code Node.OfLong} covering the elements of the input nodes */ @SafeVarargs - public static Node.OfLong longNode(Node.OfLong... nodes) { + static Node.OfLong longNode(Node.OfLong... nodes) { Objects.requireNonNull(nodes); if (nodes.length > 1) { return new LongConcNode(nodes); @@ -453,106 +369,63 @@ return nodes[0]; } else { - return emptyLongNode(); + return EMPTY_LONG_NODE; } } /** - * Created a truncated {@link Node.OfLong} from an input {@link Node.OfLong}. + * Produces a {@link Node.Builder.OfLong}. * - * @param n the input node. - * @param from the offset from which to truncate from - * @param to the offset form which to truncate up to (but not including) - * @return a truncated node. + * @param exactSizeIfKnown -1 if a variable size builder is requested, + * otherwise the exact capacity desired. A fixed capacity builder will + * fail if the wrong number of elements are added to the builder. + * @return a {@code Node.Builder.OfLong} */ - public static Node.OfLong truncateLongNode(Node.OfLong n, long from, long to) { - long size = truncatedSize(n.count(), from, to); - if (size == 0) - return emptyLongNode(); - - Spliterator.OfLong spliterator = n.spliterator(); - Node.Builder.OfLong nodeBuilder = Nodes.longMakeBuilder(size); - nodeBuilder.begin(size); - for (int i = 0; i < from && spliterator.tryAdvance((LongConsumer) e -> { }); i++) { } - for (int i = 0; (i < size) && spliterator.tryAdvance((LongConsumer) nodeBuilder); i++) { } - nodeBuilder.end(); - return nodeBuilder.build(); + static Node.Builder.OfLong longMakeBuilder(long exactSizeIfKnown) { + return (exactSizeIfKnown >= 0 && exactSizeIfKnown < Streams.MAX_ARRAY_SIZE) + ? new LongFixedNodeBuilder(exactSizeIfKnown) + : longMakeBuilder(); } /** - * Create a (reference) {@link Node.Builder.OfLong}. - * - * @param exactSizeIfKnown if >=0 then a builder will be created that has a fixed capacity of exactly - * exactSizeIfKnown elements; if < 0 then the builder has variable capacity. - * A fixed capacity builder will fail if an element is added and the builder has reached - * capacity. - * @return a {@code Node.Builder.OfLong} - */ - public static Node.Builder.OfLong longMakeBuilder(long exactSizeIfKnown) { - return (exactSizeIfKnown >= 0 && exactSizeIfKnown < Streams.MAX_ARRAY_SIZE) - ? longMakeFixedSizeBuilder(exactSizeIfKnown) - : longMakeVariableSizeBuilder(); - } - - /** - * Create a fixed size {@link Node.Builder.OfLong}. - * - * @param size the fixed size of the builder. - * @return a {@code Node.Builder.OfLong} - */ - public static Node.Builder.OfLong longMakeFixedSizeBuilder(long size) { - assert size < Streams.MAX_ARRAY_SIZE; - return new LongFixedNodeBuilder(size); - } - - /** - * Create a variable size @{link Node.Builder.OfLong}. + * Produces a variable size @{link Node.Builder.OfLong}. * * @return a {@code Node.Builder.OfLong} */ - public static Node.Builder.OfLong longMakeVariableSizeBuilder() { + static Node.Builder.OfLong longMakeBuilder() { return new LongSpinedNodeBuilder(); } // Double nodes /** - * Create an empty {@link Node.OfDouble}. + * Produces a {@link Node.OfDouble} describing a double[] array. + * <p> + * The node will hold a reference to the array and will not make a copy. * - * @return an empty node. + * @param array the array + * @return a node holding an array */ - public static Node.OfDouble emptyDoubleNode() { - return EMPTY_DOUBLE_NODE; - } - - /** - * Create a {@link Node.OfDouble} whose contents is a double[] array. - * <p> - * The created node will hold the reference to the array and will not make - * a copy. - * - * @param array the array. - * @return a node holding an array. - */ - public static Node.OfDouble doubleNode(final double[] array) { + static Node.OfDouble doubleNode(final double[] array) { return new DoubleArrayNode(array); } /** - * Create a concatenated {@link Node.OfDouble} that has two or more children. - * <p>The count of the concatenated node is equal to the sum - * of the count of each child. Traversal of the concatenated node - * traverses the content of each child in encounter order of the list of children. - * Splitting a spliterator obtained from the concatenated node preserves - * the encounter order of the list of children. + * Produces a concatenated {@link Node.OfDouble} that has two or more children. + * <p>The count of the concatenated node is equal to the sum of the count + * of each child. Traversal of the concatenated node traverses the content + * of each child in encounter order of the list of children. Splitting a + * spliterator obtained from the concatenated node preserves the encounter + * order of the list of children. * - * @param nodes the list of child nodes. - * @return a concatenated node if the size of the list is > 1. If the size is 0 then an - * empty node is returned (see {@link #emptyNode()}). If the size is 1 then the single - * node contained in the list is returned. + * <p>The result may be a concatenated node, the input sole node if the size + * of the list is 1, or an empty node. + * + * @param nodes the input nodes + * @return a {@code Node.ofDouble} covering the elements of the input nodes */ @SafeVarargs - public static Node.OfDouble doubleNode(Node.OfDouble... nodes) { + static Node.OfDouble doubleNode(Node.OfDouble... nodes) { Objects.requireNonNull(nodes); if (nodes.length > 1) { return new DoubleConcNode(nodes); @@ -561,97 +434,116 @@ return nodes[0]; } else { - return emptyDoubleNode(); + return EMPTY_DOUBLE_NODE; } } /** - * Created a truncated {@link Node.OfDouble} from an input {@link Node.OfDouble}. + * Produces a {@link Node.Builder.OfDouble}. * - * @param n the input node. - * @param from the offset from which to truncate from - * @param to the offset form which to truncate up to (but not including) - * @return a truncated node. + * @param exactSizeIfKnown -1 if a variable size builder is requested, + * otherwise the exact capacity desired. A fixed capacity builder will + * fail if the wrong number of elements are added to the builder. + * @return a {@code Node.Builder.OfDouble} */ - public static Node.OfDouble truncateDoubleNode(Node.OfDouble n, long from, long to) { - long size = truncatedSize(n.count(), from, to); - if (size == 0) - return emptyDoubleNode(); - - Spliterator.OfDouble spliterator = n.spliterator(); - Node.Builder.OfDouble nodeBuilder = Nodes.doubleMakeBuilder(size); - nodeBuilder.begin(size); - for (int i = 0; i < from && spliterator.tryAdvance((DoubleConsumer) e -> { }); i++) { } - for (int i = 0; (i < size) && spliterator.tryAdvance((DoubleConsumer) nodeBuilder); i++) { } - nodeBuilder.end(); - return nodeBuilder.build(); + static Node.Builder.OfDouble doubleMakeBuilder(long exactSizeIfKnown) { + return (exactSizeIfKnown >= 0 && exactSizeIfKnown < Streams.MAX_ARRAY_SIZE) + ? new DoubleFixedNodeBuilder(exactSizeIfKnown) + : doubleMakeBuilder(); } /** - * Create a (reference) {@link Node.Builder.OfDouble}. - * - * @param exactSizeIfKnown if >=0 then a builder will be created that has a fixed capacity of exactly - * exactSizeIfKnown elements; if < 0 then the builder has variable capacity. - * A fixed capacity builder will fail if an element is added and the builder has reached - * capacity. - * @return a {@code Node.Builder.OfDouble} - */ - public static Node.Builder.OfDouble doubleMakeBuilder(long exactSizeIfKnown) { - return (exactSizeIfKnown >= 0 && exactSizeIfKnown < Streams.MAX_ARRAY_SIZE) - ? doubleMakeFixedSizeBuilder(exactSizeIfKnown) - : doubleMakeVariableSizeBuilder(); - } - - /** - * Create a fixed size {@link Node.Builder.OfDouble}. - * - * @param size the fixed size of the builder. - * @return a {@code Node.Builder.OfDouble} - */ - public static Node.Builder.OfDouble doubleMakeFixedSizeBuilder(long size) { - assert size < Streams.MAX_ARRAY_SIZE; - return new DoubleFixedNodeBuilder(size); - } - - /** - * Create a variable size @{link Node.Builder.OfDouble}. + * Produces a variable size @{link Node.Builder.OfDouble}. * * @return a {@code Node.Builder.OfDouble} */ - public static Node.Builder.OfDouble doubleMakeVariableSizeBuilder() { + static Node.Builder.OfDouble doubleMakeBuilder() { return new DoubleSpinedNodeBuilder(); } // Implementations - private static final Node EMPTY_NODE = new EmptyNode(); - - private static class EmptyNode<T> implements Node<T> { - - EmptyNode() {} // Avoid creation of special accessor - - @Override - public Spliterator<T> spliterator() { - return Spliterators.emptySpliterator(); - } + private static abstract class EmptyNode<T, T_ARR, T_CONS> implements Node<T> { + EmptyNode() { } @Override public T[] asArray(IntFunction<T[]> generator) { return generator.apply(0); } - @Override - public void copyInto(T[] array, int offset) { } + public void copyInto(T_ARR array, int offset) { } @Override public long count() { return 0; } - @Override - public void forEach(Consumer<? super T> consumer) { } + public void forEach(T_CONS consumer) { } + + private static class OfRef<T> extends EmptyNode<T, T[], Consumer<? super T>> { + private OfRef() { + super(); + } + + @Override + public Spliterator<T> spliterator() { + return Spliterators.emptySpliterator(); + } + } + + private static final class OfInt + extends EmptyNode<Integer, int[], IntConsumer> + implements Node.OfInt { + + OfInt() { } // Avoid creation of special accessor + + @Override + public Spliterator.OfInt spliterator() { + return Spliterators.emptyIntSpliterator(); + } + + @Override + public int[] asIntArray() { + return EMPTY_INT_ARRAY; + } + } + + private static final class OfLong + extends EmptyNode<Long, long[], LongConsumer> + implements Node.OfLong { + + OfLong() { } // Avoid creation of special accessor + + @Override + public Spliterator.OfLong spliterator() { + return Spliterators.emptyLongSpliterator(); + } + + @Override + public long[] asLongArray() { + return EMPTY_LONG_ARRAY; + } + } + + private static final class OfDouble + extends EmptyNode<Double, double[], DoubleConsumer> + implements Node.OfDouble { + + OfDouble() { } // Avoid creation of special accessor + + @Override + public Spliterator.OfDouble spliterator() { + return Spliterators.emptyDoubleSpliterator(); + } + + @Override + public double[] asDoubleArray() { + return EMPTY_DOUBLE_ARRAY; + } + } } + /** Node class for a reference array */ private static class ArrayNode<T> implements Node<T> { final T[] array; int curSize; @@ -708,10 +600,12 @@ @Override public String toString() { - return String.format("ArrayNode[%d][%s]", array.length - curSize, Arrays.toString(array)); + return String.format("ArrayNode[%d][%s]", + array.length - curSize, Arrays.toString(array)); } } + /** Node class for a Collection */ private static final class CollectionNode<T> implements Node<T> { private final Collection<T> c; @@ -756,6 +650,7 @@ } } + /** Node class for an internal node with two or more children */ private static final class ConcNode<T> implements Node<T> { private final Node<T>[] nodes; private final long size; @@ -829,6 +724,7 @@ } } + /** Abstract class for spliterator for all internal node classes */ private static abstract class InternalNodeSpliterator<T, S extends Spliterator<T>, N extends Node<T>, C> implements Spliterator<T> { // Node we are pointing to @@ -971,7 +867,8 @@ return Spliterator.SIZED; } - private static final class OfRef<T> extends InternalNodeSpliterator<T, Spliterator<T>, Node<T>, Consumer<? super T>> { + private static final class OfRef<T> + extends InternalNodeSpliterator<T, Spliterator<T>, Node<T>, Consumer<? super T>> { OfRef(Node<T> curNode) { super(curNode); @@ -983,7 +880,8 @@ } @Override - protected boolean tryAdvance(Spliterator<T> spliterator, Consumer<? super T> consumer) { + protected boolean tryAdvance(Spliterator<T> spliterator, + Consumer<? super T> consumer) { return spliterator.tryAdvance(consumer); } @@ -1009,7 +907,8 @@ } } - private static final class OfInt extends InternalNodeSpliterator<Integer, Spliterator.OfInt, Node.OfInt, IntConsumer> + private static final class OfInt + extends InternalNodeSpliterator<Integer, Spliterator.OfInt, Node.OfInt, IntConsumer> implements Spliterator.OfInt { OfInt(Node.OfInt cur) { @@ -1022,7 +921,8 @@ } @Override - protected boolean tryAdvance(Spliterator.OfInt spliterator, IntConsumer consumer) { + protected boolean tryAdvance(Spliterator.OfInt spliterator, + IntConsumer consumer) { return spliterator.tryAdvance(consumer); } @@ -1048,7 +948,8 @@ } } - private static final class OfLong extends InternalNodeSpliterator<Long, Spliterator.OfLong, Node.OfLong, LongConsumer> + private static final class OfLong + extends InternalNodeSpliterator<Long, Spliterator.OfLong, Node.OfLong, LongConsumer> implements Spliterator.OfLong { OfLong(Node.OfLong cur) { @@ -1061,7 +962,8 @@ } @Override - protected boolean tryAdvance(Spliterator.OfLong spliterator, LongConsumer consumer) { + protected boolean tryAdvance(Spliterator.OfLong spliterator, + LongConsumer consumer) { return spliterator.tryAdvance(consumer); } @@ -1087,7 +989,8 @@ } } - private static final class OfDouble extends InternalNodeSpliterator<Double, Spliterator.OfDouble, Node.OfDouble, DoubleConsumer> + private static final class OfDouble + extends InternalNodeSpliterator<Double, Spliterator.OfDouble, Node.OfDouble, DoubleConsumer> implements Spliterator.OfDouble { OfDouble(Node.OfDouble cur) { @@ -1100,7 +1003,8 @@ } @Override - protected boolean tryAdvance(Spliterator.OfDouble spliterator, DoubleConsumer consumer) { + protected boolean tryAdvance(Spliterator.OfDouble spliterator, + DoubleConsumer consumer) { return spliterator.tryAdvance(consumer); } @@ -1127,32 +1031,29 @@ } } - private static final class FixedNodeBuilder<T> extends ArrayNode<T> implements Node.Builder<T> { + /** Fixed-sized builder class for reference nodes */ + private static final class FixedNodeBuilder<T> + extends ArrayNode<T> + implements Node.Builder<T> { FixedNodeBuilder(long size, IntFunction<T[]> generator) { super(size, generator); assert size < Streams.MAX_ARRAY_SIZE; } - // - @Override public Node<T> build() { - if (curSize < array.length) { - throw new IllegalStateException(String.format("Current size %d is less than fixed size %d", curSize, array.length)); - } - + if (curSize < array.length) + throw new IllegalStateException(String.format("Current size %d is less than fixed size %d", + curSize, array.length)); return this; } - // - @Override public void begin(long size) { - if (size != array.length) { - throw new IllegalStateException(String.format("Begin size %d is not equal to fixed size %d", size, array.length)); - } - + if (size != array.length) + throw new IllegalStateException(String.format("Begin size %d is not equal to fixed size %d", + size, array.length)); curSize = 0; } @@ -1161,24 +1062,29 @@ if (curSize < array.length) { array[curSize++] = t; } else { - throw new IllegalStateException(String.format("Accept exceeded fixed size of %d", array.length)); + throw new IllegalStateException(String.format("Accept exceeded fixed size of %d", + array.length)); } } @Override public void end() { - if (curSize < array.length) { - throw new IllegalStateException(String.format("End size %d is less than fixed size %d", curSize, array.length)); - } + if (curSize < array.length) + throw new IllegalStateException(String.format("End size %d is less than fixed size %d", + curSize, array.length)); } @Override public String toString() { - return String.format("FixedNodeBuilder[%d][%s]", array.length - curSize, Arrays.toString(array)); + return String.format("FixedNodeBuilder[%d][%s]", + array.length - curSize, Arrays.toString(array)); } } - private static final class SpinedNodeBuilder<T> extends SpinedBuffer<T> implements Node<T>, Node.Builder<T> { + /** Variable-sized builder class for reference nodes */ + private static final class SpinedNodeBuilder<T> + extends SpinedBuffer<T> + implements Node<T>, Node.Builder<T> { private boolean building = false; SpinedNodeBuilder() {} // Avoid creation of special accessor @@ -1239,81 +1145,11 @@ // private static final int[] EMPTY_INT_ARRAY = new int[0]; - private static final long[] EMPTY_LONG_ARRAY = new long[0]; - private static final double[] EMPTY_DOUBLE_ARRAY = new double[0]; - private static final Node.OfInt EMPTY_INT_NODE = new EmptyIntNode(); - - private static final Node.OfLong EMPTY_LONG_NODE = new EmptyLongNode(); - - private static final Node.OfDouble EMPTY_DOUBLE_NODE = new EmptyDoubleNode(); - - private static final class EmptyIntNode extends EmptyNode<Integer> implements Node.OfInt { - - EmptyIntNode() {} // Avoid creation of special accessor - - @Override - public Spliterator.OfInt spliterator() { - return Spliterators.emptyIntSpliterator(); - } - - @Override - public int[] asIntArray() { - return EMPTY_INT_ARRAY; - } - - @Override - public void copyInto(int[] array, int offset) { } - - @Override - public void forEach(IntConsumer consumer) { } - } - - private static final class EmptyLongNode extends EmptyNode<Long> implements Node.OfLong { - - EmptyLongNode() {} // Avoid creation of special accessor - - @Override - public Spliterator.OfLong spliterator() { - return Spliterators.emptyLongSpliterator(); - } - - @Override - public long[] asLongArray() { - return EMPTY_LONG_ARRAY; - } - - @Override - public void copyInto(long[] array, int offset) { } - - @Override - public void forEach(LongConsumer consumer) { } - } - - private static final class EmptyDoubleNode extends EmptyNode<Double> implements Node.OfDouble { - - EmptyDoubleNode() {} // Avoid creation of special accessor - - @Override - public Spliterator.OfDouble spliterator() { - return Spliterators.emptyDoubleSpliterator(); - } - - @Override - public double[] asDoubleArray() { - return EMPTY_DOUBLE_ARRAY; - } - - @Override - public void copyInto(double[] array, int offset) { } - - @Override - public void forEach(DoubleConsumer consumer) { } - } - - private abstract static class AbstractPrimitiveConcNode<E, N extends Node<E>> implements Node<E> { + private abstract static class AbstractPrimitiveConcNode<E, N extends Node<E>> + implements Node<E> { final N[] nodes; final long size; @@ -1328,8 +1164,6 @@ this.size = count; } - // Node - @Override public int getChildCount() { return nodes.length; @@ -1400,8 +1234,6 @@ return curSize; } - // Traversable - @Override public void forEach(IntConsumer consumer) { for (int i = 0; i < curSize; i++) { @@ -1409,11 +1241,10 @@ } } - // - @Override public String toString() { - return String.format("IntArrayNode[%d][%s]", array.length - curSize, Arrays.toString(array)); + return String.format("IntArrayNode[%d][%s]", + array.length - curSize, Arrays.toString(array)); } } @@ -1433,8 +1264,6 @@ this.curSize = array.length; } - // Node - @Override public Spliterator.OfLong spliterator() { return Arrays.spliterator(array, 0, curSize); @@ -1459,8 +1288,6 @@ return curSize; } - // Traversable - @Override public void forEach(LongConsumer consumer) { for (int i = 0; i < curSize; i++) { @@ -1468,11 +1295,10 @@ } } - // - @Override public String toString() { - return String.format("LongArrayNode[%d][%s]", array.length - curSize, Arrays.toString(array)); + return String.format("LongArrayNode[%d][%s]", + array.length - curSize, Arrays.toString(array)); } } @@ -1492,8 +1318,6 @@ this.curSize = array.length; } - // Node - @Override public Spliterator.OfDouble spliterator() { return Arrays.spliterator(array, 0, curSize); @@ -1518,8 +1342,6 @@ return curSize; } - // Traversable - @Override public void forEach(DoubleConsumer consumer) { for (int i = 0; i < curSize; i++) { @@ -1527,15 +1349,16 @@ } } - // - @Override public String toString() { - return String.format("DoubleArrayNode[%d][%s]", array.length - curSize, Arrays.toString(array)); + return String.format("DoubleArrayNode[%d][%s]", + array.length - curSize, Arrays.toString(array)); } } - private static final class IntConcNode extends AbstractPrimitiveConcNode<Integer, Node.OfInt> implements Node.OfInt { + private static final class IntConcNode + extends AbstractPrimitiveConcNode<Integer, Node.OfInt> + implements Node.OfInt { IntConcNode(Node.OfInt[] nodes) { super(nodes); @@ -1568,7 +1391,9 @@ } } - private static final class LongConcNode extends AbstractPrimitiveConcNode<Long, Node.OfLong> implements Node.OfLong { + private static final class LongConcNode + extends AbstractPrimitiveConcNode<Long, Node.OfLong> + implements Node.OfLong { LongConcNode(Node.OfLong[] nodes) { super(nodes); @@ -1601,7 +1426,9 @@ } } - private static final class DoubleConcNode extends AbstractPrimitiveConcNode<Double, Node.OfDouble> implements Node.OfDouble { + private static final class DoubleConcNode + extends AbstractPrimitiveConcNode<Double, Node.OfDouble> + implements Node.OfDouble { DoubleConcNode(Node.OfDouble[] nodes) { super(nodes); @@ -1634,30 +1461,30 @@ } } - private static final class IntFixedNodeBuilder extends IntArrayNode implements Node.Builder.OfInt { + private static final class IntFixedNodeBuilder + extends IntArrayNode + implements Node.Builder.OfInt { IntFixedNodeBuilder(long size) { super(size); assert size < Streams.MAX_ARRAY_SIZE; } - // - @Override public Node.OfInt build() { if (curSize < array.length) { - throw new IllegalStateException(String.format("Current size %d is less than fixed size %d", curSize, array.length)); + throw new IllegalStateException(String.format("Current size %d is less than fixed size %d", + curSize, array.length)); } return this; } - // - @Override public void begin(long size) { if (size != array.length) { - throw new IllegalStateException(String.format("Begin size %d is not equal to fixed size %d", size, array.length)); + throw new IllegalStateException(String.format("Begin size %d is not equal to fixed size %d", + size, array.length)); } curSize = 0; @@ -1668,47 +1495,50 @@ if (curSize < array.length) { array[curSize++] = i; } else { - throw new IllegalStateException(String.format("Accept exceeded fixed size of %d", array.length)); + throw new IllegalStateException(String.format("Accept exceeded fixed size of %d", + array.length)); } } @Override public void end() { if (curSize < array.length) { - throw new IllegalStateException(String.format("End size %d is less than fixed size %d", curSize, array.length)); + throw new IllegalStateException(String.format("End size %d is less than fixed size %d", + curSize, array.length)); } } @Override public String toString() { - return String.format("IntFixedNodeBuilder[%d][%s]", array.length - curSize, Arrays.toString(array)); + return String.format("IntFixedNodeBuilder[%d][%s]", + array.length - curSize, Arrays.toString(array)); } } - private static final class LongFixedNodeBuilder extends LongArrayNode implements Node.Builder.OfLong { + private static final class LongFixedNodeBuilder + extends LongArrayNode + implements Node.Builder.OfLong { LongFixedNodeBuilder(long size) { super(size); assert size < Streams.MAX_ARRAY_SIZE; } - // - @Override public Node.OfLong build() { if (curSize < array.length) { - throw new IllegalStateException(String.format("Current size %d is less than fixed size %d", curSize, array.length)); + throw new IllegalStateException(String.format("Current size %d is less than fixed size %d", + curSize, array.length)); } return this; } - // - @Override public void begin(long size) { if (size != array.length) { - throw new IllegalStateException(String.format("Begin size %d is not equal to fixed size %d", size, array.length)); + throw new IllegalStateException(String.format("Begin size %d is not equal to fixed size %d", + size, array.length)); } curSize = 0; @@ -1719,47 +1549,50 @@ if (curSize < array.length) { array[curSize++] = i; } else { - throw new IllegalStateException(String.format("Accept exceeded fixed size of %d", array.length)); + throw new IllegalStateException(String.format("Accept exceeded fixed size of %d", + array.length)); } } @Override public void end() { if (curSize < array.length) { - throw new IllegalStateException(String.format("End size %d is less than fixed size %d", curSize, array.length)); + throw new IllegalStateException(String.format("End size %d is less than fixed size %d", + curSize, array.length)); } } @Override public String toString() { - return String.format("LongFixedNodeBuilder[%d][%s]", array.length - curSize, Arrays.toString(array)); + return String.format("LongFixedNodeBuilder[%d][%s]", + array.length - curSize, Arrays.toString(array)); } } - private static final class DoubleFixedNodeBuilder extends DoubleArrayNode implements Node.Builder.OfDouble { + private static final class DoubleFixedNodeBuilder + extends DoubleArrayNode + implements Node.Builder.OfDouble { DoubleFixedNodeBuilder(long size) { super(size); assert size < Streams.MAX_ARRAY_SIZE; } - // - @Override public Node.OfDouble build() { if (curSize < array.length) { - throw new IllegalStateException(String.format("Current size %d is less than fixed size %d", curSize, array.length)); + throw new IllegalStateException(String.format("Current size %d is less than fixed size %d", + curSize, array.length)); } return this; } - // - @Override public void begin(long size) { if (size != array.length) { - throw new IllegalStateException(String.format("Begin size %d is not equal to fixed size %d", size, array.length)); + throw new IllegalStateException(String.format("Begin size %d is not equal to fixed size %d", + size, array.length)); } curSize = 0; @@ -1770,24 +1603,29 @@ if (curSize < array.length) { array[curSize++] = i; } else { - throw new IllegalStateException(String.format("Accept exceeded fixed size of %d", array.length)); + throw new IllegalStateException(String.format("Accept exceeded fixed size of %d", + array.length)); } } @Override public void end() { if (curSize < array.length) { - throw new IllegalStateException(String.format("End size %d is less than fixed size %d", curSize, array.length)); + throw new IllegalStateException(String.format("End size %d is less than fixed size %d", + curSize, array.length)); } } @Override public String toString() { - return String.format("DoubleFixedNodeBuilder[%d][%s]", array.length - curSize, Arrays.toString(array)); + return String.format("DoubleFixedNodeBuilder[%d][%s]", + array.length - curSize, Arrays.toString(array)); } } - private static final class IntSpinedNodeBuilder extends SpinedBuffer.OfInt implements Node.OfInt, Node.Builder.OfInt { + private static final class IntSpinedNodeBuilder + extends SpinedBuffer.OfInt + implements Node.OfInt, Node.Builder.OfInt { private boolean building = false; IntSpinedNodeBuilder() {} // Avoid creation of special accessor @@ -1845,7 +1683,9 @@ } } - private static final class LongSpinedNodeBuilder extends SpinedBuffer.OfLong implements Node.OfLong, Node.Builder.OfLong { + private static final class LongSpinedNodeBuilder + extends SpinedBuffer.OfLong + implements Node.OfLong, Node.Builder.OfLong { private boolean building = false; LongSpinedNodeBuilder() {} // Avoid creation of special accessor @@ -1903,7 +1743,9 @@ } } - private static final class DoubleSpinedNodeBuilder extends SpinedBuffer.OfDouble implements Node.OfDouble, Node.Builder.OfDouble { + private static final class DoubleSpinedNodeBuilder + extends SpinedBuffer.OfDouble + implements Node.OfDouble, Node.Builder.OfDouble { private boolean building = false; DoubleSpinedNodeBuilder() {} // Avoid creation of special accessor
--- a/src/share/classes/java/util/stream/SliceOps.java Thu Apr 11 20:37:23 2013 -0400 +++ b/src/share/classes/java/util/stream/SliceOps.java Thu Apr 11 23:01:10 2013 -0400 @@ -298,7 +298,7 @@ @Override protected final Node<T> getEmptyResult() { - return Nodes.createEmptyNode(op.getOutputShape()); + return Nodes.emptyNode(op.getOutputShape()); } @Override @@ -340,7 +340,7 @@ visit(nodes, 0); Node<T> result; if (nodes.size() == 0) - result = Nodes.createEmptyNode(op.getOutputShape()); + result = Nodes.emptyNode(op.getOutputShape()); else if (nodes.size() == 1) result = nodes.get(0); else @@ -409,7 +409,7 @@ if (skipLeft == 0 && skipRight == 0) return input; else { - return Nodes.createTruncatedNode(input, skipLeft, thisNodeSize - skipRight, generator); + return Nodes.truncateNode(input, skipLeft, thisNodeSize - skipRight, generator); } } }
--- a/test-ng/boottests/java/util/stream/DoubleNodeTest.java Thu Apr 11 20:37:23 2013 -0400 +++ b/test-ng/boottests/java/util/stream/DoubleNodeTest.java Thu Apr 11 23:01:10 2013 -0400 @@ -24,19 +24,12 @@ */ package java.util.stream; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.PrimitiveIterator; -import java.util.Spliterator; import java.util.Spliterators; import java.util.function.Function; -import java.util.function.Supplier; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -60,7 +53,7 @@ nodes.add(degenerateTree(Spliterators.iteratorFromSpliterator(Arrays.spliterator(array)))); nodes.add(tree(toList(array), l -> Nodes.doubleNode(toDoubleArray(l)))); nodes.add(fill(array, Nodes.doubleMakeBuilder(array.length))); - nodes.add(fill(array, Nodes.doubleMakeVariableSizeBuilder())); + nodes.add(fill(array, Nodes.doubleMakeBuilder())); for (Node<Double> node : nodes) { params.add(new Object[]{array, node});
--- a/test-ng/boottests/java/util/stream/IntNodeTest.java Thu Apr 11 20:37:23 2013 -0400 +++ b/test-ng/boottests/java/util/stream/IntNodeTest.java Thu Apr 11 23:01:10 2013 -0400 @@ -53,7 +53,7 @@ nodes.add(degenerateTree(Spliterators.iteratorFromSpliterator(Arrays.spliterator(array)))); nodes.add(tree(toList(array), l -> Nodes.intNode(toIntArray(l)))); nodes.add(fill(array, Nodes.intMakeBuilder(array.length))); - nodes.add(fill(array, Nodes.intMakeVariableSizeBuilder())); + nodes.add(fill(array, Nodes.intMakeBuilder())); for (Node<Integer> node : nodes) { params.add(new Object[]{array, node});
--- a/test-ng/boottests/java/util/stream/LongNodeTest.java Thu Apr 11 20:37:23 2013 -0400 +++ b/test-ng/boottests/java/util/stream/LongNodeTest.java Thu Apr 11 23:01:10 2013 -0400 @@ -53,7 +53,7 @@ nodes.add(degenerateTree(Spliterators.iteratorFromSpliterator(Arrays.spliterator(array)))); nodes.add(tree(toList(array), l -> Nodes.longNode(toLongArray(l)))); nodes.add(fill(array, Nodes.longMakeBuilder(array.length))); - nodes.add(fill(array, Nodes.longMakeVariableSizeBuilder())); + nodes.add(fill(array, Nodes.longMakeBuilder())); for (Node<Long> node : nodes) { params.add(new Object[]{array, node});
--- a/test-ng/boottests/java/util/stream/NodeBuilderTest.java Thu Apr 11 20:37:23 2013 -0400 +++ b/test-ng/boottests/java/util/stream/NodeBuilderTest.java Thu Apr 11 23:01:10 2013 -0400 @@ -55,7 +55,7 @@ } List<Function<Integer, Node.Builder<Integer>>> ms = Arrays.asList( - s -> Nodes.makeVariableSizeBuilder(), + s -> Nodes.makeBuilder(), s -> Nodes.makeBuilder(s, LambdaTestHelpers.integerArrayGenerator) ); @@ -100,7 +100,7 @@ } List<Function<Integer, Node.Builder<Integer>>> ms = Arrays.asList( - s -> Nodes.intMakeVariableSizeBuilder(), + s -> Nodes.intMakeBuilder(), s -> Nodes.intMakeBuilder(s) ); @@ -149,7 +149,7 @@ } List<Function<Integer, Node.Builder<Long>>> ms = Arrays.asList( - s -> Nodes.longMakeVariableSizeBuilder(), + s -> Nodes.longMakeBuilder(), s -> Nodes.longMakeBuilder(s) ); @@ -198,7 +198,7 @@ } List<Function<Integer, Node.Builder<Double>>> ms = Arrays.asList( - s -> Nodes.doubleMakeVariableSizeBuilder(), + s -> Nodes.doubleMakeBuilder(), s -> Nodes.doubleMakeBuilder(s) );
--- a/test-ng/boottests/java/util/stream/NodeTest.java Thu Apr 11 20:37:23 2013 -0400 +++ b/test-ng/boottests/java/util/stream/NodeTest.java Thu Apr 11 23:01:10 2013 -0400 @@ -29,7 +29,6 @@ import java.util.*; import java.util.function.Function; -import java.util.Spliterator; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; @@ -55,7 +54,7 @@ nodes.add(tree(Arrays.asList(array), l -> Nodes.node(l.toArray(new Integer[l.size()])))); nodes.add(tree(Arrays.asList(array), l -> Nodes.node(l))); nodes.add(fill(array, Nodes.makeBuilder(array.length, LambdaTestHelpers.integerArrayGenerator))); - nodes.add(fill(array, Nodes.makeVariableSizeBuilder())); + nodes.add(fill(array, Nodes.makeBuilder())); for (int i = 0; i < nodes.size(); i++) { params.add(new Object[]{array, nodes.get(i)});