changeset 7307:830af530db9c

Move truncate code out of Node and into SliceOp, its only consumer
author briangoetz
date Mon, 11 Feb 2013 16:21:51 -0500
parents 7ab253f0022b
children ffe9f459d921
files src/share/classes/java/util/stream/Node.java src/share/classes/java/util/stream/SliceOp.java
diffstat 2 files changed, 20 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/util/stream/Node.java	Mon Feb 11 17:00:08 2013 +0100
+++ b/src/share/classes/java/util/stream/Node.java	Mon Feb 11 16:21:51 2013 -0500
@@ -88,8 +88,8 @@
      */
     void copyInto(T[] array, int offset);
 
-    default Node<T> truncate(long from, long to, IntFunction<T[]> generator) {
-        return Nodes.truncateNode(this, from, to, generator);
+    default StreamShape getShape() {
+        return StreamShape.REFERENCE;
     }
 
     /**
@@ -171,8 +171,8 @@
 
         void copyInto(int[] array, int offset);
 
-        default OfInt truncate(long from, long to, IntFunction<Integer[]> generator) {
-            return Nodes.truncateIntNode(this, from, to);
+        default StreamShape getShape() {
+            return StreamShape.INT_VALUE;
         }
     }
 
@@ -218,9 +218,8 @@
 
         void copyInto(long[] array, int offset);
 
-        @Override
-        default OfLong truncate(long from, long to, IntFunction<Long[]> generator) {
-            return Nodes.truncateLongNode(this, from, to);
+        default StreamShape getShape() {
+            return StreamShape.LONG_VALUE;
         }
     }
 
@@ -266,9 +265,8 @@
 
         void copyInto(double[] array, int offset);
 
-        @Override
-        default OfDouble truncate(long from, long to, IntFunction<Double[]> generator) {
-            return Nodes.truncateDoubleNode(this, from, to);
+        default StreamShape getShape() {
+            return StreamShape.DOUBLE_VALUE;
         }
     }
 }
--- a/src/share/classes/java/util/stream/SliceOp.java	Mon Feb 11 17:00:08 2013 +0100
+++ b/src/share/classes/java/util/stream/SliceOp.java	Mon Feb 11 16:21:51 2013 -0500
@@ -358,7 +358,18 @@
             if (skipLeft == 0 && skipRight == 0)
                 return input;
             else {
-                return input.truncate(skipLeft, thisNodeSize - skipRight, helper.arrayGenerator());
+                switch (input.getShape()) {
+                    case REFERENCE:
+                        return Nodes.truncateNode(input, skipLeft, thisNodeSize - skipRight, helper.arrayGenerator());
+                    case INT_VALUE:
+                        return (Node<T>) Nodes.truncateIntNode((Node.OfInt) input, skipLeft, thisNodeSize - skipRight);
+                    case LONG_VALUE:
+                        return (Node<T>) Nodes.truncateLongNode((Node.OfLong) input, skipLeft, thisNodeSize - skipRight);
+                    case DOUBLE_VALUE:
+                        return (Node<T>) Nodes.truncateDoubleNode((Node.OfDouble) input, skipLeft, thisNodeSize - skipRight);
+                    default:
+                        throw new IllegalStateException("Unknown shape " + input.getShape());
+                }
             }
         }
     }