changeset 8449:5097c0fece93

Merge
author mduigou
date Wed, 01 May 2013 07:59:39 -0700
parents 993cb4bb1ea3 e05ae11a0854
children 59f22c48f695
files
diffstat 15 files changed, 71 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/io/BufferedReader.java	Tue Apr 30 15:51:45 2013 -0700
+++ b/src/share/classes/java/io/BufferedReader.java	Wed May 01 07:59:39 2013 -0700
@@ -537,16 +537,28 @@
      *
      * <p>Each element consumed by the {@code Stream} caused a line to be
      * read from this {@code BufferedReader}. Since the {@code Stream} does
-     * not necessary consume all lines, it is possible to mix and use
+     * not necessarily consume all lines, it is possible to mix and use
      * different read methods on a {@code BufferedReader}. Each method will
      * simply pick up from where it was left on last read.
      *
+     * <p>The reader must not be operated on during the execution of the terminal
+     * stream operation. Otherwise, the result of the terminal stream operation is
+     * undefined
+     *
+     * <p>Noted that some terminal stream operations make no guarantee how many
+     * element to be consumed. Therefore after execution of the terminal
+     * stream operation there are no guarantees that the reader will be at a
+     * specific position from which to read the next character or line.
+     *
      * <p>If an {@link IOException} is thrown when accessing the underlying
      * {@code BufferedReader}, it is wrapped in an {@link
      * UncheckedIOException} which will be thrown from the {@code Stream}
      * method that caused the read to take place. For example, when trying to
      * read from the {@code Stream} after the {@code BufferedReader} is
-     * closed, will throw an {@code UnchecheckedIOException}.
+     * closed, will throw an {@code UncheckedIOException}. Note that This
+     * method will return the {@code Stream} even if this {@code
+     * BufferedReader} is closed, but the operation cause reading will throw
+     * {@code UncheckedIOException}.
      *
      * @return a {@code Stream<String>} providing the lines of text
      *         described by this {@code BufferedReader}
