Skip to content
Permalink
Browse files
Misc clean ups.
- else { if } -> else if
- new kind of Number() -> valueOf()
- String replaceAll(S,S) -> replace(CS,CS)
- Initialize collections on creation
- Use diamonds
- Create arrays with {}s.
  • Loading branch information
garydgregory committed Aug 25, 2021
1 parent 799ca30 commit 94691c7bb045545a3cc5ec7744d50dc69eae8456
Showing 54 changed files with 288 additions and 325 deletions.
@@ -106,28 +106,28 @@ public class DataConfiguration extends AbstractConfiguration
public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";

/** Empty array constant. */
private static final URL[] EMPTY_URL_ARRAY = new URL[0];
private static final URL[] EMPTY_URL_ARRAY = {};

/** Empty array constant. */
private static final URI[] EMPTY_URI_ARRAY = new URI[0];
private static final URI[] EMPTY_URI_ARRAY = {};

/** Empty array constant. */
private static final Locale[] EMPTY_LOCALE_ARRAY = new Locale[0];
private static final Locale[] EMPTY_LOCALE_ARRAY = {};

/** Empty array constant. */
private static final Date[] EMPTY_DATE_ARRAY = new Date[0];
private static final Date[] EMPTY_DATE_ARRAY = {};

/** Empty array constant. */
private static final Color[] EMPTY_COLOR_ARRAY = new Color[0];
private static final Color[] EMPTY_COLOR_ARRAY = {};

/** Empty array constant. */
private static final Calendar[] EMPTY_CALENDARD_ARRAY = new Calendar[0];
private static final Calendar[] EMPTY_CALENDARD_ARRAY = {};

/** Empty array constant. */
private static final BigInteger[] EMPTY_BIG_INTEGER_ARRAY = new BigInteger[0];
private static final BigInteger[] EMPTY_BIG_INTEGER_ARRAY = {};

/** Empty array constant. */
private static final BigDecimal[] EMPTY_BIG_DECIMAL_ARRAY = new BigDecimal[0];
private static final BigDecimal[] EMPTY_BIG_DECIMAL_ARRAY = {};

/** Stores temporary date formats. */
private static final ThreadLocal<String> TEMP_DATE_FORMAT = new ThreadLocal<>();
@@ -238,7 +238,7 @@ protected Iterator<String> getKeysInternal()
*/
public List<Boolean> getBooleanList(final String key)
{
return getBooleanList(key, new ArrayList<Boolean>());
return getBooleanList(key, new ArrayList<>());
}

/**
@@ -303,7 +303,7 @@ public boolean[] getBooleanArray(final String key, final boolean... defaultValue
*/
public List<Byte> getByteList(final String key)
{
return getByteList(key, new ArrayList<Byte>());
return getByteList(key, new ArrayList<>());
}

/**
@@ -368,7 +368,7 @@ public byte[] getByteArray(final String key, final byte... defaultValue)
*/
public List<Short> getShortList(final String key)
{
return getShortList(key, new ArrayList<Short>());
return getShortList(key, new ArrayList<>());
}

/**
@@ -434,7 +434,7 @@ public short[] getShortArray(final String key, final short... defaultValue)
*/
public List<Integer> getIntegerList(final String key)
{
return getIntegerList(key, new ArrayList<Integer>());
return getIntegerList(key, new ArrayList<>());
}

/**
@@ -499,7 +499,7 @@ public int[] getIntArray(final String key, final int... defaultValue)
*/
public List<Long> getLongList(final String key)
{
return getLongList(key, new ArrayList<Long>());
return getLongList(key, new ArrayList<>());
}

/**
@@ -564,7 +564,7 @@ public long[] getLongArray(final String key, final long... defaultValue)
*/
public List<Float> getFloatList(final String key)
{
return getFloatList(key, new ArrayList<Float>());
return getFloatList(key, new ArrayList<>());
}

/**
@@ -630,7 +630,7 @@ public float[] getFloatArray(final String key, final float... defaultValue)
*/
public List<Double> getDoubleList(final String key)
{
return getDoubleList(key, new ArrayList<Double>());
return getDoubleList(key, new ArrayList<>());
}

/**
@@ -695,7 +695,7 @@ public double[] getDoubleArray(final String key, final double... defaultValue)
*/
public List<BigInteger> getBigIntegerList(final String key)
{
return getBigIntegerList(key, new ArrayList<BigInteger>());
return getBigIntegerList(key, new ArrayList<>());
}

/**
@@ -760,7 +760,7 @@ public BigInteger[] getBigIntegerArray(final String key, final BigInteger... def
*/
public List<BigDecimal> getBigDecimalList(final String key)
{
return getBigDecimalList(key, new ArrayList<BigDecimal>());
return getBigDecimalList(key, new ArrayList<>());
}

/**
@@ -887,7 +887,7 @@ public URI[] getURIArray(final String key, final URI... defaultValue)
*/
public List<URI> getURIList(final String key)
{
return getURIList(key, new ArrayList<URI>());
return getURIList(key, new ArrayList<>());
}

/**
@@ -950,7 +950,7 @@ public URL getURL(final String key, final URL defaultValue)
*/
public List<URL> getURLList(final String key)
{
return getURLList(key, new ArrayList<URL>());
return getURLList(key, new ArrayList<>());
}

/**
@@ -1091,7 +1091,7 @@ public Date getDate(final String key, final Date defaultValue, final String form

public List<Date> getDateList(final String key)
{
return getDateList(key, new ArrayList<Date>());
return getDateList(key, new ArrayList<>());
}

/**
@@ -1109,7 +1109,7 @@ public List<Date> getDateList(final String key)
*/
public List<Date> getDateList(final String key, final String format)
{
return getDateList(key, new ArrayList<Date>(), format);
return getDateList(key, new ArrayList<>(), format);
}

/**
@@ -1345,7 +1345,7 @@ public Calendar getCalendar(final String key, final Calendar defaultValue, final
*/
public List<Calendar> getCalendarList(final String key)
{
return getCalendarList(key, new ArrayList<Calendar>());
return getCalendarList(key, new ArrayList<>());
}

/**
@@ -1363,7 +1363,7 @@ public List<Calendar> getCalendarList(final String key)
*/
public List<Calendar> getCalendarList(final String key, final String format)
{
return getCalendarList(key, new ArrayList<Calendar>(), format);
return getCalendarList(key, new ArrayList<>(), format);
}

/**
@@ -1549,7 +1549,7 @@ public Locale getLocale(final String key, final Locale defaultValue)
*/
public List<Locale> getLocaleList(final String key)
{
return getLocaleList(key, new ArrayList<Locale>());
return getLocaleList(key, new ArrayList<>());
}

/**
@@ -1645,7 +1645,7 @@ public Color getColor(final String key, final Color defaultValue)
*/
public List<Color> getColorList(final String key)
{
return getColorList(key, new ArrayList<Color>());
return getColorList(key, new ArrayList<>());
}

/**
@@ -48,7 +48,7 @@ public class EnvironmentConfiguration extends MapConfiguration
*/
public EnvironmentConfiguration()
{
super(new HashMap<String, Object>(System.getenv()));
super(new HashMap<>(System.getenv()));
}

/**
@@ -664,17 +664,13 @@ else if (escape && quote == c)

result.append(c);
}
} else if (isCommentChar(c) && Character.isWhitespace(lastChar))
{
stop = true;
}
else
{
if (isCommentChar(c) && Character.isWhitespace(lastChar))
{
stop = true;
}
else
{
result.append(c);
}
result.append(c);
}

i++;
@@ -874,7 +870,7 @@ private String escapeComments(final String value)

if (quoted)
{
return '"' + value.replaceAll("\"", "\\\\\\\"") + '"';
return '"' + value.replace("\"", "\\\"") + '"';
}
return value;
}
@@ -934,14 +930,10 @@ public Set<String> getSections()
{
inSection = true;
sections.add(node.getNodeName());
}
else
} else if (!inSection && !globalSection)
{
if (!inSection && !globalSection)
{
globalSection = true;
sections.add(null);
}
globalSection = true;
sections.add(null);
}
}
}
@@ -205,7 +205,7 @@ protected Iterator<String> getKeysInternal(final String prefix)
final Set<String> keys = new HashSet<>();
if (context != null)
{
recursiveGetKeys(keys, context, prefix, new HashSet<Context>());
recursiveGetKeys(keys, context, prefix, new HashSet<>());
}
else if (containsKey(prefix))
{
@@ -352,7 +352,7 @@ protected boolean containsKeyInternal(String key)
{
return false;
}
key = key.replaceAll("\\.", "/");
key = key.replace('.', '/');
try
{
// throws a NamingException if JNDI doesn't contain the key.
@@ -410,7 +410,7 @@ protected Object getPropertyInternal(String key)

try
{
key = key.replaceAll("\\.", "/");
key = key.replace('.', '/');
return getBaseContext().lookup(key);
}
catch (final NameNotFoundException | NotContextException nctxex)
@@ -1206,10 +1206,10 @@ public void writeProperty(final String key, final Object value,
private static String includeOptional = "includeoptional";

/** The list of possible key/value separators */
private static final char[] SEPARATORS = new char[] {'=', ':'};
private static final char[] SEPARATORS = {'=', ':'};

/** The white space characters used as key/value separators. */
private static final char[] WHITE_SPACE = new char[]{' ', '\t', '\f'};
private static final char[] WHITE_SPACE = {' ', '\t', '\f'};

/** Constant for the platform specific line separator.*/
private static final String LINE_SEPARATOR = System.getProperty("line.separator");
@@ -89,7 +89,7 @@

/** Stores a map with the registered bean factories. */
private final Map<String, BeanFactory> beanFactories = Collections
.synchronizedMap(new HashMap<String, BeanFactory>());
.synchronizedMap(new HashMap<>());

/**
* Stores the default bean factory, which is used if no other factory
@@ -36,7 +36,7 @@
class MultiWrapDynaClass implements DynaClass
{
/** An empty array for converting the properties collection to an array. */
private static final DynaProperty[] EMPTY_PROPS = new DynaProperty[0];
private static final DynaProperty[] EMPTY_PROPS = {};

/** A collection with all properties of this class. */
private final Collection<DynaProperty> properties;
@@ -156,31 +156,26 @@ protected Collection<String> splitString(final String s, final boolean trim)
}
token.append(c);
inEscape = false;
}

else
} else if (c == getDelimiter())
{
if (c == getDelimiter())
{
// found a list delimiter -> add token and
// reset buffer
String t = token.toString();
if (trim)
{
t = t.trim();
}
list.add(t);
token = new StringBuilder();
}
else if (c == ESCAPE)
{
// potentially escape next character
inEscape = true;
}
else
// found a list delimiter -> add token and
// reset buffer
String t = token.toString();
if (trim)
{
token.append(c);
t = t.trim();
}
list.add(t);
token = new StringBuilder();
}
else if (c == ESCAPE)
{
// potentially escape next character
inEscape = true;
}
else
{
token.append(c);
}
}

0 comments on commit 94691c7

Please sign in to comment.