jdk/test/java/util/Spliterator/SpliteratorCharacteristics.java
changeset 28667 2245cc40bf5d
parent 20489 cce02e4a6cbe
child 32991 b27c76b82713
equal deleted inserted replaced
28666:49cdfa0ea390 28667:2245cc40bf5d
     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.
    21  * questions.
    21  * questions.
    22  */
    22  */
    23 
    23 
    24 /**
    24 /**
    25  * @test
    25  * @test
    26  * @bug 8020156 8020009 8022326 8012913 8024405 8024408
    26  * @bug 8020156 8020009 8022326 8012913 8024405 8024408 8071477
    27  * @run testng SpliteratorCharacteristics
    27  * @run testng SpliteratorCharacteristics
    28  */
    28  */
    29 
    29 
    30 import org.testng.annotations.Test;
    30 import org.testng.annotations.Test;
    31 
    31 
    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);