Minor internal clean ups. Add and use constants.

This commit is contained in:
Gary Gregory 2020-12-23 10:24:13 -05:00
parent b1da31ef40
commit 157ba27be7
4 changed files with 20 additions and 12 deletions

View File

@ -49,6 +49,9 @@ final class CharRange implements Iterable<Character>, Serializable {
/** Cached toString. */
private transient String iToString;
/** Empty array. */
static final CharRange[] EMPTY_ARRAY = new CharRange[0];
/**
* <p>Constructs a {@code CharRange} over a set of characters,
* optionally negating the range.</p>

View File

@ -224,7 +224,7 @@ protected void add(final String str) {
// NOTE: This is no longer public as CharRange is no longer a public class.
// It may be replaced when CharSet moves to Range.
/*public*/ CharRange[] getCharRanges() {
return set.toArray(new CharRange[0]);
return set.toArray(CharRange.EMPTY_ARRAY);
}
//-----------------------------------------------------------------------

View File

@ -479,13 +479,13 @@ private static String paddedValue(final long value, final boolean padWithZeros,
return padWithZeros ? StringUtils.leftPad(longString, count, '0') : longString;
}
static final Object y = "y";
static final Object M = "M";
static final Object d = "d";
static final Object H = "H";
static final Object m = "m";
static final Object s = "s";
static final Object S = "S";
static final String y = "y";
static final String M = "M";
static final String d = "d";
static final String H = "H";
static final String m = "m";
static final String s = "s";
static final String S = "S";
/**
* Parses a classic date format string into Tokens
@ -507,7 +507,7 @@ static Token[] lexx(final String format) {
buffer.append(ch); // buffer can't be null if inLiteral is true
continue;
}
Object value = null;
String value = null;
switch (ch) {
// TODO: Need to handle escaping of '
case '\'':
@ -563,15 +563,17 @@ static Token[] lexx(final String format) {
if (inLiteral) { // i.e. we have not found the end of the literal
throw new IllegalArgumentException("Unmatched quote in format: " + format);
}
return list.toArray(new Token[0]);
return list.toArray(Token.EMPTY_ARRAY);
}
//-----------------------------------------------------------------------
/**
* Element that is parsed from the format pattern.
*/
static class Token {
/** Empty array. */
private static final Token[] EMPTY_ARRAY = new Token[0];
/**
* Helper method to determine if a set of tokens contain a value
*

View File

@ -91,6 +91,9 @@ public class FastDatePrinter implements DatePrinter, Serializable {
// taking the value and adding (mathematically) the ASCII value for '0'.
// So, don't change this code! It works and is very fast.
/** Empty array. */
private static final Rule[] EMPTY_RULE_ARRAY = new Rule[0];
/**
* Required for serialization support.
*
@ -161,7 +164,7 @@ protected FastDatePrinter(final String pattern, final TimeZone timeZone, final L
*/
private void init() {
final List<Rule> rulesList = parsePattern();
mRules = rulesList.toArray(new Rule[0]);
mRules = rulesList.toArray(EMPTY_RULE_ARRAY);
int len = 0;
for (int i=mRules.length; --i >= 0; ) {