|
20 | 20 | import uk.co.real_logic.sbe.util.ValidationUtil; |
21 | 21 |
|
22 | 22 | import java.lang.reflect.Field; |
23 | | -import java.lang.reflect.Modifier; |
24 | 23 | import java.nio.charset.Charset; |
25 | 24 | import java.nio.charset.StandardCharsets; |
26 | 25 | import java.util.EnumMap; |
27 | 26 | import java.util.HashMap; |
28 | 27 | import java.util.Map; |
29 | 28 |
|
| 29 | +import static java.lang.reflect.Modifier.STATIC; |
| 30 | + |
30 | 31 | /** |
31 | 32 | * Utilities for mapping between IR and the Java language. |
32 | 33 | */ |
@@ -88,27 +89,28 @@ public String toString() |
88 | 89 | TYPE_NAME_BY_PRIMITIVE_TYPE_MAP.put(PrimitiveType.DOUBLE, "double"); |
89 | 90 | } |
90 | 91 |
|
91 | | - /** Indexes known charset aliases to the name of the instance in {@link StandardCharsets}. */ |
| 92 | + /** |
| 93 | + * Indexes known charset aliases to the name of the instance in {@link StandardCharsets}. |
| 94 | + */ |
92 | 95 | private static final Map<String, String> STD_CHARSETS = new HashMap<>(); |
93 | 96 |
|
94 | 97 | static |
95 | 98 | { |
96 | 99 | try |
97 | 100 | { |
98 | | - for (Field f : StandardCharsets.class.getDeclaredFields()) |
| 101 | + for (final Field field : StandardCharsets.class.getDeclaredFields()) |
99 | 102 | { |
100 | | - if (Charset.class.isAssignableFrom(f.getType()) |
101 | | - && ((f.getModifiers() & Modifier.STATIC) == Modifier.STATIC)) |
| 103 | + if (Charset.class.isAssignableFrom(field.getType()) && ((field.getModifiers() & STATIC) == STATIC)) |
102 | 104 | { |
103 | | - final Charset c = (Charset) f.get(null); |
104 | | - STD_CHARSETS.put(c.name(), f.getName()); |
105 | | - c.aliases().forEach(alias -> STD_CHARSETS.put(alias, f.getName())); |
| 105 | + final Charset charset = (Charset)field.get(null); |
| 106 | + STD_CHARSETS.put(charset.name(), field.getName()); |
| 107 | + charset.aliases().forEach((alias) -> STD_CHARSETS.put(alias, field.getName())); |
106 | 108 | } |
107 | 109 | } |
108 | 110 | } |
109 | | - catch (IllegalAccessException e) |
| 111 | + catch (final IllegalAccessException ex) |
110 | 112 | { |
111 | | - throw new RuntimeException(e); |
| 113 | + throw new RuntimeException(ex); |
112 | 114 | } |
113 | 115 | } |
114 | 116 |
|
@@ -199,16 +201,17 @@ public static void append(final StringBuilder builder, final String indent, fina |
199 | 201 | } |
200 | 202 |
|
201 | 203 | /** |
202 | | - * Return java code to fetch an instance of {@link java.nio.charset.Charset} corresponding to the given encoding. |
203 | | - * @param encoding the encoding (eg. UTF-8). |
204 | | - * @return the code to fetch the assiciated charset. |
| 204 | + * Code to fetch an instance of {@link java.nio.charset.Charset} corresponding to the given encoding. |
| 205 | + * |
| 206 | + * @param encoding as a string name (eg. UTF-8). |
| 207 | + * @return the code to fetch the associated Charset. |
205 | 208 | */ |
206 | | - public static String charset(String encoding) |
| 209 | + public static String charset(final String encoding) |
207 | 210 | { |
208 | | - final String charset = STD_CHARSETS.get(encoding); |
209 | | - if (charset != null) |
| 211 | + final String charsetName = STD_CHARSETS.get(encoding); |
| 212 | + if (charsetName != null) |
210 | 213 | { |
211 | | - return "java.nio.charset.StandardCharsets." + charset; |
| 214 | + return "java.nio.charset.StandardCharsets." + charsetName; |
212 | 215 | } |
213 | 216 | else |
214 | 217 | { |
|
0 commit comments