author | dl |
Wed, 21 Dec 2016 14:22:53 -0800 | |
changeset 42926 | 8b9cacdadb2d |
child 44589 | 64d9270bd24c |
permissions | -rw-r--r-- |
42926
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
1 |
/* |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
3 |
* |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
4 |
* This code is free software; you can redistribute it and/or modify it |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
5 |
* under the terms of the GNU General Public License version 2 only, as |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
6 |
* published by the Free Software Foundation. |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
7 |
* |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
8 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
9 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
10 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
11 |
* version 2 for more details (a copy is included in the LICENSE file that |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
12 |
* accompanied this code). |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
13 |
* |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License version |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
15 |
* 2 along with this work; if not, write to the Free Software Foundation, |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
16 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
17 |
* |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
18 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
19 |
* or visit www.oracle.com if you need additional information or have any |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
20 |
* questions. |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
21 |
*/ |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
22 |
|
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
23 |
/* |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
24 |
* This file is available under and governed by the GNU General Public |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
25 |
* License version 2 only, as published by the Free Software Foundation. |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
26 |
* However, the following notice accompanied the original version of this |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
27 |
* file: |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
28 |
* |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
29 |
* Written by Doug Lea and Martin Buchholz with assistance from |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
30 |
* members of JCP JSR-166 Expert Group and released to the public |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
31 |
* domain, as explained at |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
32 |
* http://creativecommons.org/publicdomain/zero/1.0/ |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
33 |
*/ |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
34 |
|
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
35 |
import java.util.concurrent.LinkedBlockingDeque; |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
36 |
import java.util.Spliterator; |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
37 |
|
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
38 |
import junit.framework.Test; |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
39 |
import junit.framework.TestSuite; |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
40 |
|
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
41 |
public class LinkedBlockingDeque8Test extends JSR166TestCase { |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
42 |
public static void main(String[] args) { |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
43 |
main(suite(), args); |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
44 |
} |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
45 |
|
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
46 |
public static Test suite() { |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
47 |
return newTestSuite(LinkedBlockingDeque8Test.class); |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
48 |
} |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
49 |
|
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
50 |
/** |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
51 |
* Spliterator.getComparator always throws IllegalStateException |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
52 |
*/ |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
53 |
public void testSpliterator_getComparator() { |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
54 |
assertThrows(IllegalStateException.class, |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
55 |
() -> new LinkedBlockingDeque().spliterator().getComparator()); |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
56 |
} |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
57 |
|
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
58 |
/** |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
59 |
* Spliterator characteristics are as advertised |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
60 |
*/ |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
61 |
public void testSpliterator_characteristics() { |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
62 |
LinkedBlockingDeque q = new LinkedBlockingDeque(); |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
63 |
Spliterator s = q.spliterator(); |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
64 |
int characteristics = s.characteristics(); |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
65 |
int required = Spliterator.CONCURRENT |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
66 |
| Spliterator.NONNULL |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
67 |
| Spliterator.ORDERED; |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
68 |
assertEquals(required, characteristics & required); |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
69 |
assertTrue(s.hasCharacteristics(required)); |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
70 |
assertEquals(0, characteristics |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
71 |
& (Spliterator.DISTINCT |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
72 |
| Spliterator.IMMUTABLE |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
73 |
| Spliterator.SORTED)); |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
74 |
} |
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
75 |
|
8b9cacdadb2d
8171051: LinkedBlockingQueue spliterator needs to support node self-linking
dl
parents:
diff
changeset
|
76 |
} |