1
1
package bwapi ;
2
2
3
-
4
3
import java .util .HashMap ;
5
4
import java .util .Map ;
6
5
import java .util .Objects ;
@@ -61,21 +60,7 @@ public final class Color {
61
60
*/
62
61
public final static Color Grey = new Color (74 );
63
62
64
- private final static Map <Integer , String > defaultColors = new HashMap <>();
65
- static {
66
- defaultColors .put (Color .Red .id , "Red" );
67
- defaultColors .put (Color .Blue .id , "Blue" );
68
- defaultColors .put (Color .Teal .id , "Teal" );
69
- defaultColors .put (Color .Purple .id , "Purple" );
70
- defaultColors .put (Color .Orange .id , "Orange" );
71
- defaultColors .put (Color .Brown .id , "Brown" );
72
- defaultColors .put (Color .White .id , "White" );
73
- defaultColors .put (Color .Yellow .id , "Yellow" );
74
- defaultColors .put (Color .Green .id , "Green" );
75
- defaultColors .put (Color .Cyan .id , "Cyan" );
76
- defaultColors .put (Color .Black .id , "Black" );
77
- defaultColors .put (Color .Grey .id , "Grey" );
78
- }
63
+ private static Map <Integer , String > defaultColors = null ;
79
64
80
65
private static final RGBQUAD RGBRESERVE = new RGBQUAD (0 , 0 , 0 , 0xFF );
81
66
@@ -210,8 +195,9 @@ public int hashCode() {
210
195
211
196
@ Override
212
197
public String toString () {
213
- if (defaultColors .containsKey (id )) {
214
- return "Color." + defaultColors .get (id );
198
+ String defaultColor = getDefaultColor (id );
199
+ if (defaultColor != null ) {
200
+ return "Color." + defaultColor ;
215
201
}
216
202
return "Color{" +
217
203
"red=" + red () +
@@ -237,4 +223,23 @@ private static class RGBQUAD {
237
223
this .rgbReserved = (byte )rgbReserved ;
238
224
}
239
225
}
226
+
227
+ private static String getDefaultColor (final int id ) {
228
+ if (defaultColors == null ) {
229
+ defaultColors = new HashMap <>();
230
+ defaultColors .put (Color .Red .id , "Red" );
231
+ defaultColors .put (Color .Blue .id , "Blue" );
232
+ defaultColors .put (Color .Teal .id , "Teal" );
233
+ defaultColors .put (Color .Purple .id , "Purple" );
234
+ defaultColors .put (Color .Orange .id , "Orange" );
235
+ defaultColors .put (Color .Brown .id , "Brown" );
236
+ defaultColors .put (Color .White .id , "White" );
237
+ defaultColors .put (Color .Yellow .id , "Yellow" );
238
+ defaultColors .put (Color .Green .id , "Green" );
239
+ defaultColors .put (Color .Cyan .id , "Cyan" );
240
+ defaultColors .put (Color .Black .id , "Black" );
241
+ defaultColors .put (Color .Grey .id , "Grey" );
242
+ }
243
+ return defaultColors .getOrDefault (id ,null );
244
+ }
240
245
}
0 commit comments