Skip to content

Commit a6913cf

Browse files
committed
Replace instances of Hashtable with HashMap
1 parent 64c401a commit a6913cf

6 files changed

Lines changed: 49 additions & 48 deletions

File tree

app/src/processing/app/Base.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2821,7 +2821,7 @@ static public String contentsToClassPath(File folder) {
28212821
* @return array of possible package names
28222822
*/
28232823
static public String[] packageListFromClassPath(String path) {
2824-
Hashtable table = new Hashtable();
2824+
Map<String, Object> map = new HashMap<String, Object>();
28252825
String pieces[] =
28262826
PApplet.split(path, File.pathSeparatorChar);
28272827

@@ -2832,32 +2832,32 @@ static public String[] packageListFromClassPath(String path) {
28322832
if (pieces[i].toLowerCase().endsWith(".jar") ||
28332833
pieces[i].toLowerCase().endsWith(".zip")) {
28342834
//System.out.println("checking " + pieces[i]);
2835-
packageListFromZip(pieces[i], table);
2835+
packageListFromZip(pieces[i], map);
28362836

28372837
} else { // it's another type of file or directory
28382838
File dir = new File(pieces[i]);
28392839
if (dir.exists() && dir.isDirectory()) {
2840-
packageListFromFolder(dir, null, table);
2840+
packageListFromFolder(dir, null, map);
28412841
//importCount = magicImportsRecursive(dir, null,
2842-
// table);
2842+
// map);
28432843
//imports, importCount);
28442844
}
28452845
}
28462846
}
2847-
int tableCount = table.size();
2848-
String output[] = new String[tableCount];
2847+
int mapCount = map.size();
2848+
String output[] = new String[mapCount];
28492849
int index = 0;
2850-
Enumeration e = table.keys();
2851-
while (e.hasMoreElements()) {
2852-
output[index++] = ((String) e.nextElement()).replace('/', '.');
2850+
Set<String> set = map.keySet();
2851+
for (String s : set) {
2852+
output[index++] = s.replace('/', '.');
28532853
}
28542854
//System.arraycopy(imports, 0, output, 0, importCount);
28552855
//PApplet.printarr(output);
28562856
return output;
28572857
}
28582858

28592859

2860-
static private void packageListFromZip(String filename, Hashtable table) {
2860+
static private void packageListFromZip(String filename, Map<String, Object> map) {
28612861
try {
28622862
ZipFile file = new ZipFile(filename);
28632863
Enumeration entries = file.entries();
@@ -2872,8 +2872,8 @@ static private void packageListFromZip(String filename, Hashtable table) {
28722872
if (slash == -1) continue;
28732873

28742874
String pname = name.substring(0, slash);
2875-
if (table.get(pname) == null) {
2876-
table.put(pname, new Object());
2875+
if (map.get(pname) == null) {
2876+
map.put(pname, new Object());
28772877
}
28782878
}
28792879
}
@@ -2893,7 +2893,7 @@ static private void packageListFromZip(String filename, Hashtable table) {
28932893
* walk down into that folder and continue.
28942894
*/
28952895
static private void packageListFromFolder(File dir, String sofar,
2896-
Hashtable table) {
2896+
Map<String, Object> map) {
28972897
//String imports[],
28982898
//int importCount) {
28992899
//System.err.println("checking dir '" + dir + "'");
@@ -2907,15 +2907,15 @@ static private void packageListFromFolder(File dir, String sofar,
29072907
if (sub.isDirectory()) {
29082908
String nowfar =
29092909
(sofar == null) ? files[i] : (sofar + "." + files[i]);
2910-
packageListFromFolder(sub, nowfar, table);
2910+
packageListFromFolder(sub, nowfar, map);
29112911
//System.out.println(nowfar);
29122912
//imports[importCount++] = nowfar;
29132913
//importCount = magicImportsRecursive(sub, nowfar,
29142914
// imports, importCount);
29152915
} else if (!foundClass) { // if no classes found in this folder yet
29162916
if (files[i].endsWith(".class")) {
29172917
//System.out.println("unique class: " + files[i] + " for " + sofar);
2918-
table.put(sofar, new Object());
2918+
map.put(sofar, new Object());
29192919
foundClass = true;
29202920
}
29212921
}

app/src/processing/app/WebServer.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,13 @@ protected static void log(String s) {
109109
//public static void main(String[] a) throws Exception {
110110
static public int launch(String zipPath) throws IOException {
111111
final ZipFile zip = new ZipFile(zipPath);
112-
final HashMap<String, ZipEntry> entries = new HashMap();
112+
final Map<String, ZipEntry> entries = new HashMap<String, ZipEntry>();
113113
Enumeration en = zip.entries();
114114
while (en.hasMoreElements()) {
115115
ZipEntry entry = (ZipEntry) en.nextElement();
116116
entries.put(entry.getName(), entry);
117117
}
118-
118+
119119
// if (a.length > 0) {
120120
// port = Integer.parseInt(a[0]);
121121
// }
@@ -164,9 +164,9 @@ public void run() {
164164

165165

166166
class WebServerWorker /*extends WebServer*/ implements HttpConstants, Runnable {
167-
ZipFile zip;
168-
HashMap<String, ZipEntry> entries;
169-
167+
private final ZipFile zip;
168+
private final Map<String, ZipEntry> entries;
169+
170170
final static int BUF_SIZE = 2048;
171171

172172
static final byte[] EOL = { (byte)'\r', (byte)'\n' };
@@ -176,10 +176,10 @@ class WebServerWorker /*extends WebServer*/ implements HttpConstants, Runnable {
176176
/* Socket to client we're handling */
177177
private Socket s;
178178

179-
WebServerWorker(ZipFile zip, HashMap entries) {
179+
WebServerWorker(ZipFile zip, Map<String, ZipEntry> entries) {
180180
this.entries = entries;
181181
this.zip = zip;
182-
182+
183183
buf = new byte[BUF_SIZE];
184184
s = null;
185185
}
@@ -468,7 +468,7 @@ void sendFile(InputStream is, PrintStream ps) throws IOException {
468468
}
469469

470470
/* mapping of file extensions to content-types */
471-
static java.util.Hashtable map = new java.util.Hashtable();
471+
static Map<String, String> map = new HashMap<String, String>();
472472

473473
static {
474474
fillMap();

app/src/processing/app/syntax/DefaultInputHandler.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
import javax.swing.KeyStroke;
1313
import java.awt.event.*;
1414
import java.awt.Toolkit;
15-
import java.util.Hashtable;
15+
import java.util.Map;
16+
import java.util.HashMap;
1617
import java.util.StringTokenizer;
1718

1819
/**
@@ -28,7 +29,7 @@ public class DefaultInputHandler extends InputHandler
2829
*/
2930
public DefaultInputHandler()
3031
{
31-
bindings = currentBindings = new Hashtable();
32+
bindings = currentBindings = new HashMap();
3233
}
3334

3435
/**
@@ -88,7 +89,7 @@ public void addDefaultKeyBindings()
8889
*/
8990
public void addKeyBinding(String keyBinding, ActionListener action)
9091
{
91-
Hashtable current = bindings;
92+
Map current = bindings;
9293

9394
StringTokenizer st = new StringTokenizer(keyBinding);
9495
while(st.hasMoreTokens())
@@ -100,13 +101,13 @@ public void addKeyBinding(String keyBinding, ActionListener action)
100101
if(st.hasMoreTokens())
101102
{
102103
Object o = current.get(keyStroke);
103-
if(o instanceof Hashtable)
104-
current = (Hashtable)o;
104+
if(o instanceof Map)
105+
current = (Map)o;
105106
else
106107
{
107-
o = new Hashtable();
108+
o = new HashMap();
108109
current.put(keyStroke,o);
109-
current = (Hashtable)o;
110+
current = (Map)o;
110111
}
111112
}
112113
else
@@ -222,9 +223,9 @@ else if(o instanceof ActionListener)
222223
evt.consume();
223224
return;
224225
}
225-
else if(o instanceof Hashtable)
226+
else if(o instanceof Map)
226227
{
227-
currentBindings = (Hashtable)o;
228+
currentBindings = (Map)o;
228229
evt.consume();
229230
return;
230231
}
@@ -257,9 +258,9 @@ public void keyTyped(KeyEvent evt)
257258
Character.toUpperCase(c));
258259
Object o = currentBindings.get(keyStroke);
259260

260-
if(o instanceof Hashtable)
261+
if(o instanceof Map)
261262
{
262-
currentBindings = (Hashtable)o;
263+
currentBindings = (Map)o;
263264
return;
264265
}
265266
else if(o instanceof ActionListener)
@@ -368,8 +369,8 @@ else if(key.length() == 0)
368369
}
369370

370371
// private members
371-
private Hashtable bindings;
372-
private Hashtable currentBindings;
372+
private Map bindings;
373+
private Map currentBindings;
373374

374375
private DefaultInputHandler(DefaultInputHandler copy)
375376
{

app/src/processing/app/syntax/InputHandler.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ public abstract class InputHandler extends KeyAdapter
9090
// Default action
9191
public static final ActionListener INSERT_CHAR = new insert_char();
9292

93-
private static Hashtable actions;
93+
private static Map<String, ActionListener> actions;
9494

9595
static
9696
{
97-
actions = new Hashtable();
97+
actions = new HashMap<String, ActionListener>();
9898
actions.put("backspace",BACKSPACE);
9999
actions.put("backspace-word",BACKSPACE_WORD);
100100
actions.put("delete",DELETE);
@@ -149,10 +149,9 @@ public static ActionListener getAction(String name)
149149
*/
150150
public static String getActionName(ActionListener listener)
151151
{
152-
Enumeration en = getActions();
153-
while(en.hasMoreElements())
152+
Set<String> set = getActions();
153+
for (String name : set)
154154
{
155-
String name = (String)en.nextElement();
156155
ActionListener _listener = getAction(name);
157156
if(_listener == listener) {
158157
return name;
@@ -164,9 +163,9 @@ public static String getActionName(ActionListener listener)
164163
/**
165164
* Returns an enumeration of all available actions.
166165
*/
167-
public static Enumeration getActions()
166+
public static Set<String> getActions()
168167
{
169-
return actions.keys();
168+
return actions.keySet();
170169
}
171170

172171
/**

core/src/processing/core/PGraphicsJava2D.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import java.awt.image.*;
3131
import java.io.InputStream;
3232
import java.util.Arrays;
33-
import java.util.Hashtable;
33+
import java.util.HashMap;
3434
import java.util.Map;
3535
import java.util.zip.GZIPInputStream;
3636

@@ -1754,7 +1754,7 @@ public void textSize(float size) {
17541754
//if (font != null && (textFont.isStream() || hints[ENABLE_NATIVE_FONTS])) {
17551755
if (font != null) {
17561756
Map<TextAttribute, Object> map =
1757-
new Hashtable<TextAttribute, Object>();
1757+
new HashMap<TextAttribute, Object>();
17581758
map.put(TextAttribute.SIZE, size);
17591759
map.put(TextAttribute.KERNING,
17601760
TextAttribute.KERNING_ON);

core/src/processing/core/PShapeOBJ.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import java.io.BufferedReader;
44
import java.io.File;
55
import java.util.ArrayList;
6-
import java.util.Hashtable;
6+
import java.util.HashMap;
7+
import java.util.Map;
78

89
/**
910
* This class is not part of the Processing API and should not be used
@@ -159,7 +160,7 @@ static protected void parseOBJ(PApplet parent, String path,
159160
ArrayList<PVector> coords,
160161
ArrayList<PVector> normals,
161162
ArrayList<PVector> texcoords) {
162-
Hashtable<String, Integer> mtlTable = new Hashtable<String, Integer>();
163+
Map<String, Integer> mtlTable = new HashMap<String, Integer>();
163164
int mtlIdxCur = -1;
164165
boolean readv, readvn, readvt;
165166
try {
@@ -321,7 +322,7 @@ static protected void parseOBJ(PApplet parent, String path,
321322
static protected void parseMTL(PApplet parent, String path,
322323
BufferedReader reader,
323324
ArrayList<OBJMaterial> materials,
324-
Hashtable<String, Integer> materialsHash) {
325+
Map<String, Integer> materialsHash) {
325326
try {
326327
String line;
327328
OBJMaterial currentMtl = null;

0 commit comments

Comments
 (0)