Skip to content

Commit 345ce78

Browse files
committed
[Java] Code cleanup.
1 parent 9ef643c commit 345ce78

File tree

1 file changed

+20
-17
lines changed
  • sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java

1 file changed

+20
-17
lines changed

sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaUtil.java

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@
2020
import uk.co.real_logic.sbe.util.ValidationUtil;
2121

2222
import java.lang.reflect.Field;
23-
import java.lang.reflect.Modifier;
2423
import java.nio.charset.Charset;
2524
import java.nio.charset.StandardCharsets;
2625
import java.util.EnumMap;
2726
import java.util.HashMap;
2827
import java.util.Map;
2928

29+
import static java.lang.reflect.Modifier.STATIC;
30+
3031
/**
3132
* Utilities for mapping between IR and the Java language.
3233
*/
@@ -88,27 +89,28 @@ public String toString()
8889
TYPE_NAME_BY_PRIMITIVE_TYPE_MAP.put(PrimitiveType.DOUBLE, "double");
8990
}
9091

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+
*/
9295
private static final Map<String, String> STD_CHARSETS = new HashMap<>();
9396

9497
static
9598
{
9699
try
97100
{
98-
for (Field f : StandardCharsets.class.getDeclaredFields())
101+
for (final Field field : StandardCharsets.class.getDeclaredFields())
99102
{
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))
102104
{
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()));
106108
}
107109
}
108110
}
109-
catch (IllegalAccessException e)
111+
catch (final IllegalAccessException ex)
110112
{
111-
throw new RuntimeException(e);
113+
throw new RuntimeException(ex);
112114
}
113115
}
114116

@@ -199,16 +201,17 @@ public static void append(final StringBuilder builder, final String indent, fina
199201
}
200202

201203
/**
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.
205208
*/
206-
public static String charset(String encoding)
209+
public static String charset(final String encoding)
207210
{
208-
final String charset = STD_CHARSETS.get(encoding);
209-
if (charset != null)
211+
final String charsetName = STD_CHARSETS.get(encoding);
212+
if (charsetName != null)
210213
{
211-
return "java.nio.charset.StandardCharsets." + charset;
214+
return "java.nio.charset.StandardCharsets." + charsetName;
212215
}
213216
else
214217
{

0 commit comments

Comments
 (0)