author | pliden |
Thu, 26 Sep 2019 13:56:58 +0200 | |
changeset 58355 | de246fd65587 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
28969
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
1 |
/* |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
2 |
* Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved. |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
4 |
* |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
10 |
* |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
15 |
* accompanied this code). |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
16 |
* |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
20 |
* |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
23 |
* questions. |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
24 |
*/ |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
25 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
26 |
package build.tools.charsetmapping; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
27 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
28 |
import java.io.*; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
29 |
import java.util.*; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
30 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
31 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
32 |
/** |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
33 |
* Reads a map in the form of a sequence of key/value-expression pairs from the |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
34 |
* standard input, attempts to construct a hash map that fits within the given |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
35 |
* table-size and chain-depth constraints, and, if successful, writes source |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
36 |
* code to the standard output for a subclass of sun.util.PreHashedMap that |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
37 |
* implements the map. |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
38 |
* |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
39 |
* @see sun.util.PreHashedMap |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
40 |
* |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
41 |
* @author Mark Reinhold |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
42 |
*/ |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
43 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
44 |
public class Hasher { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
45 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
46 |
private PrintStream err = System.err; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
47 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
48 |
boolean verbose = false; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
49 |
List<String> keys = new ArrayList<>(); // Key strings |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
50 |
List<String> values = new ArrayList<>(); // Value expressions |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
51 |
String pkg = null; // Package prefix for generated class |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
52 |
String cln = null; // Name of generated class |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
53 |
String vtype = null; // Value type |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
54 |
int maxBits = 11; // lg table size |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
55 |
int maxDepth = 3; // Max chain depth |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
56 |
boolean inner = false; // Generating an inner class? |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
57 |
boolean empty = false; // Generating an empty table? |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
58 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
59 |
Object[] ht; // Hash table itself |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
60 |
int nb; // Number of bits (lg table size) |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
61 |
int md; // Maximum chain depth |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
62 |
int mask; // Hash-code mask |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
63 |
int shift; // Hash-code shift size |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
64 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
65 |
int hash(String w) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
66 |
return (w.hashCode() >> shift) & mask; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
67 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
68 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
69 |
// Build a hash table of size 2^nb, shifting the hash code by s bits |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
70 |
// |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
71 |
void build(int nb, int s) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
72 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
73 |
this.nb = nb; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
74 |
this.shift = s; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
75 |
int n = 1 << nb; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
76 |
this.mask = n - 1; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
77 |
ht = new Object[n]; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
78 |
int nw = keys.size(); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
79 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
80 |
for (int i = 0; i < nw; i++) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
81 |
String w = keys.get(i); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
82 |
String v = values.get(i); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
83 |
int h = hash(w); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
84 |
if (ht[h] == null) |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
85 |
ht[h] = new Object[] { w, v }; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
86 |
else |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
87 |
ht[h] = new Object[] { w, v, ht[h] }; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
88 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
89 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
90 |
this.md = 0; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
91 |
for (int i = 0; i < n; i++) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
92 |
int d = 1; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
93 |
for (Object[] a = (Object[])ht[i]; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
94 |
a != null && a.length > 2; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
95 |
a = (Object[])a[2], d++); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
96 |
this.md = Math.max(md, d); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
97 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
98 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
99 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
100 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
101 |
Hasher build() { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
102 |
// Iterate through acceptable table sizes |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
103 |
for (int nb = 2; nb < maxBits; nb++) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
104 |
// Iterate through possible shift sizes |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
105 |
for (int s = 0; s < (32 - nb); s++) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
106 |
build(nb, s); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
107 |
if (verbose) |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
108 |
err.println("nb=" + nb + " s=" + s + " md=" + md); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
109 |
if (md <= maxDepth) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
110 |
// Success |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
111 |
if (verbose) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
112 |
if (cln != null) |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
113 |
err.print(cln + ": "); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
114 |
err.println("Table size " + (1 << nb) + " (" + nb + " bits)" |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
115 |
+ ", shift " + shift |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
116 |
+ ", max chain depth " + md); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
117 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
118 |
return this; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
119 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
120 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
121 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
122 |
throw new RuntimeException("Cannot find a suitable size" |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
123 |
+ " within given constraints"); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
124 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
125 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
126 |
// Look for the given key in the hash table |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
127 |
// |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
128 |
String get(String k) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
129 |
int h = hash(k); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
130 |
Object[] a = (Object[])ht[h]; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
131 |
for (;;) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
132 |
if (a[0].equals(k)) |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
133 |
return (String)a[1]; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
134 |
if (a.length < 3) |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
135 |
return null; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
136 |
a = (Object[])a[2]; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
137 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
138 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
139 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
140 |
// Test that all input keys can be found in the table |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
141 |
// |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
142 |
Hasher test() { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
143 |
if (verbose) |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
144 |
err.println(); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
145 |
for (int i = 0, n = keys.size(); i < n; i++) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
146 |
String w = keys.get(i); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
147 |
String v = get(w); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
148 |
if (verbose) |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
149 |
err.println(hash(w) + "\t" + w); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
150 |
if (!v.equals(values.get(i))) |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
151 |
throw new Error("Incorrect value: " + w + " --> " |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
152 |
+ v + ", should be " + values.get(i)); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
153 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
154 |
return this; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
155 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
156 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
157 |
String ind = ""; // Indent prefix |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
158 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
159 |
// Generate code for a single table entry |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
160 |
// |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
161 |
void genEntry(Object[] a, int depth, PrintStream out) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
162 |
Object v = empty ? null : a[1]; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
163 |
out.print("new Object[] { \"" + a[0] + "\", " + v); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
164 |
if (a.length < 3) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
165 |
out.print(" }"); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
166 |
return; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
167 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
168 |
out.println(","); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
169 |
out.print(ind + " "); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
170 |
for (int i = 0; i < depth; i++) |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
171 |
out.print(" "); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
172 |
genEntry((Object[])a[2], depth + 1, out); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
173 |
out.print(" }"); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
174 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
175 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
176 |
// Generate a PreHashedMap subclass from the computed hash table |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
177 |
// |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
178 |
Hasher generate(PrintStream out) throws IOException { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
179 |
if (cln == null) |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
180 |
return this; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
181 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
182 |
if (inner) |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
183 |
ind = " "; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
184 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
185 |
if (!inner && pkg != null) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
186 |
out.println(); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
187 |
out.println("package " + pkg + ";"); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
188 |
out.println(); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
189 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
190 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
191 |
if (inner) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
192 |
out.println(ind + "private static final class " + cln); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
193 |
} else { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
194 |
out.println(); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
195 |
out.println("public final class " + cln); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
196 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
197 |
out.println(ind + " extends sun.util.PreHashedMap<" + vtype +">"); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
198 |
out.println(ind + "{"); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
199 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
200 |
out.println(); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
201 |
out.println(ind + " private static final int ROWS = " |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
202 |
+ ht.length + ";"); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
203 |
out.println(ind + " private static final int SIZE = " |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
204 |
+ keys.size() + ";"); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
205 |
out.println(ind + " private static final int SHIFT = " |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
206 |
+ shift + ";"); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
207 |
out.println(ind + " private static final int MASK = 0x" |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
208 |
+ Integer.toHexString(mask) + ";"); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
209 |
out.println(); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
210 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
211 |
out.println(ind + " " + (inner ? "private " : "public ") |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
212 |
+ cln + "() {"); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
213 |
out.println(ind + " super(ROWS, SIZE, SHIFT, MASK);"); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
214 |
out.println(ind + " }"); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
215 |
out.println(); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
216 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
217 |
out.println(ind + " protected void init(Object[] ht) {"); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
218 |
for (int i = 0; i < ht.length; i++) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
219 |
if (ht[i] == null) |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
220 |
continue; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
221 |
Object[] a = (Object[])ht[i]; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
222 |
out.print(ind + " ht[" + i + "] = "); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
223 |
genEntry(a, 0, out); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
224 |
out.println(";"); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
225 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
226 |
out.println(ind + " }"); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
227 |
out.println(); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
228 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
229 |
out.println(ind + "}"); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
230 |
if (inner) |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
231 |
out.println(); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
232 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
233 |
return this; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
234 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
235 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
236 |
private Hasher(List<String> keys, List<String> values, |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
237 |
String pkg, String cln, String vtype, |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
238 |
int maxBits, int maxDepth, |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
239 |
boolean inner, boolean empty, |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
240 |
boolean verbose) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
241 |
this.keys = keys; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
242 |
this.values = values; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
243 |
this.pkg = pkg; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
244 |
this.cln = cln; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
245 |
this.vtype = vtype; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
246 |
this.maxBits = maxBits; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
247 |
this.maxDepth = maxDepth; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
248 |
this.inner = inner; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
249 |
this.empty = empty; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
250 |
this.verbose = verbose; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
251 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
252 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
253 |
public static void genClass(PrintStream out, |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
254 |
List<String> keys, List<String> values, |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
255 |
String pkg, String cln, String vtype, |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
256 |
int maxBits, int maxDepth, |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
257 |
boolean inner, boolean empty, boolean verbose) |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
258 |
throws IOException { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
259 |
new Hasher(keys, values, pkg, cln, vtype, |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
260 |
maxBits, maxDepth, inner, empty, verbose) |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
261 |
.build() |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
262 |
.test() |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
263 |
.generate(out); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
264 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff
changeset
|
265 |
} |