@@ -574,11 +586,9 @@
             @Override
             public String next() {
                 if (nextLine != null || hasNext()) {
-                    try {
-                        return nextLine;
-                    } finally {
-                        nextLine = null;
-                    }
+                    String line = nextLine;
+                    nextLine = null;
+                    return line;
                 } else {
                     throw new NoSuchElementException();
                 }
--- a/src/share/classes/java/io/UncheckedIOException.java	Tue Apr 30 15:51:45 2013 -0700
+++ b/src/share/classes/java/io/UncheckedIOException.java	Wed May 01 07:59:39 2013 -0700
@@ -29,8 +29,7 @@
 /**
  * Wraps an {@link IOException} with an unchecked exception.
  *
- * @see     java.io.IOException
- * @since   JDK1.8
+ * @since   1.8
  */
 public class UncheckedIOException extends RuntimeException {
     private static final long serialVersionUID = -8134305061645241065L;
--- a/src/share/classes/java/nio/file/Files.java	Tue Apr 30 15:51:45 2013 -0700
+++ b/src/share/classes/java/nio/file/Files.java	Wed May 01 07:59:39 2013 -0700
@@ -3409,15 +3409,18 @@
      * Path} by searching for files in a file tree rooted at a given starting
      * file.
      *
-     * <p> This method walks the file tree in exactly the manner specified by
+     * <p>This method walks the file tree in exactly the manner specified by
      * the {@link #walk walk} method. For each file encountered, the given
      * {@link BiPredicate} is invoked with its {@link Path} and {@link
      * BasicFileAttributes}. The {@code Path} object is obtained as if by
      * {@link Path#resolve(Path) resolving} the relative path against {@code
      * start} and is only included in the returned {@link CloseableStream} if
-     * the {@code BiPredicate} returns true.
-     *
-     * <p> If an {@link IOException} is thrown when accessing the directory
+     * the {@code BiPredicate} returns true. Compare to calling {@link
+     * java.util.stream.Stream#filter filter} on the {@code Stream} returned
+     * by {@code walk} method, this method is more efficient by avoiding
+     * redundant retrieval of the {@code BasicFileAttributes}.
+     *
+     * <p>If an {@link IOException} is thrown when accessing the directory
      * after returned from this method, it is wrapped in an {@link
      * UncheckedIOException} which will be thrown from the method that caused
      * the access to take place.
--- a/src/share/classes/java/util/zip/ZipFile.java	Tue Apr 30 15:51:45 2013 -0700
+++ b/src/share/classes/java/util/zip/ZipFile.java	Wed May 01 07:59:39 2013 -0700
@@ -536,9 +536,11 @@
     }
 
     /**
-     * Return a {@code Stream} of the ZIP file entries.
+     * Return an ordered {@code Stream} over the ZIP file entries.
+     * Entries appear in the {@code Stream} in the order they appear in
+     * the central directory of the ZIP file.
      *
-     * @return a {@code Stream} of entries in this ZIP file
+     * @return an ordered {@code Stream} of entries in this ZIP file
      * @throws IllegalStateException if the zip file has been closed
      * @since 1.8
      */
--- a/test-ng/bootlib/java/util/stream/LambdaTestHelpers.java	Tue Apr 30 15:51:45 2013 -0700
+++ b/test-ng/bootlib/java/util/stream/LambdaTestHelpers.java	Wed May 01 07:59:39 2013 -0700
@@ -132,6 +132,15 @@
         return t -> predicate.test(t) ? forTrue : forFalse;
     }
 
+    public static <T> Function<T, T> identity() {
+        return t -> t;
+    }
+
+    public static<V, T, R> Function<V, R> compose(Function<? super T, ? extends R> after, Function<? super V, ? extends T> before) {
+        Objects.requireNonNull(before);
+        return (V v) -> after.apply(before.apply(v));
+    }
+
     public static List<Integer> empty() {
         ArrayList<Integer> list = new ArrayList<>();
         list.add(null);
--- a/test-ng/tests/org/openjdk/tests/java/util/regex/PatternTest.java	Tue Apr 30 15:51:45 2013 -0700
+++ b/test-ng/tests/org/openjdk/tests/java/util/regex/PatternTest.java	Wed May 01 07:59:39 2013 -0700
@@ -8,6 +8,7 @@
 import java.util.function.Function;
 import java.util.function.Supplier;
 import java.util.regex.Pattern;
+import java.util.stream.LambdaTestHelpers;
 import java.util.stream.OpTestCase;
 import java.util.stream.Stream;
 import java.util.stream.TestData;
@@ -97,6 +98,6 @@
     public void testStrings(String description, String input, Pattern pattern, List<String> expected) {
 	Supplier<Stream<String>> ss =  () -> pattern.splitAsStream(input);
 	withData(TestData.Factory.ofSupplier(description, ss))
-		 .stream(Function.identity()).expectedResult(expected).exercise();
+		 .stream(LambdaTestHelpers.identity()).expectedResult(expected).exercise();
     }
 }
--- a/test-ng/tests/org/openjdk/tests/java/util/stream/ForEachOpTest.java	Tue Apr 30 15:51:45 2013 -0700
+++ b/test-ng/tests/org/openjdk/tests/java/util/stream/ForEachOpTest.java	Wed May 01 07:59:39 2013 -0700
@@ -79,7 +79,7 @@
 
         // Test multiple stages
         withData(data).
-                terminal(s -> s.map(Function.identity()), terminalFunc).
+                terminal(s -> s.map(LambdaTestHelpers.identity()), terminalFunc).
                 expectedResult(input).
                 exercise();
     }
@@ -100,7 +100,7 @@
 
         // Test multiple stages
         withData(data).
-                terminal(s -> s.map(Function.identity()), terminalFunc).
+                terminal(s -> s.map(LambdaTestHelpers.identity()), terminalFunc).
                 parallelEqualityAsserter(LambdaTestHelpers::assertContentsUnordered).
                 exercise();
     }
