author | martin |
Mon, 27 Oct 2014 16:24:43 -0700 | |
changeset 27718 | 5e08d0fb67c9 |
permissions | -rw-r--r-- |
27718
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
1 |
/* |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
2 |
* Copyright 2014 Google, Inc. All Rights Reserved. |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
4 |
* |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
8 |
* |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
13 |
* accompanied this code). |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
14 |
* |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
18 |
* |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
21 |
* questions. |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
22 |
*/ |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
23 |
|
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
24 |
/* @test |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
25 |
* @bug 8062194 |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
26 |
* @summary Ensure Attribute iteration order is the insertion order. |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
27 |
*/ |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
28 |
|
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
29 |
import java.util.Arrays; |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
30 |
import java.util.Map; |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
31 |
import java.util.jar.Attributes; |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
32 |
import java.util.jar.Attributes.Name; |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
33 |
|
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
34 |
public class IterationOrder { |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
35 |
static void checkOrder(Attributes.Name k0, String v0, |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
36 |
Attributes.Name k1, String v1, |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
37 |
Attributes.Name k2, String v2) { |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
38 |
Attributes x = new Attributes(); |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
39 |
x.put(k0, v0); |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
40 |
x.put(k1, v1); |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
41 |
x.put(k2, v2); |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
42 |
Map.Entry<?,?>[] entries |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
43 |
= x.entrySet().toArray(new Map.Entry<?,?>[3]); |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
44 |
if (!(entries.length == 3 |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
45 |
&& entries[0].getKey() == k0 |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
46 |
&& entries[0].getValue() == v0 |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
47 |
&& entries[1].getKey() == k1 |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
48 |
&& entries[1].getValue() == v1 |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
49 |
&& entries[2].getKey() == k2 |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
50 |
&& entries[2].getValue() == v2)) { |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
51 |
throw new AssertionError(Arrays.toString(entries)); |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
52 |
} |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
53 |
|
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
54 |
Object[] keys = x.keySet().toArray(); |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
55 |
if (!(keys.length == 3 |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
56 |
&& keys[0] == k0 |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
57 |
&& keys[1] == k1 |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
58 |
&& keys[2] == k2)) { |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
59 |
throw new AssertionError(Arrays.toString(keys)); |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
60 |
} |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
61 |
} |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
62 |
|
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
63 |
public static void main(String[] args) throws Exception { |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
64 |
Attributes.Name k0 = Name.MANIFEST_VERSION; |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
65 |
Attributes.Name k1 = Name.MAIN_CLASS; |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
66 |
Attributes.Name k2 = Name.SEALED; |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
67 |
String v0 = "42.0"; |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
68 |
String v1 = "com.google.Hello"; |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
69 |
String v2 = "yes"; |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
70 |
checkOrder(k0, v0, k1, v1, k2, v2); |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
71 |
checkOrder(k1, v1, k0, v0, k2, v2); |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
72 |
checkOrder(k2, v2, k1, v1, k0, v0); |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
73 |
} |
5e08d0fb67c9
8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents:
diff
changeset
|
74 |
} |