Skip to content

Commit 9c72ded

Browse files
author
Andrey Turbanov
committedJan 9, 2025
8346036: Unnecessary Hashtable usage in javax.swing.text.html.parser.Entity
Reviewed-by: aivanov, azvegint
1 parent 3024a73 commit 9c72ded

File tree

1 file changed

+15
-26
lines changed
  • src/java.desktop/share/classes/javax/swing/text/html/parser

1 file changed

+15
-26
lines changed
 

‎src/java.desktop/share/classes/javax/swing/text/html/parser/Entity.java

+15-26
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,13 +25,7 @@
2525

2626
package javax.swing.text.html.parser;
2727

28-
import java.util.Hashtable;
29-
import java.io.IOException;
30-
import java.io.InputStream;
31-
import java.io.InputStreamReader;
32-
import java.io.Reader;
33-
import java.io.CharArrayReader;
34-
import java.net.URL;
28+
import java.util.Map;
3529

3630
/**
3731
* An entity is described in a DTD using the ENTITY construct.
@@ -40,8 +34,7 @@
4034
* @see DTD
4135
* @author Arthur van Hoff
4236
*/
43-
public final
44-
class Entity implements DTDConstants {
37+
public final class Entity implements DTDConstants {
4538
/**
4639
* The name of the entity.
4740
*/
@@ -117,20 +110,17 @@ public String getString() {
117110
return new String(data);
118111
}
119112

120-
121-
static Hashtable<String, Integer> entityTypes = new Hashtable<String, Integer>();
122-
123-
static {
124-
entityTypes.put("PUBLIC", Integer.valueOf(PUBLIC));
125-
entityTypes.put("CDATA", Integer.valueOf(CDATA));
126-
entityTypes.put("SDATA", Integer.valueOf(SDATA));
127-
entityTypes.put("PI", Integer.valueOf(PI));
128-
entityTypes.put("STARTTAG", Integer.valueOf(STARTTAG));
129-
entityTypes.put("ENDTAG", Integer.valueOf(ENDTAG));
130-
entityTypes.put("MS", Integer.valueOf(MS));
131-
entityTypes.put("MD", Integer.valueOf(MD));
132-
entityTypes.put("SYSTEM", Integer.valueOf(SYSTEM));
133-
}
113+
private static final Map<String, Integer> entityTypes = Map.of(
114+
"PUBLIC", PUBLIC,
115+
"CDATA", CDATA,
116+
"SDATA", SDATA,
117+
"PI", PI,
118+
"STARTTAG", STARTTAG,
119+
"ENDTAG", ENDTAG,
120+
"MS", MS,
121+
"MD", MD,
122+
"SYSTEM", SYSTEM
123+
);
134124

135125
/**
136126
* Converts <code>nm</code> string to the corresponding
@@ -144,7 +134,6 @@ public String getString() {
144134
* to "CDATA", if none exists
145135
*/
146136
public static int name2type(String nm) {
147-
Integer i = entityTypes.get(nm);
148-
return (i == null) ? CDATA : i.intValue();
137+
return entityTypes.getOrDefault(nm, CDATA);
149138
}
150139
}

0 commit comments

Comments
 (0)
Please sign in to comment.