--- a/test-ng/tests/org/openjdk/tests/java/util/stream/GroupByOpTest.java	Tue Apr 30 15:51:45 2013 -0700
+++ b/test-ng/tests/org/openjdk/tests/java/util/stream/GroupByOpTest.java	Wed May 01 07:59:39 2013 -0700
@@ -115,8 +115,8 @@
             new MapperData<>(mId, uniqueSize),
             new MapperData<>(mZero, Math.min(1, data.size())),
             new MapperData<>(mDoubler, uniqueSize),
-            new MapperData<>(mId.compose(mDoubler), uniqueSize),
-            new MapperData<>(mDoubler.compose(mDoubler), uniqueSize),
+            new MapperData<>(LambdaTestHelpers.compose(mId, mDoubler), uniqueSize),
+            new MapperData<>(LambdaTestHelpers.compose(mDoubler, mDoubler), uniqueSize),
 
             new MapperData<>(LambdaTestHelpers.forPredicate(pFalse, true, false), Math.min(1, uniqueSize)),
             new MapperData<>(LambdaTestHelpers.forPredicate(pTrue, true, false), Math.min(1, uniqueSize)),
--- a/test-ng/tests/org/openjdk/tests/java/util/stream/InfiniteStreamWithLimitOpTest.java	Tue Apr 30 15:51:45 2013 -0700
+++ b/test-ng/tests/org/openjdk/tests/java/util/stream/InfiniteStreamWithLimitOpTest.java	Wed May 01 07:59:39 2013 -0700
@@ -31,7 +31,6 @@
 import java.util.List;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
-import java.util.stream.Streams;
 
 import static java.util.stream.LambdaTestHelpers.assertContents;
 
@@ -59,8 +58,11 @@
     }
 
     public void testInfiniteWithLimitToShortCircuitTerminal() {
-        Stream.generate(() -> (Integer) 1).limit(4).toArray();
-        Stream.generate(() -> (Integer) 1).limit(4).filter(i -> true).toArray();
-        Stream.generate(() -> (Integer) 1).limit(4).collect(Collectors.toList());
+        Object[] array = Stream.generate(() -> 1).limit(4).toArray();
+        assertEquals(4, array.length);
+        array = Stream.generate(() -> 1).limit(4).filter(i -> true).toArray();
+        assertEquals(4, array.length);
+        List<Integer> result = Stream.generate(() -> 1).limit(4).collect(Collectors.toList());
+        assertEquals(result, Arrays.asList(1, 1, 1, 1));
     }
 }
--- a/test-ng/tests/org/openjdk/tests/java/util/stream/MapOpTest.java	Tue Apr 30 15:51:45 2013 -0700
+++ b/test-ng/tests/org/openjdk/tests/java/util/stream/MapOpTest.java	Wed May 01 07:59:39 2013 -0700
@@ -56,8 +56,8 @@
         assertCountSum(countTo(10).stream().map(mDoubler), 10, 110);
         assertCountSum(countTo(10).stream().map(mDoubler).map(mDoubler), 10, 220);
 
-        exerciseOps(countTo(0), s -> s.map(Function.identity()), countTo(0));
-        exerciseOps(countTo(1000), s -> s.map(Function.identity()), countTo(1000));
+        exerciseOps(countTo(0), s -> s.map(LambdaTestHelpers.identity()), countTo(0));
+        exerciseOps(countTo(1000), s -> s.map(LambdaTestHelpers.identity()), countTo(1000));
         // @@@ Force cast to integer so output is Stream<Integer> rather an IntStream
         //     this just ensures that no warnings are logged about boxing
         //     when the result is compared with the output
@@ -86,8 +86,8 @@
         exerciseOpsInt(data, s -> s.map(mId), s -> s.map(e -> e), s -> s.map(e -> e), s -> s.map(e -> e));
         exerciseOpsInt(data, s -> s.map(mZero), s -> s.map(e -> 0), s -> s.map(e -> 0), s -> s.map(e -> 0));
         exerciseOpsInt(data, s -> s.map(mDoubler), s -> s.map(e -> 2*e), s -> s.map(e -> 2*e), s -> s.map(e -> 2*e));
-        exerciseOpsInt(data, s -> s.map(mId.compose(mDoubler)), s -> s.map(e -> 2*e), s -> s.map(e -> 2*e), s -> s.map(e -> 2*e));
-        exerciseOpsInt(data, s -> s.map(mDoubler.compose(mDoubler)), s -> s.map(e -> 4*e), s -> s.map(e -> 4*e), s -> s.map(e -> 4*e));
+        exerciseOpsInt(data, s -> s.map(LambdaTestHelpers.compose(mId, mDoubler)), s -> s.map(e -> 2*e), s -> s.map(e -> 2*e), s -> s.map(e -> 2*e));
+        exerciseOpsInt(data, s -> s.map(LambdaTestHelpers.compose(mDoubler, mDoubler)), s -> s.map(e -> 4*e), s -> s.map(e -> 4*e), s -> s.map(e -> 4*e));
         exerciseOps(data, s -> s.mapToInt(i -> i));
         exerciseOps(data, s -> s.mapToLong(i -> i));
         exerciseOps(data, s -> s.mapToDouble(i -> i));
--- a/test-ng/tests/org/openjdk/tests/java/util/stream/SequentialOpTest.java	Tue Apr 30 15:51:45 2013 -0700
+++ b/test-ng/tests/org/openjdk/tests/java/util/stream/SequentialOpTest.java	Wed May 01 07:59:39 2013 -0700
@@ -52,7 +52,7 @@
     @Test(dataProvider = "StreamTestData<Integer>", dataProviderClass = StreamTestDataProvider.class,
           groups = { "serialization-hostile" })
     public void testLazy(String name, TestData.OfRef<Integer> data) {
-        Function<Integer, Integer> id = Function.identity();
+        Function<Integer, Integer> id = LambdaTestHelpers.identity();
         AtomicInteger counter = new AtomicInteger();
         Supplier<Stream<Integer>>[] suppliers = new Supplier[] { () -> data.stream(), () -> data.parallelStream() };
         UnaryOperator<Stream<Integer>>[] configs
@@ -93,7 +93,7 @@
     @SuppressWarnings({"rawtypes", "unchecked"})
     @Test(dataProvider = "StreamTestData<Integer>", dataProviderClass = StreamTestDataProvider.class)
     public void testMixedSeqPar(String name, TestData.OfRef<Integer> data) {
-        Function<Integer, Integer> id = Function.identity();
+        Function<Integer, Integer> id = LambdaTestHelpers.identity();
         UnaryOperator<Stream<Integer>>[] changers
                 = new UnaryOperator[] {
                 (UnaryOperator<Stream<Integer>>) s -> s,
--- a/test-ng/tests/org/openjdk/tests/java/util/stream/StreamBuilderTest.java	Tue Apr 30 15:51:45 2013 -0700
+++ b/test-ng/tests/org/openjdk/tests/java/util/stream/StreamBuilderTest.java	Wed May 01 07:59:39 2013 -0700
@@ -33,6 +33,7 @@
 import java.util.function.Function;
 import java.util.stream.DoubleStream;
 import java.util.stream.IntStream;
+import java.util.stream.LambdaTestHelpers;
 import java.util.stream.LongStream;
 import java.util.stream.OpTestCase;
 import java.util.stream.Stream;
@@ -83,7 +84,7 @@
                 exercise();
 
         withData(data).
-                stream(s -> s.map(Function.identity())).
+                stream(s -> s.map(LambdaTestHelpers.identity())).
                 expectedResult(Collections.singletonList(1)).
                 exercise();
     }
@@ -127,7 +128,7 @@
                 exercise();
 
         withData(data).
-                stream(s -> s.map(Function.identity())).
+                stream(s -> s.map(LambdaTestHelpers.identity())).
                 expectedResult(IntStream.range(0, size).boxed().collect(toList())).
                 exercise();
     }
--- a/test-ng/tests/org/openjdk/tests/java/util/stream/StreamSpliteratorTest.java	Tue Apr 30 15:51:45 2013 -0700
+++ b/test-ng/tests/org/openjdk/tests/java/util/stream/StreamSpliteratorTest.java	Wed May 01 07:59:39 2013 -0700
@@ -38,6 +38,7 @@
 import java.util.stream.DoubleStreamTestDataProvider;
 import java.util.stream.IntStream;
 import java.util.stream.IntStreamTestDataProvider;
+import java.util.stream.LambdaTestHelpers;
 import java.util.stream.LongStream;
 import java.util.stream.LongStreamTestDataProvider;
 import java.util.stream.OpTestCase;
@@ -254,7 +255,7 @@
         List<UnaryOperator<Stream<Integer>>> intermediateOps = Arrays.asList(
                 s -> s.parallel(),
                 // The following ensures the wrapping spliterator is tested
-                s -> s.map(Function.identity()).parallel()
+                s -> s.map(LambdaTestHelpers.identity()).parallel()
         );
 
         for (Consumer<Stream<Integer>> terminalOp : terminalOps) {
--- a/test-ng/tests/org/openjdk/tests/java/util/stream/TabulatorsTest.java	Tue Apr 30 15:51:45 2013 -0700
+++ b/test-ng/tests/org/openjdk/tests/java/util/stream/TabulatorsTest.java	Wed May 01 07:59:39 2013 -0700
@@ -326,23 +326,23 @@
         exerciseMapTabulation(data,
                               groupingBy(classifier, reducing(0, Integer::sum)),
                               new GroupedMapAssertion<>(classifier, HashMap.class,
-                                                        new ReduceAssertion<>(0, Function.identity(), Integer::sum)));
+                                                        new ReduceAssertion<>(0, LambdaTestHelpers.identity(), Integer::sum)));
         // with concurrent
         exerciseMapTabulation(data,
                               groupingByConcurrent(classifier, reducing(0, Integer::sum)),
                               new GroupedMapAssertion<>(classifier, ConcurrentHashMap.class,
-                                                        new ReduceAssertion<>(0, Function.identity(), Integer::sum)));
+                                                        new ReduceAssertion<>(0, LambdaTestHelpers.identity(), Integer::sum)));
 
         // With explicit constructors
         exerciseMapTabulation(data,
                               groupingBy(classifier, TreeMap::new, reducing(0, Integer::sum)),
                               new GroupedMapAssertion<>(classifier, TreeMap.class,
-                                                        new ReduceAssertion<>(0, Function.identity(), Integer::sum)));
+                                                        new ReduceAssertion<>(0, LambdaTestHelpers.identity(), Integer::sum)));
         // with concurrent
         exerciseMapTabulation(data,
                               groupingByConcurrent(classifier, ConcurrentSkipListMap::new, reducing(0, Integer::sum)),
                               new GroupedMapAssertion<>(classifier, ConcurrentSkipListMap.class,
-                                                        new ReduceAssertion<>(0, Function.identity(), Integer::sum)));
+                                                        new ReduceAssertion<>(0, LambdaTestHelpers.identity(), Integer::sum)));
 
         // Single-level map-reduce
         exerciseMapTabulation(data,
@@ -395,6 +395,6 @@
         exerciseMapTabulation(data,
                               partitioningBy(classifier, reducing(0, Integer::sum)),
                               new PartitionAssertion<>(classifier,
-                                                       new ReduceAssertion<>(0, Function.identity(), Integer::sum)));
+                                                       new ReduceAssertion<>(0, LambdaTestHelpers.identity(), Integer::sum)));
     }
 }
--- a/test/java/io/BufferedReader/Lines.java	Tue Apr 30 15:51:45 2013 -0700
+++ b/test/java/io/BufferedReader/Lines.java	Wed May 01 07:59:39 2013 -0700
@@ -1,12 +1,10 @@
 /*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
+ * published by the Free Software Foundation.
  *
  * This code is distributed in the hope that it will be useful, but WITHOUT
  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
@@ -103,7 +101,9 @@
         }
 
         @Override
-        public void close() { closed = true; }
+        public void close() {
+            closed = true;
+        }
 
         @Override
         public int read(char[] buf, int off, int len) throws IOException {