1 /* |
1 /* |
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
57 import static org.testng.Assert.*; |
57 import static org.testng.Assert.*; |
58 |
58 |
59 @Test |
59 @Test |
60 public class SpliteratorCharacteristics { |
60 public class SpliteratorCharacteristics { |
61 |
61 |
|
62 public void testSpliteratorFromCharSequence() { |
|
63 class CharSequenceImpl implements CharSequence { |
|
64 final String s; |
|
65 |
|
66 public CharSequenceImpl(String s) { |
|
67 this.s = s; |
|
68 } |
|
69 |
|
70 @Override |
|
71 public int length() { |
|
72 return s.length(); |
|
73 } |
|
74 |
|
75 @Override |
|
76 public char charAt(int index) { |
|
77 return s.charAt(index); |
|
78 } |
|
79 |
|
80 @Override |
|
81 public CharSequence subSequence(int start, int end) { |
|
82 return s.subSequence(start, end); |
|
83 } |
|
84 |
|
85 @Override |
|
86 public String toString() { |
|
87 return s; |
|
88 } |
|
89 } |
|
90 |
|
91 CharSequence cs = "A"; |
|
92 Spliterator.OfInt s = cs.chars().spliterator(); |
|
93 assertCharacteristics(s, Spliterator.IMMUTABLE | Spliterator.ORDERED | |
|
94 Spliterator.SIZED | Spliterator.SUBSIZED); |
|
95 assertHasNotCharacteristics(s, Spliterator.CONCURRENT); |
|
96 s = cs.codePoints().spliterator(); |
|
97 assertCharacteristics(s, Spliterator.IMMUTABLE | Spliterator.ORDERED); |
|
98 assertHasNotCharacteristics(s, Spliterator.CONCURRENT); |
|
99 |
|
100 for (CharSequence c : Arrays.asList(new CharSequenceImpl("A"), |
|
101 new StringBuilder("A"), |
|
102 new StringBuffer("A"))) { |
|
103 s = cs.chars().spliterator(); |
|
104 assertCharacteristics(s, Spliterator.ORDERED | |
|
105 Spliterator.SIZED | Spliterator.SUBSIZED); |
|
106 assertHasNotCharacteristics(s, Spliterator.CONCURRENT); |
|
107 s = cs.codePoints().spliterator(); |
|
108 assertCharacteristics(s, Spliterator.ORDERED); |
|
109 assertHasNotCharacteristics(s, Spliterator.CONCURRENT); |
|
110 } |
|
111 } |
|
112 |
62 public void testSpliteratorFromCollection() { |
113 public void testSpliteratorFromCollection() { |
63 List<Integer> l = Arrays.asList(1, 2, 3, 4); |
114 List<Integer> l = Arrays.asList(1, 2, 3, 4); |
64 |
115 |
65 { |
116 { |
66 Spliterator<?> s = Spliterators.spliterator(l, 0); |
117 Spliterator<?> s = Spliterators.spliterator(l, 0); |