Minor Improvement: (#700)

* Add final variable.try to make the code read-only
This commit is contained in:
Arturo Bernal 2021-02-10 23:18:22 +01:00 committed by GitHub
parent 202076602a
commit 8c0bae01e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 23 additions and 23 deletions

View File

@ -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 * @throws IllegalArgumentException if both arguments are null
*/ */
public static <T> T[] add(final T[] array, final T element) { public static <T> T[] add(final T[] array, final T element) {
Class<?> type; final Class<?> type;
if (array != null) { if (array != null) {
type = array.getClass().getComponentType(); type = array.getClass().getComponentType();
} else if (element != null) { } else if (element != null) {

View File

@ -1061,7 +1061,7 @@ public static boolean isInnerClass(final Class<?> cls) {
public static Class<?> getClass( public static Class<?> getClass(
final ClassLoader classLoader, final String className, final boolean initialize) throws ClassNotFoundException { final ClassLoader classLoader, final String className, final boolean initialize) throws ClassNotFoundException {
try { try {
Class<?> clazz; final Class<?> clazz;
if (namePrimitiveMap.containsKey(className)) { if (namePrimitiveMap.containsKey(className)) {
clazz = namePrimitiveMap.get(className); clazz = namePrimitiveMap.get(className);
} else { } else {
@ -1173,7 +1173,7 @@ public static Method getPublicMethod(final Class<?> cls, final String methodName
if (!Modifier.isPublic(candidateClass.getModifiers())) { if (!Modifier.isPublic(candidateClass.getModifiers())) {
continue; continue;
} }
Method candidateMethod; final Method candidateMethod;
try { try {
candidateMethod = candidateClass.getMethod(methodName, parameterTypes); candidateMethod = candidateClass.getMethod(methodName, parameterTypes);
} catch (final NoSuchMethodException ex) { } catch (final NoSuchMethodException ex) {

View File

@ -399,7 +399,7 @@ public static String random(int count, int start, int end, final boolean letters
final int gap = end - start; final int gap = end - start;
while (count-- != 0) { while (count-- != 0) {
int codePoint; final int codePoint;
if (chars == null) { if (chars == null) {
codePoint = random.nextInt(gap) + start; codePoint = random.nextInt(gap) + start;

View File

@ -4739,7 +4739,7 @@ public static String join(final Object[] array, final String delimiter) {
* {@code endIndex < 0} or <br> * {@code endIndex < 0} or <br>
* {@code endIndex > array.length()} * {@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) { if (array == null) {
return 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) { private static int[] matches(final CharSequence first, final CharSequence second) {
CharSequence max; final CharSequence max;
CharSequence min; final CharSequence min;
if (first.length() > second.length()) { if (first.length() > second.length()) {
max = first; max = first;
min = second; min = second;

View File

@ -811,7 +811,7 @@ public DiffBuilder<T> append(final String fieldName, final Object lhs,
return this; return this;
} }
Object objectToTest; final Object objectToTest;
if (lhs != null) { if (lhs != null) {
objectToTest = lhs; objectToTest = lhs;
} else { } else {

View File

@ -175,7 +175,7 @@ public synchronized boolean start() {
// Determine the executor to use and whether a temporary one has to // Determine the executor to use and whether a temporary one has to
// be created // be created
ExecutorService tempExec; final ExecutorService tempExec;
executor = getExternalExecutor(); executor = getExternalExecutor();
if (executor == null) { if (executor == null) {
executor = tempExec = createExecutor(); executor = tempExec = createExecutor();

View File

@ -376,7 +376,7 @@ private void changeStateAndStartNewCheckInterval(final State newState) {
*/ */
private CheckIntervalData nextCheckIntervalData(final int increment, private CheckIntervalData nextCheckIntervalData(final int increment,
final CheckIntervalData currentData, final State currentState, final long time) { final CheckIntervalData currentData, final State currentState, final long time) {
CheckIntervalData nextData; final CheckIntervalData nextData;
if (stateStrategy(currentState).isCheckIntervalFinished(this, currentData, time)) { if (stateStrategy(currentState).isCheckIntervalFinished(this, currentData, time)) {
nextData = new CheckIntervalData(increment, time); nextData = new CheckIntervalData(increment, time);
} else { } else {

View File

@ -176,7 +176,7 @@ protected int getTaskCount() {
*/ */
@Override @Override
protected MultiBackgroundInitializerResults initialize() throws Exception { protected MultiBackgroundInitializerResults initialize() throws Exception {
Map<String, BackgroundInitializer<?>> inits; final Map<String, BackgroundInitializer<?>> inits;
synchronized (this) { synchronized (this) {
// create a snapshot to operate on // create a snapshot to operate on
inits = new HashMap<>( inits = new HashMap<>(

View File

@ -178,7 +178,7 @@ public static Fraction getFraction(final int whole, final int numerator, final i
if (numerator < 0) { if (numerator < 0) {
throw new ArithmeticException("The numerator must not be negative"); throw new ArithmeticException("The numerator must not be negative");
} }
long numeratorValue; final long numeratorValue;
if (whole < 0) { if (whole < 0) {
numeratorValue = whole * (long) denominator - numerator; numeratorValue = whole * (long) denominator - numerator;
} else { } else {

View File

@ -683,9 +683,9 @@ public static Number createNumber(final String str) {
return createInteger(str); return createInteger(str);
} }
final char lastChar = str.charAt(length - 1); final char lastChar = str.charAt(length - 1);
String mant; final String mant;
String dec; final String dec;
String exp; final String exp;
final int decPos = str.indexOf('.'); final int decPos = str.indexOf('.');
final int expPos = str.indexOf('e') + str.indexOf('E') + 1; // assumes both not present 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) // if both e and E are present, this is caught by the checks on expPos (which prevent IOOBE)

View File

@ -1021,7 +1021,7 @@ private static List<Class<?>> getAllSuperclassesAndInterfaces(final Class<?> cls
int interfaceIndex = 0; int interfaceIndex = 0;
while (interfaceIndex < allInterfaces.size() || while (interfaceIndex < allInterfaces.size() ||
superClassIndex < allSuperclasses.size()) { superClassIndex < allSuperclasses.size()) {
Class<?> acls; final Class<?> acls;
if (interfaceIndex >= allInterfaces.size()) { if (interfaceIndex >= allInterfaces.size()) {
acls = allSuperclasses.get(superClassIndex++); acls = allSuperclasses.get(superClassIndex++);
} else if ((superClassIndex >= allSuperclasses.size()) || (interfaceIndex < superClassIndex) || !(superClassIndex < interfaceIndex)) { } else if ((superClassIndex >= allSuperclasses.size()) || (interfaceIndex < superClassIndex) || !(superClassIndex < interfaceIndex)) {

View File

@ -885,7 +885,7 @@ private static Map<TypeVariable<?>, Type> getTypeArguments(
} }
final Type ownerType = parameterizedType.getOwnerType(); final Type ownerType = parameterizedType.getOwnerType();
Map<TypeVariable<?>, Type> typeVarAssigns; final Map<TypeVariable<?>, Type> typeVarAssigns;
if (ownerType instanceof ParameterizedType) { if (ownerType instanceof ParameterizedType) {
// get the owner type arguments first // get the owner type arguments first

View File

@ -133,7 +133,7 @@ public int translate(final CharSequence input, final int index, final Writer out
} }
} }
int entityValue; final int entityValue;
try { try {
if (isHex) { if (isHex) {
entityValue = Integer.parseInt(input.subSequence(start, end).toString(), 16); entityValue = Integer.parseInt(input.subSequence(start, end).toString(), 16);

View File

@ -131,7 +131,7 @@ protected FastDateParser(final String pattern, final TimeZone timeZone, final Lo
final Calendar definingCalendar = Calendar.getInstance(timeZone, this.locale); final Calendar definingCalendar = Calendar.getInstance(timeZone, this.locale);
int centuryStartYear; final int centuryStartYear;
if (centuryStart!=null) { if (centuryStart!=null) {
definingCalendar.setTime(centuryStart); definingCalendar.setTime(centuryStart);
centuryStartYear = definingCalendar.get(Calendar.YEAR); centuryStartYear = definingCalendar.get(Calendar.YEAR);

View File

@ -189,7 +189,7 @@ static String getPatternForStyle(final Integer dateStyle, final Integer timeStyl
String pattern = cDateTimeInstanceCache.get(key); String pattern = cDateTimeInstanceCache.get(key);
if (pattern == null) { if (pattern == null) {
try { try {
DateFormat formatter; final DateFormat formatter;
if (dateStyle == null) { if (dateStyle == null) {
formatter = DateFormat.getTimeInstance(timeStyle.intValue(), safeLocale); formatter = DateFormat.getTimeInstance(timeStyle.intValue(), safeLocale);
} else if (timeStyle == null) { } else if (timeStyle == null) {
@ -217,7 +217,7 @@ static String getPatternForStyle(final Integer dateStyle, final Integer timeStyl
*/ */
private static final class ArrayKey { private static final class ArrayKey {
private static int computeHashCode(Object[] keys) { private static int computeHashCode(final Object[] keys) {
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
result = prime * result + Arrays.hashCode(keys); result = prime * result + Arrays.hashCode(keys);
@ -243,7 +243,7 @@ public int hashCode() {
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(final Object obj) {
if (this == obj) { if (this == obj) {
return true; return true;
} }
@ -253,7 +253,7 @@ public boolean equals(Object obj) {
if (getClass() != obj.getClass()) { if (getClass() != obj.getClass()) {
return false; return false;
} }
ArrayKey other = (ArrayKey) obj; final ArrayKey other = (ArrayKey) obj;
return Arrays.deepEquals(keys, other.keys); return Arrays.deepEquals(keys, other.keys);
} }