1 /* 2 * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package java.util.stream; 24 25 import org.testng.annotations.DataProvider; 26 27 import java.util.*; 28 import java.util.Spliterators; 29 import java.util.function.Supplier; 30 31 /** 32 * StreamTestDataProvider 33 * 34 * @author Brian Goetz 35 */ 36 /** TestNG DataProvider for ref-valued streams */ 37 public class StreamTestDataProvider { 38 private static final Integer[] to0 = new Integer[0]; 39 private static final Integer[] to1 = new Integer[1]; 40 private static final Integer[] to10 = new Integer[10]; 41 private static final Integer[] to100 = new Integer[100]; 42 private static final Integer[] to1000 = new Integer[1000]; 43 private static final Integer[] reversed = new Integer[100]; 44 private static final Integer[] ones = new Integer[100]; 45 private static final Integer[] twice = new Integer[200]; 46 private static final Integer[] pseudoRandom; 47 48 private static final Object[][] testData; 49 private static final Object[][] withNullTestData; 50 private static final Object[][] spliteratorTestData; 51 52 static { 53 Integer[][] arrays = {to0, to1, to10, to100, to1000}; 54 for (Integer[] arr : arrays) { 55 for (int i = 0; i < arr.length; i++) { 56 arr[i] = i; 57 } 58 } 59 for (int i = 0; i < reversed.length; i++) { 60 reversed[i] = reversed.length - i; 61 } 62 for (int i = 0; i < ones.length; i++) { 63 ones[i] = 1; 64 } 65 System.arraycopy(to100, 0, twice, 0, to100.length); 66 System.arraycopy(to100, 0, twice, to100.length, to100.length); 67 pseudoRandom = new Integer[LambdaTestHelpers.LONG_STRING.length()]; 68 for (int i = 0; i < LambdaTestHelpers.LONG_STRING.length(); i++) { 69 pseudoRandom[i] = (int) LambdaTestHelpers.LONG_STRING.charAt(i); 70 } 71 } 72 73 static final Object[][] arrays = { 74 {"empty", to0}, 75 {"0..1", to1}, 76 {"0..10", to10}, 77 {"0..100", to100}, 78 {"0..1000", to1000}, 79 {"100x[1]", ones}, 80 {"2x[0..100]", twice}, 81 {"reverse 0..100", reversed}, 82 {"pseudorandom", pseudoRandom} 83 }; 84 85 static { 86 { 87 List<Object[]> list = new ArrayList<>(); 88 for (Object[] data : arrays) { 89 final Object name = data[0]; 90 final Integer[] ints = (Integer[])data[1]; 91 final List<Integer> intsAsList = Arrays.asList(ints); 92 93 list.add(arrayDataDescr("array:" + name, ints)); 94 list.add(collectionDataDescr("ArrayList.asList:" + name, intsAsList)); 95 list.add(collectionDataDescr("ArrayList:" + name, new ArrayList<>(intsAsList))); 96 list.add(streamDataDescr("DelegatingStream(ArrayList):" + name, 97 () -> new ArrayList<>(intsAsList).stream())); 98 List<Integer> aList = new ArrayList<>(intsAsList); | 1 /* 2 * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package java.util.stream; 24 25 import org.testng.annotations.DataProvider; 26 27 import java.util.*; 28 import java.util.Spliterators; 29 import java.util.function.Supplier; 30 31 /** 32 * StreamTestDataProvider 33 * 34 * @author Brian Goetz 35 */ 36 /** TestNG DataProvider for ref-valued streams */ 37 public class StreamTestDataProvider { 38 private static final Integer[] to0 = new Integer[0]; 39 private static final Integer[] to1 = new Integer[1]; 40 private static final Integer[] to10 = new Integer[10]; 41 private static final Integer[] to100 = new Integer[100]; 42 private static final Integer[] reversed = new Integer[100]; 43 private static final Integer[] ones = new Integer[100]; 44 private static final Integer[] twice = new Integer[200]; 45 private static final Integer[] pseudoRandom; 46 47 private static final Object[][] testData; 48 private static final Object[][] withNullTestData; 49 private static final Object[][] spliteratorTestData; 50 51 static { 52 Integer[][] arrays = {to0, to1, to10, to100}; 53 for (Integer[] arr : arrays) { 54 for (int i = 0; i < arr.length; i++) { 55 arr[i] = i; 56 } 57 } 58 for (int i = 0; i < reversed.length; i++) { 59 reversed[i] = reversed.length - i; 60 } 61 for (int i = 0; i < ones.length; i++) { 62 ones[i] = 1; 63 } 64 System.arraycopy(to100, 0, twice, 0, to100.length); 65 System.arraycopy(to100, 0, twice, to100.length, to100.length); 66 pseudoRandom = new Integer[LambdaTestHelpers.LONG_STRING.length()]; 67 for (int i = 0; i < LambdaTestHelpers.LONG_STRING.length(); i++) { 68 pseudoRandom[i] = (int) LambdaTestHelpers.LONG_STRING.charAt(i); 69 } 70 } 71 72 static final Object[][] arrays = { 73 {"empty", to0}, 74 {"0..1", to1}, 75 {"0..10", to10}, 76 {"0..100", to100}, 77 {"100x[1]", ones}, 78 {"2x[0..100]", twice}, 79 {"reverse 0..100", reversed}, 80 {"pseudorandom", pseudoRandom} 81 }; 82 83 static { 84 { 85 List<Object[]> list = new ArrayList<>(); 86 for (Object[] data : arrays) { 87 final Object name = data[0]; 88 final Integer[] ints = (Integer[])data[1]; 89 final List<Integer> intsAsList = Arrays.asList(ints); 90 91 list.add(arrayDataDescr("array:" + name, ints)); 92 list.add(collectionDataDescr("ArrayList.asList:" + name, intsAsList)); 93 list.add(collectionDataDescr("ArrayList:" + name, new ArrayList<>(intsAsList))); 94 list.add(streamDataDescr("DelegatingStream(ArrayList):" + name, 95 () -> new ArrayList<>(intsAsList).stream())); 96 List<Integer> aList = new ArrayList<>(intsAsList); |