Minor Improvement: (#700)
* Add final variable.try to make the code read-only
This commit is contained in:
parent
202076602a
commit
8c0bae01e5
|
@ -785,7 +785,7 @@ public static <T> T[] add(final T[] array, final int index, final T element) {
|
|||
* @throws IllegalArgumentException if both arguments are null
|
||||
*/
|
||||
public static <T> T[] add(final T[] array, final T element) {
|
||||
Class<?> type;
|
||||
final Class<?> type;
|
||||
if (array != null) {
|
||||
type = array.getClass().getComponentType();
|
||||
} else if (element != null) {
|
||||
|
|
|
@ -1061,7 +1061,7 @@ public static boolean isInnerClass(final Class<?> cls) {
|
|||
public static Class<?> getClass(
|
||||
final ClassLoader classLoader, final String className, final boolean initialize) throws ClassNotFoundException {
|
||||
try {
|
||||
Class<?> clazz;
|
||||
final Class<?> clazz;
|
||||
if (namePrimitiveMap.containsKey(className)) {
|
||||
clazz = namePrimitiveMap.get(className);
|
||||
} else {
|
||||
|
@ -1173,7 +1173,7 @@ public static Method getPublicMethod(final Class<?> cls, final String methodName
|
|||
if (!Modifier.isPublic(candidateClass.getModifiers())) {
|
||||
continue;
|
||||
}
|
||||
Method candidateMethod;
|
||||
final Method candidateMethod;
|
||||
try {
|
||||
candidateMethod = candidateClass.getMethod(methodName, parameterTypes);
|
||||
} catch (final NoSuchMethodException ex) {
|
||||
|
|
|
@ -399,7 +399,7 @@ public static String random(int count, int start, int end, final boolean letters
|
|||
final int gap = end - start;
|
||||
|
||||
while (count-- != 0) {
|
||||
int codePoint;
|
||||
final int codePoint;
|
||||
if (chars == null) {
|
||||
codePoint = random.nextInt(gap) + start;
|
||||
|
||||
|
|
|
@ -4739,7 +4739,7 @@ public static String join(final Object[] array, final String delimiter) {
|
|||
* {@code endIndex < 0} or <br>
|
||||
* {@code endIndex > array.length()}
|
||||
*/
|
||||
public static String join(final Object[] array, String delimiter, final int startIndex, final int endIndex) {
|
||||
public static String join(final Object[] array, final String delimiter, final int startIndex, final int endIndex) {
|
||||
if (array == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -5423,8 +5423,8 @@ public static String lowerCase(final String str, final Locale locale) {
|
|||
}
|
||||
|
||||
private static int[] matches(final CharSequence first, final CharSequence second) {
|
||||
CharSequence max;
|
||||
CharSequence min;
|
||||
final CharSequence max;
|
||||
final CharSequence min;
|
||||
if (first.length() > second.length()) {
|
||||
max = first;
|
||||
min = second;
|
||||
|
|
|
@ -811,7 +811,7 @@ public DiffBuilder<T> append(final String fieldName, final Object lhs,
|
|||
return this;
|
||||
}
|
||||
|
||||
Object objectToTest;
|
||||
final Object objectToTest;
|
||||
if (lhs != null) {
|
||||
objectToTest = lhs;
|
||||
} else {
|
||||
|
|
|
@ -175,7 +175,7 @@ public synchronized boolean start() {
|
|||
|
||||
// Determine the executor to use and whether a temporary one has to
|
||||
// be created
|
||||
ExecutorService tempExec;
|
||||
final ExecutorService tempExec;
|
||||
executor = getExternalExecutor();
|
||||
if (executor == null) {
|
||||
executor = tempExec = createExecutor();
|
||||
|
|
|
@ -376,7 +376,7 @@ private void changeStateAndStartNewCheckInterval(final State newState) {
|
|||
*/
|
||||
private CheckIntervalData nextCheckIntervalData(final int increment,
|
||||
final CheckIntervalData currentData, final State currentState, final long time) {
|
||||
CheckIntervalData nextData;
|
||||
final CheckIntervalData nextData;
|
||||
if (stateStrategy(currentState).isCheckIntervalFinished(this, currentData, time)) {
|
||||
nextData = new CheckIntervalData(increment, time);
|
||||
} else {
|
||||
|
|
|
@ -176,7 +176,7 @@ protected int getTaskCount() {
|
|||
*/
|
||||
@Override
|
||||
protected MultiBackgroundInitializerResults initialize() throws Exception {
|
||||
Map<String, BackgroundInitializer<?>> inits;
|
||||
final Map<String, BackgroundInitializer<?>> inits;
|
||||
synchronized (this) {
|
||||
// create a snapshot to operate on
|
||||
inits = new HashMap<>(
|
||||
|
|
|
@ -178,7 +178,7 @@ public static Fraction getFraction(final int whole, final int numerator, final i
|
|||
if (numerator < 0) {
|
||||
throw new ArithmeticException("The numerator must not be negative");
|
||||
}
|
||||
long numeratorValue;
|
||||
final long numeratorValue;
|
||||
if (whole < 0) {
|
||||
numeratorValue = whole * (long) denominator - numerator;
|
||||
} else {
|
||||
|
|
|
@ -683,9 +683,9 @@ public static Number createNumber(final String str) {
|
|||
return createInteger(str);
|
||||
}
|
||||
final char lastChar = str.charAt(length - 1);
|
||||
String mant;
|
||||
String dec;
|
||||
String exp;
|
||||
final String mant;
|
||||
final String dec;
|
||||
final String exp;
|
||||
final int decPos = str.indexOf('.');
|
||||
final int expPos = str.indexOf('e') + str.indexOf('E') + 1; // assumes both not present
|
||||
// if both e and E are present, this is caught by the checks on expPos (which prevent IOOBE)
|
||||
|
|
|
@ -1021,7 +1021,7 @@ private static List<Class<?>> getAllSuperclassesAndInterfaces(final Class<?> cls
|
|||
int interfaceIndex = 0;
|
||||
while (interfaceIndex < allInterfaces.size() ||
|
||||
superClassIndex < allSuperclasses.size()) {
|
||||
Class<?> acls;
|
||||
final Class<?> acls;
|
||||
if (interfaceIndex >= allInterfaces.size()) {
|
||||
acls = allSuperclasses.get(superClassIndex++);
|
||||
} else if ((superClassIndex >= allSuperclasses.size()) || (interfaceIndex < superClassIndex) || !(superClassIndex < interfaceIndex)) {
|
||||
|
|
|
@ -885,7 +885,7 @@ private static Map<TypeVariable<?>, Type> getTypeArguments(
|
|||
}
|
||||
|
||||
final Type ownerType = parameterizedType.getOwnerType();
|
||||
Map<TypeVariable<?>, Type> typeVarAssigns;
|
||||
final Map<TypeVariable<?>, Type> typeVarAssigns;
|
||||
|
||||
if (ownerType instanceof ParameterizedType) {
|
||||
// get the owner type arguments first
|
||||
|
|
|
@ -133,7 +133,7 @@ public int translate(final CharSequence input, final int index, final Writer out
|
|||
}
|
||||
}
|
||||
|
||||
int entityValue;
|
||||
final int entityValue;
|
||||
try {
|
||||
if (isHex) {
|
||||
entityValue = Integer.parseInt(input.subSequence(start, end).toString(), 16);
|
||||
|
|
|
@ -131,7 +131,7 @@ protected FastDateParser(final String pattern, final TimeZone timeZone, final Lo
|
|||
|
||||
final Calendar definingCalendar = Calendar.getInstance(timeZone, this.locale);
|
||||
|
||||
int centuryStartYear;
|
||||
final int centuryStartYear;
|
||||
if (centuryStart!=null) {
|
||||
definingCalendar.setTime(centuryStart);
|
||||
centuryStartYear = definingCalendar.get(Calendar.YEAR);
|
||||
|
|
|
@ -189,7 +189,7 @@ static String getPatternForStyle(final Integer dateStyle, final Integer timeStyl
|
|||
String pattern = cDateTimeInstanceCache.get(key);
|
||||
if (pattern == null) {
|
||||
try {
|
||||
DateFormat formatter;
|
||||
final DateFormat formatter;
|
||||
if (dateStyle == null) {
|
||||
formatter = DateFormat.getTimeInstance(timeStyle.intValue(), safeLocale);
|
||||
} else if (timeStyle == null) {
|
||||
|
@ -217,7 +217,7 @@ static String getPatternForStyle(final Integer dateStyle, final Integer timeStyl
|
|||
*/
|
||||
private static final class ArrayKey {
|
||||
|
||||
private static int computeHashCode(Object[] keys) {
|
||||
private static int computeHashCode(final Object[] keys) {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + Arrays.hashCode(keys);
|
||||
|
@ -243,7 +243,7 @@ public int hashCode() {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
public boolean equals(final Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
|
@ -253,7 +253,7 @@ public boolean equals(Object obj) {
|
|||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
ArrayKey other = (ArrayKey) obj;
|
||||
final ArrayKey other = (ArrayKey) obj;
|
||||
return Arrays.deepEquals(keys, other.keys);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue