Add final modifier to local variables.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1436770 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5bd622dab0
commit
5292526e47
|
@ -71,9 +71,10 @@ public class AnnotationUtils {
|
|||
@Override
|
||||
protected String getShortClassName(final java.lang.Class<?> cls) {
|
||||
Class<? extends Annotation> annotationType = null;
|
||||
for (Class<?> iface : ClassUtils.getAllInterfaces(cls)) {
|
||||
for (final Class<?> iface : ClassUtils.getAllInterfaces(cls)) {
|
||||
if (Annotation.class.isAssignableFrom(iface)) {
|
||||
@SuppressWarnings("unchecked") // OK because we just checked the assignability
|
||||
final
|
||||
Class<? extends Annotation> found = (Class<? extends Annotation>) iface;
|
||||
annotationType = found;
|
||||
break;
|
||||
|
@ -125,27 +126,27 @@ public static boolean equals(final Annotation a1, final Annotation a2) {
|
|||
if (a1 == null || a2 == null) {
|
||||
return false;
|
||||
}
|
||||
Class<? extends Annotation> type = a1.annotationType();
|
||||
Class<? extends Annotation> type2 = a2.annotationType();
|
||||
final Class<? extends Annotation> type = a1.annotationType();
|
||||
final Class<? extends Annotation> type2 = a2.annotationType();
|
||||
Validate.notNull(type, "Annotation %s with null annotationType()", a1);
|
||||
Validate.notNull(type2, "Annotation %s with null annotationType()", a2);
|
||||
if (!type.equals(type2)) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
for (Method m : type.getDeclaredMethods()) {
|
||||
for (final Method m : type.getDeclaredMethods()) {
|
||||
if (m.getParameterTypes().length == 0
|
||||
&& isValidAnnotationMemberType(m.getReturnType())) {
|
||||
Object v1 = m.invoke(a1);
|
||||
Object v2 = m.invoke(a2);
|
||||
final Object v1 = m.invoke(a1);
|
||||
final Object v2 = m.invoke(a2);
|
||||
if (!memberEquals(m.getReturnType(), v1, v2)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IllegalAccessException ex) {
|
||||
} catch (final IllegalAccessException ex) {
|
||||
return false;
|
||||
} catch (InvocationTargetException ex) {
|
||||
} catch (final InvocationTargetException ex) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -165,18 +166,18 @@ && isValidAnnotationMemberType(m.getReturnType())) {
|
|||
*/
|
||||
public static int hashCode(final Annotation a) {
|
||||
int result = 0;
|
||||
Class<? extends Annotation> type = a.annotationType();
|
||||
for (Method m : type.getDeclaredMethods()) {
|
||||
final Class<? extends Annotation> type = a.annotationType();
|
||||
for (final Method m : type.getDeclaredMethods()) {
|
||||
try {
|
||||
Object value = m.invoke(a);
|
||||
final Object value = m.invoke(a);
|
||||
if (value == null) {
|
||||
throw new IllegalStateException(
|
||||
String.format("Annotation method %s returned null", m));
|
||||
}
|
||||
result += hashMember(m.getName(), value);
|
||||
} catch (RuntimeException ex) {
|
||||
} catch (final RuntimeException ex) {
|
||||
throw ex;
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
@ -192,16 +193,16 @@ public static int hashCode(final Annotation a) {
|
|||
* {@code null}
|
||||
*/
|
||||
public static String toString(final Annotation a) {
|
||||
ToStringBuilder builder = new ToStringBuilder(a, TO_STRING_STYLE);
|
||||
for (Method m : a.annotationType().getDeclaredMethods()) {
|
||||
final ToStringBuilder builder = new ToStringBuilder(a, TO_STRING_STYLE);
|
||||
for (final Method m : a.annotationType().getDeclaredMethods()) {
|
||||
if (m.getParameterTypes().length > 0) {
|
||||
continue; //wtf?
|
||||
}
|
||||
try {
|
||||
builder.append(m.getName(), m.invoke(a));
|
||||
} catch (RuntimeException ex) {
|
||||
} catch (final RuntimeException ex) {
|
||||
throw ex;
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
@ -239,7 +240,7 @@ public static boolean isValidAnnotationMemberType(Class<?> type) {
|
|||
* @return a hash code for this member
|
||||
*/
|
||||
private static int hashMember(final String name, final Object value) {
|
||||
int part1 = name.hashCode() * 127;
|
||||
final int part1 = name.hashCode() * 127;
|
||||
if (value.getClass().isArray()) {
|
||||
return part1 ^ arrayMemberHash(value.getClass().getComponentType(), value);
|
||||
}
|
||||
|
|
|
@ -237,12 +237,12 @@ public static Map<Object, Object> toMap(final Object[] array) {
|
|||
}
|
||||
final Map<Object, Object> map = new HashMap<Object, Object>((int) (array.length * 1.5));
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
Object object = array[i];
|
||||
final Object object = array[i];
|
||||
if (object instanceof Map.Entry<?, ?>) {
|
||||
Map.Entry<?,?> entry = (Map.Entry<?,?>) object;
|
||||
final Map.Entry<?,?> entry = (Map.Entry<?,?>) object;
|
||||
map.put(entry.getKey(), entry.getValue());
|
||||
} else if (object instanceof Object[]) {
|
||||
Object[] entry = (Object[]) object;
|
||||
final Object[] entry = (Object[]) object;
|
||||
if (entry.length < 2) {
|
||||
throw new IllegalArgumentException("Array element " + i + ", '"
|
||||
+ object
|
||||
|
@ -853,14 +853,15 @@ public static <T> T[] subarray(final T[] array, int startIndexInclusive, int end
|
|||
if (endIndexExclusive > array.length) {
|
||||
endIndexExclusive = array.length;
|
||||
}
|
||||
int newSize = endIndexExclusive - startIndexInclusive;
|
||||
Class<?> type = array.getClass().getComponentType();
|
||||
final int newSize = endIndexExclusive - startIndexInclusive;
|
||||
final Class<?> type = array.getClass().getComponentType();
|
||||
if (newSize <= 0) {
|
||||
@SuppressWarnings("unchecked") // OK, because array is of type T
|
||||
final T[] emptyArray = (T[]) Array.newInstance(type, 0);
|
||||
return emptyArray;
|
||||
}
|
||||
@SuppressWarnings("unchecked") // OK, because array is of type T
|
||||
final
|
||||
T[] subarray = (T[]) Array.newInstance(type, newSize);
|
||||
System.arraycopy(array, startIndexInclusive, subarray, 0, newSize);
|
||||
return subarray;
|
||||
|
@ -895,12 +896,12 @@ public static long[] subarray(final long[] array, int startIndexInclusive, int e
|
|||
if (endIndexExclusive > array.length) {
|
||||
endIndexExclusive = array.length;
|
||||
}
|
||||
int newSize = endIndexExclusive - startIndexInclusive;
|
||||
final int newSize = endIndexExclusive - startIndexInclusive;
|
||||
if (newSize <= 0) {
|
||||
return EMPTY_LONG_ARRAY;
|
||||
}
|
||||
|
||||
long[] subarray = new long[newSize];
|
||||
final long[] subarray = new long[newSize];
|
||||
System.arraycopy(array, startIndexInclusive, subarray, 0, newSize);
|
||||
return subarray;
|
||||
}
|
||||
|
@ -934,12 +935,12 @@ public static int[] subarray(final int[] array, int startIndexInclusive, int end
|
|||
if (endIndexExclusive > array.length) {
|
||||
endIndexExclusive = array.length;
|
||||
}
|
||||
int newSize = endIndexExclusive - startIndexInclusive;
|
||||
final int newSize = endIndexExclusive - startIndexInclusive;
|
||||
if (newSize <= 0) {
|
||||
return EMPTY_INT_ARRAY;
|
||||
}
|
||||
|
||||
int[] subarray = new int[newSize];
|
||||
final int[] subarray = new int[newSize];
|
||||
System.arraycopy(array, startIndexInclusive, subarray, 0, newSize);
|
||||
return subarray;
|
||||
}
|
||||
|
@ -973,12 +974,12 @@ public static short[] subarray(final short[] array, int startIndexInclusive, int
|
|||
if (endIndexExclusive > array.length) {
|
||||
endIndexExclusive = array.length;
|
||||
}
|
||||
int newSize = endIndexExclusive - startIndexInclusive;
|
||||
final int newSize = endIndexExclusive - startIndexInclusive;
|
||||
if (newSize <= 0) {
|
||||
return EMPTY_SHORT_ARRAY;
|
||||
}
|
||||
|
||||
short[] subarray = new short[newSize];
|
||||
final short[] subarray = new short[newSize];
|
||||
System.arraycopy(array, startIndexInclusive, subarray, 0, newSize);
|
||||
return subarray;
|
||||
}
|
||||
|
@ -1012,12 +1013,12 @@ public static char[] subarray(final char[] array, int startIndexInclusive, int e
|
|||
if (endIndexExclusive > array.length) {
|
||||
endIndexExclusive = array.length;
|
||||
}
|
||||
int newSize = endIndexExclusive - startIndexInclusive;
|
||||
final int newSize = endIndexExclusive - startIndexInclusive;
|
||||
if (newSize <= 0) {
|
||||
return EMPTY_CHAR_ARRAY;
|
||||
}
|
||||
|
||||
char[] subarray = new char[newSize];
|
||||
final char[] subarray = new char[newSize];
|
||||
System.arraycopy(array, startIndexInclusive, subarray, 0, newSize);
|
||||
return subarray;
|
||||
}
|
||||
|
@ -1051,12 +1052,12 @@ public static byte[] subarray(final byte[] array, int startIndexInclusive, int e
|
|||
if (endIndexExclusive > array.length) {
|
||||
endIndexExclusive = array.length;
|
||||
}
|
||||
int newSize = endIndexExclusive - startIndexInclusive;
|
||||
final int newSize = endIndexExclusive - startIndexInclusive;
|
||||
if (newSize <= 0) {
|
||||
return EMPTY_BYTE_ARRAY;
|
||||
}
|
||||
|
||||
byte[] subarray = new byte[newSize];
|
||||
final byte[] subarray = new byte[newSize];
|
||||
System.arraycopy(array, startIndexInclusive, subarray, 0, newSize);
|
||||
return subarray;
|
||||
}
|
||||
|
@ -1090,12 +1091,12 @@ public static double[] subarray(final double[] array, int startIndexInclusive, i
|
|||
if (endIndexExclusive > array.length) {
|
||||
endIndexExclusive = array.length;
|
||||
}
|
||||
int newSize = endIndexExclusive - startIndexInclusive;
|
||||
final int newSize = endIndexExclusive - startIndexInclusive;
|
||||
if (newSize <= 0) {
|
||||
return EMPTY_DOUBLE_ARRAY;
|
||||
}
|
||||
|
||||
double[] subarray = new double[newSize];
|
||||
final double[] subarray = new double[newSize];
|
||||
System.arraycopy(array, startIndexInclusive, subarray, 0, newSize);
|
||||
return subarray;
|
||||
}
|
||||
|
@ -1129,12 +1130,12 @@ public static float[] subarray(final float[] array, int startIndexInclusive, int
|
|||
if (endIndexExclusive > array.length) {
|
||||
endIndexExclusive = array.length;
|
||||
}
|
||||
int newSize = endIndexExclusive - startIndexInclusive;
|
||||
final int newSize = endIndexExclusive - startIndexInclusive;
|
||||
if (newSize <= 0) {
|
||||
return EMPTY_FLOAT_ARRAY;
|
||||
}
|
||||
|
||||
float[] subarray = new float[newSize];
|
||||
final float[] subarray = new float[newSize];
|
||||
System.arraycopy(array, startIndexInclusive, subarray, 0, newSize);
|
||||
return subarray;
|
||||
}
|
||||
|
@ -1168,12 +1169,12 @@ public static boolean[] subarray(final boolean[] array, int startIndexInclusive,
|
|||
if (endIndexExclusive > array.length) {
|
||||
endIndexExclusive = array.length;
|
||||
}
|
||||
int newSize = endIndexExclusive - startIndexInclusive;
|
||||
final int newSize = endIndexExclusive - startIndexInclusive;
|
||||
if (newSize <= 0) {
|
||||
return EMPTY_BOOLEAN_ARRAY;
|
||||
}
|
||||
|
||||
boolean[] subarray = new boolean[newSize];
|
||||
final boolean[] subarray = new boolean[newSize];
|
||||
System.arraycopy(array, startIndexInclusive, subarray, 0, newSize);
|
||||
return subarray;
|
||||
}
|
||||
|
@ -2327,8 +2328,8 @@ public static int indexOf(final double[] array, final double valueToFind, int st
|
|||
if (startIndex < 0) {
|
||||
startIndex = 0;
|
||||
}
|
||||
double min = valueToFind - tolerance;
|
||||
double max = valueToFind + tolerance;
|
||||
final double min = valueToFind - tolerance;
|
||||
final double max = valueToFind + tolerance;
|
||||
for (int i = startIndex; i < array.length; i++) {
|
||||
if (array[i] >= min && array[i] <= max) {
|
||||
return i;
|
||||
|
@ -2425,8 +2426,8 @@ public static int lastIndexOf(final double[] array, final double valueToFind, in
|
|||
} else if (startIndex >= array.length) {
|
||||
startIndex = array.length - 1;
|
||||
}
|
||||
double min = valueToFind - tolerance;
|
||||
double max = valueToFind + tolerance;
|
||||
final double min = valueToFind - tolerance;
|
||||
final double max = valueToFind + tolerance;
|
||||
for (int i = startIndex; i >= 0; i--) {
|
||||
if (array[i] >= min && array[i] <= max) {
|
||||
return i;
|
||||
|
@ -2717,7 +2718,7 @@ public static char[] toPrimitive(final Character[] array, final char valueForNul
|
|||
}
|
||||
final char[] result = new char[array.length];
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
Character b = array[i];
|
||||
final Character b = array[i];
|
||||
result[i] = (b == null ? valueForNull : b.charValue());
|
||||
}
|
||||
return result;
|
||||
|
@ -2785,7 +2786,7 @@ public static long[] toPrimitive(final Long[] array, final long valueForNull) {
|
|||
}
|
||||
final long[] result = new long[array.length];
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
Long b = array[i];
|
||||
final Long b = array[i];
|
||||
result[i] = (b == null ? valueForNull : b.longValue());
|
||||
}
|
||||
return result;
|
||||
|
@ -2853,7 +2854,7 @@ public static int[] toPrimitive(final Integer[] array, final int valueForNull) {
|
|||
}
|
||||
final int[] result = new int[array.length];
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
Integer b = array[i];
|
||||
final Integer b = array[i];
|
||||
result[i] = (b == null ? valueForNull : b.intValue());
|
||||
}
|
||||
return result;
|
||||
|
@ -2921,7 +2922,7 @@ public static short[] toPrimitive(final Short[] array, final short valueForNull)
|
|||
}
|
||||
final short[] result = new short[array.length];
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
Short b = array[i];
|
||||
final Short b = array[i];
|
||||
result[i] = (b == null ? valueForNull : b.shortValue());
|
||||
}
|
||||
return result;
|
||||
|
@ -2989,7 +2990,7 @@ public static byte[] toPrimitive(final Byte[] array, final byte valueForNull) {
|
|||
}
|
||||
final byte[] result = new byte[array.length];
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
Byte b = array[i];
|
||||
final Byte b = array[i];
|
||||
result[i] = (b == null ? valueForNull : b.byteValue());
|
||||
}
|
||||
return result;
|
||||
|
@ -3057,7 +3058,7 @@ public static double[] toPrimitive(final Double[] array, final double valueForNu
|
|||
}
|
||||
final double[] result = new double[array.length];
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
Double b = array[i];
|
||||
final Double b = array[i];
|
||||
result[i] = (b == null ? valueForNull : b.doubleValue());
|
||||
}
|
||||
return result;
|
||||
|
@ -3125,7 +3126,7 @@ public static float[] toPrimitive(final Float[] array, final float valueForNull)
|
|||
}
|
||||
final float[] result = new float[array.length];
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
Float b = array[i];
|
||||
final Float b = array[i];
|
||||
result[i] = (b == null ? valueForNull : b.floatValue());
|
||||
}
|
||||
return result;
|
||||
|
@ -3193,7 +3194,7 @@ public static boolean[] toPrimitive(final Boolean[] array, final boolean valueFo
|
|||
}
|
||||
final boolean[] result = new boolean[array.length];
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
Boolean b = array[i];
|
||||
final Boolean b = array[i];
|
||||
result[i] = (b == null ? valueForNull : b.booleanValue());
|
||||
}
|
||||
return result;
|
||||
|
@ -3453,11 +3454,12 @@ public static <T> T[] addAll(final T[] array1, final T... array2) {
|
|||
}
|
||||
final Class<?> type1 = array1.getClass().getComponentType();
|
||||
@SuppressWarnings("unchecked") // OK, because array is of type T
|
||||
final
|
||||
T[] joinedArray = (T[]) Array.newInstance(type1, array1.length + array2.length);
|
||||
System.arraycopy(array1, 0, joinedArray, 0, array1.length);
|
||||
try {
|
||||
System.arraycopy(array2, 0, joinedArray, array1.length, array2.length);
|
||||
} catch (ArrayStoreException ase) {
|
||||
} catch (final ArrayStoreException ase) {
|
||||
// Check if problem was due to incompatible types
|
||||
/*
|
||||
* We do this here, rather than before the copy because:
|
||||
|
@ -3497,7 +3499,7 @@ public static boolean[] addAll(final boolean[] array1, final boolean... array2)
|
|||
} else if (array2 == null) {
|
||||
return clone(array1);
|
||||
}
|
||||
boolean[] joinedArray = new boolean[array1.length + array2.length];
|
||||
final boolean[] joinedArray = new boolean[array1.length + array2.length];
|
||||
System.arraycopy(array1, 0, joinedArray, 0, array1.length);
|
||||
System.arraycopy(array2, 0, joinedArray, array1.length, array2.length);
|
||||
return joinedArray;
|
||||
|
@ -3526,7 +3528,7 @@ public static char[] addAll(final char[] array1, final char... array2) {
|
|||
} else if (array2 == null) {
|
||||
return clone(array1);
|
||||
}
|
||||
char[] joinedArray = new char[array1.length + array2.length];
|
||||
final char[] joinedArray = new char[array1.length + array2.length];
|
||||
System.arraycopy(array1, 0, joinedArray, 0, array1.length);
|
||||
System.arraycopy(array2, 0, joinedArray, array1.length, array2.length);
|
||||
return joinedArray;
|
||||
|
@ -3555,7 +3557,7 @@ public static byte[] addAll(final byte[] array1, final byte... array2) {
|
|||
} else if (array2 == null) {
|
||||
return clone(array1);
|
||||
}
|
||||
byte[] joinedArray = new byte[array1.length + array2.length];
|
||||
final byte[] joinedArray = new byte[array1.length + array2.length];
|
||||
System.arraycopy(array1, 0, joinedArray, 0, array1.length);
|
||||
System.arraycopy(array2, 0, joinedArray, array1.length, array2.length);
|
||||
return joinedArray;
|
||||
|
@ -3584,7 +3586,7 @@ public static short[] addAll(final short[] array1, final short... array2) {
|
|||
} else if (array2 == null) {
|
||||
return clone(array1);
|
||||
}
|
||||
short[] joinedArray = new short[array1.length + array2.length];
|
||||
final short[] joinedArray = new short[array1.length + array2.length];
|
||||
System.arraycopy(array1, 0, joinedArray, 0, array1.length);
|
||||
System.arraycopy(array2, 0, joinedArray, array1.length, array2.length);
|
||||
return joinedArray;
|
||||
|
@ -3613,7 +3615,7 @@ public static int[] addAll(final int[] array1, final int... array2) {
|
|||
} else if (array2 == null) {
|
||||
return clone(array1);
|
||||
}
|
||||
int[] joinedArray = new int[array1.length + array2.length];
|
||||
final int[] joinedArray = new int[array1.length + array2.length];
|
||||
System.arraycopy(array1, 0, joinedArray, 0, array1.length);
|
||||
System.arraycopy(array2, 0, joinedArray, array1.length, array2.length);
|
||||
return joinedArray;
|
||||
|
@ -3642,7 +3644,7 @@ public static long[] addAll(final long[] array1, final long... array2) {
|
|||
} else if (array2 == null) {
|
||||
return clone(array1);
|
||||
}
|
||||
long[] joinedArray = new long[array1.length + array2.length];
|
||||
final long[] joinedArray = new long[array1.length + array2.length];
|
||||
System.arraycopy(array1, 0, joinedArray, 0, array1.length);
|
||||
System.arraycopy(array2, 0, joinedArray, array1.length, array2.length);
|
||||
return joinedArray;
|
||||
|
@ -3671,7 +3673,7 @@ public static float[] addAll(final float[] array1, final float... array2) {
|
|||
} else if (array2 == null) {
|
||||
return clone(array1);
|
||||
}
|
||||
float[] joinedArray = new float[array1.length + array2.length];
|
||||
final float[] joinedArray = new float[array1.length + array2.length];
|
||||
System.arraycopy(array1, 0, joinedArray, 0, array1.length);
|
||||
System.arraycopy(array2, 0, joinedArray, array1.length, array2.length);
|
||||
return joinedArray;
|
||||
|
@ -3700,7 +3702,7 @@ public static double[] addAll(final double[] array1, final double... array2) {
|
|||
} else if (array2 == null) {
|
||||
return clone(array1);
|
||||
}
|
||||
double[] joinedArray = new double[array1.length + array2.length];
|
||||
final double[] joinedArray = new double[array1.length + array2.length];
|
||||
System.arraycopy(array1, 0, joinedArray, 0, array1.length);
|
||||
System.arraycopy(array2, 0, joinedArray, array1.length, array2.length);
|
||||
return joinedArray;
|
||||
|
@ -3745,6 +3747,7 @@ public static <T> T[] add(final T[] array, final T element) {
|
|||
throw new IllegalArgumentException("Arguments cannot both be null");
|
||||
}
|
||||
@SuppressWarnings("unchecked") // type must be T
|
||||
final
|
||||
T[] newArray = (T[]) copyArrayGrow1(array, type);
|
||||
newArray[newArray.length - 1] = element;
|
||||
return newArray;
|
||||
|
@ -3772,7 +3775,7 @@ public static <T> T[] add(final T[] array, final T element) {
|
|||
* @since 2.1
|
||||
*/
|
||||
public static boolean[] add(final boolean[] array, final boolean element) {
|
||||
boolean[] newArray = (boolean[])copyArrayGrow1(array, Boolean.TYPE);
|
||||
final boolean[] newArray = (boolean[])copyArrayGrow1(array, Boolean.TYPE);
|
||||
newArray[newArray.length - 1] = element;
|
||||
return newArray;
|
||||
}
|
||||
|
@ -3799,7 +3802,7 @@ public static boolean[] add(final boolean[] array, final boolean element) {
|
|||
* @since 2.1
|
||||
*/
|
||||
public static byte[] add(final byte[] array, final byte element) {
|
||||
byte[] newArray = (byte[])copyArrayGrow1(array, Byte.TYPE);
|
||||
final byte[] newArray = (byte[])copyArrayGrow1(array, Byte.TYPE);
|
||||
newArray[newArray.length - 1] = element;
|
||||
return newArray;
|
||||
}
|
||||
|
@ -3826,7 +3829,7 @@ public static byte[] add(final byte[] array, final byte element) {
|
|||
* @since 2.1
|
||||
*/
|
||||
public static char[] add(final char[] array, final char element) {
|
||||
char[] newArray = (char[])copyArrayGrow1(array, Character.TYPE);
|
||||
final char[] newArray = (char[])copyArrayGrow1(array, Character.TYPE);
|
||||
newArray[newArray.length - 1] = element;
|
||||
return newArray;
|
||||
}
|
||||
|
@ -3853,7 +3856,7 @@ public static char[] add(final char[] array, final char element) {
|
|||
* @since 2.1
|
||||
*/
|
||||
public static double[] add(final double[] array, final double element) {
|
||||
double[] newArray = (double[])copyArrayGrow1(array, Double.TYPE);
|
||||
final double[] newArray = (double[])copyArrayGrow1(array, Double.TYPE);
|
||||
newArray[newArray.length - 1] = element;
|
||||
return newArray;
|
||||
}
|
||||
|
@ -3880,7 +3883,7 @@ public static double[] add(final double[] array, final double element) {
|
|||
* @since 2.1
|
||||
*/
|
||||
public static float[] add(final float[] array, final float element) {
|
||||
float[] newArray = (float[])copyArrayGrow1(array, Float.TYPE);
|
||||
final float[] newArray = (float[])copyArrayGrow1(array, Float.TYPE);
|
||||
newArray[newArray.length - 1] = element;
|
||||
return newArray;
|
||||
}
|
||||
|
@ -3907,7 +3910,7 @@ public static float[] add(final float[] array, final float element) {
|
|||
* @since 2.1
|
||||
*/
|
||||
public static int[] add(final int[] array, final int element) {
|
||||
int[] newArray = (int[])copyArrayGrow1(array, Integer.TYPE);
|
||||
final int[] newArray = (int[])copyArrayGrow1(array, Integer.TYPE);
|
||||
newArray[newArray.length - 1] = element;
|
||||
return newArray;
|
||||
}
|
||||
|
@ -3934,7 +3937,7 @@ public static int[] add(final int[] array, final int element) {
|
|||
* @since 2.1
|
||||
*/
|
||||
public static long[] add(final long[] array, final long element) {
|
||||
long[] newArray = (long[])copyArrayGrow1(array, Long.TYPE);
|
||||
final long[] newArray = (long[])copyArrayGrow1(array, Long.TYPE);
|
||||
newArray[newArray.length - 1] = element;
|
||||
return newArray;
|
||||
}
|
||||
|
@ -3961,7 +3964,7 @@ public static long[] add(final long[] array, final long element) {
|
|||
* @since 2.1
|
||||
*/
|
||||
public static short[] add(final short[] array, final short element) {
|
||||
short[] newArray = (short[])copyArrayGrow1(array, Short.TYPE);
|
||||
final short[] newArray = (short[])copyArrayGrow1(array, Short.TYPE);
|
||||
newArray[newArray.length - 1] = element;
|
||||
return newArray;
|
||||
}
|
||||
|
@ -3977,8 +3980,8 @@ public static short[] add(final short[] array, final short element) {
|
|||
*/
|
||||
private static Object copyArrayGrow1(final Object array, final Class<?> newArrayComponentType) {
|
||||
if (array != null) {
|
||||
int arrayLength = Array.getLength(array);
|
||||
Object newArray = Array.newInstance(array.getClass().getComponentType(), arrayLength + 1);
|
||||
final int arrayLength = Array.getLength(array);
|
||||
final Object newArray = Array.newInstance(array.getClass().getComponentType(), arrayLength + 1);
|
||||
System.arraycopy(array, 0, newArray, 0, arrayLength);
|
||||
return newArray;
|
||||
}
|
||||
|
@ -4294,15 +4297,15 @@ private static Object add(final Object array, final int index, final Object elem
|
|||
if (index != 0) {
|
||||
throw new IndexOutOfBoundsException("Index: " + index + ", Length: 0");
|
||||
}
|
||||
Object joinedArray = Array.newInstance(clss, 1);
|
||||
final Object joinedArray = Array.newInstance(clss, 1);
|
||||
Array.set(joinedArray, 0, element);
|
||||
return joinedArray;
|
||||
}
|
||||
int length = Array.getLength(array);
|
||||
final int length = Array.getLength(array);
|
||||
if (index > length || index < 0) {
|
||||
throw new IndexOutOfBoundsException("Index: " + index + ", Length: " + length);
|
||||
}
|
||||
Object result = Array.newInstance(clss, length + 1);
|
||||
final Object result = Array.newInstance(clss, length + 1);
|
||||
System.arraycopy(array, 0, result, 0, index);
|
||||
Array.set(result, index, element);
|
||||
if (index < length) {
|
||||
|
@ -4372,7 +4375,7 @@ public static <T> T[] remove(final T[] array, final int index) {
|
|||
* @since 2.1
|
||||
*/
|
||||
public static <T> T[] removeElement(final T[] array, final Object element) {
|
||||
int index = indexOf(array, element);
|
||||
final int index = indexOf(array, element);
|
||||
if (index == INDEX_NOT_FOUND) {
|
||||
return clone(array);
|
||||
}
|
||||
|
@ -4437,7 +4440,7 @@ public static boolean[] remove(final boolean[] array, final int index) {
|
|||
* @since 2.1
|
||||
*/
|
||||
public static boolean[] removeElement(final boolean[] array, final boolean element) {
|
||||
int index = indexOf(array, element);
|
||||
final int index = indexOf(array, element);
|
||||
if (index == INDEX_NOT_FOUND) {
|
||||
return clone(array);
|
||||
}
|
||||
|
@ -4502,7 +4505,7 @@ public static byte[] remove(final byte[] array, final int index) {
|
|||
* @since 2.1
|
||||
*/
|
||||
public static byte[] removeElement(final byte[] array, final byte element) {
|
||||
int index = indexOf(array, element);
|
||||
final int index = indexOf(array, element);
|
||||
if (index == INDEX_NOT_FOUND) {
|
||||
return clone(array);
|
||||
}
|
||||
|
@ -4567,7 +4570,7 @@ public static char[] remove(final char[] array, final int index) {
|
|||
* @since 2.1
|
||||
*/
|
||||
public static char[] removeElement(final char[] array, final char element) {
|
||||
int index = indexOf(array, element);
|
||||
final int index = indexOf(array, element);
|
||||
if (index == INDEX_NOT_FOUND) {
|
||||
return clone(array);
|
||||
}
|
||||
|
@ -4632,7 +4635,7 @@ public static double[] remove(final double[] array, final int index) {
|
|||
* @since 2.1
|
||||
*/
|
||||
public static double[] removeElement(final double[] array, final double element) {
|
||||
int index = indexOf(array, element);
|
||||
final int index = indexOf(array, element);
|
||||
if (index == INDEX_NOT_FOUND) {
|
||||
return clone(array);
|
||||
}
|
||||
|
@ -4697,7 +4700,7 @@ public static float[] remove(final float[] array, final int index) {
|
|||
* @since 2.1
|
||||
*/
|
||||
public static float[] removeElement(final float[] array, final float element) {
|
||||
int index = indexOf(array, element);
|
||||
final int index = indexOf(array, element);
|
||||
if (index == INDEX_NOT_FOUND) {
|
||||
return clone(array);
|
||||
}
|
||||
|
@ -4762,7 +4765,7 @@ public static int[] remove(final int[] array, final int index) {
|
|||
* @since 2.1
|
||||
*/
|
||||
public static int[] removeElement(final int[] array, final int element) {
|
||||
int index = indexOf(array, element);
|
||||
final int index = indexOf(array, element);
|
||||
if (index == INDEX_NOT_FOUND) {
|
||||
return clone(array);
|
||||
}
|
||||
|
@ -4827,7 +4830,7 @@ public static long[] remove(final long[] array, final int index) {
|
|||
* @since 2.1
|
||||
*/
|
||||
public static long[] removeElement(final long[] array, final long element) {
|
||||
int index = indexOf(array, element);
|
||||
final int index = indexOf(array, element);
|
||||
if (index == INDEX_NOT_FOUND) {
|
||||
return clone(array);
|
||||
}
|
||||
|
@ -4892,7 +4895,7 @@ public static short[] remove(final short[] array, final int index) {
|
|||
* @since 2.1
|
||||
*/
|
||||
public static short[] removeElement(final short[] array, final short element) {
|
||||
int index = indexOf(array, element);
|
||||
final int index = indexOf(array, element);
|
||||
if (index == INDEX_NOT_FOUND) {
|
||||
return clone(array);
|
||||
}
|
||||
|
@ -4921,12 +4924,12 @@ public static short[] removeElement(final short[] array, final short element) {
|
|||
* @since 2.1
|
||||
*/
|
||||
private static Object remove(final Object array, final int index) {
|
||||
int length = getLength(array);
|
||||
final int length = getLength(array);
|
||||
if (index < 0 || index >= length) {
|
||||
throw new IndexOutOfBoundsException("Index: " + index + ", Length: " + length);
|
||||
}
|
||||
|
||||
Object result = Array.newInstance(array.getClass().getComponentType(), length - 1);
|
||||
final Object result = Array.newInstance(array.getClass().getComponentType(), length - 1);
|
||||
System.arraycopy(array, 0, result, 0, index);
|
||||
if (index < length - 1) {
|
||||
System.arraycopy(array, index + 1, result, index, length - index - 1);
|
||||
|
@ -4998,18 +5001,18 @@ public static <T> T[] removeElements(final T[] array, final T... values) {
|
|||
if (isEmpty(array) || isEmpty(values)) {
|
||||
return clone(array);
|
||||
}
|
||||
HashMap<T, MutableInt> occurrences = new HashMap<T, MutableInt>(values.length);
|
||||
for (T v : values) {
|
||||
MutableInt count = occurrences.get(v);
|
||||
final HashMap<T, MutableInt> occurrences = new HashMap<T, MutableInt>(values.length);
|
||||
for (final T v : values) {
|
||||
final MutableInt count = occurrences.get(v);
|
||||
if (count == null) {
|
||||
occurrences.put(v, new MutableInt(1));
|
||||
} else {
|
||||
count.increment();
|
||||
}
|
||||
}
|
||||
BitSet toRemove = new BitSet();
|
||||
for (Map.Entry<T, MutableInt> e : occurrences.entrySet()) {
|
||||
T v = e.getKey();
|
||||
final BitSet toRemove = new BitSet();
|
||||
for (final Map.Entry<T, MutableInt> e : occurrences.entrySet()) {
|
||||
final T v = e.getKey();
|
||||
int found = 0;
|
||||
for (int i = 0, ct = e.getValue().intValue(); i < ct; i++) {
|
||||
found = indexOf(array, v, found);
|
||||
|
@ -5020,6 +5023,7 @@ public static <T> T[] removeElements(final T[] array, final T... values) {
|
|||
}
|
||||
}
|
||||
@SuppressWarnings("unchecked") // removeAll() always creates an array of the same type as its input
|
||||
final
|
||||
T[] result = (T[]) removeAll(array, toRemove);
|
||||
return result;
|
||||
}
|
||||
|
@ -5088,19 +5092,19 @@ public static byte[] removeElements(final byte[] array, final byte... values) {
|
|||
if (isEmpty(array) || isEmpty(values)) {
|
||||
return clone(array);
|
||||
}
|
||||
HashMap<Byte, MutableInt> occurrences = new HashMap<Byte, MutableInt>(values.length);
|
||||
for (byte v : values) {
|
||||
Byte boxed = Byte.valueOf(v);
|
||||
MutableInt count = occurrences.get(boxed);
|
||||
final HashMap<Byte, MutableInt> occurrences = new HashMap<Byte, MutableInt>(values.length);
|
||||
for (final byte v : values) {
|
||||
final Byte boxed = Byte.valueOf(v);
|
||||
final MutableInt count = occurrences.get(boxed);
|
||||
if (count == null) {
|
||||
occurrences.put(boxed, new MutableInt(1));
|
||||
} else {
|
||||
count.increment();
|
||||
}
|
||||
}
|
||||
BitSet toRemove = new BitSet();
|
||||
for (Map.Entry<Byte, MutableInt> e : occurrences.entrySet()) {
|
||||
Byte v = e.getKey();
|
||||
final BitSet toRemove = new BitSet();
|
||||
for (final Map.Entry<Byte, MutableInt> e : occurrences.entrySet()) {
|
||||
final Byte v = e.getKey();
|
||||
int found = 0;
|
||||
for (int i = 0, ct = e.getValue().intValue(); i < ct; i++) {
|
||||
found = indexOf(array, v.byteValue(), found);
|
||||
|
@ -5177,19 +5181,19 @@ public static short[] removeElements(final short[] array, final short... values)
|
|||
if (isEmpty(array) || isEmpty(values)) {
|
||||
return clone(array);
|
||||
}
|
||||
HashMap<Short, MutableInt> occurrences = new HashMap<Short, MutableInt>(values.length);
|
||||
for (short v : values) {
|
||||
Short boxed = Short.valueOf(v);
|
||||
MutableInt count = occurrences.get(boxed);
|
||||
final HashMap<Short, MutableInt> occurrences = new HashMap<Short, MutableInt>(values.length);
|
||||
for (final short v : values) {
|
||||
final Short boxed = Short.valueOf(v);
|
||||
final MutableInt count = occurrences.get(boxed);
|
||||
if (count == null) {
|
||||
occurrences.put(boxed, new MutableInt(1));
|
||||
} else {
|
||||
count.increment();
|
||||
}
|
||||
}
|
||||
BitSet toRemove = new BitSet();
|
||||
for (Map.Entry<Short, MutableInt> e : occurrences.entrySet()) {
|
||||
Short v = e.getKey();
|
||||
final BitSet toRemove = new BitSet();
|
||||
for (final Map.Entry<Short, MutableInt> e : occurrences.entrySet()) {
|
||||
final Short v = e.getKey();
|
||||
int found = 0;
|
||||
for (int i = 0, ct = e.getValue().intValue(); i < ct; i++) {
|
||||
found = indexOf(array, v.shortValue(), found);
|
||||
|
@ -5266,19 +5270,19 @@ public static int[] removeElements(final int[] array, final int... values) {
|
|||
if (isEmpty(array) || isEmpty(values)) {
|
||||
return clone(array);
|
||||
}
|
||||
HashMap<Integer, MutableInt> occurrences = new HashMap<Integer, MutableInt>(values.length);
|
||||
for (int v : values) {
|
||||
Integer boxed = Integer.valueOf(v);
|
||||
MutableInt count = occurrences.get(boxed);
|
||||
final HashMap<Integer, MutableInt> occurrences = new HashMap<Integer, MutableInt>(values.length);
|
||||
for (final int v : values) {
|
||||
final Integer boxed = Integer.valueOf(v);
|
||||
final MutableInt count = occurrences.get(boxed);
|
||||
if (count == null) {
|
||||
occurrences.put(boxed, new MutableInt(1));
|
||||
} else {
|
||||
count.increment();
|
||||
}
|
||||
}
|
||||
BitSet toRemove = new BitSet();
|
||||
for (Map.Entry<Integer, MutableInt> e : occurrences.entrySet()) {
|
||||
Integer v = e.getKey();
|
||||
final BitSet toRemove = new BitSet();
|
||||
for (final Map.Entry<Integer, MutableInt> e : occurrences.entrySet()) {
|
||||
final Integer v = e.getKey();
|
||||
int found = 0;
|
||||
for (int i = 0, ct = e.getValue().intValue(); i < ct; i++) {
|
||||
found = indexOf(array, v.intValue(), found);
|
||||
|
@ -5355,19 +5359,19 @@ public static char[] removeElements(final char[] array, final char... values) {
|
|||
if (isEmpty(array) || isEmpty(values)) {
|
||||
return clone(array);
|
||||
}
|
||||
HashMap<Character, MutableInt> occurrences = new HashMap<Character, MutableInt>(values.length);
|
||||
for (char v : values) {
|
||||
Character boxed = Character.valueOf(v);
|
||||
MutableInt count = occurrences.get(boxed);
|
||||
final HashMap<Character, MutableInt> occurrences = new HashMap<Character, MutableInt>(values.length);
|
||||
for (final char v : values) {
|
||||
final Character boxed = Character.valueOf(v);
|
||||
final MutableInt count = occurrences.get(boxed);
|
||||
if (count == null) {
|
||||
occurrences.put(boxed, new MutableInt(1));
|
||||
} else {
|
||||
count.increment();
|
||||
}
|
||||
}
|
||||
BitSet toRemove = new BitSet();
|
||||
for (Map.Entry<Character, MutableInt> e : occurrences.entrySet()) {
|
||||
Character v = e.getKey();
|
||||
final BitSet toRemove = new BitSet();
|
||||
for (final Map.Entry<Character, MutableInt> e : occurrences.entrySet()) {
|
||||
final Character v = e.getKey();
|
||||
int found = 0;
|
||||
for (int i = 0, ct = e.getValue().intValue(); i < ct; i++) {
|
||||
found = indexOf(array, v.charValue(), found);
|
||||
|
@ -5444,19 +5448,19 @@ public static long[] removeElements(final long[] array, final long... values) {
|
|||
if (isEmpty(array) || isEmpty(values)) {
|
||||
return clone(array);
|
||||
}
|
||||
HashMap<Long, MutableInt> occurrences = new HashMap<Long, MutableInt>(values.length);
|
||||
for (long v : values) {
|
||||
Long boxed = Long.valueOf(v);
|
||||
MutableInt count = occurrences.get(boxed);
|
||||
final HashMap<Long, MutableInt> occurrences = new HashMap<Long, MutableInt>(values.length);
|
||||
for (final long v : values) {
|
||||
final Long boxed = Long.valueOf(v);
|
||||
final MutableInt count = occurrences.get(boxed);
|
||||
if (count == null) {
|
||||
occurrences.put(boxed, new MutableInt(1));
|
||||
} else {
|
||||
count.increment();
|
||||
}
|
||||
}
|
||||
BitSet toRemove = new BitSet();
|
||||
for (Map.Entry<Long, MutableInt> e : occurrences.entrySet()) {
|
||||
Long v = e.getKey();
|
||||
final BitSet toRemove = new BitSet();
|
||||
for (final Map.Entry<Long, MutableInt> e : occurrences.entrySet()) {
|
||||
final Long v = e.getKey();
|
||||
int found = 0;
|
||||
for (int i = 0, ct = e.getValue().intValue(); i < ct; i++) {
|
||||
found = indexOf(array, v.longValue(), found);
|
||||
|
@ -5533,19 +5537,19 @@ public static float[] removeElements(final float[] array, final float... values)
|
|||
if (isEmpty(array) || isEmpty(values)) {
|
||||
return clone(array);
|
||||
}
|
||||
HashMap<Float, MutableInt> occurrences = new HashMap<Float, MutableInt>(values.length);
|
||||
for (float v : values) {
|
||||
Float boxed = Float.valueOf(v);
|
||||
MutableInt count = occurrences.get(boxed);
|
||||
final HashMap<Float, MutableInt> occurrences = new HashMap<Float, MutableInt>(values.length);
|
||||
for (final float v : values) {
|
||||
final Float boxed = Float.valueOf(v);
|
||||
final MutableInt count = occurrences.get(boxed);
|
||||
if (count == null) {
|
||||
occurrences.put(boxed, new MutableInt(1));
|
||||
} else {
|
||||
count.increment();
|
||||
}
|
||||
}
|
||||
BitSet toRemove = new BitSet();
|
||||
for (Map.Entry<Float, MutableInt> e : occurrences.entrySet()) {
|
||||
Float v = e.getKey();
|
||||
final BitSet toRemove = new BitSet();
|
||||
for (final Map.Entry<Float, MutableInt> e : occurrences.entrySet()) {
|
||||
final Float v = e.getKey();
|
||||
int found = 0;
|
||||
for (int i = 0, ct = e.getValue().intValue(); i < ct; i++) {
|
||||
found = indexOf(array, v.floatValue(), found);
|
||||
|
@ -5622,19 +5626,19 @@ public static double[] removeElements(final double[] array, final double... valu
|
|||
if (isEmpty(array) || isEmpty(values)) {
|
||||
return clone(array);
|
||||
}
|
||||
HashMap<Double, MutableInt> occurrences = new HashMap<Double, MutableInt>(values.length);
|
||||
for (double v : values) {
|
||||
Double boxed = Double.valueOf(v);
|
||||
MutableInt count = occurrences.get(boxed);
|
||||
final HashMap<Double, MutableInt> occurrences = new HashMap<Double, MutableInt>(values.length);
|
||||
for (final double v : values) {
|
||||
final Double boxed = Double.valueOf(v);
|
||||
final MutableInt count = occurrences.get(boxed);
|
||||
if (count == null) {
|
||||
occurrences.put(boxed, new MutableInt(1));
|
||||
} else {
|
||||
count.increment();
|
||||
}
|
||||
}
|
||||
BitSet toRemove = new BitSet();
|
||||
for (Map.Entry<Double, MutableInt> e : occurrences.entrySet()) {
|
||||
Double v = e.getKey();
|
||||
final BitSet toRemove = new BitSet();
|
||||
for (final Map.Entry<Double, MutableInt> e : occurrences.entrySet()) {
|
||||
final Double v = e.getKey();
|
||||
int found = 0;
|
||||
for (int i = 0, ct = e.getValue().intValue(); i < ct; i++) {
|
||||
found = indexOf(array, v.doubleValue(), found);
|
||||
|
@ -5707,19 +5711,19 @@ public static boolean[] removeElements(final boolean[] array, final boolean... v
|
|||
if (isEmpty(array) || isEmpty(values)) {
|
||||
return clone(array);
|
||||
}
|
||||
HashMap<Boolean, MutableInt> occurrences = new HashMap<Boolean, MutableInt>(2); // only two possible values here
|
||||
for (boolean v : values) {
|
||||
Boolean boxed = Boolean.valueOf(v);
|
||||
MutableInt count = occurrences.get(boxed);
|
||||
final HashMap<Boolean, MutableInt> occurrences = new HashMap<Boolean, MutableInt>(2); // only two possible values here
|
||||
for (final boolean v : values) {
|
||||
final Boolean boxed = Boolean.valueOf(v);
|
||||
final MutableInt count = occurrences.get(boxed);
|
||||
if (count == null) {
|
||||
occurrences.put(boxed, new MutableInt(1));
|
||||
} else {
|
||||
count.increment();
|
||||
}
|
||||
}
|
||||
BitSet toRemove = new BitSet();
|
||||
for (Map.Entry<Boolean, MutableInt> e : occurrences.entrySet()) {
|
||||
Boolean v = e.getKey();
|
||||
final BitSet toRemove = new BitSet();
|
||||
for (final Map.Entry<Boolean, MutableInt> e : occurrences.entrySet()) {
|
||||
final Boolean v = e.getKey();
|
||||
int found = 0;
|
||||
for (int i = 0, ct = e.getValue().intValue(); i < ct; i++) {
|
||||
found = indexOf(array, v.booleanValue(), found);
|
||||
|
@ -5741,7 +5745,7 @@ public static boolean[] removeElements(final boolean[] array, final boolean... v
|
|||
*/
|
||||
// package protected for access by unit tests
|
||||
static Object removeAll(final Object array, final int... indices) {
|
||||
int length = getLength(array);
|
||||
final int length = getLength(array);
|
||||
int diff = 0; // number of distinct indexes, i.e. number of entries that will be removed
|
||||
|
||||
if (isNotEmpty(indices)) {
|
||||
|
@ -5750,7 +5754,7 @@ static Object removeAll(final Object array, final int... indices) {
|
|||
int i = indices.length;
|
||||
int prevIndex = length;
|
||||
while (--i >= 0) {
|
||||
int index = indices[i];
|
||||
final int index = indices[i];
|
||||
if (index < 0 || index >= length) {
|
||||
throw new IndexOutOfBoundsException("Index: " + index + ", Length: " + length);
|
||||
}
|
||||
|
@ -5761,14 +5765,14 @@ static Object removeAll(final Object array, final int... indices) {
|
|||
prevIndex = index;
|
||||
}
|
||||
}
|
||||
Object result = Array.newInstance(array.getClass().getComponentType(), length - diff);
|
||||
final Object result = Array.newInstance(array.getClass().getComponentType(), length - diff);
|
||||
if (diff < length) {
|
||||
int end = length; // index just after last copy
|
||||
int dest = length - diff; // number of entries so far not copied
|
||||
for (int i = indices.length - 1; i >= 0; i--) {
|
||||
int index = indices[i];
|
||||
final int index = indices[i];
|
||||
if (end - index > 1) { // same as (cp > 0)
|
||||
int cp = end - index - 1;
|
||||
final int cp = end - index - 1;
|
||||
dest -= cp;
|
||||
System.arraycopy(array, index + 1, result, dest, cp);
|
||||
// Afer this copy, we still have room for dest items.
|
||||
|
@ -5800,7 +5804,7 @@ static Object removeAll(final Object array, final BitSet indices) {
|
|||
// throw new IndexOutOfBoundsException("Index: " + (maxIndex-1) + ", Length: " + srcLength);
|
||||
// }
|
||||
final int removals = indices.cardinality(); // true bits are items to remove
|
||||
Object result = Array.newInstance(array.getClass().getComponentType(), srcLength - removals);
|
||||
final Object result = Array.newInstance(array.getClass().getComponentType(), srcLength - removals);
|
||||
int srcIndex=0;
|
||||
int destIndex=0;
|
||||
int count;
|
||||
|
|
|
@ -550,7 +550,7 @@ public static Boolean toBooleanObject(final String str) {
|
|||
}
|
||||
switch (str.length()) {
|
||||
case 1: {
|
||||
char ch0 = str.charAt(0);
|
||||
final char ch0 = str.charAt(0);
|
||||
if (ch0 == 'y' || ch0 == 'Y' ||
|
||||
ch0 == 't' || ch0 == 'T') {
|
||||
return Boolean.TRUE;
|
||||
|
@ -562,8 +562,8 @@ public static Boolean toBooleanObject(final String str) {
|
|||
break;
|
||||
}
|
||||
case 2: {
|
||||
char ch0 = str.charAt(0);
|
||||
char ch1 = str.charAt(1);
|
||||
final char ch0 = str.charAt(0);
|
||||
final char ch1 = str.charAt(1);
|
||||
if ((ch0 == 'o' || ch0 == 'O') &&
|
||||
(ch1 == 'n' || ch1 == 'N') ) {
|
||||
return Boolean.TRUE;
|
||||
|
@ -575,9 +575,9 @@ public static Boolean toBooleanObject(final String str) {
|
|||
break;
|
||||
}
|
||||
case 3: {
|
||||
char ch0 = str.charAt(0);
|
||||
char ch1 = str.charAt(1);
|
||||
char ch2 = str.charAt(2);
|
||||
final char ch0 = str.charAt(0);
|
||||
final char ch1 = str.charAt(1);
|
||||
final char ch2 = str.charAt(2);
|
||||
if ((ch0 == 'y' || ch0 == 'Y') &&
|
||||
(ch1 == 'e' || ch1 == 'E') &&
|
||||
(ch2 == 's' || ch2 == 'S') ) {
|
||||
|
@ -591,10 +591,10 @@ public static Boolean toBooleanObject(final String str) {
|
|||
break;
|
||||
}
|
||||
case 4: {
|
||||
char ch0 = str.charAt(0);
|
||||
char ch1 = str.charAt(1);
|
||||
char ch2 = str.charAt(2);
|
||||
char ch3 = str.charAt(3);
|
||||
final char ch0 = str.charAt(0);
|
||||
final char ch1 = str.charAt(1);
|
||||
final char ch2 = str.charAt(2);
|
||||
final char ch3 = str.charAt(3);
|
||||
if ((ch0 == 't' || ch0 == 'T') &&
|
||||
(ch1 == 'r' || ch1 == 'R') &&
|
||||
(ch2 == 'u' || ch2 == 'U') &&
|
||||
|
@ -604,11 +604,11 @@ public static Boolean toBooleanObject(final String str) {
|
|||
break;
|
||||
}
|
||||
case 5: {
|
||||
char ch0 = str.charAt(0);
|
||||
char ch1 = str.charAt(1);
|
||||
char ch2 = str.charAt(2);
|
||||
char ch3 = str.charAt(3);
|
||||
char ch4 = str.charAt(4);
|
||||
final char ch0 = str.charAt(0);
|
||||
final char ch1 = str.charAt(1);
|
||||
final char ch2 = str.charAt(2);
|
||||
final char ch3 = str.charAt(3);
|
||||
final char ch4 = str.charAt(4);
|
||||
if ((ch0 == 'f' || ch0 == 'F') &&
|
||||
(ch1 == 'a' || ch1 == 'A') &&
|
||||
(ch2 == 'l' || ch2 == 'L') &&
|
||||
|
@ -894,7 +894,7 @@ public static boolean and(final boolean... array) {
|
|||
if (array.length == 0) {
|
||||
throw new IllegalArgumentException("Array is empty");
|
||||
}
|
||||
for (boolean element : array) {
|
||||
for (final boolean element : array) {
|
||||
if (!element) {
|
||||
return false;
|
||||
}
|
||||
|
@ -929,9 +929,9 @@ public static Boolean and(final Boolean... array) {
|
|||
throw new IllegalArgumentException("Array is empty");
|
||||
}
|
||||
try {
|
||||
boolean[] primitive = ArrayUtils.toPrimitive(array);
|
||||
final boolean[] primitive = ArrayUtils.toPrimitive(array);
|
||||
return and(primitive) ? Boolean.TRUE : Boolean.FALSE;
|
||||
} catch (NullPointerException ex) {
|
||||
} catch (final NullPointerException ex) {
|
||||
throw new IllegalArgumentException("The array must not contain any null elements");
|
||||
}
|
||||
}
|
||||
|
@ -962,7 +962,7 @@ public static boolean or(final boolean... array) {
|
|||
if (array.length == 0) {
|
||||
throw new IllegalArgumentException("Array is empty");
|
||||
}
|
||||
for (boolean element : array) {
|
||||
for (final boolean element : array) {
|
||||
if (element) {
|
||||
return true;
|
||||
}
|
||||
|
@ -998,9 +998,9 @@ public static Boolean or(final Boolean... array) {
|
|||
throw new IllegalArgumentException("Array is empty");
|
||||
}
|
||||
try {
|
||||
boolean[] primitive = ArrayUtils.toPrimitive(array);
|
||||
final boolean[] primitive = ArrayUtils.toPrimitive(array);
|
||||
return or(primitive) ? Boolean.TRUE : Boolean.FALSE;
|
||||
} catch (NullPointerException ex) {
|
||||
} catch (final NullPointerException ex) {
|
||||
throw new IllegalArgumentException("The array must not contain any null elements");
|
||||
}
|
||||
}
|
||||
|
@ -1033,7 +1033,7 @@ public static boolean xor(final boolean... array) {
|
|||
|
||||
// Loops through array, comparing each item
|
||||
int trueCount = 0;
|
||||
for (boolean element : array) {
|
||||
for (final boolean element : array) {
|
||||
// If item is true, and trueCount is < 1, increments count
|
||||
// Else, xor fails
|
||||
if (element) {
|
||||
|
@ -1072,9 +1072,9 @@ public static Boolean xor(final Boolean... array) {
|
|||
throw new IllegalArgumentException("Array is empty");
|
||||
}
|
||||
try {
|
||||
boolean[] primitive = ArrayUtils.toPrimitive(array);
|
||||
final boolean[] primitive = ArrayUtils.toPrimitive(array);
|
||||
return xor(primitive) ? Boolean.TRUE : Boolean.FALSE;
|
||||
} catch (NullPointerException ex) {
|
||||
} catch (final NullPointerException ex) {
|
||||
throw new IllegalArgumentException("The array must not contain any null elements");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -97,7 +97,7 @@ public static boolean isSupported(final String name) {
|
|||
}
|
||||
try {
|
||||
return Charset.isSupported(name);
|
||||
} catch (IllegalCharsetNameException ex) {
|
||||
} catch (final IllegalCharsetNameException ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ final class CharRange implements Iterable<Character>, Serializable {
|
|||
private CharRange(char start, char end, final boolean negated) {
|
||||
super();
|
||||
if (start > end) {
|
||||
char temp = start;
|
||||
final char temp = start;
|
||||
start = end;
|
||||
end = temp;
|
||||
}
|
||||
|
@ -212,7 +212,7 @@ public boolean equals(final Object obj) {
|
|||
if (obj instanceof CharRange == false) {
|
||||
return false;
|
||||
}
|
||||
CharRange other = (CharRange) obj;
|
||||
final CharRange other = (CharRange) obj;
|
||||
return start == other.start && end == other.end && negated == other.negated;
|
||||
}
|
||||
|
||||
|
@ -234,7 +234,7 @@ public int hashCode() {
|
|||
@Override
|
||||
public String toString() {
|
||||
if (iToString == null) {
|
||||
StringBuilder buf = new StringBuilder(4);
|
||||
final StringBuilder buf = new StringBuilder(4);
|
||||
if (isNegated()) {
|
||||
buf.append('^');
|
||||
}
|
||||
|
@ -341,7 +341,7 @@ public Character next() {
|
|||
if (hasNext == false) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
char cur = current;
|
||||
final char cur = current;
|
||||
prepareNext();
|
||||
return Character.valueOf(cur);
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ static int indexOf(final CharSequence cs, final int searchChar, int start) {
|
|||
if (cs instanceof String) {
|
||||
return ((String) cs).indexOf(searchChar, start);
|
||||
} else {
|
||||
int sz = cs.length();
|
||||
final int sz = cs.length();
|
||||
if (start < 0) {
|
||||
start = 0;
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ static int lastIndexOf(final CharSequence cs, final int searchChar, int start) {
|
|||
if (cs instanceof String) {
|
||||
return ((String) cs).lastIndexOf(searchChar, start);
|
||||
} else {
|
||||
int sz = cs.length();
|
||||
final int sz = cs.length();
|
||||
if (start < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -164,8 +164,8 @@ static char[] toCharArray(final CharSequence cs) {
|
|||
if (cs instanceof String) {
|
||||
return ((String) cs).toCharArray();
|
||||
} else {
|
||||
int sz = cs.length();
|
||||
char[] array = new char[cs.length()];
|
||||
final int sz = cs.length();
|
||||
final char[] array = new char[cs.length()];
|
||||
for (int i = 0; i < sz; i++) {
|
||||
array[i] = cs.charAt(i);
|
||||
}
|
||||
|
|
|
@ -140,7 +140,7 @@ public static CharSet getInstance(final String... setStrs) {
|
|||
return null;
|
||||
}
|
||||
if (setStrs.length == 1) {
|
||||
CharSet common = COMMON.get(setStrs[0]);
|
||||
final CharSet common = COMMON.get(setStrs[0]);
|
||||
if (common != null) {
|
||||
return common;
|
||||
}
|
||||
|
@ -158,7 +158,7 @@ public static CharSet getInstance(final String... setStrs) {
|
|||
*/
|
||||
protected CharSet(final String... set) {
|
||||
super();
|
||||
int sz = set.length;
|
||||
final int sz = set.length;
|
||||
for (int i = 0; i < sz; i++) {
|
||||
add(set[i]);
|
||||
}
|
||||
|
@ -175,10 +175,10 @@ protected void add(final String str) {
|
|||
return;
|
||||
}
|
||||
|
||||
int len = str.length();
|
||||
final int len = str.length();
|
||||
int pos = 0;
|
||||
while (pos < len) {
|
||||
int remainder = len - pos;
|
||||
final int remainder = len - pos;
|
||||
if (remainder >= 4 && str.charAt(pos) == '^' && str.charAt(pos + 2) == '-') {
|
||||
// negated range
|
||||
set.add(CharRange.isNotIn(str.charAt(pos + 1), str.charAt(pos + 3)));
|
||||
|
@ -221,7 +221,7 @@ protected void add(final String str) {
|
|||
* @return {@code true} if the set contains the characters
|
||||
*/
|
||||
public boolean contains(final char ch) {
|
||||
for (CharRange range : set) {
|
||||
for (final CharRange range : set) {
|
||||
if (range.contains(ch)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -250,7 +250,7 @@ public boolean equals(final Object obj) {
|
|||
if (obj instanceof CharSet == false) {
|
||||
return false;
|
||||
}
|
||||
CharSet other = (CharSet) obj;
|
||||
final CharSet other = (CharSet) obj;
|
||||
return set.equals(other.set);
|
||||
}
|
||||
|
||||
|
|
|
@ -65,10 +65,10 @@ public static String squeeze(final String str, final String... set) {
|
|||
if (StringUtils.isEmpty(str) || deepEmpty(set)) {
|
||||
return str;
|
||||
}
|
||||
CharSet chars = CharSet.getInstance(set);
|
||||
StringBuilder buffer = new StringBuilder(str.length());
|
||||
char[] chrs = str.toCharArray();
|
||||
int sz = chrs.length;
|
||||
final CharSet chars = CharSet.getInstance(set);
|
||||
final StringBuilder buffer = new StringBuilder(str.length());
|
||||
final char[] chrs = str.toCharArray();
|
||||
final int sz = chrs.length;
|
||||
char lastChar = ' ';
|
||||
char ch = ' ';
|
||||
for (int i = 0; i < sz; i++) {
|
||||
|
@ -107,9 +107,9 @@ public static int count(final String str, final String... set) {
|
|||
if (StringUtils.isEmpty(str) || deepEmpty(set)) {
|
||||
return 0;
|
||||
}
|
||||
CharSet chars = CharSet.getInstance(set);
|
||||
final CharSet chars = CharSet.getInstance(set);
|
||||
int count = 0;
|
||||
for (char c : str.toCharArray()) {
|
||||
for (final char c : str.toCharArray()) {
|
||||
if (chars.contains(c)) {
|
||||
count++;
|
||||
}
|
||||
|
@ -185,10 +185,10 @@ public static String delete(final String str, final String... set) {
|
|||
* @return the modified String, not null
|
||||
*/
|
||||
private static String modify(final String str, final String[] set, final boolean expect) {
|
||||
CharSet chars = CharSet.getInstance(set);
|
||||
StringBuilder buffer = new StringBuilder(str.length());
|
||||
char[] chrs = str.toCharArray();
|
||||
int sz = chrs.length;
|
||||
final CharSet chars = CharSet.getInstance(set);
|
||||
final StringBuilder buffer = new StringBuilder(str.length());
|
||||
final char[] chrs = str.toCharArray();
|
||||
final int sz = chrs.length;
|
||||
for(int i=0; i<sz; i++) {
|
||||
if(chars.contains(chrs[i]) == expect) {
|
||||
buffer.append(chrs[i]);
|
||||
|
@ -206,7 +206,7 @@ private static String modify(final String str, final String[] set, final boolean
|
|||
*/
|
||||
private static boolean deepEmpty(final String[] strings) {
|
||||
if (strings != null) {
|
||||
for (String s : strings) {
|
||||
for (final String s : strings) {
|
||||
if (StringUtils.isNotEmpty(s)) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -83,8 +83,8 @@ public class ClassUtils {
|
|||
*/
|
||||
private static final Map<Class<?>, Class<?>> wrapperPrimitiveMap = new HashMap<Class<?>, Class<?>>();
|
||||
static {
|
||||
for (Class<?> primitiveClass : primitiveWrapperMap.keySet()) {
|
||||
Class<?> wrapperClass = primitiveWrapperMap.get(primitiveClass);
|
||||
for (final Class<?> primitiveClass : primitiveWrapperMap.keySet()) {
|
||||
final Class<?> wrapperClass = primitiveWrapperMap.get(primitiveClass);
|
||||
if (!primitiveClass.equals(wrapperClass)) {
|
||||
wrapperPrimitiveMap.put(wrapperClass, primitiveClass);
|
||||
}
|
||||
|
@ -188,7 +188,7 @@ public static String getShortClassName(String className) {
|
|||
return StringUtils.EMPTY;
|
||||
}
|
||||
|
||||
StringBuilder arrayPrefix = new StringBuilder();
|
||||
final StringBuilder arrayPrefix = new StringBuilder();
|
||||
|
||||
// Handle array encoding
|
||||
if (className.startsWith("[")) {
|
||||
|
@ -206,8 +206,8 @@ public static String getShortClassName(String className) {
|
|||
className = reverseAbbreviationMap.get(className);
|
||||
}
|
||||
|
||||
int lastDotIdx = className.lastIndexOf(PACKAGE_SEPARATOR_CHAR);
|
||||
int innerIdx = className.indexOf(
|
||||
final int lastDotIdx = className.lastIndexOf(PACKAGE_SEPARATOR_CHAR);
|
||||
final int innerIdx = className.indexOf(
|
||||
INNER_CLASS_SEPARATOR_CHAR, lastDotIdx == -1 ? 0 : lastDotIdx + 1);
|
||||
String out = className.substring(lastDotIdx + 1);
|
||||
if (innerIdx != -1) {
|
||||
|
@ -299,7 +299,7 @@ public static String getPackageName(String className) {
|
|||
className = className.substring(1);
|
||||
}
|
||||
|
||||
int i = className.lastIndexOf(PACKAGE_SEPARATOR_CHAR);
|
||||
final int i = className.lastIndexOf(PACKAGE_SEPARATOR_CHAR);
|
||||
if (i == -1) {
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
|
@ -319,7 +319,7 @@ public static List<Class<?>> getAllSuperclasses(final Class<?> cls) {
|
|||
if (cls == null) {
|
||||
return null;
|
||||
}
|
||||
List<Class<?>> classes = new ArrayList<Class<?>>();
|
||||
final List<Class<?>> classes = new ArrayList<Class<?>>();
|
||||
Class<?> superclass = cls.getSuperclass();
|
||||
while (superclass != null) {
|
||||
classes.add(superclass);
|
||||
|
@ -346,7 +346,7 @@ public static List<Class<?>> getAllInterfaces(final Class<?> cls) {
|
|||
return null;
|
||||
}
|
||||
|
||||
LinkedHashSet<Class<?>> interfacesFound = new LinkedHashSet<Class<?>>();
|
||||
final LinkedHashSet<Class<?>> interfacesFound = new LinkedHashSet<Class<?>>();
|
||||
getAllInterfaces(cls, interfacesFound);
|
||||
|
||||
return new ArrayList<Class<?>>(interfacesFound);
|
||||
|
@ -360,9 +360,9 @@ public static List<Class<?>> getAllInterfaces(final Class<?> cls) {
|
|||
*/
|
||||
private static void getAllInterfaces(Class<?> cls, final HashSet<Class<?>> interfacesFound) {
|
||||
while (cls != null) {
|
||||
Class<?>[] interfaces = cls.getInterfaces();
|
||||
final Class<?>[] interfaces = cls.getInterfaces();
|
||||
|
||||
for (Class<?> i : interfaces) {
|
||||
for (final Class<?> i : interfaces) {
|
||||
if (interfacesFound.add(i)) {
|
||||
getAllInterfaces(i, interfacesFound);
|
||||
}
|
||||
|
@ -390,11 +390,11 @@ public static List<Class<?>> convertClassNamesToClasses(final List<String> class
|
|||
if (classNames == null) {
|
||||
return null;
|
||||
}
|
||||
List<Class<?>> classes = new ArrayList<Class<?>>(classNames.size());
|
||||
for (String className : classNames) {
|
||||
final List<Class<?>> classes = new ArrayList<Class<?>>(classNames.size());
|
||||
for (final String className : classNames) {
|
||||
try {
|
||||
classes.add(Class.forName(className));
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
classes.add(null);
|
||||
}
|
||||
}
|
||||
|
@ -417,8 +417,8 @@ public static List<String> convertClassesToClassNames(final List<Class<?>> class
|
|||
if (classes == null) {
|
||||
return null;
|
||||
}
|
||||
List<String> classNames = new ArrayList<String>(classes.size());
|
||||
for (Class<?> cls : classes) {
|
||||
final List<String> classNames = new ArrayList<String>(classes.size());
|
||||
for (final Class<?> cls : classes) {
|
||||
if (cls == null) {
|
||||
classNames.add(null);
|
||||
} else {
|
||||
|
@ -725,7 +725,7 @@ public static Class<?>[] primitivesToWrappers(final Class<?>... classes) {
|
|||
return classes;
|
||||
}
|
||||
|
||||
Class<?>[] convertedClasses = new Class[classes.length];
|
||||
final Class<?>[] convertedClasses = new Class[classes.length];
|
||||
for (int i = 0; i < classes.length; i++) {
|
||||
convertedClasses[i] = primitiveToWrapper(classes[i]);
|
||||
}
|
||||
|
@ -775,7 +775,7 @@ public static Class<?>[] wrappersToPrimitives(final Class<?>... classes) {
|
|||
return classes;
|
||||
}
|
||||
|
||||
Class<?>[] convertedClasses = new Class[classes.length];
|
||||
final Class<?>[] convertedClasses = new Class[classes.length];
|
||||
for (int i = 0; i < classes.length; i++) {
|
||||
convertedClasses[i] = wrapperToPrimitive(classes[i]);
|
||||
}
|
||||
|
@ -814,22 +814,22 @@ public static Class<?> getClass(
|
|||
try {
|
||||
Class<?> clazz;
|
||||
if (abbreviationMap.containsKey(className)) {
|
||||
String clsName = "[" + abbreviationMap.get(className);
|
||||
final String clsName = "[" + abbreviationMap.get(className);
|
||||
clazz = Class.forName(clsName, initialize, classLoader).getComponentType();
|
||||
} else {
|
||||
clazz = Class.forName(toCanonicalName(className), initialize, classLoader);
|
||||
}
|
||||
return clazz;
|
||||
} catch (ClassNotFoundException ex) {
|
||||
} catch (final ClassNotFoundException ex) {
|
||||
// allow path separators (.) as inner class name separators
|
||||
int lastDotIndex = className.lastIndexOf(PACKAGE_SEPARATOR_CHAR);
|
||||
final int lastDotIndex = className.lastIndexOf(PACKAGE_SEPARATOR_CHAR);
|
||||
|
||||
if (lastDotIndex != -1) {
|
||||
try {
|
||||
return getClass(classLoader, className.substring(0, lastDotIndex) +
|
||||
INNER_CLASS_SEPARATOR_CHAR + className.substring(lastDotIndex + 1),
|
||||
initialize);
|
||||
} catch (ClassNotFoundException ex2) { // NOPMD
|
||||
} catch (final ClassNotFoundException ex2) { // NOPMD
|
||||
// ignore exception
|
||||
}
|
||||
}
|
||||
|
@ -881,8 +881,8 @@ public static Class<?> getClass(final String className) throws ClassNotFoundExce
|
|||
* @throws ClassNotFoundException if the class is not found
|
||||
*/
|
||||
public static Class<?> getClass(final String className, final boolean initialize) throws ClassNotFoundException {
|
||||
ClassLoader contextCL = Thread.currentThread().getContextClassLoader();
|
||||
ClassLoader loader = contextCL == null ? ClassUtils.class.getClassLoader() : contextCL;
|
||||
final ClassLoader contextCL = Thread.currentThread().getContextClassLoader();
|
||||
final ClassLoader loader = contextCL == null ? ClassUtils.class.getClassLoader() : contextCL;
|
||||
return getClass(loader, className, initialize);
|
||||
}
|
||||
|
||||
|
@ -912,23 +912,23 @@ public static Class<?> getClass(final String className, final boolean initialize
|
|||
public static Method getPublicMethod(final Class<?> cls, final String methodName, final Class<?>... parameterTypes)
|
||||
throws SecurityException, NoSuchMethodException {
|
||||
|
||||
Method declaredMethod = cls.getMethod(methodName, parameterTypes);
|
||||
final Method declaredMethod = cls.getMethod(methodName, parameterTypes);
|
||||
if (Modifier.isPublic(declaredMethod.getDeclaringClass().getModifiers())) {
|
||||
return declaredMethod;
|
||||
}
|
||||
|
||||
List<Class<?>> candidateClasses = new ArrayList<Class<?>>();
|
||||
final List<Class<?>> candidateClasses = new ArrayList<Class<?>>();
|
||||
candidateClasses.addAll(getAllInterfaces(cls));
|
||||
candidateClasses.addAll(getAllSuperclasses(cls));
|
||||
|
||||
for (Class<?> candidateClass : candidateClasses) {
|
||||
for (final Class<?> candidateClass : candidateClasses) {
|
||||
if (!Modifier.isPublic(candidateClass.getModifiers())) {
|
||||
continue;
|
||||
}
|
||||
Method candidateMethod;
|
||||
try {
|
||||
candidateMethod = candidateClass.getMethod(methodName, parameterTypes);
|
||||
} catch (NoSuchMethodException ex) {
|
||||
} catch (final NoSuchMethodException ex) {
|
||||
continue;
|
||||
}
|
||||
if (Modifier.isPublic(candidateMethod.getDeclaringClass().getModifiers())) {
|
||||
|
@ -952,12 +952,12 @@ private static String toCanonicalName(String className) {
|
|||
if (className == null) {
|
||||
throw new NullPointerException("className must not be null.");
|
||||
} else if (className.endsWith("[]")) {
|
||||
StringBuilder classNameBuffer = new StringBuilder();
|
||||
final StringBuilder classNameBuffer = new StringBuilder();
|
||||
while (className.endsWith("[]")) {
|
||||
className = className.substring(0, className.length() - 2);
|
||||
classNameBuffer.append("[");
|
||||
}
|
||||
String abbreviation = abbreviationMap.get(className);
|
||||
final String abbreviation = abbreviationMap.get(className);
|
||||
if (abbreviation != null) {
|
||||
classNameBuffer.append(abbreviation);
|
||||
} else {
|
||||
|
@ -984,7 +984,7 @@ public static Class<?>[] toClass(final Object... array) {
|
|||
} else if (array.length == 0) {
|
||||
return ArrayUtils.EMPTY_CLASS_ARRAY;
|
||||
}
|
||||
Class<?>[] classes = new Class[array.length];
|
||||
final Class<?>[] classes = new Class[array.length];
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
classes[i] = array[i] == null ? null : array[i].getClass();
|
||||
}
|
||||
|
@ -1120,7 +1120,7 @@ private static String getCanonicalName(String className) {
|
|||
className = reverseAbbreviationMap.get(className.substring(0, 1));
|
||||
}
|
||||
}
|
||||
StringBuilder canonicalClassNameBuffer = new StringBuilder(className);
|
||||
final StringBuilder canonicalClassNameBuffer = new StringBuilder(className);
|
||||
for (int i = 0; i < dim; i++) {
|
||||
canonicalClassNameBuffer.append("[]");
|
||||
}
|
||||
|
|
|
@ -512,9 +512,9 @@ public static char binaryBeMsb0ToHexDigit(boolean[] src, int srcPos) {
|
|||
if (src.length == 0) {
|
||||
throw new IllegalArgumentException("Cannot convert an empty array.");
|
||||
}
|
||||
int beSrcPos = src.length - 1 - srcPos;
|
||||
int srcLen = Math.min(4, beSrcPos + 1);
|
||||
boolean[] paddedSrc = new boolean[4];
|
||||
final int beSrcPos = src.length - 1 - srcPos;
|
||||
final int srcLen = Math.min(4, beSrcPos + 1);
|
||||
final boolean[] paddedSrc = new boolean[4];
|
||||
System.arraycopy(src, beSrcPos + 1 - srcLen, paddedSrc, 4 - srcLen, srcLen);
|
||||
src = paddedSrc;
|
||||
srcPos = 0;
|
||||
|
@ -600,7 +600,7 @@ public static char binaryBeMsb0ToHexDigit(boolean[] src, int srcPos) {
|
|||
* @throws IllegalArgumentException if {@code nibble < 0} or {@code nibble > 15}
|
||||
*/
|
||||
public static char intToHexDigit(final int nibble) {
|
||||
char c = Character.forDigit(nibble, 16);
|
||||
final char c = Character.forDigit(nibble, 16);
|
||||
if (c == Character.MIN_VALUE) {
|
||||
throw new IllegalArgumentException("nibble value not between 0 and 15: " + nibble);
|
||||
}
|
||||
|
@ -693,8 +693,8 @@ public static long intArrayToLong(final int[] src, final int srcPos, final long
|
|||
int shift = 0;
|
||||
for (int i = 0; i < nInts; i++ ) {
|
||||
shift = i * 32 + dstPos;
|
||||
long bits = ((0xffffffffL & src[i + srcPos]) << shift);
|
||||
long mask = 0xffffffffL << shift;
|
||||
final long bits = ((0xffffffffL & src[i + srcPos]) << shift);
|
||||
final long mask = 0xffffffffL << shift;
|
||||
out = (out & ~mask) | bits;
|
||||
}
|
||||
return out;
|
||||
|
@ -730,8 +730,8 @@ public static long shortArrayToLong(final short[] src, final int srcPos, final l
|
|||
int shift = 0;
|
||||
for (int i = 0; i < nShorts; i++ ) {
|
||||
shift = i * 16 + dstPos;
|
||||
long bits = (0xffffL & src[i + srcPos]) << shift;
|
||||
long mask = 0xffffL << shift;
|
||||
final long bits = (0xffffL & src[i + srcPos]) << shift;
|
||||
final long mask = 0xffffL << shift;
|
||||
out = (out & ~mask) | bits;
|
||||
}
|
||||
return out;
|
||||
|
@ -767,8 +767,8 @@ public static int shortArrayToInt(final short[] src, final int srcPos, final int
|
|||
int shift = 0;
|
||||
for (int i = 0; i < nShorts; i++ ) {
|
||||
shift = i * 16 + dstPos;
|
||||
int bits = (0xffff & src[i + srcPos]) << shift;
|
||||
int mask = 0xffff << shift;
|
||||
final int bits = (0xffff & src[i + srcPos]) << shift;
|
||||
final int mask = 0xffff << shift;
|
||||
out = (out & ~mask) | bits;
|
||||
}
|
||||
return out;
|
||||
|
@ -804,8 +804,8 @@ public static long byteArrayToLong(final byte[] src, final int srcPos, final lon
|
|||
int shift = 0;
|
||||
for (int i = 0; i < nBytes; i++ ) {
|
||||
shift = i * 8 + dstPos;
|
||||
long bits = (0xffL & src[i + srcPos]) << shift;
|
||||
long mask = 0xffL << shift;
|
||||
final long bits = (0xffL & src[i + srcPos]) << shift;
|
||||
final long mask = 0xffL << shift;
|
||||
out = (out & ~mask) | bits;
|
||||
}
|
||||
return out;
|
||||
|
@ -840,8 +840,8 @@ public static int byteArrayToInt(final byte[] src, final int srcPos, final int d
|
|||
int shift = 0;
|
||||
for (int i = 0; i < nBytes; i++ ) {
|
||||
shift = i * 8 + dstPos;
|
||||
int bits = (0xff & src[i + srcPos]) << shift;
|
||||
int mask = 0xff << shift;
|
||||
final int bits = (0xff & src[i + srcPos]) << shift;
|
||||
final int mask = 0xff << shift;
|
||||
out = (out & ~mask) | bits;
|
||||
}
|
||||
return out;
|
||||
|
@ -877,8 +877,8 @@ public static short byteArrayToShort(final byte[] src, final int srcPos, final s
|
|||
int shift = 0;
|
||||
for (int i = 0; i < nBytes; i++ ) {
|
||||
shift = i * 8 + dstPos;
|
||||
int bits = (0xff & src[i + srcPos]) << shift;
|
||||
int mask = 0xff << shift;
|
||||
final int bits = (0xff & src[i + srcPos]) << shift;
|
||||
final int mask = 0xff << shift;
|
||||
out = (short)((out & ~mask) | bits);
|
||||
}
|
||||
return out;
|
||||
|
@ -911,8 +911,8 @@ public static long hexToLong(final String src, final int srcPos, final long dstI
|
|||
int shift = 0;
|
||||
for (int i = 0; i < nHex; i++ ) {
|
||||
shift = i * 4 + dstPos;
|
||||
long bits = (0xfL & hexDigitToInt(src.charAt(i + srcPos))) << shift;
|
||||
long mask = 0xfL << shift;
|
||||
final long bits = (0xfL & hexDigitToInt(src.charAt(i + srcPos))) << shift;
|
||||
final long mask = 0xfL << shift;
|
||||
out = (out & ~mask) | bits;
|
||||
}
|
||||
return out;
|
||||
|
@ -945,8 +945,8 @@ public static int hexToInt(final String src, final int srcPos, final int dstInit
|
|||
int shift = 0;
|
||||
for (int i = 0; i < nHex; i++ ) {
|
||||
shift = i * 4 + dstPos;
|
||||
int bits = (0xf & hexDigitToInt(src.charAt(i + srcPos))) << shift;
|
||||
int mask = 0xf << shift;
|
||||
final int bits = (0xf & hexDigitToInt(src.charAt(i + srcPos))) << shift;
|
||||
final int mask = 0xf << shift;
|
||||
out = (out & ~mask) | bits;
|
||||
}
|
||||
return out;
|
||||
|
@ -979,8 +979,8 @@ public static short hexToShort(final String src, final int srcPos, final short d
|
|||
int shift = 0;
|
||||
for (int i = 0; i < nHex; i++ ) {
|
||||
shift = i * 4 + dstPos;
|
||||
int bits = (0xf & hexDigitToInt(src.charAt(i + srcPos))) << shift;
|
||||
int mask = 0xf << shift;
|
||||
final int bits = (0xf & hexDigitToInt(src.charAt(i + srcPos))) << shift;
|
||||
final int mask = 0xf << shift;
|
||||
out = (short)((out & ~mask) | bits);
|
||||
}
|
||||
return out;
|
||||
|
@ -1013,8 +1013,8 @@ public static byte hexToByte(final String src, final int srcPos, final byte dstI
|
|||
int shift = 0;
|
||||
for (int i = 0; i < nHex; i++ ) {
|
||||
shift = i * 4 + dstPos;
|
||||
int bits = (0xf & hexDigitToInt(src.charAt(i + srcPos))) << shift;
|
||||
int mask = 0xf << shift;
|
||||
final int bits = (0xf & hexDigitToInt(src.charAt(i + srcPos))) << shift;
|
||||
final int mask = 0xf << shift;
|
||||
out = (byte)((out & ~mask) | bits);
|
||||
}
|
||||
return out;
|
||||
|
@ -1050,8 +1050,8 @@ public static long binaryToLong(final boolean[] src, final int srcPos, final lon
|
|||
int shift = 0;
|
||||
for (int i = 0; i < nBools; i++ ) {
|
||||
shift = i * 1 + dstPos;
|
||||
long bits = (src[i + srcPos] ? 1L : 0) << shift;
|
||||
long mask = 0x1L << shift;
|
||||
final long bits = (src[i + srcPos] ? 1L : 0) << shift;
|
||||
final long mask = 0x1L << shift;
|
||||
out = (out & ~mask) | bits;
|
||||
}
|
||||
return out;
|
||||
|
@ -1086,8 +1086,8 @@ public static int binaryToInt(final boolean[] src, final int srcPos, final int d
|
|||
int shift = 0;
|
||||
for (int i = 0; i < nBools; i++ ) {
|
||||
shift = i * 1 + dstPos;
|
||||
int bits = (src[i + srcPos] ? 1 : 0) << shift;
|
||||
int mask = 0x1 << shift;
|
||||
final int bits = (src[i + srcPos] ? 1 : 0) << shift;
|
||||
final int mask = 0x1 << shift;
|
||||
out = (out & ~mask) | bits;
|
||||
}
|
||||
return out;
|
||||
|
@ -1123,8 +1123,8 @@ public static short binaryToShort(final boolean[] src, final int srcPos, final s
|
|||
int shift = 0;
|
||||
for (int i = 0; i < nBools; i++ ) {
|
||||
shift = i * 1 + dstPos;
|
||||
int bits = (src[i + srcPos] ? 1 : 0) << shift;
|
||||
int mask = 0x1 << shift;
|
||||
final int bits = (src[i + srcPos] ? 1 : 0) << shift;
|
||||
final int mask = 0x1 << shift;
|
||||
out = (short)((out & ~mask) | bits);
|
||||
}
|
||||
return out;
|
||||
|
@ -1159,8 +1159,8 @@ public static byte binaryToByte(final boolean[] src, final int srcPos, final byt
|
|||
int shift = 0;
|
||||
for (int i = 0; i < nBools; i++ ) {
|
||||
shift = i * 1 + dstPos;
|
||||
int bits = (src[i + srcPos] ? 1 : 0) << shift;
|
||||
int mask = 0x1 << shift;
|
||||
final int bits = (src[i + srcPos] ? 1 : 0) << shift;
|
||||
final int mask = 0x1 << shift;
|
||||
out = (byte)((out & ~mask) | bits);
|
||||
}
|
||||
return out;
|
||||
|
@ -1392,12 +1392,12 @@ public static String longToHex(final long src, final int srcPos, final String ds
|
|||
throw new IllegalArgumentException(
|
||||
"(nHexs-1)*4+srcPos is greather or equal to than 64");
|
||||
}
|
||||
StringBuilder sb = new StringBuilder(dstInit);
|
||||
final StringBuilder sb = new StringBuilder(dstInit);
|
||||
int shift = 0;
|
||||
int append = sb.length();
|
||||
for (int i = 0; i < nHexs; i++ ) {
|
||||
shift = i * 4 + srcPos;
|
||||
int bits = (int)(0xF & (src >> shift));
|
||||
final int bits = (int)(0xF & (src >> shift));
|
||||
if (dstPos + i == append) {
|
||||
++append;
|
||||
sb.append(intToHexDigit(bits));
|
||||
|
@ -1432,12 +1432,12 @@ public static String intToHex(final int src, final int srcPos, final String dstI
|
|||
throw new IllegalArgumentException(
|
||||
"(nHexs-1)*4+srcPos is greather or equal to than 32");
|
||||
}
|
||||
StringBuilder sb = new StringBuilder(dstInit);
|
||||
final StringBuilder sb = new StringBuilder(dstInit);
|
||||
int shift = 0;
|
||||
int append = sb.length();
|
||||
for (int i = 0; i < nHexs; i++ ) {
|
||||
shift = i * 4 + srcPos;
|
||||
int bits = 0xF & (src >> shift);
|
||||
final int bits = 0xF & (src >> shift);
|
||||
if (dstPos + i == append) {
|
||||
++append;
|
||||
sb.append(intToHexDigit(bits));
|
||||
|
@ -1472,12 +1472,12 @@ public static String shortToHex(final short src, final int srcPos, final String
|
|||
throw new IllegalArgumentException(
|
||||
"(nHexs-1)*4+srcPos is greather or equal to than 16");
|
||||
}
|
||||
StringBuilder sb = new StringBuilder(dstInit);
|
||||
final StringBuilder sb = new StringBuilder(dstInit);
|
||||
int shift = 0;
|
||||
int append = sb.length();
|
||||
for (int i = 0; i < nHexs; i++ ) {
|
||||
shift = i * 4 + srcPos;
|
||||
int bits = 0xF & (src >> shift);
|
||||
final int bits = 0xF & (src >> shift);
|
||||
if (dstPos + i == append) {
|
||||
++append;
|
||||
sb.append(intToHexDigit(bits));
|
||||
|
@ -1512,12 +1512,12 @@ public static String byteToHex(final byte src, final int srcPos, final String ds
|
|||
throw new IllegalArgumentException(
|
||||
"(nHexs-1)*4+srcPos is greather or equal to than 8");
|
||||
}
|
||||
StringBuilder sb = new StringBuilder(dstInit);
|
||||
final StringBuilder sb = new StringBuilder(dstInit);
|
||||
int shift = 0;
|
||||
int append = sb.length();
|
||||
for (int i = 0; i < nHexs; i++ ) {
|
||||
shift = i * 4 + srcPos;
|
||||
int bits = 0xF & (src >> shift);
|
||||
final int bits = 0xF & (src >> shift);
|
||||
if (dstPos + i == append) {
|
||||
++append;
|
||||
sb.append(intToHexDigit(bits));
|
||||
|
|
|
@ -56,8 +56,8 @@ public EnumUtils() {
|
|||
* @return the modifiable map of enum names to enums, never null
|
||||
*/
|
||||
public static <E extends Enum<E>> Map<String, E> getEnumMap(final Class<E> enumClass) {
|
||||
Map<String, E> map = new LinkedHashMap<String, E>();
|
||||
for (E e: enumClass.getEnumConstants()) {
|
||||
final Map<String, E> map = new LinkedHashMap<String, E>();
|
||||
for (final E e: enumClass.getEnumConstants()) {
|
||||
map.put(e.name(), e);
|
||||
}
|
||||
return map;
|
||||
|
@ -94,7 +94,7 @@ public static <E extends Enum<E>> boolean isValidEnum(final Class<E> enumClass,
|
|||
try {
|
||||
Enum.valueOf(enumClass, enumName);
|
||||
return true;
|
||||
} catch (IllegalArgumentException ex) {
|
||||
} catch (final IllegalArgumentException ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ public static <E extends Enum<E>> E getEnum(final Class<E> enumClass, final Stri
|
|||
}
|
||||
try {
|
||||
return Enum.valueOf(enumClass, enumName);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
} catch (final IllegalArgumentException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ public static <E extends Enum<E>> long generateBitVector(final Class<E> enumClas
|
|||
checkBitVectorable(enumClass);
|
||||
Validate.notNull(values);
|
||||
long total = 0;
|
||||
for (E constant : values) {
|
||||
for (final E constant : values) {
|
||||
Validate.isTrue(constant != null, NULL_ELEMENTS_NOT_PERMITTED);
|
||||
total |= 1 << constant.ordinal();
|
||||
}
|
||||
|
@ -170,12 +170,12 @@ public static <E extends Enum<E>> long[] generateBitVectors(final Class<E> enumC
|
|||
asEnum(enumClass);
|
||||
Validate.notNull(values);
|
||||
final EnumSet<E> condensed = EnumSet.noneOf(enumClass);
|
||||
for (E constant : values) {
|
||||
for (final E constant : values) {
|
||||
Validate.isTrue(constant != null, NULL_ELEMENTS_NOT_PERMITTED);
|
||||
condensed.add(constant);
|
||||
}
|
||||
final long[] result = new long[(enumClass.getEnumConstants().length - 1) / Long.SIZE + 1];
|
||||
for (E value : condensed) {
|
||||
for (final E value : condensed) {
|
||||
result[value.ordinal() / Long.SIZE] |= 1 << (value.ordinal() % Long.SIZE);
|
||||
}
|
||||
ArrayUtils.reverse(result);
|
||||
|
@ -226,7 +226,7 @@ public static <E extends Enum<E>> long[] generateBitVectors(final Class<E> enumC
|
|||
final EnumSet<E> condensed = EnumSet.noneOf(enumClass);
|
||||
Collections.addAll(condensed, values);
|
||||
final long[] result = new long[(enumClass.getEnumConstants().length - 1) / Long.SIZE + 1];
|
||||
for (E value : condensed) {
|
||||
for (final E value : condensed) {
|
||||
result[value.ordinal() / Long.SIZE] |= 1 << (value.ordinal() % Long.SIZE);
|
||||
}
|
||||
ArrayUtils.reverse(result);
|
||||
|
@ -268,8 +268,8 @@ public static <E extends Enum<E>> EnumSet<E> processBitVectors(final Class<E> en
|
|||
final EnumSet<E> results = EnumSet.noneOf(asEnum(enumClass));
|
||||
values = ArrayUtils.clone(Validate.notNull(values));
|
||||
ArrayUtils.reverse(values);
|
||||
for (E constant : enumClass.getEnumConstants()) {
|
||||
int block = constant.ordinal() / Long.SIZE;
|
||||
for (final E constant : enumClass.getEnumConstants()) {
|
||||
final int block = constant.ordinal() / Long.SIZE;
|
||||
if (block < values.length && (values[block] & 1 << (constant.ordinal() % Long.SIZE)) != 0) {
|
||||
results.add(constant);
|
||||
}
|
||||
|
|
|
@ -184,7 +184,7 @@ public static List<Locale> localeLookupList(final Locale locale) {
|
|||
* @return the unmodifiable list of Locale objects, 0 being locale, not null
|
||||
*/
|
||||
public static List<Locale> localeLookupList(final Locale locale, final Locale defaultLocale) {
|
||||
List<Locale> list = new ArrayList<Locale>(4);
|
||||
final List<Locale> list = new ArrayList<Locale>(4);
|
||||
if (locale != null) {
|
||||
list.add(locale);
|
||||
if (locale.getVariant().length() > 0) {
|
||||
|
@ -256,9 +256,9 @@ public static List<Locale> languagesByCountry(final String countryCode) {
|
|||
List<Locale> langs = cLanguagesByCountry.get(countryCode);
|
||||
if (langs == null) {
|
||||
langs = new ArrayList<Locale>();
|
||||
List<Locale> locales = availableLocaleList();
|
||||
final List<Locale> locales = availableLocaleList();
|
||||
for (int i = 0; i < locales.size(); i++) {
|
||||
Locale locale = locales.get(i);
|
||||
final Locale locale = locales.get(i);
|
||||
if (countryCode.equals(locale.getCountry()) &&
|
||||
locale.getVariant().isEmpty()) {
|
||||
langs.add(locale);
|
||||
|
@ -288,9 +288,9 @@ public static List<Locale> countriesByLanguage(final String languageCode) {
|
|||
List<Locale> countries = cCountriesByLanguage.get(languageCode);
|
||||
if (countries == null) {
|
||||
countries = new ArrayList<Locale>();
|
||||
List<Locale> locales = availableLocaleList();
|
||||
final List<Locale> locales = availableLocaleList();
|
||||
for (int i = 0; i < locales.size(); i++) {
|
||||
Locale locale = locales.get(i);
|
||||
final Locale locale = locales.get(i);
|
||||
if (languageCode.equals(locale.getLanguage()) &&
|
||||
locale.getCountry().length() != 0 &&
|
||||
locale.getVariant().isEmpty()) {
|
||||
|
@ -313,7 +313,7 @@ static class SyncAvoid {
|
|||
private static final Set<Locale> AVAILABLE_LOCALE_SET;
|
||||
|
||||
static {
|
||||
List<Locale> list = new ArrayList<Locale>(Arrays.asList(Locale.getAvailableLocales())); // extra safe
|
||||
final List<Locale> list = new ArrayList<Locale>(Arrays.asList(Locale.getAvailableLocales())); // extra safe
|
||||
AVAILABLE_LOCALE_LIST = Collections.unmodifiableList(list);
|
||||
AVAILABLE_LOCALE_SET = Collections.unmodifiableSet(new HashSet<Locale>(list));
|
||||
}
|
||||
|
|
|
@ -118,7 +118,7 @@ public static <T> T defaultIfNull(final T object, final T defaultValue) {
|
|||
*/
|
||||
public static <T> T firstNonNull(final T... values) {
|
||||
if (values != null) {
|
||||
for (T val : values) {
|
||||
for (final T val : values) {
|
||||
if (val != null) {
|
||||
return val;
|
||||
}
|
||||
|
@ -222,7 +222,7 @@ public static int hashCode(final Object obj) {
|
|||
public static int hashCodeMulti(final Object... objects) {
|
||||
int hash = 1;
|
||||
if (objects != null) {
|
||||
for (Object object : objects) {
|
||||
for (final Object object : objects) {
|
||||
hash = hash * 31 + ObjectUtils.hashCode(object);
|
||||
}
|
||||
}
|
||||
|
@ -251,7 +251,7 @@ public static String identityToString(final Object object) {
|
|||
if (object == null) {
|
||||
return null;
|
||||
}
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
final StringBuffer buffer = new StringBuffer();
|
||||
identityToString(buffer, object);
|
||||
return buffer.toString();
|
||||
}
|
||||
|
@ -344,7 +344,7 @@ public static String toString(final Object obj, final String nullStr) {
|
|||
public static <T extends Comparable<? super T>> T min(final T... values) {
|
||||
T result = null;
|
||||
if (values != null) {
|
||||
for (T value : values) {
|
||||
for (final T value : values) {
|
||||
if (compare(value, result, true) < 0) {
|
||||
result = value;
|
||||
}
|
||||
|
@ -369,7 +369,7 @@ public static <T extends Comparable<? super T>> T min(final T... values) {
|
|||
public static <T extends Comparable<? super T>> T max(final T... values) {
|
||||
T result = null;
|
||||
if (values != null) {
|
||||
for (T value : values) {
|
||||
for (final T value : values) {
|
||||
if (compare(value, result, false) > 0) {
|
||||
result = value;
|
||||
}
|
||||
|
@ -429,9 +429,10 @@ public static <T extends Comparable<? super T>> int compare(final T c1, final T
|
|||
public static <T extends Comparable<? super T>> T median(final T... items) {
|
||||
Validate.notEmpty(items);
|
||||
Validate.noNullElements(items);
|
||||
TreeSet<T> sort = new TreeSet<T>();
|
||||
final TreeSet<T> sort = new TreeSet<T>();
|
||||
Collections.addAll(sort, items);
|
||||
@SuppressWarnings("unchecked") //we know all items added were T instances
|
||||
final
|
||||
T result = (T) sort.toArray()[(sort.size() - 1) / 2];
|
||||
return result;
|
||||
}
|
||||
|
@ -451,9 +452,10 @@ public static <T> T median(final Comparator<T> comparator, final T... items) {
|
|||
Validate.notEmpty(items, "null/empty items");
|
||||
Validate.noNullElements(items);
|
||||
Validate.notNull(comparator, "null comparator");
|
||||
TreeSet<T> sort = new TreeSet<T>(comparator);
|
||||
final TreeSet<T> sort = new TreeSet<T>(comparator);
|
||||
Collections.addAll(sort, items);
|
||||
@SuppressWarnings("unchecked") //we know all items added were T instances
|
||||
final
|
||||
T result = (T) sort.toArray()[(sort.size() - 1) / 2];
|
||||
return result;
|
||||
}
|
||||
|
@ -470,9 +472,9 @@ public static <T> T median(final Comparator<T> comparator, final T... items) {
|
|||
*/
|
||||
public static <T> T mode(final T... items) {
|
||||
if (ArrayUtils.isNotEmpty(items)) {
|
||||
HashMap<T, MutableInt> occurrences = new HashMap<T, MutableInt>(items.length);
|
||||
for (T t : items) {
|
||||
MutableInt count = occurrences.get(t);
|
||||
final HashMap<T, MutableInt> occurrences = new HashMap<T, MutableInt>(items.length);
|
||||
for (final T t : items) {
|
||||
final MutableInt count = occurrences.get(t);
|
||||
if (count == null) {
|
||||
occurrences.put(t, new MutableInt(1));
|
||||
} else {
|
||||
|
@ -481,8 +483,8 @@ public static <T> T mode(final T... items) {
|
|||
}
|
||||
T result = null;
|
||||
int max = 0;
|
||||
for (Map.Entry<T, MutableInt> e : occurrences.entrySet()) {
|
||||
int cmp = e.getValue().intValue();
|
||||
for (final Map.Entry<T, MutableInt> e : occurrences.entrySet()) {
|
||||
final int cmp = e.getValue().intValue();
|
||||
if (cmp == max) {
|
||||
result = null;
|
||||
} else if (cmp > max) {
|
||||
|
|
|
@ -248,8 +248,8 @@ public static String random(int count, int start, int end, final boolean letters
|
|||
}
|
||||
}
|
||||
|
||||
char[] buffer = new char[count];
|
||||
int gap = end - start;
|
||||
final char[] buffer = new char[count];
|
||||
final int gap = end - start;
|
||||
|
||||
while (count-- != 0) {
|
||||
char ch;
|
||||
|
|
|
@ -386,8 +386,8 @@ public Range<T> intersectionWith(final Range<T> other) {
|
|||
if (this.equals(other)) {
|
||||
return this;
|
||||
}
|
||||
T min = getComparator().compare(minimum, other.minimum) < 0 ? other.minimum : minimum;
|
||||
T max = getComparator().compare(maximum, other.maximum) < 0 ? maximum : other.maximum;
|
||||
final T min = getComparator().compare(minimum, other.minimum) < 0 ? other.minimum : minimum;
|
||||
final T max = getComparator().compare(maximum, other.maximum) < 0 ? maximum : other.maximum;
|
||||
return between(min, max, getComparator());
|
||||
}
|
||||
|
||||
|
@ -411,6 +411,7 @@ public boolean equals(final Object obj) {
|
|||
return false;
|
||||
} else {
|
||||
@SuppressWarnings("unchecked") // OK because we checked the class above
|
||||
final
|
||||
Range<T> range = (Range<T>) obj;
|
||||
return minimum.equals(range.minimum) &&
|
||||
maximum.equals(range.maximum);
|
||||
|
@ -446,7 +447,7 @@ public int hashCode() {
|
|||
public String toString() {
|
||||
String result = toString;
|
||||
if (result == null) {
|
||||
StringBuilder buf = new StringBuilder(32);
|
||||
final StringBuilder buf = new StringBuilder(32);
|
||||
buf.append('[');
|
||||
buf.append(minimum);
|
||||
buf.append("..");
|
||||
|
|
|
@ -79,8 +79,8 @@ public static <T extends Serializable> T clone(final T object) {
|
|||
if (object == null) {
|
||||
return null;
|
||||
}
|
||||
byte[] objectData = serialize(object);
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(objectData);
|
||||
final byte[] objectData = serialize(object);
|
||||
final ByteArrayInputStream bais = new ByteArrayInputStream(objectData);
|
||||
|
||||
ClassLoaderAwareObjectInputStream in = null;
|
||||
try {
|
||||
|
@ -92,19 +92,20 @@ public static <T extends Serializable> T clone(final T object) {
|
|||
* is of the same type as the original serialized object
|
||||
*/
|
||||
@SuppressWarnings("unchecked") // see above
|
||||
final
|
||||
T readObject = (T) in.readObject();
|
||||
return readObject;
|
||||
|
||||
} catch (ClassNotFoundException ex) {
|
||||
} catch (final ClassNotFoundException ex) {
|
||||
throw new SerializationException("ClassNotFoundException while reading cloned object data", ex);
|
||||
} catch (IOException ex) {
|
||||
} catch (final IOException ex) {
|
||||
throw new SerializationException("IOException while reading cloned object data", ex);
|
||||
} finally {
|
||||
try {
|
||||
if (in != null) {
|
||||
in.close();
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
} catch (final IOException ex) {
|
||||
throw new SerializationException("IOException on closing cloned object data InputStream.", ex);
|
||||
}
|
||||
}
|
||||
|
@ -137,14 +138,14 @@ public static void serialize(final Serializable obj, final OutputStream outputSt
|
|||
out = new ObjectOutputStream(outputStream);
|
||||
out.writeObject(obj);
|
||||
|
||||
} catch (IOException ex) {
|
||||
} catch (final IOException ex) {
|
||||
throw new SerializationException(ex);
|
||||
} finally {
|
||||
try {
|
||||
if (out != null) {
|
||||
out.close();
|
||||
}
|
||||
} catch (IOException ex) { // NOPMD
|
||||
} catch (final IOException ex) { // NOPMD
|
||||
// ignore close exception
|
||||
}
|
||||
}
|
||||
|
@ -159,7 +160,7 @@ public static void serialize(final Serializable obj, final OutputStream outputSt
|
|||
* @throws SerializationException (runtime) if the serialization fails
|
||||
*/
|
||||
public static byte[] serialize(final Serializable obj) {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
|
||||
final ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
|
||||
serialize(obj, baos);
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
@ -207,16 +208,16 @@ public static <T> T deserialize(final InputStream inputStream) {
|
|||
in = new ObjectInputStream(inputStream);
|
||||
return (T) in.readObject();
|
||||
|
||||
} catch (ClassNotFoundException ex) {
|
||||
} catch (final ClassNotFoundException ex) {
|
||||
throw new SerializationException(ex);
|
||||
} catch (IOException ex) {
|
||||
} catch (final IOException ex) {
|
||||
throw new SerializationException(ex);
|
||||
} finally {
|
||||
try {
|
||||
if (in != null) {
|
||||
in.close();
|
||||
}
|
||||
} catch (IOException ex) { // NOPMD
|
||||
} catch (final IOException ex) { // NOPMD
|
||||
// ignore close exception
|
||||
}
|
||||
}
|
||||
|
@ -300,14 +301,14 @@ public ClassLoaderAwareObjectInputStream(final InputStream in, final ClassLoader
|
|||
*/
|
||||
@Override
|
||||
protected Class<?> resolveClass(final ObjectStreamClass desc) throws IOException, ClassNotFoundException {
|
||||
String name = desc.getName();
|
||||
final String name = desc.getName();
|
||||
try {
|
||||
return Class.forName(name, false, classLoader);
|
||||
} catch (ClassNotFoundException ex) {
|
||||
} catch (final ClassNotFoundException ex) {
|
||||
try {
|
||||
return Class.forName(name, false, Thread.currentThread().getContextClassLoader());
|
||||
} catch (ClassNotFoundException cnfe) {
|
||||
Class<?> cls = primitiveTypes.get(name);
|
||||
} catch (final ClassNotFoundException cnfe) {
|
||||
final Class<?> cls = primitiveTypes.get(name);
|
||||
if (cls != null) {
|
||||
return cls;
|
||||
} else {
|
||||
|
|
|
@ -286,7 +286,7 @@ public int translate(final CharSequence input, final int index, final Writer out
|
|||
}
|
||||
|
||||
// strip quotes
|
||||
String quoteless = input.subSequence(1, input.length() - 1).toString();
|
||||
final String quoteless = input.subSequence(1, input.length() - 1).toString();
|
||||
|
||||
if ( StringUtils.containsAny(quoteless, CSV_SEARCH_CHARS) ) {
|
||||
// deal with escaped quotes; ie) ""
|
||||
|
|
|
@ -316,7 +316,7 @@ public static String trim(final String str) {
|
|||
* @since 2.0
|
||||
*/
|
||||
public static String trimToNull(final String str) {
|
||||
String ts = trim(str);
|
||||
final String ts = trim(str);
|
||||
return isEmpty(ts) ? null : ts;
|
||||
}
|
||||
|
||||
|
@ -608,7 +608,7 @@ public static String[] stripAll(final String[] strs, final String stripChars) {
|
|||
if (strs == null || (strsLen = strs.length) == 0) {
|
||||
return strs;
|
||||
}
|
||||
String[] newArr = new String[strsLen];
|
||||
final String[] newArr = new String[strsLen];
|
||||
for (int i = 0; i < strsLen; i++) {
|
||||
newArr[i] = strip(strs[i], stripChars);
|
||||
}
|
||||
|
@ -637,8 +637,8 @@ public static String stripAccents(final String input) {
|
|||
if(input == null) {
|
||||
return null;
|
||||
}
|
||||
Pattern pattern = Pattern.compile("\\p{InCombiningDiacriticalMarks}+");//$NON-NLS-1$
|
||||
String decomposed = Normalizer.normalize(input, Normalizer.Form.NFD);
|
||||
final Pattern pattern = Pattern.compile("\\p{InCombiningDiacriticalMarks}+");//$NON-NLS-1$
|
||||
final String decomposed = Normalizer.normalize(input, Normalizer.Form.NFD);
|
||||
// Note that this doesn't correctly remove ligatures...
|
||||
return pattern.matcher(decomposed).replaceAll("");//$NON-NLS-1$
|
||||
}
|
||||
|
@ -988,7 +988,7 @@ public static int indexOfIgnoreCase(final CharSequence str, final CharSequence s
|
|||
if (startPos < 0) {
|
||||
startPos = 0;
|
||||
}
|
||||
int endLimit = str.length() - searchStr.length() + 1;
|
||||
final int endLimit = str.length() - searchStr.length() + 1;
|
||||
if (startPos > endLimit) {
|
||||
return INDEX_NOT_FOUND;
|
||||
}
|
||||
|
@ -1338,8 +1338,8 @@ public static boolean containsIgnoreCase(final CharSequence str, final CharSeque
|
|||
if (str == null || searchStr == null) {
|
||||
return false;
|
||||
}
|
||||
int len = searchStr.length();
|
||||
int max = str.length() - len;
|
||||
final int len = searchStr.length();
|
||||
final int max = str.length() - len;
|
||||
for (int i = 0; i <= max; i++) {
|
||||
if (CharSequenceUtils.regionMatches(str, true, i, searchStr, 0, len)) {
|
||||
return true;
|
||||
|
@ -1361,7 +1361,7 @@ public static boolean containsWhitespace(final CharSequence seq) {
|
|||
if (isEmpty(seq)) {
|
||||
return false;
|
||||
}
|
||||
int strLen = seq.length();
|
||||
final int strLen = seq.length();
|
||||
for (int i = 0; i < strLen; i++) {
|
||||
if (Character.isWhitespace(seq.charAt(i))) {
|
||||
return true;
|
||||
|
@ -1399,12 +1399,12 @@ public static int indexOfAny(final CharSequence cs, final char... searchChars) {
|
|||
if (isEmpty(cs) || ArrayUtils.isEmpty(searchChars)) {
|
||||
return INDEX_NOT_FOUND;
|
||||
}
|
||||
int csLen = cs.length();
|
||||
int csLast = csLen - 1;
|
||||
int searchLen = searchChars.length;
|
||||
int searchLast = searchLen - 1;
|
||||
final int csLen = cs.length();
|
||||
final int csLast = csLen - 1;
|
||||
final int searchLen = searchChars.length;
|
||||
final int searchLast = searchLen - 1;
|
||||
for (int i = 0; i < csLen; i++) {
|
||||
char ch = cs.charAt(i);
|
||||
final char ch = cs.charAt(i);
|
||||
for (int j = 0; j < searchLen; j++) {
|
||||
if (searchChars[j] == ch) {
|
||||
if (i < csLast && j < searchLast && Character.isHighSurrogate(ch)) {
|
||||
|
@ -1481,12 +1481,12 @@ public static boolean containsAny(final CharSequence cs, final char... searchCha
|
|||
if (isEmpty(cs) || ArrayUtils.isEmpty(searchChars)) {
|
||||
return false;
|
||||
}
|
||||
int csLength = cs.length();
|
||||
int searchLength = searchChars.length;
|
||||
int csLast = csLength - 1;
|
||||
int searchLast = searchLength - 1;
|
||||
final int csLength = cs.length();
|
||||
final int searchLength = searchChars.length;
|
||||
final int csLast = csLength - 1;
|
||||
final int searchLast = searchLength - 1;
|
||||
for (int i = 0; i < csLength; i++) {
|
||||
char ch = cs.charAt(i);
|
||||
final char ch = cs.charAt(i);
|
||||
for (int j = 0; j < searchLength; j++) {
|
||||
if (searchChars[j] == ch) {
|
||||
if (Character.isHighSurrogate(ch)) {
|
||||
|
@ -1572,13 +1572,13 @@ public static int indexOfAnyBut(final CharSequence cs, final char... searchChars
|
|||
if (isEmpty(cs) || ArrayUtils.isEmpty(searchChars)) {
|
||||
return INDEX_NOT_FOUND;
|
||||
}
|
||||
int csLen = cs.length();
|
||||
int csLast = csLen - 1;
|
||||
int searchLen = searchChars.length;
|
||||
int searchLast = searchLen - 1;
|
||||
final int csLen = cs.length();
|
||||
final int csLast = csLen - 1;
|
||||
final int searchLen = searchChars.length;
|
||||
final int searchLast = searchLen - 1;
|
||||
outer:
|
||||
for (int i = 0; i < csLen; i++) {
|
||||
char ch = cs.charAt(i);
|
||||
final char ch = cs.charAt(i);
|
||||
for (int j = 0; j < searchLen; j++) {
|
||||
if (searchChars[j] == ch) {
|
||||
if (i < csLast && j < searchLast && Character.isHighSurrogate(ch)) {
|
||||
|
@ -1622,12 +1622,12 @@ public static int indexOfAnyBut(final CharSequence seq, final CharSequence searc
|
|||
if (isEmpty(seq) || isEmpty(searchChars)) {
|
||||
return INDEX_NOT_FOUND;
|
||||
}
|
||||
int strLen = seq.length();
|
||||
final int strLen = seq.length();
|
||||
for (int i = 0; i < strLen; i++) {
|
||||
char ch = seq.charAt(i);
|
||||
boolean chFound = CharSequenceUtils.indexOf(searchChars, ch, 0) >= 0;
|
||||
final char ch = seq.charAt(i);
|
||||
final boolean chFound = CharSequenceUtils.indexOf(searchChars, ch, 0) >= 0;
|
||||
if (i + 1 < strLen && Character.isHighSurrogate(ch)) {
|
||||
char ch2 = seq.charAt(i + 1);
|
||||
final char ch2 = seq.charAt(i + 1);
|
||||
if (chFound && CharSequenceUtils.indexOf(searchChars, ch2, 0) < 0) {
|
||||
return i;
|
||||
}
|
||||
|
@ -1737,12 +1737,12 @@ public static boolean containsNone(final CharSequence cs, final char... searchCh
|
|||
if (cs == null || searchChars == null) {
|
||||
return true;
|
||||
}
|
||||
int csLen = cs.length();
|
||||
int csLast = csLen - 1;
|
||||
int searchLen = searchChars.length;
|
||||
int searchLast = searchLen - 1;
|
||||
final int csLen = cs.length();
|
||||
final int csLast = csLen - 1;
|
||||
final int searchLen = searchChars.length;
|
||||
final int searchLast = searchLen - 1;
|
||||
for (int i = 0; i < csLen; i++) {
|
||||
char ch = cs.charAt(i);
|
||||
final char ch = cs.charAt(i);
|
||||
for (int j = 0; j < searchLen; j++) {
|
||||
if (searchChars[j] == ch) {
|
||||
if (Character.isHighSurrogate(ch)) {
|
||||
|
@ -1826,14 +1826,14 @@ public static int indexOfAny(final CharSequence str, final CharSequence... searc
|
|||
if (str == null || searchStrs == null) {
|
||||
return INDEX_NOT_FOUND;
|
||||
}
|
||||
int sz = searchStrs.length;
|
||||
final int sz = searchStrs.length;
|
||||
|
||||
// String's can't have a MAX_VALUEth index.
|
||||
int ret = Integer.MAX_VALUE;
|
||||
|
||||
int tmp = 0;
|
||||
for (int i = 0; i < sz; i++) {
|
||||
CharSequence search = searchStrs[i];
|
||||
final CharSequence search = searchStrs[i];
|
||||
if (search == null) {
|
||||
continue;
|
||||
}
|
||||
|
@ -1880,11 +1880,11 @@ public static int lastIndexOfAny(final CharSequence str, final CharSequence... s
|
|||
if (str == null || searchStrs == null) {
|
||||
return INDEX_NOT_FOUND;
|
||||
}
|
||||
int sz = searchStrs.length;
|
||||
final int sz = searchStrs.length;
|
||||
int ret = INDEX_NOT_FOUND;
|
||||
int tmp = 0;
|
||||
for (int i = 0; i < sz; i++) {
|
||||
CharSequence search = searchStrs[i];
|
||||
final CharSequence search = searchStrs[i];
|
||||
if (search == null) {
|
||||
continue;
|
||||
}
|
||||
|
@ -2155,7 +2155,7 @@ public static String substringBefore(final String str, final String separator) {
|
|||
if (separator.length() == 0) {
|
||||
return EMPTY;
|
||||
}
|
||||
int pos = str.indexOf(separator);
|
||||
final int pos = str.indexOf(separator);
|
||||
if (pos == INDEX_NOT_FOUND) {
|
||||
return str;
|
||||
}
|
||||
|
@ -2197,7 +2197,7 @@ public static String substringAfter(final String str, final String separator) {
|
|||
if (separator == null) {
|
||||
return EMPTY;
|
||||
}
|
||||
int pos = str.indexOf(separator);
|
||||
final int pos = str.indexOf(separator);
|
||||
if (pos == INDEX_NOT_FOUND) {
|
||||
return EMPTY;
|
||||
}
|
||||
|
@ -2235,7 +2235,7 @@ public static String substringBeforeLast(final String str, final String separato
|
|||
if (isEmpty(str) || isEmpty(separator)) {
|
||||
return str;
|
||||
}
|
||||
int pos = str.lastIndexOf(separator);
|
||||
final int pos = str.lastIndexOf(separator);
|
||||
if (pos == INDEX_NOT_FOUND) {
|
||||
return str;
|
||||
}
|
||||
|
@ -2278,7 +2278,7 @@ public static String substringAfterLast(final String str, final String separator
|
|||
if (isEmpty(separator)) {
|
||||
return EMPTY;
|
||||
}
|
||||
int pos = str.lastIndexOf(separator);
|
||||
final int pos = str.lastIndexOf(separator);
|
||||
if (pos == INDEX_NOT_FOUND || pos == str.length() - separator.length()) {
|
||||
return EMPTY;
|
||||
}
|
||||
|
@ -2343,9 +2343,9 @@ public static String substringBetween(final String str, final String open, final
|
|||
if (str == null || open == null || close == null) {
|
||||
return null;
|
||||
}
|
||||
int start = str.indexOf(open);
|
||||
final int start = str.indexOf(open);
|
||||
if (start != INDEX_NOT_FOUND) {
|
||||
int end = str.indexOf(close, start + open.length());
|
||||
final int end = str.indexOf(close, start + open.length());
|
||||
if (end != INDEX_NOT_FOUND) {
|
||||
return str.substring(start + open.length(), end);
|
||||
}
|
||||
|
@ -2379,13 +2379,13 @@ public static String[] substringsBetween(final String str, final String open, fi
|
|||
if (str == null || isEmpty(open) || isEmpty(close)) {
|
||||
return null;
|
||||
}
|
||||
int strLen = str.length();
|
||||
final int strLen = str.length();
|
||||
if (strLen == 0) {
|
||||
return ArrayUtils.EMPTY_STRING_ARRAY;
|
||||
}
|
||||
int closeLen = close.length();
|
||||
int openLen = open.length();
|
||||
List<String> list = new ArrayList<String>();
|
||||
final int closeLen = close.length();
|
||||
final int openLen = open.length();
|
||||
final List<String> list = new ArrayList<String>();
|
||||
int pos = 0;
|
||||
while (pos < strLen - closeLen) {
|
||||
int start = str.indexOf(open, pos);
|
||||
|
@ -2393,7 +2393,7 @@ public static String[] substringsBetween(final String str, final String open, fi
|
|||
break;
|
||||
}
|
||||
start += openLen;
|
||||
int end = str.indexOf(close, start);
|
||||
final int end = str.indexOf(close, start);
|
||||
if (end < 0) {
|
||||
break;
|
||||
}
|
||||
|
@ -2668,7 +2668,7 @@ private static String[] splitByWholeSeparatorWorker(
|
|||
return null;
|
||||
}
|
||||
|
||||
int len = str.length();
|
||||
final int len = str.length();
|
||||
|
||||
if (len == 0) {
|
||||
return ArrayUtils.EMPTY_STRING_ARRAY;
|
||||
|
@ -2679,9 +2679,9 @@ private static String[] splitByWholeSeparatorWorker(
|
|||
return splitWorker(str, null, max, preserveAllTokens);
|
||||
}
|
||||
|
||||
int separatorLength = separator.length();
|
||||
final int separatorLength = separator.length();
|
||||
|
||||
ArrayList<String> substrings = new ArrayList<String>();
|
||||
final ArrayList<String> substrings = new ArrayList<String>();
|
||||
int numberOfSubstrings = 0;
|
||||
int beg = 0;
|
||||
int end = 0;
|
||||
|
@ -2811,11 +2811,11 @@ private static String[] splitWorker(final String str, final char separatorChar,
|
|||
if (str == null) {
|
||||
return null;
|
||||
}
|
||||
int len = str.length();
|
||||
final int len = str.length();
|
||||
if (len == 0) {
|
||||
return ArrayUtils.EMPTY_STRING_ARRAY;
|
||||
}
|
||||
List<String> list = new ArrayList<String>();
|
||||
final List<String> list = new ArrayList<String>();
|
||||
int i = 0, start = 0;
|
||||
boolean match = false;
|
||||
boolean lastMatch = false;
|
||||
|
@ -2938,11 +2938,11 @@ private static String[] splitWorker(final String str, final String separatorChar
|
|||
if (str == null) {
|
||||
return null;
|
||||
}
|
||||
int len = str.length();
|
||||
final int len = str.length();
|
||||
if (len == 0) {
|
||||
return ArrayUtils.EMPTY_STRING_ARRAY;
|
||||
}
|
||||
List<String> list = new ArrayList<String>();
|
||||
final List<String> list = new ArrayList<String>();
|
||||
int sizePlus1 = 1;
|
||||
int i = 0, start = 0;
|
||||
boolean match = false;
|
||||
|
@ -2969,7 +2969,7 @@ private static String[] splitWorker(final String str, final String separatorChar
|
|||
}
|
||||
} else if (separatorChars.length() == 1) {
|
||||
// Optimise 1 character case
|
||||
char sep = separatorChars.charAt(0);
|
||||
final char sep = separatorChars.charAt(0);
|
||||
while (i < len) {
|
||||
if (str.charAt(i) == sep) {
|
||||
if (match || preserveAllTokens) {
|
||||
|
@ -3087,17 +3087,17 @@ private static String[] splitByCharacterType(final String str, final boolean cam
|
|||
if (str.length() == 0) {
|
||||
return ArrayUtils.EMPTY_STRING_ARRAY;
|
||||
}
|
||||
char[] c = str.toCharArray();
|
||||
List<String> list = new ArrayList<String>();
|
||||
final char[] c = str.toCharArray();
|
||||
final List<String> list = new ArrayList<String>();
|
||||
int tokenStart = 0;
|
||||
int currentType = Character.getType(c[tokenStart]);
|
||||
for (int pos = tokenStart + 1; pos < c.length; pos++) {
|
||||
int type = Character.getType(c[pos]);
|
||||
final int type = Character.getType(c[pos]);
|
||||
if (type == currentType) {
|
||||
continue;
|
||||
}
|
||||
if (camelCase && type == Character.LOWERCASE_LETTER && currentType == Character.UPPERCASE_LETTER) {
|
||||
int newTokenStart = pos - 1;
|
||||
final int newTokenStart = pos - 1;
|
||||
if (newTokenStart != tokenStart) {
|
||||
list.add(new String(c, tokenStart, newTokenStart - tokenStart));
|
||||
tokenStart = newTokenStart;
|
||||
|
@ -3424,11 +3424,11 @@ public static String join(final Object[] array, final char separator, final int
|
|||
if (array == null) {
|
||||
return null;
|
||||
}
|
||||
int noOfItems = endIndex - startIndex;
|
||||
final int noOfItems = endIndex - startIndex;
|
||||
if (noOfItems <= 0) {
|
||||
return EMPTY;
|
||||
}
|
||||
StringBuilder buf = new StringBuilder(noOfItems * 16);
|
||||
final StringBuilder buf = new StringBuilder(noOfItems * 16);
|
||||
for (int i = startIndex; i < endIndex; i++) {
|
||||
if (i > startIndex) {
|
||||
buf.append(separator);
|
||||
|
@ -3475,11 +3475,11 @@ public static String join(final long[] array, final char separator, final int st
|
|||
if (array == null) {
|
||||
return null;
|
||||
}
|
||||
int noOfItems = endIndex - startIndex;
|
||||
final int noOfItems = endIndex - startIndex;
|
||||
if (noOfItems <= 0) {
|
||||
return EMPTY;
|
||||
}
|
||||
StringBuilder buf = new StringBuilder(noOfItems * 16);
|
||||
final StringBuilder buf = new StringBuilder(noOfItems * 16);
|
||||
for (int i = startIndex; i < endIndex; i++) {
|
||||
if (i > startIndex) {
|
||||
buf.append(separator);
|
||||
|
@ -3524,11 +3524,11 @@ public static String join(final int[] array, final char separator, final int sta
|
|||
if (array == null) {
|
||||
return null;
|
||||
}
|
||||
int noOfItems = endIndex - startIndex;
|
||||
final int noOfItems = endIndex - startIndex;
|
||||
if (noOfItems <= 0) {
|
||||
return EMPTY;
|
||||
}
|
||||
StringBuilder buf = new StringBuilder(noOfItems * 16);
|
||||
final StringBuilder buf = new StringBuilder(noOfItems * 16);
|
||||
for (int i = startIndex; i < endIndex; i++) {
|
||||
if (i > startIndex) {
|
||||
buf.append(separator);
|
||||
|
@ -3573,11 +3573,11 @@ public static String join(final byte[] array, final char separator, final int st
|
|||
if (array == null) {
|
||||
return null;
|
||||
}
|
||||
int noOfItems = endIndex - startIndex;
|
||||
final int noOfItems = endIndex - startIndex;
|
||||
if (noOfItems <= 0) {
|
||||
return EMPTY;
|
||||
}
|
||||
StringBuilder buf = new StringBuilder(noOfItems * 16);
|
||||
final StringBuilder buf = new StringBuilder(noOfItems * 16);
|
||||
for (int i = startIndex; i < endIndex; i++) {
|
||||
if (i > startIndex) {
|
||||
buf.append(separator);
|
||||
|
@ -3622,11 +3622,11 @@ public static String join(final short[] array, final char separator, final int s
|
|||
if (array == null) {
|
||||
return null;
|
||||
}
|
||||
int noOfItems = endIndex - startIndex;
|
||||
final int noOfItems = endIndex - startIndex;
|
||||
if (noOfItems <= 0) {
|
||||
return EMPTY;
|
||||
}
|
||||
StringBuilder buf = new StringBuilder(noOfItems * 16);
|
||||
final StringBuilder buf = new StringBuilder(noOfItems * 16);
|
||||
for (int i = startIndex; i < endIndex; i++) {
|
||||
if (i > startIndex) {
|
||||
buf.append(separator);
|
||||
|
@ -3671,11 +3671,11 @@ public static String join(final char[] array, final char separator, final int st
|
|||
if (array == null) {
|
||||
return null;
|
||||
}
|
||||
int noOfItems = endIndex - startIndex;
|
||||
final int noOfItems = endIndex - startIndex;
|
||||
if (noOfItems <= 0) {
|
||||
return EMPTY;
|
||||
}
|
||||
StringBuilder buf = new StringBuilder(noOfItems * 16);
|
||||
final StringBuilder buf = new StringBuilder(noOfItems * 16);
|
||||
for (int i = startIndex; i < endIndex; i++) {
|
||||
if (i > startIndex) {
|
||||
buf.append(separator);
|
||||
|
@ -3720,11 +3720,11 @@ public static String join(final double[] array, final char separator, final int
|
|||
if (array == null) {
|
||||
return null;
|
||||
}
|
||||
int noOfItems = endIndex - startIndex;
|
||||
final int noOfItems = endIndex - startIndex;
|
||||
if (noOfItems <= 0) {
|
||||
return EMPTY;
|
||||
}
|
||||
StringBuilder buf = new StringBuilder(noOfItems * 16);
|
||||
final StringBuilder buf = new StringBuilder(noOfItems * 16);
|
||||
for (int i = startIndex; i < endIndex; i++) {
|
||||
if (i > startIndex) {
|
||||
buf.append(separator);
|
||||
|
@ -3769,11 +3769,11 @@ public static String join(final float[] array, final char separator, final int s
|
|||
if (array == null) {
|
||||
return null;
|
||||
}
|
||||
int noOfItems = endIndex - startIndex;
|
||||
final int noOfItems = endIndex - startIndex;
|
||||
if (noOfItems <= 0) {
|
||||
return EMPTY;
|
||||
}
|
||||
StringBuilder buf = new StringBuilder(noOfItems * 16);
|
||||
final StringBuilder buf = new StringBuilder(noOfItems * 16);
|
||||
for (int i = startIndex; i < endIndex; i++) {
|
||||
if (i > startIndex) {
|
||||
buf.append(separator);
|
||||
|
@ -3859,12 +3859,12 @@ public static String join(final Object[] array, String separator, final int star
|
|||
|
||||
// endIndex - startIndex > 0: Len = NofStrings *(len(firstString) + len(separator))
|
||||
// (Assuming that all Strings are roughly equally long)
|
||||
int noOfItems = endIndex - startIndex;
|
||||
final int noOfItems = endIndex - startIndex;
|
||||
if (noOfItems <= 0) {
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
StringBuilder buf = new StringBuilder(noOfItems * 16);
|
||||
final StringBuilder buf = new StringBuilder(noOfItems * 16);
|
||||
|
||||
for (int i = startIndex; i < endIndex; i++) {
|
||||
if (i > startIndex) {
|
||||
|
@ -3900,20 +3900,20 @@ public static String join(final Iterator<?> iterator, final char separator) {
|
|||
if (!iterator.hasNext()) {
|
||||
return EMPTY;
|
||||
}
|
||||
Object first = iterator.next();
|
||||
final Object first = iterator.next();
|
||||
if (!iterator.hasNext()) {
|
||||
return ObjectUtils.toString(first);
|
||||
}
|
||||
|
||||
// two or more elements
|
||||
StringBuilder buf = new StringBuilder(256); // Java default is 16, probably too small
|
||||
final StringBuilder buf = new StringBuilder(256); // Java default is 16, probably too small
|
||||
if (first != null) {
|
||||
buf.append(first);
|
||||
}
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
buf.append(separator);
|
||||
Object obj = iterator.next();
|
||||
final Object obj = iterator.next();
|
||||
if (obj != null) {
|
||||
buf.append(obj);
|
||||
}
|
||||
|
@ -3944,13 +3944,13 @@ public static String join(final Iterator<?> iterator, final String separator) {
|
|||
if (!iterator.hasNext()) {
|
||||
return EMPTY;
|
||||
}
|
||||
Object first = iterator.next();
|
||||
final Object first = iterator.next();
|
||||
if (!iterator.hasNext()) {
|
||||
return ObjectUtils.toString(first);
|
||||
}
|
||||
|
||||
// two or more elements
|
||||
StringBuilder buf = new StringBuilder(256); // Java default is 16, probably too small
|
||||
final StringBuilder buf = new StringBuilder(256); // Java default is 16, probably too small
|
||||
if (first != null) {
|
||||
buf.append(first);
|
||||
}
|
||||
|
@ -3959,7 +3959,7 @@ public static String join(final Iterator<?> iterator, final String separator) {
|
|||
if (separator != null) {
|
||||
buf.append(separator);
|
||||
}
|
||||
Object obj = iterator.next();
|
||||
final Object obj = iterator.next();
|
||||
if (obj != null) {
|
||||
buf.append(obj);
|
||||
}
|
||||
|
@ -4029,8 +4029,8 @@ public static String deleteWhitespace(final String str) {
|
|||
if (isEmpty(str)) {
|
||||
return str;
|
||||
}
|
||||
int sz = str.length();
|
||||
char[] chs = new char[sz];
|
||||
final int sz = str.length();
|
||||
final char[] chs = new char[sz];
|
||||
int count = 0;
|
||||
for (int i = 0; i < sz; i++) {
|
||||
if (!Character.isWhitespace(str.charAt(i))) {
|
||||
|
@ -4237,7 +4237,7 @@ public static String remove(final String str, final char remove) {
|
|||
if (isEmpty(str) || str.indexOf(remove) == INDEX_NOT_FOUND) {
|
||||
return str;
|
||||
}
|
||||
char[] chars = str.toCharArray();
|
||||
final char[] chars = str.toCharArray();
|
||||
int pos = 0;
|
||||
for (int i = 0; i < chars.length; i++) {
|
||||
if (chars[i] != remove) {
|
||||
|
@ -4380,11 +4380,11 @@ public static String replace(final String text, final String searchString, final
|
|||
if (end == INDEX_NOT_FOUND) {
|
||||
return text;
|
||||
}
|
||||
int replLength = searchString.length();
|
||||
final int replLength = searchString.length();
|
||||
int increase = replacement.length() - replLength;
|
||||
increase = increase < 0 ? 0 : increase;
|
||||
increase *= max < 0 ? 16 : max > 64 ? 64 : max;
|
||||
StringBuilder buf = new StringBuilder(text.length() + increase);
|
||||
final StringBuilder buf = new StringBuilder(text.length() + increase);
|
||||
while (end != INDEX_NOT_FOUND) {
|
||||
buf.append(text.substring(start, end)).append(replacement);
|
||||
start = end + replLength;
|
||||
|
@ -4487,7 +4487,7 @@ public static String replaceEach(final String text, final String[] searchList, f
|
|||
public static String replaceEachRepeatedly(final String text, final String[] searchList, final String[] replacementList) {
|
||||
// timeToLive should be 0 if not used or nothing to replace, else it's
|
||||
// the length of the replace array
|
||||
int timeToLive = searchList == null ? 0 : searchList.length;
|
||||
final int timeToLive = searchList == null ? 0 : searchList.length;
|
||||
return replaceEach(text, searchList, replacementList, true, timeToLive);
|
||||
}
|
||||
|
||||
|
@ -4556,8 +4556,8 @@ private static String replaceEach(
|
|||
"output of one loop is the input of another");
|
||||
}
|
||||
|
||||
int searchLength = searchList.length;
|
||||
int replacementLength = replacementList.length;
|
||||
final int searchLength = searchList.length;
|
||||
final int replacementLength = replacementList.length;
|
||||
|
||||
// make sure lengths are ok, these need to be equal
|
||||
if (searchLength != replacementLength) {
|
||||
|
@ -4568,7 +4568,7 @@ private static String replaceEach(
|
|||
}
|
||||
|
||||
// keep track of which still have matches
|
||||
boolean[] noMoreMatchesForReplIndex = new boolean[searchLength];
|
||||
final boolean[] noMoreMatchesForReplIndex = new boolean[searchLength];
|
||||
|
||||
// index on index that the match was found
|
||||
int textIndex = -1;
|
||||
|
@ -4611,7 +4611,7 @@ private static String replaceEach(
|
|||
if (searchList[i] == null || replacementList[i] == null) {
|
||||
continue;
|
||||
}
|
||||
int greater = replacementList[i].length() - searchList[i].length();
|
||||
final int greater = replacementList[i].length() - searchList[i].length();
|
||||
if (greater > 0) {
|
||||
increase += 3 * greater; // assume 3 matches
|
||||
}
|
||||
|
@ -4619,7 +4619,7 @@ private static String replaceEach(
|
|||
// have upper-bound at 20% increase, then let Java take over
|
||||
increase = Math.min(increase, text.length() / 5);
|
||||
|
||||
StringBuilder buf = new StringBuilder(text.length() + increase);
|
||||
final StringBuilder buf = new StringBuilder(text.length() + increase);
|
||||
|
||||
while (textIndex != -1) {
|
||||
|
||||
|
@ -4655,11 +4655,11 @@ private static String replaceEach(
|
|||
// NOTE: logic duplicated above END
|
||||
|
||||
}
|
||||
int textLength = text.length();
|
||||
final int textLength = text.length();
|
||||
for (int i = start; i < textLength; i++) {
|
||||
buf.append(text.charAt(i));
|
||||
}
|
||||
String result = buf.toString();
|
||||
final String result = buf.toString();
|
||||
if (!repeat) {
|
||||
return result;
|
||||
}
|
||||
|
@ -4740,12 +4740,12 @@ public static String replaceChars(final String str, final String searchChars, St
|
|||
replaceChars = EMPTY;
|
||||
}
|
||||
boolean modified = false;
|
||||
int replaceCharsLength = replaceChars.length();
|
||||
int strLength = str.length();
|
||||
StringBuilder buf = new StringBuilder(strLength);
|
||||
final int replaceCharsLength = replaceChars.length();
|
||||
final int strLength = str.length();
|
||||
final StringBuilder buf = new StringBuilder(strLength);
|
||||
for (int i = 0; i < strLength; i++) {
|
||||
char ch = str.charAt(i);
|
||||
int index = searchChars.indexOf(ch);
|
||||
final char ch = str.charAt(i);
|
||||
final int index = searchChars.indexOf(ch);
|
||||
if (index >= 0) {
|
||||
modified = true;
|
||||
if (index < replaceCharsLength) {
|
||||
|
@ -4799,7 +4799,7 @@ public static String overlay(final String str, String overlay, int start, int en
|
|||
if (overlay == null) {
|
||||
overlay = EMPTY;
|
||||
}
|
||||
int len = str.length();
|
||||
final int len = str.length();
|
||||
if (start < 0) {
|
||||
start = 0;
|
||||
}
|
||||
|
@ -4813,7 +4813,7 @@ public static String overlay(final String str, String overlay, int start, int en
|
|||
end = len;
|
||||
}
|
||||
if (start > end) {
|
||||
int temp = start;
|
||||
final int temp = start;
|
||||
start = end;
|
||||
end = temp;
|
||||
}
|
||||
|
@ -4857,7 +4857,7 @@ public static String chomp(final String str) {
|
|||
}
|
||||
|
||||
if (str.length() == 1) {
|
||||
char ch = str.charAt(0);
|
||||
final char ch = str.charAt(0);
|
||||
if (ch == CharUtils.CR || ch == CharUtils.LF) {
|
||||
return EMPTY;
|
||||
}
|
||||
|
@ -4865,7 +4865,7 @@ public static String chomp(final String str) {
|
|||
}
|
||||
|
||||
int lastIdx = str.length() - 1;
|
||||
char last = str.charAt(lastIdx);
|
||||
final char last = str.charAt(lastIdx);
|
||||
|
||||
if (last == CharUtils.LF) {
|
||||
if (str.charAt(lastIdx - 1) == CharUtils.CR) {
|
||||
|
@ -4938,13 +4938,13 @@ public static String chop(final String str) {
|
|||
if (str == null) {
|
||||
return null;
|
||||
}
|
||||
int strLen = str.length();
|
||||
final int strLen = str.length();
|
||||
if (strLen < 2) {
|
||||
return EMPTY;
|
||||
}
|
||||
int lastIdx = strLen - 1;
|
||||
String ret = str.substring(0, lastIdx);
|
||||
char last = str.charAt(lastIdx);
|
||||
final int lastIdx = strLen - 1;
|
||||
final String ret = str.substring(0, lastIdx);
|
||||
final char last = str.charAt(lastIdx);
|
||||
if (last == CharUtils.LF && ret.charAt(lastIdx - 1) == CharUtils.CR) {
|
||||
return ret.substring(0, lastIdx - 1);
|
||||
}
|
||||
|
@ -4983,7 +4983,7 @@ public static String repeat(final String str, final int repeat) {
|
|||
if (repeat <= 0) {
|
||||
return EMPTY;
|
||||
}
|
||||
int inputLength = str.length();
|
||||
final int inputLength = str.length();
|
||||
if (repeat == 1 || inputLength == 0) {
|
||||
return str;
|
||||
}
|
||||
|
@ -4991,21 +4991,21 @@ public static String repeat(final String str, final int repeat) {
|
|||
return repeat(str.charAt(0), repeat);
|
||||
}
|
||||
|
||||
int outputLength = inputLength * repeat;
|
||||
final int outputLength = inputLength * repeat;
|
||||
switch (inputLength) {
|
||||
case 1 :
|
||||
return repeat(str.charAt(0), repeat);
|
||||
case 2 :
|
||||
char ch0 = str.charAt(0);
|
||||
char ch1 = str.charAt(1);
|
||||
char[] output2 = new char[outputLength];
|
||||
final char ch0 = str.charAt(0);
|
||||
final char ch1 = str.charAt(1);
|
||||
final char[] output2 = new char[outputLength];
|
||||
for (int i = repeat * 2 - 2; i >= 0; i--, i--) {
|
||||
output2[i] = ch0;
|
||||
output2[i + 1] = ch1;
|
||||
}
|
||||
return new String(output2);
|
||||
default :
|
||||
StringBuilder buf = new StringBuilder(outputLength);
|
||||
final StringBuilder buf = new StringBuilder(outputLength);
|
||||
for (int i = 0; i < repeat; i++) {
|
||||
buf.append(str);
|
||||
}
|
||||
|
@ -5038,7 +5038,7 @@ public static String repeat(final String str, final String separator, final int
|
|||
return repeat(str, repeat);
|
||||
} else {
|
||||
// given that repeat(String, int) is quite optimized, better to rely on it than try and splice this into it
|
||||
String result = repeat(str + separator, repeat);
|
||||
final String result = repeat(str + separator, repeat);
|
||||
return removeEnd(result, separator);
|
||||
}
|
||||
}
|
||||
|
@ -5066,7 +5066,7 @@ public static String repeat(final String str, final String separator, final int
|
|||
* @see #repeat(String, int)
|
||||
*/
|
||||
public static String repeat(final char ch, final int repeat) {
|
||||
char[] buf = new char[repeat];
|
||||
final char[] buf = new char[repeat];
|
||||
for (int i = repeat - 1; i >= 0; i--) {
|
||||
buf[i] = ch;
|
||||
}
|
||||
|
@ -5121,7 +5121,7 @@ public static String rightPad(final String str, final int size, final char padCh
|
|||
if (str == null) {
|
||||
return null;
|
||||
}
|
||||
int pads = size - str.length();
|
||||
final int pads = size - str.length();
|
||||
if (pads <= 0) {
|
||||
return str; // returns original String when possible
|
||||
}
|
||||
|
@ -5161,9 +5161,9 @@ public static String rightPad(final String str, final int size, String padStr) {
|
|||
if (isEmpty(padStr)) {
|
||||
padStr = SPACE;
|
||||
}
|
||||
int padLen = padStr.length();
|
||||
int strLen = str.length();
|
||||
int pads = size - strLen;
|
||||
final int padLen = padStr.length();
|
||||
final int strLen = str.length();
|
||||
final int pads = size - strLen;
|
||||
if (pads <= 0) {
|
||||
return str; // returns original String when possible
|
||||
}
|
||||
|
@ -5176,8 +5176,8 @@ public static String rightPad(final String str, final int size, String padStr) {
|
|||
} else if (pads < padLen) {
|
||||
return str.concat(padStr.substring(0, pads));
|
||||
} else {
|
||||
char[] padding = new char[pads];
|
||||
char[] padChars = padStr.toCharArray();
|
||||
final char[] padding = new char[pads];
|
||||
final char[] padChars = padStr.toCharArray();
|
||||
for (int i = 0; i < pads; i++) {
|
||||
padding[i] = padChars[i % padLen];
|
||||
}
|
||||
|
@ -5233,7 +5233,7 @@ public static String leftPad(final String str, final int size, final char padCha
|
|||
if (str == null) {
|
||||
return null;
|
||||
}
|
||||
int pads = size - str.length();
|
||||
final int pads = size - str.length();
|
||||
if (pads <= 0) {
|
||||
return str; // returns original String when possible
|
||||
}
|
||||
|
@ -5273,9 +5273,9 @@ public static String leftPad(final String str, final int size, String padStr) {
|
|||
if (isEmpty(padStr)) {
|
||||
padStr = SPACE;
|
||||
}
|
||||
int padLen = padStr.length();
|
||||
int strLen = str.length();
|
||||
int pads = size - strLen;
|
||||
final int padLen = padStr.length();
|
||||
final int strLen = str.length();
|
||||
final int pads = size - strLen;
|
||||
if (pads <= 0) {
|
||||
return str; // returns original String when possible
|
||||
}
|
||||
|
@ -5288,8 +5288,8 @@ public static String leftPad(final String str, final int size, String padStr) {
|
|||
} else if (pads < padLen) {
|
||||
return padStr.substring(0, pads).concat(str);
|
||||
} else {
|
||||
char[] padding = new char[pads];
|
||||
char[] padChars = padStr.toCharArray();
|
||||
final char[] padding = new char[pads];
|
||||
final char[] padChars = padStr.toCharArray();
|
||||
for (int i = 0; i < pads; i++) {
|
||||
padding[i] = padChars[i % padLen];
|
||||
}
|
||||
|
@ -5369,8 +5369,8 @@ public static String center(String str, final int size, final char padChar) {
|
|||
if (str == null || size <= 0) {
|
||||
return str;
|
||||
}
|
||||
int strLen = str.length();
|
||||
int pads = size - strLen;
|
||||
final int strLen = str.length();
|
||||
final int pads = size - strLen;
|
||||
if (pads <= 0) {
|
||||
return str;
|
||||
}
|
||||
|
@ -5412,8 +5412,8 @@ public static String center(String str, final int size, String padStr) {
|
|||
if (isEmpty(padStr)) {
|
||||
padStr = SPACE;
|
||||
}
|
||||
int strLen = str.length();
|
||||
int pads = size - strLen;
|
||||
final int strLen = str.length();
|
||||
final int pads = size - strLen;
|
||||
if (pads <= 0) {
|
||||
return str;
|
||||
}
|
||||
|
@ -5616,10 +5616,10 @@ public static String swapCase(final String str) {
|
|||
return str;
|
||||
}
|
||||
|
||||
char[] buffer = str.toCharArray();
|
||||
final char[] buffer = str.toCharArray();
|
||||
|
||||
for (int i = 0; i < buffer.length; i++) {
|
||||
char ch = buffer[i];
|
||||
final char ch = buffer[i];
|
||||
if (Character.isUpperCase(ch)) {
|
||||
buffer[i] = Character.toLowerCase(ch);
|
||||
} else if (Character.isTitleCase(ch)) {
|
||||
|
@ -5692,7 +5692,7 @@ public static boolean isAlpha(final CharSequence cs) {
|
|||
if (cs == null || cs.length() == 0) {
|
||||
return false;
|
||||
}
|
||||
int sz = cs.length();
|
||||
final int sz = cs.length();
|
||||
for (int i = 0; i < sz; i++) {
|
||||
if (Character.isLetter(cs.charAt(i)) == false) {
|
||||
return false;
|
||||
|
@ -5727,7 +5727,7 @@ public static boolean isAlphaSpace(final CharSequence cs) {
|
|||
if (cs == null) {
|
||||
return false;
|
||||
}
|
||||
int sz = cs.length();
|
||||
final int sz = cs.length();
|
||||
for (int i = 0; i < sz; i++) {
|
||||
if (Character.isLetter(cs.charAt(i)) == false && cs.charAt(i) != ' ') {
|
||||
return false;
|
||||
|
@ -5762,7 +5762,7 @@ public static boolean isAlphanumeric(final CharSequence cs) {
|
|||
if (cs == null || cs.length() == 0) {
|
||||
return false;
|
||||
}
|
||||
int sz = cs.length();
|
||||
final int sz = cs.length();
|
||||
for (int i = 0; i < sz; i++) {
|
||||
if (Character.isLetterOrDigit(cs.charAt(i)) == false) {
|
||||
return false;
|
||||
|
@ -5797,7 +5797,7 @@ public static boolean isAlphanumericSpace(final CharSequence cs) {
|
|||
if (cs == null) {
|
||||
return false;
|
||||
}
|
||||
int sz = cs.length();
|
||||
final int sz = cs.length();
|
||||
for (int i = 0; i < sz; i++) {
|
||||
if (Character.isLetterOrDigit(cs.charAt(i)) == false && cs.charAt(i) != ' ') {
|
||||
return false;
|
||||
|
@ -5836,7 +5836,7 @@ public static boolean isAsciiPrintable(final CharSequence cs) {
|
|||
if (cs == null) {
|
||||
return false;
|
||||
}
|
||||
int sz = cs.length();
|
||||
final int sz = cs.length();
|
||||
for (int i = 0; i < sz; i++) {
|
||||
if (CharUtils.isAsciiPrintable(cs.charAt(i)) == false) {
|
||||
return false;
|
||||
|
@ -5879,7 +5879,7 @@ public static boolean isNumeric(final CharSequence cs) {
|
|||
if (cs == null || cs.length() == 0) {
|
||||
return false;
|
||||
}
|
||||
int sz = cs.length();
|
||||
final int sz = cs.length();
|
||||
for (int i = 0; i < sz; i++) {
|
||||
if (Character.isDigit(cs.charAt(i)) == false) {
|
||||
return false;
|
||||
|
@ -5916,7 +5916,7 @@ public static boolean isNumericSpace(final CharSequence cs) {
|
|||
if (cs == null) {
|
||||
return false;
|
||||
}
|
||||
int sz = cs.length();
|
||||
final int sz = cs.length();
|
||||
for (int i = 0; i < sz; i++) {
|
||||
if (Character.isDigit(cs.charAt(i)) == false && cs.charAt(i) != ' ') {
|
||||
return false;
|
||||
|
@ -5949,7 +5949,7 @@ public static boolean isWhitespace(final CharSequence cs) {
|
|||
if (cs == null) {
|
||||
return false;
|
||||
}
|
||||
int sz = cs.length();
|
||||
final int sz = cs.length();
|
||||
for (int i = 0; i < sz; i++) {
|
||||
if (Character.isWhitespace(cs.charAt(i)) == false) {
|
||||
return false;
|
||||
|
@ -5981,7 +5981,7 @@ public static boolean isAllLowerCase(final CharSequence cs) {
|
|||
if (cs == null || isEmpty(cs)) {
|
||||
return false;
|
||||
}
|
||||
int sz = cs.length();
|
||||
final int sz = cs.length();
|
||||
for (int i = 0; i < sz; i++) {
|
||||
if (Character.isLowerCase(cs.charAt(i)) == false) {
|
||||
return false;
|
||||
|
@ -6013,7 +6013,7 @@ public static boolean isAllUpperCase(final CharSequence cs) {
|
|||
if (cs == null || isEmpty(cs)) {
|
||||
return false;
|
||||
}
|
||||
int sz = cs.length();
|
||||
final int sz = cs.length();
|
||||
for (int i = 0; i < sz; i++) {
|
||||
if (Character.isUpperCase(cs.charAt(i)) == false) {
|
||||
return false;
|
||||
|
@ -6157,7 +6157,7 @@ public static String reverseDelimited(final String str, final char separatorChar
|
|||
}
|
||||
// could implement manually, but simple way is to reuse other,
|
||||
// probably slower, methods.
|
||||
String[] strs = split(str, separatorChar);
|
||||
final String[] strs = split(str, separatorChar);
|
||||
ArrayUtils.reverse(strs);
|
||||
return join(strs, separatorChar);
|
||||
}
|
||||
|
@ -6302,11 +6302,11 @@ public static String abbreviateMiddle(final String str, final String middle, fin
|
|||
return str;
|
||||
}
|
||||
|
||||
int targetSting = length-middle.length();
|
||||
int startOffset = targetSting/2+targetSting%2;
|
||||
int endOffset = str.length()-targetSting/2;
|
||||
final int targetSting = length-middle.length();
|
||||
final int startOffset = targetSting/2+targetSting%2;
|
||||
final int endOffset = str.length()-targetSting/2;
|
||||
|
||||
StringBuilder builder = new StringBuilder(length);
|
||||
final StringBuilder builder = new StringBuilder(length);
|
||||
builder.append(str.substring(0,startOffset));
|
||||
builder.append(middle);
|
||||
builder.append(str.substring(endOffset));
|
||||
|
@ -6348,7 +6348,7 @@ public static String difference(final String str1, final String str2) {
|
|||
if (str2 == null) {
|
||||
return str1;
|
||||
}
|
||||
int at = indexOfDifference(str1, str2);
|
||||
final int at = indexOfDifference(str1, str2);
|
||||
if (at == INDEX_NOT_FOUND) {
|
||||
return EMPTY;
|
||||
}
|
||||
|
@ -6437,7 +6437,7 @@ public static int indexOfDifference(final CharSequence... css) {
|
|||
}
|
||||
boolean anyStringNull = false;
|
||||
boolean allStringsNull = true;
|
||||
int arrayLen = css.length;
|
||||
final int arrayLen = css.length;
|
||||
int shortestStrLen = Integer.MAX_VALUE;
|
||||
int longestStrLen = 0;
|
||||
|
||||
|
@ -6468,7 +6468,7 @@ public static int indexOfDifference(final CharSequence... css) {
|
|||
// find the position with the first difference across all strings
|
||||
int firstDiff = -1;
|
||||
for (int stringPos = 0; stringPos < shortestStrLen; stringPos++) {
|
||||
char comparisonChar = css[0].charAt(stringPos);
|
||||
final char comparisonChar = css[0].charAt(stringPos);
|
||||
for (int arrayPos = 1; arrayPos < arrayLen; arrayPos++) {
|
||||
if (css[arrayPos].charAt(stringPos) != comparisonChar) {
|
||||
firstDiff = stringPos;
|
||||
|
@ -6526,7 +6526,7 @@ public static String getCommonPrefix(final String... strs) {
|
|||
if (strs == null || strs.length == 0) {
|
||||
return EMPTY;
|
||||
}
|
||||
int smallestIndexOfDiff = indexOfDifference(strs);
|
||||
final int smallestIndexOfDiff = indexOfDifference(strs);
|
||||
if (smallestIndexOfDiff == INDEX_NOT_FOUND) {
|
||||
// all strings were identical
|
||||
if (strs[0] == null) {
|
||||
|
@ -6613,7 +6613,7 @@ allows us to retain the previous cost counts as required by the algorithm (takin
|
|||
|
||||
if (n > m) {
|
||||
// swap the input strings to consume less memory
|
||||
CharSequence tmp = s;
|
||||
final CharSequence tmp = s;
|
||||
s = t;
|
||||
t = tmp;
|
||||
n = m;
|
||||
|
@ -6753,7 +6753,7 @@ distance is O(nm), but a bound of k allows us to reduce it to O(km) time by only
|
|||
|
||||
if (n > m) {
|
||||
// swap the two strings to consume less memory
|
||||
CharSequence tmp = s;
|
||||
final CharSequence tmp = s;
|
||||
s = t;
|
||||
t = tmp;
|
||||
n = m;
|
||||
|
@ -6765,7 +6765,7 @@ distance is O(nm), but a bound of k allows us to reduce it to O(km) time by only
|
|||
int _d[]; // placeholder to assist in swapping p and d
|
||||
|
||||
// fill in starting table values
|
||||
int boundary = Math.min(n, threshold) + 1;
|
||||
final int boundary = Math.min(n, threshold) + 1;
|
||||
for (int i = 0; i < boundary; i++) {
|
||||
p[i] = i;
|
||||
}
|
||||
|
@ -6776,12 +6776,12 @@ distance is O(nm), but a bound of k allows us to reduce it to O(km) time by only
|
|||
|
||||
// iterates through t
|
||||
for (int j = 1; j <= m; j++) {
|
||||
char t_j = t.charAt(j - 1); // jth character of t
|
||||
final char t_j = t.charAt(j - 1); // jth character of t
|
||||
d[0] = j;
|
||||
|
||||
// compute stripe indices, constrain to array size
|
||||
int min = Math.max(1, j - threshold);
|
||||
int max = Math.min(n, j + threshold);
|
||||
final int min = Math.max(1, j - threshold);
|
||||
final int max = Math.min(n, j + threshold);
|
||||
|
||||
// the stripe may lead off of the table if s and t are of different sizes
|
||||
if (min > max) {
|
||||
|
@ -6918,7 +6918,7 @@ public static boolean startsWithAny(final CharSequence string, final CharSequenc
|
|||
if (isEmpty(string) || ArrayUtils.isEmpty(searchStrings)) {
|
||||
return false;
|
||||
}
|
||||
for (CharSequence searchString : searchStrings) {
|
||||
for (final CharSequence searchString : searchStrings) {
|
||||
if (StringUtils.startsWith(string, searchString)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -7001,7 +7001,7 @@ private static boolean endsWith(final CharSequence str, final CharSequence suffi
|
|||
if (suffix.length() > str.length()) {
|
||||
return false;
|
||||
}
|
||||
int strOffset = str.length() - suffix.length();
|
||||
final int strOffset = str.length() - suffix.length();
|
||||
return CharSequenceUtils.regionMatches(str, ignoreCase, strOffset, suffix, 0, suffix.length());
|
||||
}
|
||||
|
||||
|
@ -7075,7 +7075,7 @@ public static boolean endsWithAny(final CharSequence string, final CharSequence.
|
|||
if (isEmpty(string) || ArrayUtils.isEmpty(searchStrings)) {
|
||||
return false;
|
||||
}
|
||||
for (CharSequence searchString : searchStrings) {
|
||||
for (final CharSequence searchString : searchStrings) {
|
||||
if (StringUtils.endsWith(string, searchString)) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1319,7 +1319,7 @@ private static boolean getOSMatchesName(final String osNamePrefix) {
|
|||
private static String getSystemProperty(final String property) {
|
||||
try {
|
||||
return System.getProperty(property);
|
||||
} catch (SecurityException ex) {
|
||||
} catch (final SecurityException ex) {
|
||||
// we are not allowed to look at this property
|
||||
System.err.println("Caught a SecurityException reading the system property '" + property
|
||||
+ "'; the SystemUtils property value will default to null.");
|
||||
|
|
|
@ -506,7 +506,7 @@ public static <T> T[] noNullElements(final T[] array, final String message, fina
|
|||
Validate.notNull(array);
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
if (array[i] == null) {
|
||||
Object[] values2 = ArrayUtils.add(values, Integer.valueOf(i));
|
||||
final Object[] values2 = ArrayUtils.add(values, Integer.valueOf(i));
|
||||
throw new IllegalArgumentException(String.format(message, values2));
|
||||
}
|
||||
}
|
||||
|
@ -567,9 +567,9 @@ public static <T> T[] noNullElements(final T[] array) {
|
|||
public static <T extends Iterable<?>> T noNullElements(final T iterable, final String message, final Object... values) {
|
||||
Validate.notNull(iterable);
|
||||
int i = 0;
|
||||
for (Iterator<?> it = iterable.iterator(); it.hasNext(); i++) {
|
||||
for (final Iterator<?> it = iterable.iterator(); it.hasNext(); i++) {
|
||||
if (it.next() == null) {
|
||||
Object[] values2 = ArrayUtils.addAll(values, Integer.valueOf(i));
|
||||
final Object[] values2 = ArrayUtils.addAll(values, Integer.valueOf(i));
|
||||
throw new IllegalArgumentException(String.format(message, values2));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -282,7 +282,7 @@ public static int reflectionCompare(
|
|||
if (!lhsClazz.isInstance(rhs)) {
|
||||
throw new ClassCastException();
|
||||
}
|
||||
CompareToBuilder compareToBuilder = new CompareToBuilder();
|
||||
final CompareToBuilder compareToBuilder = new CompareToBuilder();
|
||||
reflectionAppend(lhs, rhs, lhsClazz, compareToBuilder, compareTransients, excludeFields);
|
||||
while (lhsClazz.getSuperclass() != null && lhsClazz != reflectUpToClass) {
|
||||
lhsClazz = lhsClazz.getSuperclass();
|
||||
|
@ -310,17 +310,17 @@ private static void reflectionAppend(
|
|||
final boolean useTransients,
|
||||
final String[] excludeFields) {
|
||||
|
||||
Field[] fields = clazz.getDeclaredFields();
|
||||
final Field[] fields = clazz.getDeclaredFields();
|
||||
AccessibleObject.setAccessible(fields, true);
|
||||
for (int i = 0; i < fields.length && builder.comparison == 0; i++) {
|
||||
Field f = fields[i];
|
||||
final Field f = fields[i];
|
||||
if (!ArrayUtils.contains(excludeFields, f.getName())
|
||||
&& (f.getName().indexOf('$') == -1)
|
||||
&& (useTransients || !Modifier.isTransient(f.getModifiers()))
|
||||
&& (!Modifier.isStatic(f.getModifiers()))) {
|
||||
try {
|
||||
builder.append(f.get(lhs), f.get(rhs));
|
||||
} catch (IllegalAccessException e) {
|
||||
} catch (final IllegalAccessException e) {
|
||||
// This can't happen. Would get a Security exception instead.
|
||||
// Throw a runtime exception in case the impossible happens.
|
||||
throw new InternalError("Unexpected IllegalAccessException");
|
||||
|
|
|
@ -132,8 +132,8 @@ static Set<Pair<IDKey, IDKey>> getRegistry() {
|
|||
* @return the pair
|
||||
*/
|
||||
static Pair<IDKey, IDKey> getRegisterPair(final Object lhs, final Object rhs) {
|
||||
IDKey left = new IDKey(lhs);
|
||||
IDKey right = new IDKey(rhs);
|
||||
final IDKey left = new IDKey(lhs);
|
||||
final IDKey right = new IDKey(rhs);
|
||||
return Pair.of(left, right);
|
||||
}
|
||||
|
||||
|
@ -151,9 +151,9 @@ static Pair<IDKey, IDKey> getRegisterPair(final Object lhs, final Object rhs) {
|
|||
* @since 3.0
|
||||
*/
|
||||
static boolean isRegistered(final Object lhs, final Object rhs) {
|
||||
Set<Pair<IDKey, IDKey>> registry = getRegistry();
|
||||
Pair<IDKey, IDKey> pair = getRegisterPair(lhs, rhs);
|
||||
Pair<IDKey, IDKey> swappedPair = Pair.of(pair.getLeft(), pair.getRight());
|
||||
final Set<Pair<IDKey, IDKey>> registry = getRegistry();
|
||||
final Pair<IDKey, IDKey> pair = getRegisterPair(lhs, rhs);
|
||||
final Pair<IDKey, IDKey> swappedPair = Pair.of(pair.getLeft(), pair.getRight());
|
||||
|
||||
return registry != null
|
||||
&& (registry.contains(pair) || registry.contains(swappedPair));
|
||||
|
@ -175,8 +175,8 @@ static void register(final Object lhs, final Object rhs) {
|
|||
}
|
||||
}
|
||||
|
||||
Set<Pair<IDKey, IDKey>> registry = getRegistry();
|
||||
Pair<IDKey, IDKey> pair = getRegisterPair(lhs, rhs);
|
||||
final Set<Pair<IDKey, IDKey>> registry = getRegistry();
|
||||
final Pair<IDKey, IDKey> pair = getRegisterPair(lhs, rhs);
|
||||
registry.add(pair);
|
||||
}
|
||||
|
||||
|
@ -195,7 +195,7 @@ static void register(final Object lhs, final Object rhs) {
|
|||
static void unregister(final Object lhs, final Object rhs) {
|
||||
Set<Pair<IDKey, IDKey>> registry = getRegistry();
|
||||
if (registry != null) {
|
||||
Pair<IDKey, IDKey> pair = getRegisterPair(lhs, rhs);
|
||||
final Pair<IDKey, IDKey> pair = getRegisterPair(lhs, rhs);
|
||||
registry.remove(pair);
|
||||
synchronized (EqualsBuilder.class) {
|
||||
//read again
|
||||
|
@ -333,8 +333,8 @@ public static boolean reflectionEquals(final Object lhs, final Object rhs, final
|
|||
// class or in classes between the leaf and root.
|
||||
// If we are not testing transients or a subclass has no ivars,
|
||||
// then a subclass can test equals to a superclass.
|
||||
Class<?> lhsClass = lhs.getClass();
|
||||
Class<?> rhsClass = rhs.getClass();
|
||||
final Class<?> lhsClass = lhs.getClass();
|
||||
final Class<?> rhsClass = rhs.getClass();
|
||||
Class<?> testClass;
|
||||
if (lhsClass.isInstance(rhs)) {
|
||||
testClass = lhsClass;
|
||||
|
@ -352,14 +352,14 @@ public static boolean reflectionEquals(final Object lhs, final Object rhs, final
|
|||
// The two classes are not related.
|
||||
return false;
|
||||
}
|
||||
EqualsBuilder equalsBuilder = new EqualsBuilder();
|
||||
final EqualsBuilder equalsBuilder = new EqualsBuilder();
|
||||
try {
|
||||
reflectionAppend(lhs, rhs, testClass, equalsBuilder, testTransients, excludeFields);
|
||||
while (testClass.getSuperclass() != null && testClass != reflectUpToClass) {
|
||||
testClass = testClass.getSuperclass();
|
||||
reflectionAppend(lhs, rhs, testClass, equalsBuilder, testTransients, excludeFields);
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
} catch (final IllegalArgumentException e) {
|
||||
// In this case, we tried to test a subclass vs. a superclass and
|
||||
// the subclass has ivars or the ivars are transient and
|
||||
// we are testing transients.
|
||||
|
@ -395,17 +395,17 @@ private static void reflectionAppend(
|
|||
|
||||
try {
|
||||
register(lhs, rhs);
|
||||
Field[] fields = clazz.getDeclaredFields();
|
||||
final Field[] fields = clazz.getDeclaredFields();
|
||||
AccessibleObject.setAccessible(fields, true);
|
||||
for (int i = 0; i < fields.length && builder.isEquals; i++) {
|
||||
Field f = fields[i];
|
||||
final Field f = fields[i];
|
||||
if (!ArrayUtils.contains(excludeFields, f.getName())
|
||||
&& (f.getName().indexOf('$') == -1)
|
||||
&& (useTransients || !Modifier.isTransient(f.getModifiers()))
|
||||
&& (!Modifier.isStatic(f.getModifiers()))) {
|
||||
try {
|
||||
builder.append(f.get(lhs), f.get(rhs));
|
||||
} catch (IllegalAccessException e) {
|
||||
} catch (final IllegalAccessException e) {
|
||||
//this can't happen. Would get a Security exception instead
|
||||
//throw a runtime exception in case the impossible happens.
|
||||
throw new InternalError("Unexpected IllegalAccessException");
|
||||
|
@ -455,7 +455,7 @@ public EqualsBuilder append(final Object lhs, final Object rhs) {
|
|||
this.setEquals(false);
|
||||
return this;
|
||||
}
|
||||
Class<?> lhsClass = lhs.getClass();
|
||||
final Class<?> lhsClass = lhs.getClass();
|
||||
if (!lhsClass.isArray()) {
|
||||
// The simple case, not an array, just test the element
|
||||
isEquals = lhs.equals(rhs);
|
||||
|
|
|
@ -148,7 +148,7 @@ static Set<IDKey> getRegistry() {
|
|||
* @since 2.3
|
||||
*/
|
||||
static boolean isRegistered(final Object value) {
|
||||
Set<IDKey> registry = getRegistry();
|
||||
final Set<IDKey> registry = getRegistry();
|
||||
return registry != null && registry.contains(new IDKey(value));
|
||||
}
|
||||
|
||||
|
@ -175,17 +175,17 @@ private static void reflectionAppend(final Object object, final Class<?> clazz,
|
|||
}
|
||||
try {
|
||||
register(object);
|
||||
Field[] fields = clazz.getDeclaredFields();
|
||||
final Field[] fields = clazz.getDeclaredFields();
|
||||
AccessibleObject.setAccessible(fields, true);
|
||||
for (Field field : fields) {
|
||||
for (final Field field : fields) {
|
||||
if (!ArrayUtils.contains(excludeFields, field.getName())
|
||||
&& (field.getName().indexOf('$') == -1)
|
||||
&& (useTransients || !Modifier.isTransient(field.getModifiers()))
|
||||
&& (!Modifier.isStatic(field.getModifiers()))) {
|
||||
try {
|
||||
Object fieldValue = field.get(object);
|
||||
final Object fieldValue = field.get(object);
|
||||
builder.append(fieldValue);
|
||||
} catch (IllegalAccessException e) {
|
||||
} catch (final IllegalAccessException e) {
|
||||
// this can't happen. Would get a Security exception instead
|
||||
// throw a runtime exception in case the impossible happens.
|
||||
throw new InternalError("Unexpected IllegalAccessException");
|
||||
|
@ -335,7 +335,7 @@ public static <T> int reflectionHashCode(final int initialNonZeroOddNumber, fina
|
|||
if (object == null) {
|
||||
throw new IllegalArgumentException("The object to build a hash code for must not be null");
|
||||
}
|
||||
HashCodeBuilder builder = new HashCodeBuilder(initialNonZeroOddNumber, multiplierNonZeroOddNumber);
|
||||
final HashCodeBuilder builder = new HashCodeBuilder(initialNonZeroOddNumber, multiplierNonZeroOddNumber);
|
||||
Class<?> clazz = object.getClass();
|
||||
reflectionAppend(object, clazz, builder, testTransients, excludeFields);
|
||||
while (clazz.getSuperclass() != null && clazz != reflectUpToClass) {
|
||||
|
@ -591,7 +591,7 @@ public HashCodeBuilder append(final boolean[] array) {
|
|||
if (array == null) {
|
||||
iTotal = iTotal * iConstant;
|
||||
} else {
|
||||
for (boolean element : array) {
|
||||
for (final boolean element : array) {
|
||||
append(element);
|
||||
}
|
||||
}
|
||||
|
@ -629,7 +629,7 @@ public HashCodeBuilder append(final byte[] array) {
|
|||
if (array == null) {
|
||||
iTotal = iTotal * iConstant;
|
||||
} else {
|
||||
for (byte element : array) {
|
||||
for (final byte element : array) {
|
||||
append(element);
|
||||
}
|
||||
}
|
||||
|
@ -663,7 +663,7 @@ public HashCodeBuilder append(final char[] array) {
|
|||
if (array == null) {
|
||||
iTotal = iTotal * iConstant;
|
||||
} else {
|
||||
for (char element : array) {
|
||||
for (final char element : array) {
|
||||
append(element);
|
||||
}
|
||||
}
|
||||
|
@ -696,7 +696,7 @@ public HashCodeBuilder append(final double[] array) {
|
|||
if (array == null) {
|
||||
iTotal = iTotal * iConstant;
|
||||
} else {
|
||||
for (double element : array) {
|
||||
for (final double element : array) {
|
||||
append(element);
|
||||
}
|
||||
}
|
||||
|
@ -730,7 +730,7 @@ public HashCodeBuilder append(final float[] array) {
|
|||
if (array == null) {
|
||||
iTotal = iTotal * iConstant;
|
||||
} else {
|
||||
for (float element : array) {
|
||||
for (final float element : array) {
|
||||
append(element);
|
||||
}
|
||||
}
|
||||
|
@ -764,7 +764,7 @@ public HashCodeBuilder append(final int[] array) {
|
|||
if (array == null) {
|
||||
iTotal = iTotal * iConstant;
|
||||
} else {
|
||||
for (int element : array) {
|
||||
for (final int element : array) {
|
||||
append(element);
|
||||
}
|
||||
}
|
||||
|
@ -802,7 +802,7 @@ public HashCodeBuilder append(final long[] array) {
|
|||
if (array == null) {
|
||||
iTotal = iTotal * iConstant;
|
||||
} else {
|
||||
for (long element : array) {
|
||||
for (final long element : array) {
|
||||
append(element);
|
||||
}
|
||||
}
|
||||
|
@ -866,7 +866,7 @@ public HashCodeBuilder append(final Object[] array) {
|
|||
if (array == null) {
|
||||
iTotal = iTotal * iConstant;
|
||||
} else {
|
||||
for (Object element : array) {
|
||||
for (final Object element : array) {
|
||||
append(element);
|
||||
}
|
||||
}
|
||||
|
@ -900,7 +900,7 @@ public HashCodeBuilder append(final short[] array) {
|
|||
if (array == null) {
|
||||
iTotal = iTotal * iConstant;
|
||||
} else {
|
||||
for (short element : array) {
|
||||
for (final short element : array) {
|
||||
append(element);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ public boolean equals(final Object other) {
|
|||
if (!(other instanceof IDKey)) {
|
||||
return false;
|
||||
}
|
||||
IDKey idKey = (IDKey) other;
|
||||
final IDKey idKey = (IDKey) other;
|
||||
if (id != idKey.id) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -322,8 +322,8 @@ static String[] toNoNullStringArray(final Collection<String> collection) {
|
|||
* @return The given array or a new array without null.
|
||||
*/
|
||||
static String[] toNoNullStringArray(final Object[] array) {
|
||||
List<String> list = new ArrayList<String>(array.length);
|
||||
for (Object e : array) {
|
||||
final List<String> list = new ArrayList<String>(array.length);
|
||||
for (final Object e : array) {
|
||||
if (e != null) {
|
||||
list.add(e.toString());
|
||||
}
|
||||
|
@ -510,17 +510,17 @@ protected void appendFieldsIn(final Class<?> clazz) {
|
|||
this.reflectionAppendArray(this.getObject());
|
||||
return;
|
||||
}
|
||||
Field[] fields = clazz.getDeclaredFields();
|
||||
final Field[] fields = clazz.getDeclaredFields();
|
||||
AccessibleObject.setAccessible(fields, true);
|
||||
for (Field field : fields) {
|
||||
String fieldName = field.getName();
|
||||
for (final Field field : fields) {
|
||||
final String fieldName = field.getName();
|
||||
if (this.accept(field)) {
|
||||
try {
|
||||
// Warning: Field.get(Object) creates wrappers objects
|
||||
// for primitive types.
|
||||
Object fieldValue = this.getValue(field);
|
||||
final Object fieldValue = this.getValue(field);
|
||||
this.append(fieldName, fieldValue);
|
||||
} catch (IllegalAccessException ex) {
|
||||
} catch (final IllegalAccessException ex) {
|
||||
//this can't happen. Would get a Security exception
|
||||
// instead
|
||||
//throw a runtime exception in case the impossible
|
||||
|
@ -659,7 +659,7 @@ public ReflectionToStringBuilder setExcludeFieldNames(final String... excludeFie
|
|||
*/
|
||||
public void setUpToClass(final Class<?> clazz) {
|
||||
if (clazz != null) {
|
||||
Object object = getObject();
|
||||
final Object object = getObject();
|
||||
if (object != null && clazz.isInstance(object) == false) {
|
||||
throw new IllegalArgumentException("Specified class is not a superclass of the object");
|
||||
}
|
||||
|
|
|
@ -169,7 +169,7 @@ static Map<Object, Object> getRegistry() {
|
|||
* object.
|
||||
*/
|
||||
static boolean isRegistered(final Object value) {
|
||||
Map<Object, Object> m = getRegistry();
|
||||
final Map<Object, Object> m = getRegistry();
|
||||
return m != null && m.containsKey(value);
|
||||
}
|
||||
|
||||
|
@ -184,7 +184,7 @@ static boolean isRegistered(final Object value) {
|
|||
*/
|
||||
static void register(final Object value) {
|
||||
if (value != null) {
|
||||
Map<Object, Object> m = getRegistry();
|
||||
final Map<Object, Object> m = getRegistry();
|
||||
if (m == null) {
|
||||
REGISTRY.set(new WeakHashMap<Object, Object>());
|
||||
}
|
||||
|
@ -206,7 +206,7 @@ static void register(final Object value) {
|
|||
*/
|
||||
static void unregister(final Object value) {
|
||||
if (value != null) {
|
||||
Map<Object, Object> m = getRegistry();
|
||||
final Map<Object, Object> m = getRegistry();
|
||||
if (m != null) {
|
||||
m.remove(value);
|
||||
if (m.isEmpty()) {
|
||||
|
@ -354,10 +354,10 @@ public void appendSuper(final StringBuffer buffer, final String superToString) {
|
|||
*/
|
||||
public void appendToString(final StringBuffer buffer, final String toString) {
|
||||
if (toString != null) {
|
||||
int pos1 = toString.indexOf(contentStart) + contentStart.length();
|
||||
int pos2 = toString.lastIndexOf(contentEnd);
|
||||
final int pos1 = toString.indexOf(contentStart) + contentStart.length();
|
||||
final int pos2 = toString.lastIndexOf(contentEnd);
|
||||
if (pos1 != pos2 && pos1 >= 0 && pos2 >= 0) {
|
||||
String data = toString.substring(pos1, pos2);
|
||||
final String data = toString.substring(pos1, pos2);
|
||||
if (fieldSeparatorAtStart) {
|
||||
removeLastFieldSeparator(buffer);
|
||||
}
|
||||
|
@ -406,8 +406,8 @@ public void appendEnd(final StringBuffer buffer, final Object object) {
|
|||
* @since 2.0
|
||||
*/
|
||||
protected void removeLastFieldSeparator(final StringBuffer buffer) {
|
||||
int len = buffer.length();
|
||||
int sepLen = fieldSeparator.length();
|
||||
final int len = buffer.length();
|
||||
final int sepLen = fieldSeparator.length();
|
||||
if (len > 0 && sepLen > 0 && len >= sepLen) {
|
||||
boolean match = true;
|
||||
for (int i = 0; i < sepLen; i++) {
|
||||
|
@ -898,7 +898,7 @@ public void append(final StringBuffer buffer, final String fieldName, final Obje
|
|||
protected void appendDetail(final StringBuffer buffer, final String fieldName, final Object[] array) {
|
||||
buffer.append(arrayStart);
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
Object item = array[i];
|
||||
final Object item = array[i];
|
||||
if (i > 0) {
|
||||
buffer.append(arraySeparator);
|
||||
}
|
||||
|
@ -923,9 +923,9 @@ protected void appendDetail(final StringBuffer buffer, final String fieldName, f
|
|||
*/
|
||||
protected void reflectionAppendArrayDetail(final StringBuffer buffer, final String fieldName, final Object array) {
|
||||
buffer.append(arrayStart);
|
||||
int length = Array.getLength(array);
|
||||
final int length = Array.getLength(array);
|
||||
for (int i = 0; i < length; i++) {
|
||||
Object item = Array.get(array, i);
|
||||
final Object item = Array.get(array, i);
|
||||
if (i > 0) {
|
||||
buffer.append(arraySeparator);
|
||||
}
|
||||
|
|
|
@ -210,10 +210,10 @@ public synchronized boolean start() {
|
|||
public T get() throws ConcurrentException {
|
||||
try {
|
||||
return getFuture().get();
|
||||
} catch (ExecutionException execex) {
|
||||
} catch (final ExecutionException execex) {
|
||||
ConcurrentUtils.handleCause(execex);
|
||||
return null; // should not be reached
|
||||
} catch (InterruptedException iex) {
|
||||
} catch (final InterruptedException iex) {
|
||||
// reset interrupted state
|
||||
Thread.currentThread().interrupt();
|
||||
throw new ConcurrentException(iex);
|
||||
|
|
|
@ -202,7 +202,7 @@ public long getThreadCount() {
|
|||
*/
|
||||
@Override
|
||||
public Thread newThread(final Runnable r) {
|
||||
Thread t = getWrappedFactory().newThread(r);
|
||||
final Thread t = getWrappedFactory().newThread(r);
|
||||
initializeThread(t);
|
||||
|
||||
return t;
|
||||
|
@ -219,7 +219,7 @@ public Thread newThread(final Runnable r) {
|
|||
private void initializeThread(final Thread t) {
|
||||
|
||||
if (getNamingPattern() != null) {
|
||||
Long count = Long.valueOf(threadCounter.incrementAndGet());
|
||||
final Long count = Long.valueOf(threadCounter.incrementAndGet());
|
||||
t.setName(String.format(getNamingPattern(), count));
|
||||
}
|
||||
|
||||
|
@ -375,7 +375,7 @@ public void reset() {
|
|||
*/
|
||||
@Override
|
||||
public BasicThreadFactory build() {
|
||||
BasicThreadFactory factory = new BasicThreadFactory(this);
|
||||
final BasicThreadFactory factory = new BasicThreadFactory(this);
|
||||
reset();
|
||||
return factory;
|
||||
}
|
||||
|
|
|
@ -103,7 +103,7 @@ public static ConcurrentRuntimeException extractCauseUnchecked(
|
|||
*/
|
||||
public static void handleCause(final ExecutionException ex)
|
||||
throws ConcurrentException {
|
||||
ConcurrentException cex = extractCause(ex);
|
||||
final ConcurrentException cex = extractCause(ex);
|
||||
|
||||
if (cex != null) {
|
||||
throw cex;
|
||||
|
@ -124,7 +124,7 @@ public static void handleCause(final ExecutionException ex)
|
|||
* wrapped in the thrown runtime exception
|
||||
*/
|
||||
public static void handleCauseUnchecked(final ExecutionException ex) {
|
||||
ConcurrentRuntimeException crex = extractCauseUnchecked(ex);
|
||||
final ConcurrentRuntimeException crex = extractCauseUnchecked(ex);
|
||||
|
||||
if (crex != null) {
|
||||
throw crex;
|
||||
|
@ -200,7 +200,7 @@ public static <T> T initialize(final ConcurrentInitializer<T> initializer)
|
|||
public static <T> T initializeUnchecked(final ConcurrentInitializer<T> initializer) {
|
||||
try {
|
||||
return initialize(initializer);
|
||||
} catch (ConcurrentException cex) {
|
||||
} catch (final ConcurrentException cex) {
|
||||
throw new ConcurrentRuntimeException(cex.getCause());
|
||||
}
|
||||
}
|
||||
|
@ -243,7 +243,7 @@ public static <K, V> V putIfAbsent(final ConcurrentMap<K, V> map, final K key, f
|
|||
return null;
|
||||
}
|
||||
|
||||
V result = map.putIfAbsent(key, value);
|
||||
final V result = map.putIfAbsent(key, value);
|
||||
return result != null ? result : value;
|
||||
}
|
||||
|
||||
|
@ -273,7 +273,7 @@ public static <K, V> V createIfAbsent(final ConcurrentMap<K, V> map, final K key
|
|||
return null;
|
||||
}
|
||||
|
||||
V value = map.get(key);
|
||||
final V value = map.get(key);
|
||||
if (value == null) {
|
||||
return putIfAbsent(map, key, init.get());
|
||||
}
|
||||
|
@ -299,7 +299,7 @@ public static <K, V> V createIfAbsentUnchecked(final ConcurrentMap<K, V> map,
|
|||
final K key, final ConcurrentInitializer<V> init) {
|
||||
try {
|
||||
return createIfAbsent(map, key, init);
|
||||
} catch (ConcurrentException cex) {
|
||||
} catch (final ConcurrentException cex) {
|
||||
throw new ConcurrentRuntimeException(cex.getCause());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -110,7 +110,7 @@ public boolean equals(final Object obj) {
|
|||
return false;
|
||||
}
|
||||
|
||||
ConstantInitializer<?> c = (ConstantInitializer<?>) obj;
|
||||
final ConstantInitializer<?> c = (ConstantInitializer<?>) obj;
|
||||
return ObjectUtils.equals(getObject(), c.getObject());
|
||||
}
|
||||
|
||||
|
|
|
@ -164,7 +164,7 @@ public void addInitializer(final String name, final BackgroundInitializer<?> ini
|
|||
protected int getTaskCount() {
|
||||
int result = 1;
|
||||
|
||||
for (BackgroundInitializer<?> bi : childInitializers.values()) {
|
||||
for (final BackgroundInitializer<?> bi : childInitializers.values()) {
|
||||
result += bi.getTaskCount();
|
||||
}
|
||||
|
||||
|
@ -191,8 +191,8 @@ protected MultiBackgroundInitializerResults initialize() throws Exception {
|
|||
}
|
||||
|
||||
// start the child initializers
|
||||
ExecutorService exec = getActiveExecutor();
|
||||
for (BackgroundInitializer<?> bi : inits.values()) {
|
||||
final ExecutorService exec = getActiveExecutor();
|
||||
for (final BackgroundInitializer<?> bi : inits.values()) {
|
||||
if (bi.getExternalExecutor() == null) {
|
||||
// share the executor service if necessary
|
||||
bi.setExternalExecutor(exec);
|
||||
|
@ -201,12 +201,12 @@ protected MultiBackgroundInitializerResults initialize() throws Exception {
|
|||
}
|
||||
|
||||
// collect the results
|
||||
Map<String, Object> results = new HashMap<String, Object>();
|
||||
Map<String, ConcurrentException> excepts = new HashMap<String, ConcurrentException>();
|
||||
for (Map.Entry<String, BackgroundInitializer<?>> e : inits.entrySet()) {
|
||||
final Map<String, Object> results = new HashMap<String, Object>();
|
||||
final Map<String, ConcurrentException> excepts = new HashMap<String, ConcurrentException>();
|
||||
for (final Map.Entry<String, BackgroundInitializer<?>> e : inits.entrySet()) {
|
||||
try {
|
||||
results.put(e.getKey(), e.getValue().get());
|
||||
} catch (ConcurrentException cex) {
|
||||
} catch (final ConcurrentException cex) {
|
||||
excepts.put(e.getKey(), cex);
|
||||
}
|
||||
}
|
||||
|
@ -340,7 +340,7 @@ public boolean isSuccessful() {
|
|||
* @throws NoSuchElementException if the name is unknown
|
||||
*/
|
||||
private BackgroundInitializer<?> checkName(final String name) {
|
||||
BackgroundInitializer<?> init = initializers.get(name);
|
||||
final BackgroundInitializer<?> init = initializers.get(name);
|
||||
if (init == null) {
|
||||
throw new NoSuchElementException(
|
||||
"No child initializer with name " + name);
|
||||
|
|
|
@ -210,7 +210,7 @@ public TimedSemaphore(final ScheduledExecutorService service, final long timePer
|
|||
executorService = service;
|
||||
ownExecutor = false;
|
||||
} else {
|
||||
ScheduledThreadPoolExecutor s = new ScheduledThreadPoolExecutor(
|
||||
final ScheduledThreadPoolExecutor s = new ScheduledThreadPoolExecutor(
|
||||
THREAD_POOL_SIZE);
|
||||
s.setContinueExistingPeriodicTasksAfterShutdownPolicy(false);
|
||||
s.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
|
||||
|
|
|
@ -218,15 +218,15 @@ public L[] getListeners() {
|
|||
* @throws IOException if an IO error occurs
|
||||
*/
|
||||
private void writeObject(final ObjectOutputStream objectOutputStream) throws IOException {
|
||||
ArrayList<L> serializableListeners = new ArrayList<L>();
|
||||
final ArrayList<L> serializableListeners = new ArrayList<L>();
|
||||
|
||||
// don't just rely on instanceof Serializable:
|
||||
ObjectOutputStream testObjectOutputStream = new ObjectOutputStream(new ByteArrayOutputStream());
|
||||
for (L listener : listeners) {
|
||||
for (final L listener : listeners) {
|
||||
try {
|
||||
testObjectOutputStream.writeObject(listener);
|
||||
serializableListeners.add(listener);
|
||||
} catch (IOException exception) {
|
||||
} catch (final IOException exception) {
|
||||
//recreate test stream in case of indeterminate state
|
||||
testObjectOutputStream = new ObjectOutputStream(new ByteArrayOutputStream());
|
||||
}
|
||||
|
@ -246,11 +246,13 @@ private void writeObject(final ObjectOutputStream objectOutputStream) throws IOE
|
|||
*/
|
||||
private void readObject(final ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
|
||||
@SuppressWarnings("unchecked") // Will throw CCE here if not correct
|
||||
final
|
||||
L[] listeners = (L[]) objectInputStream.readObject();
|
||||
|
||||
this.listeners = new CopyOnWriteArrayList<L>(listeners);
|
||||
|
||||
@SuppressWarnings("unchecked") // Will throw CCE here if not correct
|
||||
final
|
||||
Class<L> listenerInterface = (Class<L>) listeners.getClass().getComponentType();
|
||||
|
||||
initializeTransientFields(listenerInterface, Thread.currentThread().getContextClassLoader());
|
||||
|
@ -263,6 +265,7 @@ private void readObject(final ObjectInputStream objectInputStream) throws IOExce
|
|||
*/
|
||||
private void initializeTransientFields(final Class<L> listenerInterface, final ClassLoader classLoader) {
|
||||
@SuppressWarnings("unchecked") // Will throw CCE here if not correct
|
||||
final
|
||||
L[] array = (L[]) Array.newInstance(listenerInterface, 0);
|
||||
this.prototypeArray = array;
|
||||
createProxy(listenerInterface, classLoader);
|
||||
|
@ -306,7 +309,7 @@ protected class ProxyInvocationHandler implements InvocationHandler {
|
|||
*/
|
||||
@Override
|
||||
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
|
||||
for (L listener : listeners) {
|
||||
for (final L listener : listeners) {
|
||||
method.invoke(listener, args);
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -48,15 +48,15 @@ public class EventUtils {
|
|||
public static <L> void addEventListener(final Object eventSource, final Class<L> listenerType, final L listener) {
|
||||
try {
|
||||
MethodUtils.invokeMethod(eventSource, "add" + listenerType.getSimpleName(), listener);
|
||||
} catch (NoSuchMethodException e) {
|
||||
} catch (final NoSuchMethodException e) {
|
||||
throw new IllegalArgumentException("Class " + eventSource.getClass().getName()
|
||||
+ " does not have a public add" + listenerType.getSimpleName()
|
||||
+ " method which takes a parameter of type " + listenerType.getName() + ".");
|
||||
} catch (IllegalAccessException e) {
|
||||
} catch (final IllegalAccessException e) {
|
||||
throw new IllegalArgumentException("Class " + eventSource.getClass().getName()
|
||||
+ " does not have an accessible add" + listenerType.getSimpleName ()
|
||||
+ " method which takes a parameter of type " + listenerType.getName() + ".");
|
||||
} catch (InvocationTargetException e) {
|
||||
} catch (final InvocationTargetException e) {
|
||||
throw new RuntimeException("Unable to add listener.", e.getCause());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -125,7 +125,7 @@ public List<Pair<String, Object>> getContextEntries() {
|
|||
*/
|
||||
@Override
|
||||
public String getFormattedExceptionMessage(final String baseMessage){
|
||||
StringBuilder buffer = new StringBuilder(256);
|
||||
final StringBuilder buffer = new StringBuilder(256);
|
||||
if (baseMessage != null) {
|
||||
buffer.append(baseMessage);
|
||||
}
|
||||
|
@ -150,7 +150,7 @@ public String getFormattedExceptionMessage(final String baseMessage){
|
|||
String valueStr;
|
||||
try {
|
||||
valueStr = value.toString();
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
valueStr = "Exception thrown on toString(): " + ExceptionUtils.getStackTrace(e);
|
||||
}
|
||||
buffer.append(valueStr);
|
||||
|
|
|
@ -147,9 +147,9 @@ public static Throwable getCause(final Throwable throwable, String[] methodNames
|
|||
methodNames = CAUSE_METHOD_NAMES;
|
||||
}
|
||||
|
||||
for (String methodName : methodNames) {
|
||||
for (final String methodName : methodNames) {
|
||||
if (methodName != null) {
|
||||
Throwable cause = getCauseUsingMethodName(throwable, methodName);
|
||||
final Throwable cause = getCauseUsingMethodName(throwable, methodName);
|
||||
if (cause != null) {
|
||||
return cause;
|
||||
}
|
||||
|
@ -177,7 +177,7 @@ public static Throwable getCause(final Throwable throwable, String[] methodNames
|
|||
* <code>null</code> if none found or null throwable input
|
||||
*/
|
||||
public static Throwable getRootCause(final Throwable throwable) {
|
||||
List<Throwable> list = getThrowableList(throwable);
|
||||
final List<Throwable> list = getThrowableList(throwable);
|
||||
return list.size() < 2 ? null : (Throwable)list.get(list.size() - 1);
|
||||
}
|
||||
|
||||
|
@ -193,20 +193,20 @@ private static Throwable getCauseUsingMethodName(final Throwable throwable, fina
|
|||
Method method = null;
|
||||
try {
|
||||
method = throwable.getClass().getMethod(methodName);
|
||||
} catch (NoSuchMethodException ignored) { // NOPMD
|
||||
} catch (final NoSuchMethodException ignored) { // NOPMD
|
||||
// exception ignored
|
||||
} catch (SecurityException ignored) { // NOPMD
|
||||
} catch (final SecurityException ignored) { // NOPMD
|
||||
// exception ignored
|
||||
}
|
||||
|
||||
if (method != null && Throwable.class.isAssignableFrom(method.getReturnType())) {
|
||||
try {
|
||||
return (Throwable) method.invoke(throwable);
|
||||
} catch (IllegalAccessException ignored) { // NOPMD
|
||||
} catch (final IllegalAccessException ignored) { // NOPMD
|
||||
// exception ignored
|
||||
} catch (IllegalArgumentException ignored) { // NOPMD
|
||||
} catch (final IllegalArgumentException ignored) { // NOPMD
|
||||
// exception ignored
|
||||
} catch (InvocationTargetException ignored) { // NOPMD
|
||||
} catch (final InvocationTargetException ignored) { // NOPMD
|
||||
// exception ignored
|
||||
}
|
||||
}
|
||||
|
@ -254,7 +254,7 @@ public static int getThrowableCount(final Throwable throwable) {
|
|||
* @return the array of throwables, never null
|
||||
*/
|
||||
public static Throwable[] getThrowables(final Throwable throwable) {
|
||||
List<Throwable> list = getThrowableList(throwable);
|
||||
final List<Throwable> list = getThrowableList(throwable);
|
||||
return list.toArray(new Throwable[list.size()]);
|
||||
}
|
||||
|
||||
|
@ -278,7 +278,7 @@ public static Throwable[] getThrowables(final Throwable throwable) {
|
|||
* @since Commons Lang 2.2
|
||||
*/
|
||||
public static List<Throwable> getThrowableList(Throwable throwable) {
|
||||
List<Throwable> list = new ArrayList<Throwable>();
|
||||
final List<Throwable> list = new ArrayList<Throwable>();
|
||||
while (throwable != null && list.contains(throwable) == false) {
|
||||
list.add(throwable);
|
||||
throwable = ExceptionUtils.getCause(throwable);
|
||||
|
@ -390,7 +390,7 @@ private static int indexOf(final Throwable throwable, final Class<?> type, int f
|
|||
if (fromIndex < 0) {
|
||||
fromIndex = 0;
|
||||
}
|
||||
Throwable[] throwables = ExceptionUtils.getThrowables(throwable);
|
||||
final Throwable[] throwables = ExceptionUtils.getThrowables(throwable);
|
||||
if (fromIndex >= throwables.length) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -459,8 +459,8 @@ public static void printRootCauseStackTrace(final Throwable throwable, final Pri
|
|||
if (stream == null) {
|
||||
throw new IllegalArgumentException("The PrintStream must not be null");
|
||||
}
|
||||
String trace[] = getRootCauseStackTrace(throwable);
|
||||
for (String element : trace) {
|
||||
final String trace[] = getRootCauseStackTrace(throwable);
|
||||
for (final String element : trace) {
|
||||
stream.println(element);
|
||||
}
|
||||
stream.flush();
|
||||
|
@ -492,8 +492,8 @@ public static void printRootCauseStackTrace(final Throwable throwable, final Pri
|
|||
if (writer == null) {
|
||||
throw new IllegalArgumentException("The PrintWriter must not be null");
|
||||
}
|
||||
String trace[] = getRootCauseStackTrace(throwable);
|
||||
for (String element : trace) {
|
||||
final String trace[] = getRootCauseStackTrace(throwable);
|
||||
for (final String element : trace) {
|
||||
writer.println(element);
|
||||
}
|
||||
writer.flush();
|
||||
|
@ -517,12 +517,12 @@ public static String[] getRootCauseStackTrace(final Throwable throwable) {
|
|||
if (throwable == null) {
|
||||
return ArrayUtils.EMPTY_STRING_ARRAY;
|
||||
}
|
||||
Throwable throwables[] = getThrowables(throwable);
|
||||
int count = throwables.length;
|
||||
List<String> frames = new ArrayList<String>();
|
||||
final Throwable throwables[] = getThrowables(throwable);
|
||||
final int count = throwables.length;
|
||||
final List<String> frames = new ArrayList<String>();
|
||||
List<String> nextTrace = getStackFrameList(throwables[count - 1]);
|
||||
for (int i = count; --i >= 0;) {
|
||||
List<String> trace = nextTrace;
|
||||
final List<String> trace = nextTrace;
|
||||
if (i != 0) {
|
||||
nextTrace = getStackFrameList(throwables[i - 1]);
|
||||
removeCommonFrames(trace, nextTrace);
|
||||
|
@ -556,8 +556,8 @@ public static void removeCommonFrames(final List<String> causeFrames, final List
|
|||
while (causeFrameIndex >= 0 && wrapperFrameIndex >= 0) {
|
||||
// Remove the frame from the cause trace if it is the same
|
||||
// as in the wrapper trace
|
||||
String causeFrame = causeFrames.get(causeFrameIndex);
|
||||
String wrapperFrame = wrapperFrames.get(wrapperFrameIndex);
|
||||
final String causeFrame = causeFrames.get(causeFrameIndex);
|
||||
final String wrapperFrame = wrapperFrames.get(wrapperFrameIndex);
|
||||
if (causeFrame.equals(wrapperFrame)) {
|
||||
causeFrames.remove(causeFrameIndex);
|
||||
}
|
||||
|
@ -580,8 +580,8 @@ public static void removeCommonFrames(final List<String> causeFrames, final List
|
|||
* <code>printStackTrace(PrintWriter)</code> method
|
||||
*/
|
||||
public static String getStackTrace(final Throwable throwable) {
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw, true);
|
||||
final StringWriter sw = new StringWriter();
|
||||
final PrintWriter pw = new PrintWriter(sw, true);
|
||||
throwable.printStackTrace(pw);
|
||||
return sw.getBuffer().toString();
|
||||
}
|
||||
|
@ -616,9 +616,9 @@ public static String[] getStackFrames(final Throwable throwable) {
|
|||
* @return an array where each element is a line from the argument
|
||||
*/
|
||||
static String[] getStackFrames(final String stackTrace) {
|
||||
String linebreak = SystemUtils.LINE_SEPARATOR;
|
||||
StringTokenizer frames = new StringTokenizer(stackTrace, linebreak);
|
||||
List<String> list = new ArrayList<String>();
|
||||
final String linebreak = SystemUtils.LINE_SEPARATOR;
|
||||
final StringTokenizer frames = new StringTokenizer(stackTrace, linebreak);
|
||||
final List<String> list = new ArrayList<String>();
|
||||
while (frames.hasMoreTokens()) {
|
||||
list.add(frames.nextToken());
|
||||
}
|
||||
|
@ -638,15 +638,15 @@ static String[] getStackFrames(final String stackTrace) {
|
|||
* @return List of stack frames
|
||||
*/
|
||||
static List<String> getStackFrameList(final Throwable t) {
|
||||
String stackTrace = getStackTrace(t);
|
||||
String linebreak = SystemUtils.LINE_SEPARATOR;
|
||||
StringTokenizer frames = new StringTokenizer(stackTrace, linebreak);
|
||||
List<String> list = new ArrayList<String>();
|
||||
final String stackTrace = getStackTrace(t);
|
||||
final String linebreak = SystemUtils.LINE_SEPARATOR;
|
||||
final StringTokenizer frames = new StringTokenizer(stackTrace, linebreak);
|
||||
final List<String> list = new ArrayList<String>();
|
||||
boolean traceStarted = false;
|
||||
while (frames.hasMoreTokens()) {
|
||||
String token = frames.nextToken();
|
||||
final String token = frames.nextToken();
|
||||
// Determine if the line starts with <whitespace>at
|
||||
int at = token.indexOf("at");
|
||||
final int at = token.indexOf("at");
|
||||
if (at != -1 && token.substring(0, at).trim().isEmpty()) {
|
||||
traceStarted = true;
|
||||
list.add(token);
|
||||
|
@ -672,8 +672,8 @@ public static String getMessage(final Throwable th) {
|
|||
if (th == null) {
|
||||
return "";
|
||||
}
|
||||
String clsName = ClassUtils.getShortClassName(th, null);
|
||||
String msg = th.getMessage();
|
||||
final String clsName = ClassUtils.getShortClassName(th, null);
|
||||
final String msg = th.getMessage();
|
||||
return clsName + ": " + StringUtils.defaultString(msg);
|
||||
}
|
||||
|
||||
|
|
|
@ -226,7 +226,7 @@ public static Fraction getReducedFraction(int numerator, int denominator) {
|
|||
denominator = -denominator;
|
||||
}
|
||||
// simplify fraction.
|
||||
int gcd = greatestCommonDivisor(numerator, denominator);
|
||||
final int gcd = greatestCommonDivisor(numerator, denominator);
|
||||
numerator /= gcd;
|
||||
denominator /= gcd;
|
||||
return new Fraction(numerator, denominator);
|
||||
|
@ -247,13 +247,13 @@ public static Fraction getReducedFraction(int numerator, int denominator) {
|
|||
* @throws ArithmeticException if the the algorithm does not converge
|
||||
*/
|
||||
public static Fraction getFraction(double value) {
|
||||
int sign = value < 0 ? -1 : 1;
|
||||
final int sign = value < 0 ? -1 : 1;
|
||||
value = Math.abs(value);
|
||||
if (value > Integer.MAX_VALUE || Double.isNaN(value)) {
|
||||
throw new ArithmeticException
|
||||
("The value must not be greater than Integer.MAX_VALUE or NaN");
|
||||
}
|
||||
int wholeNumber = (int) value;
|
||||
final int wholeNumber = (int) value;
|
||||
value -= wholeNumber;
|
||||
|
||||
int numer0 = 0; // the pre-previous
|
||||
|
@ -329,14 +329,14 @@ public static Fraction getFraction(String str) {
|
|||
// parse X Y/Z format
|
||||
pos = str.indexOf(' ');
|
||||
if (pos > 0) {
|
||||
int whole = Integer.parseInt(str.substring(0, pos));
|
||||
final int whole = Integer.parseInt(str.substring(0, pos));
|
||||
str = str.substring(pos + 1);
|
||||
pos = str.indexOf('/');
|
||||
if (pos < 0) {
|
||||
throw new NumberFormatException("The fraction could not be parsed as the format X Y/Z");
|
||||
} else {
|
||||
int numer = Integer.parseInt(str.substring(0, pos));
|
||||
int denom = Integer.parseInt(str.substring(pos + 1));
|
||||
final int numer = Integer.parseInt(str.substring(0, pos));
|
||||
final int denom = Integer.parseInt(str.substring(pos + 1));
|
||||
return getFraction(whole, numer, denom);
|
||||
}
|
||||
}
|
||||
|
@ -347,8 +347,8 @@ public static Fraction getFraction(String str) {
|
|||
// simple whole number
|
||||
return getFraction(Integer.parseInt(str), 1);
|
||||
} else {
|
||||
int numer = Integer.parseInt(str.substring(0, pos));
|
||||
int denom = Integer.parseInt(str.substring(pos + 1));
|
||||
final int numer = Integer.parseInt(str.substring(0, pos));
|
||||
final int denom = Integer.parseInt(str.substring(pos + 1));
|
||||
return getFraction(numer, denom);
|
||||
}
|
||||
}
|
||||
|
@ -470,7 +470,7 @@ public Fraction reduce() {
|
|||
if (numerator == 0) {
|
||||
return equals(ZERO) ? this : ZERO;
|
||||
}
|
||||
int gcd = greatestCommonDivisor(Math.abs(numerator), denominator);
|
||||
final int gcd = greatestCommonDivisor(Math.abs(numerator), denominator);
|
||||
if (gcd == 1) {
|
||||
return this;
|
||||
}
|
||||
|
@ -554,7 +554,7 @@ public Fraction pow(final int power) {
|
|||
}
|
||||
return this.invert().pow(-power);
|
||||
} else {
|
||||
Fraction f = this.multiplyBy(this);
|
||||
final Fraction f = this.multiplyBy(this);
|
||||
if (power % 2 == 0) { // if even...
|
||||
return f.pow(power/2);
|
||||
} else { // if odd...
|
||||
|
@ -637,7 +637,7 @@ private static int greatestCommonDivisor(int u, int v) {
|
|||
* an int
|
||||
*/
|
||||
private static int mulAndCheck(final int x, final int y) {
|
||||
long m = (long)x*(long)y;
|
||||
final long m = (long)x*(long)y;
|
||||
if (m < Integer.MIN_VALUE ||
|
||||
m > Integer.MAX_VALUE) {
|
||||
throw new ArithmeticException("overflow: mul");
|
||||
|
@ -656,7 +656,7 @@ private static int mulAndCheck(final int x, final int y) {
|
|||
*/
|
||||
private static int mulPosAndCheck(final int x, final int y) {
|
||||
/* assert x>=0 && y>=0; */
|
||||
long m = (long)x*(long)y;
|
||||
final long m = (long)x*(long)y;
|
||||
if (m > Integer.MAX_VALUE) {
|
||||
throw new ArithmeticException("overflow: mulPos");
|
||||
}
|
||||
|
@ -673,7 +673,7 @@ private static int mulPosAndCheck(final int x, final int y) {
|
|||
* an int
|
||||
*/
|
||||
private static int addAndCheck(final int x, final int y) {
|
||||
long s = (long)x+(long)y;
|
||||
final long s = (long)x+(long)y;
|
||||
if (s < Integer.MIN_VALUE ||
|
||||
s > Integer.MAX_VALUE) {
|
||||
throw new ArithmeticException("overflow: add");
|
||||
|
@ -691,7 +691,7 @@ private static int addAndCheck(final int x, final int y) {
|
|||
* an int
|
||||
*/
|
||||
private static int subAndCheck(final int x, final int y) {
|
||||
long s = (long)x-(long)y;
|
||||
final long s = (long)x-(long)y;
|
||||
if (s < Integer.MIN_VALUE ||
|
||||
s > Integer.MAX_VALUE) {
|
||||
throw new ArithmeticException("overflow: add");
|
||||
|
@ -750,11 +750,11 @@ private Fraction addSub(final Fraction fraction, final boolean isAdd) {
|
|||
}
|
||||
// if denominators are randomly distributed, d1 will be 1 about 61%
|
||||
// of the time.
|
||||
int d1 = greatestCommonDivisor(denominator, fraction.denominator);
|
||||
final int d1 = greatestCommonDivisor(denominator, fraction.denominator);
|
||||
if (d1==1) {
|
||||
// result is ( (u*v' +/- u'v) / u'v')
|
||||
int uvp = mulAndCheck(numerator, fraction.denominator);
|
||||
int upv = mulAndCheck(fraction.numerator, denominator);
|
||||
final int uvp = mulAndCheck(numerator, fraction.denominator);
|
||||
final int upv = mulAndCheck(fraction.numerator, denominator);
|
||||
return new Fraction
|
||||
(isAdd ? addAndCheck(uvp, upv) : subAndCheck(uvp, upv),
|
||||
mulPosAndCheck(denominator, fraction.denominator));
|
||||
|
@ -762,18 +762,18 @@ private Fraction addSub(final Fraction fraction, final boolean isAdd) {
|
|||
// the quantity 't' requires 65 bits of precision; see knuth 4.5.1
|
||||
// exercise 7. we're going to use a BigInteger.
|
||||
// t = u(v'/d1) +/- v(u'/d1)
|
||||
BigInteger uvp = BigInteger.valueOf(numerator)
|
||||
final BigInteger uvp = BigInteger.valueOf(numerator)
|
||||
.multiply(BigInteger.valueOf(fraction.denominator/d1));
|
||||
BigInteger upv = BigInteger.valueOf(fraction.numerator)
|
||||
final BigInteger upv = BigInteger.valueOf(fraction.numerator)
|
||||
.multiply(BigInteger.valueOf(denominator/d1));
|
||||
BigInteger t = isAdd ? uvp.add(upv) : uvp.subtract(upv);
|
||||
final BigInteger t = isAdd ? uvp.add(upv) : uvp.subtract(upv);
|
||||
// but d2 doesn't need extra precision because
|
||||
// d2 = gcd(t,d1) = gcd(t mod d1, d1)
|
||||
int tmodd1 = t.mod(BigInteger.valueOf(d1)).intValue();
|
||||
int d2 = tmodd1==0?d1:greatestCommonDivisor(tmodd1, d1);
|
||||
final int tmodd1 = t.mod(BigInteger.valueOf(d1)).intValue();
|
||||
final int d2 = tmodd1==0?d1:greatestCommonDivisor(tmodd1, d1);
|
||||
|
||||
// result is (t/d2) / (u'/d1)(v'/d2)
|
||||
BigInteger w = t.divide(BigInteger.valueOf(d2));
|
||||
final BigInteger w = t.divide(BigInteger.valueOf(d2));
|
||||
if (w.bitLength() > 31) {
|
||||
throw new ArithmeticException
|
||||
("overflow: numerator too large after multiply");
|
||||
|
@ -802,8 +802,8 @@ public Fraction multiplyBy(final Fraction fraction) {
|
|||
}
|
||||
// knuth 4.5.1
|
||||
// make sure we don't overflow unless the result *must* overflow.
|
||||
int d1 = greatestCommonDivisor(numerator, fraction.denominator);
|
||||
int d2 = greatestCommonDivisor(fraction.numerator, denominator);
|
||||
final int d1 = greatestCommonDivisor(numerator, fraction.denominator);
|
||||
final int d2 = greatestCommonDivisor(fraction.numerator, denominator);
|
||||
return getReducedFraction
|
||||
(mulAndCheck(numerator/d1, fraction.numerator/d2),
|
||||
mulPosAndCheck(denominator/d2, fraction.denominator/d1));
|
||||
|
@ -848,7 +848,7 @@ public boolean equals(final Object obj) {
|
|||
if (obj instanceof Fraction == false) {
|
||||
return false;
|
||||
}
|
||||
Fraction other = (Fraction) obj;
|
||||
final Fraction other = (Fraction) obj;
|
||||
return getNumerator() == other.getNumerator() &&
|
||||
getDenominator() == other.getDenominator();
|
||||
}
|
||||
|
@ -889,8 +889,8 @@ public int compareTo(final Fraction other) {
|
|||
}
|
||||
|
||||
// otherwise see which is less
|
||||
long first = (long) numerator * (long) other.denominator;
|
||||
long second = (long) other.numerator * (long) denominator;
|
||||
final long first = (long) numerator * (long) other.denominator;
|
||||
final long second = (long) other.numerator * (long) denominator;
|
||||
if (first == second) {
|
||||
return 0;
|
||||
} else if (first < second) {
|
||||
|
@ -940,7 +940,7 @@ public String toProperString() {
|
|||
// NEGATIVE (not positive) numbers, since negative numbers
|
||||
// have a larger range. otherwise numerator==Integer.MIN_VALUE
|
||||
// is handled incorrectly.
|
||||
int properNumerator = getProperNumerator();
|
||||
final int properNumerator = getProperNumerator();
|
||||
if (properNumerator == 0) {
|
||||
toProperString = Integer.toString(getProperWhole());
|
||||
} else {
|
||||
|
|
|
@ -123,7 +123,7 @@ public static int toInt(final String str, final int defaultValue) {
|
|||
}
|
||||
try {
|
||||
return Integer.parseInt(str);
|
||||
} catch (NumberFormatException nfe) {
|
||||
} catch (final NumberFormatException nfe) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
@ -172,7 +172,7 @@ public static long toLong(final String str, final long defaultValue) {
|
|||
}
|
||||
try {
|
||||
return Long.parseLong(str);
|
||||
} catch (NumberFormatException nfe) {
|
||||
} catch (final NumberFormatException nfe) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
@ -224,7 +224,7 @@ public static float toFloat(final String str, final float defaultValue) {
|
|||
}
|
||||
try {
|
||||
return Float.parseFloat(str);
|
||||
} catch (NumberFormatException nfe) {
|
||||
} catch (final NumberFormatException nfe) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
@ -276,7 +276,7 @@ public static double toDouble(final String str, final double defaultValue) {
|
|||
}
|
||||
try {
|
||||
return Double.parseDouble(str);
|
||||
} catch (NumberFormatException nfe) {
|
||||
} catch (final NumberFormatException nfe) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
@ -326,7 +326,7 @@ public static byte toByte(final String str, final byte defaultValue) {
|
|||
}
|
||||
try {
|
||||
return Byte.parseByte(str);
|
||||
} catch (NumberFormatException nfe) {
|
||||
} catch (final NumberFormatException nfe) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
@ -375,7 +375,7 @@ public static short toShort(final String str, final short defaultValue) {
|
|||
}
|
||||
try {
|
||||
return Short.parseShort(str);
|
||||
} catch (NumberFormatException nfe) {
|
||||
} catch (final NumberFormatException nfe) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
@ -453,14 +453,14 @@ public static Number createNumber(final String str) throws NumberFormatException
|
|||
// Need to deal with all possible hex prefixes here
|
||||
final String[] hex_prefixes = {"0x", "0X", "-0x", "-0X", "#", "-#"};
|
||||
int pfxLen = 0;
|
||||
for(String pfx : hex_prefixes) {
|
||||
for(final String pfx : hex_prefixes) {
|
||||
if (str.startsWith(pfx)) {
|
||||
pfxLen += pfx.length();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (pfxLen > 0) {
|
||||
int hexDigits = str.length() - pfxLen;
|
||||
final int hexDigits = str.length() - pfxLen;
|
||||
if (hexDigits > 16) { // too many for Long
|
||||
return createBigInteger(str);
|
||||
}
|
||||
|
@ -469,12 +469,12 @@ public static Number createNumber(final String str) throws NumberFormatException
|
|||
}
|
||||
return createInteger(str);
|
||||
}
|
||||
char lastChar = str.charAt(str.length() - 1);
|
||||
final char lastChar = str.charAt(str.length() - 1);
|
||||
String mant;
|
||||
String dec;
|
||||
String exp;
|
||||
int decPos = str.indexOf('.');
|
||||
int expPos = str.indexOf('e') + str.indexOf('E') + 1;
|
||||
final int decPos = str.indexOf('.');
|
||||
final int expPos = str.indexOf('e') + str.indexOf('E') + 1;
|
||||
|
||||
if (decPos > -1) {
|
||||
|
||||
|
@ -505,8 +505,8 @@ public static Number createNumber(final String str) throws NumberFormatException
|
|||
exp = null;
|
||||
}
|
||||
//Requesting a specific type..
|
||||
String numeric = str.substring(0, str.length() - 1);
|
||||
boolean allZeros = isAllZeros(mant) && isAllZeros(exp);
|
||||
final String numeric = str.substring(0, str.length() - 1);
|
||||
final boolean allZeros = isAllZeros(mant) && isAllZeros(exp);
|
||||
switch (lastChar) {
|
||||
case 'l' :
|
||||
case 'L' :
|
||||
|
@ -515,7 +515,7 @@ public static Number createNumber(final String str) throws NumberFormatException
|
|||
&& (numeric.charAt(0) == '-' && isDigits(numeric.substring(1)) || isDigits(numeric))) {
|
||||
try {
|
||||
return createLong(numeric);
|
||||
} catch (NumberFormatException nfe) { // NOPMD
|
||||
} catch (final NumberFormatException nfe) { // NOPMD
|
||||
// Too big for a long
|
||||
}
|
||||
return createBigInteger(numeric);
|
||||
|
@ -525,30 +525,30 @@ public static Number createNumber(final String str) throws NumberFormatException
|
|||
case 'f' :
|
||||
case 'F' :
|
||||
try {
|
||||
Float f = NumberUtils.createFloat(numeric);
|
||||
final Float f = NumberUtils.createFloat(numeric);
|
||||
if (!(f.isInfinite() || (f.floatValue() == 0.0F && !allZeros))) {
|
||||
//If it's too big for a float or the float value = 0 and the string
|
||||
//has non-zeros in it, then float does not have the precision we want
|
||||
return f;
|
||||
}
|
||||
|
||||
} catch (NumberFormatException nfe) { // NOPMD
|
||||
} catch (final NumberFormatException nfe) { // NOPMD
|
||||
// ignore the bad number
|
||||
}
|
||||
//$FALL-THROUGH$
|
||||
case 'd' :
|
||||
case 'D' :
|
||||
try {
|
||||
Double d = NumberUtils.createDouble(numeric);
|
||||
final Double d = NumberUtils.createDouble(numeric);
|
||||
if (!(d.isInfinite() || (d.floatValue() == 0.0D && !allZeros))) {
|
||||
return d;
|
||||
}
|
||||
} catch (NumberFormatException nfe) { // NOPMD
|
||||
} catch (final NumberFormatException nfe) { // NOPMD
|
||||
// ignore the bad number
|
||||
}
|
||||
try {
|
||||
return createBigDecimal(numeric);
|
||||
} catch (NumberFormatException e) { // NOPMD
|
||||
} catch (final NumberFormatException e) { // NOPMD
|
||||
// ignore the bad number
|
||||
}
|
||||
//$FALL-THROUGH$
|
||||
|
@ -568,33 +568,33 @@ public static Number createNumber(final String str) throws NumberFormatException
|
|||
//Must be an int,long,bigint
|
||||
try {
|
||||
return createInteger(str);
|
||||
} catch (NumberFormatException nfe) { // NOPMD
|
||||
} catch (final NumberFormatException nfe) { // NOPMD
|
||||
// ignore the bad number
|
||||
}
|
||||
try {
|
||||
return createLong(str);
|
||||
} catch (NumberFormatException nfe) { // NOPMD
|
||||
} catch (final NumberFormatException nfe) { // NOPMD
|
||||
// ignore the bad number
|
||||
}
|
||||
return createBigInteger(str);
|
||||
|
||||
} else {
|
||||
//Must be a float,double,BigDec
|
||||
boolean allZeros = isAllZeros(mant) && isAllZeros(exp);
|
||||
final boolean allZeros = isAllZeros(mant) && isAllZeros(exp);
|
||||
try {
|
||||
Float f = createFloat(str);
|
||||
final Float f = createFloat(str);
|
||||
if (!(f.isInfinite() || (f.floatValue() == 0.0F && !allZeros))) {
|
||||
return f;
|
||||
}
|
||||
} catch (NumberFormatException nfe) { // NOPMD
|
||||
} catch (final NumberFormatException nfe) { // NOPMD
|
||||
// ignore the bad number
|
||||
}
|
||||
try {
|
||||
Double d = createDouble(str);
|
||||
final Double d = createDouble(str);
|
||||
if (!(d.isInfinite() || (d.doubleValue() == 0.0D && !allZeros))) {
|
||||
return d;
|
||||
}
|
||||
} catch (NumberFormatException nfe) { // NOPMD
|
||||
} catch (final NumberFormatException nfe) { // NOPMD
|
||||
// ignore the bad number
|
||||
}
|
||||
|
||||
|
@ -1311,14 +1311,14 @@ public static boolean isNumber(final String str) {
|
|||
if (StringUtils.isEmpty(str)) {
|
||||
return false;
|
||||
}
|
||||
char[] chars = str.toCharArray();
|
||||
final char[] chars = str.toCharArray();
|
||||
int sz = chars.length;
|
||||
boolean hasExp = false;
|
||||
boolean hasDecPoint = false;
|
||||
boolean allowSigns = false;
|
||||
boolean foundDigit = false;
|
||||
// deal with any possible sign up front
|
||||
int start = (chars[0] == '-') ? 1 : 0;
|
||||
final int start = (chars[0] == '-') ? 1 : 0;
|
||||
if (sz > start + 1 && chars[start] == '0' && chars[start + 1] == 'x') {
|
||||
int i = start + 2;
|
||||
if (i == sz) {
|
||||
|
|
|
@ -178,7 +178,7 @@ public int hashCode() {
|
|||
*/
|
||||
@Override
|
||||
public int compareTo(final MutableBoolean other) {
|
||||
boolean anotherVal = other.value;
|
||||
final boolean anotherVal = other.value;
|
||||
return value == anotherVal ? 0 : (value ? 1 : -1);
|
||||
}
|
||||
|
||||
|
|
|
@ -268,7 +268,7 @@ public int hashCode() {
|
|||
*/
|
||||
@Override
|
||||
public int compareTo(final MutableByte other) {
|
||||
byte anotherVal = other.value;
|
||||
final byte anotherVal = other.value;
|
||||
return value < anotherVal ? -1 : (value == anotherVal ? 0 : 1);
|
||||
}
|
||||
|
||||
|
|
|
@ -284,7 +284,7 @@ public boolean equals(final Object obj) {
|
|||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
long bits = Double.doubleToLongBits(value);
|
||||
final long bits = Double.doubleToLongBits(value);
|
||||
return (int) (bits ^ bits >>> 32);
|
||||
}
|
||||
|
||||
|
@ -297,7 +297,7 @@ public int hashCode() {
|
|||
*/
|
||||
@Override
|
||||
public int compareTo(final MutableDouble other) {
|
||||
double anotherVal = other.value;
|
||||
final double anotherVal = other.value;
|
||||
return Double.compare(value, anotherVal);
|
||||
}
|
||||
|
||||
|
|
|
@ -298,7 +298,7 @@ public int hashCode() {
|
|||
*/
|
||||
@Override
|
||||
public int compareTo(final MutableFloat other) {
|
||||
float anotherVal = other.value;
|
||||
final float anotherVal = other.value;
|
||||
return Float.compare(value, anotherVal);
|
||||
}
|
||||
|
||||
|
|
|
@ -258,7 +258,7 @@ public int hashCode() {
|
|||
*/
|
||||
@Override
|
||||
public int compareTo(final MutableInt other) {
|
||||
int anotherVal = other.value;
|
||||
final int anotherVal = other.value;
|
||||
return value < anotherVal ? -1 : (value == anotherVal ? 0 : 1);
|
||||
}
|
||||
|
||||
|
|
|
@ -258,7 +258,7 @@ public int hashCode() {
|
|||
*/
|
||||
@Override
|
||||
public int compareTo(final MutableLong other) {
|
||||
long anotherVal = other.value;
|
||||
final long anotherVal = other.value;
|
||||
return value < anotherVal ? -1 : (value == anotherVal ? 0 : 1);
|
||||
}
|
||||
|
||||
|
|
|
@ -97,7 +97,7 @@ public boolean equals(final Object obj) {
|
|||
return true;
|
||||
}
|
||||
if (this.getClass() == obj.getClass()) {
|
||||
MutableObject<?> that = (MutableObject<?>) obj;
|
||||
final MutableObject<?> that = (MutableObject<?>) obj;
|
||||
return this.value.equals(that.value);
|
||||
} else {
|
||||
return false;
|
||||
|
|
|
@ -268,7 +268,7 @@ public int hashCode() {
|
|||
*/
|
||||
@Override
|
||||
public int compareTo(final MutableShort other) {
|
||||
short anotherVal = other.value;
|
||||
final short anotherVal = other.value;
|
||||
return value < anotherVal ? -1 : (value == anotherVal ? 0 : 1);
|
||||
}
|
||||
|
||||
|
|
|
@ -81,7 +81,7 @@ public static <T> T invokeConstructor(final Class<T> cls, Object... args)
|
|||
if (args == null) {
|
||||
args = ArrayUtils.EMPTY_OBJECT_ARRAY;
|
||||
}
|
||||
Class<?> parameterTypes[] = ClassUtils.toClass(args);
|
||||
final Class<?> parameterTypes[] = ClassUtils.toClass(args);
|
||||
return invokeConstructor(cls, args, parameterTypes);
|
||||
}
|
||||
|
||||
|
@ -113,7 +113,7 @@ public static <T> T invokeConstructor(final Class<T> cls, Object[] args, Class<?
|
|||
if (args == null) {
|
||||
args = ArrayUtils.EMPTY_OBJECT_ARRAY;
|
||||
}
|
||||
Constructor<T> ctor = getMatchingAccessibleConstructor(cls, parameterTypes);
|
||||
final Constructor<T> ctor = getMatchingAccessibleConstructor(cls, parameterTypes);
|
||||
if (ctor == null) {
|
||||
throw new NoSuchMethodException(
|
||||
"No such accessible constructor on object: " + cls.getName());
|
||||
|
@ -145,7 +145,7 @@ public static <T> T invokeExactConstructor(final Class<T> cls, Object... args)
|
|||
if (args == null) {
|
||||
args = ArrayUtils.EMPTY_OBJECT_ARRAY;
|
||||
}
|
||||
Class<?> parameterTypes[] = ClassUtils.toClass(args);
|
||||
final Class<?> parameterTypes[] = ClassUtils.toClass(args);
|
||||
return invokeExactConstructor(cls, args, parameterTypes);
|
||||
}
|
||||
|
||||
|
@ -177,7 +177,7 @@ public static <T> T invokeExactConstructor(final Class<T> cls, Object[] args,
|
|||
if (parameterTypes == null) {
|
||||
parameterTypes = ArrayUtils.EMPTY_CLASS_ARRAY;
|
||||
}
|
||||
Constructor<T> ctor = getAccessibleConstructor(cls, parameterTypes);
|
||||
final Constructor<T> ctor = getAccessibleConstructor(cls, parameterTypes);
|
||||
if (ctor == null) {
|
||||
throw new NoSuchMethodException(
|
||||
"No such accessible constructor on object: "+ cls.getName());
|
||||
|
@ -203,7 +203,7 @@ public static <T> Constructor<T> getAccessibleConstructor(final Class<T> cls,
|
|||
final Class<?>... parameterTypes) {
|
||||
try {
|
||||
return getAccessibleConstructor(cls.getConstructor(parameterTypes));
|
||||
} catch (NoSuchMethodException e) {
|
||||
} catch (final NoSuchMethodException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -245,17 +245,17 @@ public static <T> Constructor<T> getMatchingAccessibleConstructor(final Class<T>
|
|||
// see if we can find the constructor directly
|
||||
// most of the time this works and it's much faster
|
||||
try {
|
||||
Constructor<T> ctor = cls.getConstructor(parameterTypes);
|
||||
final Constructor<T> ctor = cls.getConstructor(parameterTypes);
|
||||
MemberUtils.setAccessibleWorkaround(ctor);
|
||||
return ctor;
|
||||
} catch (NoSuchMethodException e) { // NOPMD - Swallow
|
||||
} catch (final NoSuchMethodException e) { // NOPMD - Swallow
|
||||
}
|
||||
Constructor<T> result = null;
|
||||
/*
|
||||
* (1) Class.getConstructors() is documented to return Constructor<T> so as
|
||||
* long as the array is not subsequently modified, everything's fine.
|
||||
*/
|
||||
Constructor<?>[] ctors = cls.getConstructors();
|
||||
final Constructor<?>[] ctors = cls.getConstructors();
|
||||
|
||||
// return best match:
|
||||
for (Constructor<?> ctor : ctors) {
|
||||
|
@ -270,6 +270,7 @@ public static <T> Constructor<T> getMatchingAccessibleConstructor(final Class<T>
|
|||
.getParameterTypes(), parameterTypes) < 0) {
|
||||
// temporary variable for annotation, see comment above (1)
|
||||
@SuppressWarnings("unchecked")
|
||||
final
|
||||
Constructor<T> constructor = (Constructor<T>)ctor;
|
||||
result = constructor;
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ public FieldUtils() {
|
|||
* @throws IllegalArgumentException if the class or field name is null
|
||||
*/
|
||||
public static Field getField(final Class<?> cls, final String fieldName) {
|
||||
Field field = getField(cls, fieldName, false);
|
||||
final Field field = getField(cls, fieldName, false);
|
||||
MemberUtils.setAccessibleWorkaround(field);
|
||||
return field;
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ public static Field getField(final Class<?> cls, final String fieldName, final b
|
|||
// check up the superclass hierarchy
|
||||
for (Class<?> acls = cls; acls != null; acls = acls.getSuperclass()) {
|
||||
try {
|
||||
Field field = acls.getDeclaredField(fieldName);
|
||||
final Field field = acls.getDeclaredField(fieldName);
|
||||
// getDeclaredField checks for non-public scopes as well
|
||||
// and it returns accurate results
|
||||
if (!Modifier.isPublic(field.getModifiers())) {
|
||||
|
@ -105,7 +105,7 @@ public static Field getField(final Class<?> cls, final String fieldName, final b
|
|||
}
|
||||
}
|
||||
return field;
|
||||
} catch (NoSuchFieldException ex) { // NOPMD
|
||||
} catch (final NoSuchFieldException ex) { // NOPMD
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
@ -113,15 +113,15 @@ public static Field getField(final Class<?> cls, final String fieldName, final b
|
|||
// incase there is a public supersuperclass field hidden by a private/package
|
||||
// superclass field.
|
||||
Field match = null;
|
||||
for (Class<?> class1 : ClassUtils.getAllInterfaces(cls)) {
|
||||
for (final Class<?> class1 : ClassUtils.getAllInterfaces(cls)) {
|
||||
try {
|
||||
Field test = ((Class<?>) class1).getField(fieldName);
|
||||
final Field test = ((Class<?>) class1).getField(fieldName);
|
||||
if (match != null) {
|
||||
throw new IllegalArgumentException("Reference to field " + fieldName + " is ambiguous relative to " + cls
|
||||
+ "; a matching field exists on two or more implemented interfaces.");
|
||||
}
|
||||
match = test;
|
||||
} catch (NoSuchFieldException ex) { // NOPMD
|
||||
} catch (final NoSuchFieldException ex) { // NOPMD
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
@ -161,7 +161,7 @@ public static Field getDeclaredField(final Class<?> cls, final String fieldName,
|
|||
}
|
||||
try {
|
||||
// only consider the specified class by using getDeclaredField()
|
||||
Field field = cls.getDeclaredField(fieldName);
|
||||
final Field field = cls.getDeclaredField(fieldName);
|
||||
if (!MemberUtils.isAccessible(field)) {
|
||||
if (forceAccess) {
|
||||
field.setAccessible(true);
|
||||
|
@ -170,7 +170,7 @@ public static Field getDeclaredField(final Class<?> cls, final String fieldName,
|
|||
}
|
||||
}
|
||||
return field;
|
||||
} catch (NoSuchFieldException e) { // NOPMD
|
||||
} catch (final NoSuchFieldException e) { // NOPMD
|
||||
// ignore
|
||||
}
|
||||
return null;
|
||||
|
@ -231,7 +231,7 @@ public static Object readStaticField(final Class<?> cls, final String fieldName)
|
|||
*/
|
||||
public static Object readStaticField(final Class<?> cls, final String fieldName, final boolean forceAccess)
|
||||
throws IllegalAccessException {
|
||||
Field field = getField(cls, fieldName, forceAccess);
|
||||
final Field field = getField(cls, fieldName, forceAccess);
|
||||
if (field == null) {
|
||||
throw new IllegalArgumentException("Cannot locate field " + fieldName + " on " + cls);
|
||||
}
|
||||
|
@ -268,7 +268,7 @@ public static Object readDeclaredStaticField(final Class<?> cls, final String fi
|
|||
*/
|
||||
public static Object readDeclaredStaticField(final Class<?> cls, final String fieldName, final boolean forceAccess)
|
||||
throws IllegalAccessException {
|
||||
Field field = getDeclaredField(cls, fieldName, forceAccess);
|
||||
final Field field = getDeclaredField(cls, fieldName, forceAccess);
|
||||
if (field == null) {
|
||||
throw new IllegalArgumentException("Cannot locate declared field " + cls.getName() + "." + fieldName);
|
||||
}
|
||||
|
@ -337,8 +337,8 @@ public static Object readField(final Object target, final String fieldName, fina
|
|||
if (target == null) {
|
||||
throw new IllegalArgumentException("target object must not be null");
|
||||
}
|
||||
Class<?> cls = target.getClass();
|
||||
Field field = getField(cls, fieldName, forceAccess);
|
||||
final Class<?> cls = target.getClass();
|
||||
final Field field = getField(cls, fieldName, forceAccess);
|
||||
if (field == null) {
|
||||
throw new IllegalArgumentException("Cannot locate field " + fieldName + " on " + cls);
|
||||
}
|
||||
|
@ -376,8 +376,8 @@ public static Object readDeclaredField(final Object target, final String fieldNa
|
|||
if (target == null) {
|
||||
throw new IllegalArgumentException("target object must not be null");
|
||||
}
|
||||
Class<?> cls = target.getClass();
|
||||
Field field = getDeclaredField(cls, fieldName, forceAccess);
|
||||
final Class<?> cls = target.getClass();
|
||||
final Field field = getDeclaredField(cls, fieldName, forceAccess);
|
||||
if (field == null) {
|
||||
throw new IllegalArgumentException("Cannot locate declared field " + cls.getName() + "." + fieldName);
|
||||
}
|
||||
|
@ -441,7 +441,7 @@ public static void writeStaticField(final Class<?> cls, final String fieldName,
|
|||
*/
|
||||
public static void writeStaticField(final Class<?> cls, final String fieldName, final Object value, final boolean forceAccess)
|
||||
throws IllegalAccessException {
|
||||
Field field = getField(cls, fieldName, forceAccess);
|
||||
final Field field = getField(cls, fieldName, forceAccess);
|
||||
if (field == null) {
|
||||
throw new IllegalArgumentException("Cannot locate field " + fieldName + " on " + cls);
|
||||
}
|
||||
|
@ -475,7 +475,7 @@ public static void writeDeclaredStaticField(final Class<?> cls, final String fie
|
|||
*/
|
||||
public static void writeDeclaredStaticField(final Class<?> cls, final String fieldName, final Object value, final boolean forceAccess)
|
||||
throws IllegalAccessException {
|
||||
Field field = getDeclaredField(cls, fieldName, forceAccess);
|
||||
final Field field = getDeclaredField(cls, fieldName, forceAccess);
|
||||
if (field == null) {
|
||||
throw new IllegalArgumentException("Cannot locate declared field " + cls.getName() + "." + fieldName);
|
||||
}
|
||||
|
@ -547,8 +547,8 @@ public static void writeField(final Object target, final String fieldName, final
|
|||
if (target == null) {
|
||||
throw new IllegalArgumentException("target object must not be null");
|
||||
}
|
||||
Class<?> cls = target.getClass();
|
||||
Field field = getField(cls, fieldName, forceAccess);
|
||||
final Class<?> cls = target.getClass();
|
||||
final Field field = getField(cls, fieldName, forceAccess);
|
||||
if (field == null) {
|
||||
throw new IllegalArgumentException("Cannot locate declared field " + cls.getName() + "." + fieldName);
|
||||
}
|
||||
|
@ -584,8 +584,8 @@ public static void writeDeclaredField(final Object target, final String fieldNam
|
|||
if (target == null) {
|
||||
throw new IllegalArgumentException("target object must not be null");
|
||||
}
|
||||
Class<?> cls = target.getClass();
|
||||
Field field = getDeclaredField(cls, fieldName, forceAccess);
|
||||
final Class<?> cls = target.getClass();
|
||||
final Field field = getDeclaredField(cls, fieldName, forceAccess);
|
||||
if (field == null) {
|
||||
throw new IllegalArgumentException("Cannot locate declared field " + cls.getName() + "." + fieldName);
|
||||
}
|
||||
|
|
|
@ -55,12 +55,12 @@ static void setAccessibleWorkaround(final AccessibleObject o) {
|
|||
if (o == null || o.isAccessible()) {
|
||||
return;
|
||||
}
|
||||
Member m = (Member) o;
|
||||
final Member m = (Member) o;
|
||||
if (Modifier.isPublic(m.getModifiers())
|
||||
&& isPackageAccess(m.getDeclaringClass().getModifiers())) {
|
||||
try {
|
||||
o.setAccessible(true);
|
||||
} catch (SecurityException e) { // NOPMD
|
||||
} catch (final SecurityException e) { // NOPMD
|
||||
// ignore in favor of subsequent IllegalAccessException
|
||||
}
|
||||
}
|
||||
|
@ -97,8 +97,8 @@ static boolean isAccessible(final Member m) {
|
|||
* @return int consistent with <code>compare</code> semantics
|
||||
*/
|
||||
static int compareParameterTypes(final Class<?>[] left, final Class<?>[] right, final Class<?>[] actual) {
|
||||
float leftCost = getTotalTransformationCost(actual, left);
|
||||
float rightCost = getTotalTransformationCost(actual, right);
|
||||
final float leftCost = getTotalTransformationCost(actual, left);
|
||||
final float rightCost = getTotalTransformationCost(actual, right);
|
||||
return leftCost < rightCost ? -1 : rightCost < leftCost ? 1 : 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -86,7 +86,7 @@ public static Object invokeMethod(final Object object, final String methodName,
|
|||
if (args == null) {
|
||||
args = ArrayUtils.EMPTY_OBJECT_ARRAY;
|
||||
}
|
||||
Class<?>[] parameterTypes = ClassUtils.toClass(args);
|
||||
final Class<?>[] parameterTypes = ClassUtils.toClass(args);
|
||||
return invokeMethod(object, methodName, args, parameterTypes);
|
||||
}
|
||||
|
||||
|
@ -119,7 +119,7 @@ public static Object invokeMethod(final Object object, final String methodName,
|
|||
if (args == null) {
|
||||
args = ArrayUtils.EMPTY_OBJECT_ARRAY;
|
||||
}
|
||||
Method method = getMatchingAccessibleMethod(object.getClass(),
|
||||
final Method method = getMatchingAccessibleMethod(object.getClass(),
|
||||
methodName, parameterTypes);
|
||||
if (method == null) {
|
||||
throw new NoSuchMethodException("No such accessible method: "
|
||||
|
@ -153,7 +153,7 @@ public static Object invokeExactMethod(final Object object, final String methodN
|
|||
if (args == null) {
|
||||
args = ArrayUtils.EMPTY_OBJECT_ARRAY;
|
||||
}
|
||||
Class<?>[] parameterTypes = ClassUtils.toClass(args);
|
||||
final Class<?>[] parameterTypes = ClassUtils.toClass(args);
|
||||
return invokeExactMethod(object, methodName, args, parameterTypes);
|
||||
}
|
||||
|
||||
|
@ -186,7 +186,7 @@ public static Object invokeExactMethod(final Object object, final String methodN
|
|||
if (parameterTypes == null) {
|
||||
parameterTypes = ArrayUtils.EMPTY_CLASS_ARRAY;
|
||||
}
|
||||
Method method = getAccessibleMethod(object.getClass(), methodName,
|
||||
final Method method = getAccessibleMethod(object.getClass(), methodName,
|
||||
parameterTypes);
|
||||
if (method == null) {
|
||||
throw new NoSuchMethodException("No such accessible method: "
|
||||
|
@ -225,7 +225,7 @@ public static Object invokeExactStaticMethod(final Class<?> cls, final String me
|
|||
if (parameterTypes == null) {
|
||||
parameterTypes = ArrayUtils.EMPTY_CLASS_ARRAY;
|
||||
}
|
||||
Method method = getAccessibleMethod(cls, methodName, parameterTypes);
|
||||
final Method method = getAccessibleMethod(cls, methodName, parameterTypes);
|
||||
if (method == null) {
|
||||
throw new NoSuchMethodException("No such accessible method: "
|
||||
+ methodName + "() on class: " + cls.getName());
|
||||
|
@ -263,7 +263,7 @@ public static Object invokeStaticMethod(final Class<?> cls, final String methodN
|
|||
if (args == null) {
|
||||
args = ArrayUtils.EMPTY_OBJECT_ARRAY;
|
||||
}
|
||||
Class<?>[] parameterTypes = ClassUtils.toClass(args);
|
||||
final Class<?>[] parameterTypes = ClassUtils.toClass(args);
|
||||
return invokeStaticMethod(cls, methodName, args, parameterTypes);
|
||||
}
|
||||
|
||||
|
@ -299,7 +299,7 @@ public static Object invokeStaticMethod(final Class<?> cls, final String methodN
|
|||
if (args == null) {
|
||||
args = ArrayUtils.EMPTY_OBJECT_ARRAY;
|
||||
}
|
||||
Method method = getMatchingAccessibleMethod(cls, methodName,
|
||||
final Method method = getMatchingAccessibleMethod(cls, methodName,
|
||||
parameterTypes);
|
||||
if (method == null) {
|
||||
throw new NoSuchMethodException("No such accessible method: "
|
||||
|
@ -332,7 +332,7 @@ public static Object invokeExactStaticMethod(final Class<?> cls, final String me
|
|||
if (args == null) {
|
||||
args = ArrayUtils.EMPTY_OBJECT_ARRAY;
|
||||
}
|
||||
Class<?>[] parameterTypes = ClassUtils.toClass(args);
|
||||
final Class<?>[] parameterTypes = ClassUtils.toClass(args);
|
||||
return invokeExactStaticMethod(cls, methodName, args, parameterTypes);
|
||||
}
|
||||
|
||||
|
@ -353,7 +353,7 @@ public static Method getAccessibleMethod(final Class<?> cls, final String method
|
|||
try {
|
||||
return getAccessibleMethod(cls.getMethod(methodName,
|
||||
parameterTypes));
|
||||
} catch (NoSuchMethodException e) {
|
||||
} catch (final NoSuchMethodException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -371,12 +371,12 @@ public static Method getAccessibleMethod(Method method) {
|
|||
return null;
|
||||
}
|
||||
// If the declaring class is public, we are done
|
||||
Class<?> cls = method.getDeclaringClass();
|
||||
final Class<?> cls = method.getDeclaringClass();
|
||||
if (Modifier.isPublic(cls.getModifiers())) {
|
||||
return method;
|
||||
}
|
||||
String methodName = method.getName();
|
||||
Class<?>[] parameterTypes = method.getParameterTypes();
|
||||
final String methodName = method.getName();
|
||||
final Class<?>[] parameterTypes = method.getParameterTypes();
|
||||
|
||||
// Check the implemented interfaces and subinterfaces
|
||||
method = getAccessibleMethodFromInterfaceNest(cls, methodName,
|
||||
|
@ -407,7 +407,7 @@ private static Method getAccessibleMethodFromSuperclass(final Class<?> cls,
|
|||
if (Modifier.isPublic(parentClass.getModifiers())) {
|
||||
try {
|
||||
return parentClass.getMethod(methodName, parameterTypes);
|
||||
} catch (NoSuchMethodException e) {
|
||||
} catch (final NoSuchMethodException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -439,7 +439,7 @@ private static Method getAccessibleMethodFromInterfaceNest(Class<?> cls,
|
|||
for (; cls != null; cls = cls.getSuperclass()) {
|
||||
|
||||
// Check the implemented interfaces of the parent class
|
||||
Class<?>[] interfaces = cls.getInterfaces();
|
||||
final Class<?>[] interfaces = cls.getInterfaces();
|
||||
for (int i = 0; i < interfaces.length; i++) {
|
||||
// Is this interface public?
|
||||
if (!Modifier.isPublic(interfaces[i].getModifiers())) {
|
||||
|
@ -449,7 +449,7 @@ private static Method getAccessibleMethodFromInterfaceNest(Class<?> cls,
|
|||
try {
|
||||
method = interfaces[i].getDeclaredMethod(methodName,
|
||||
parameterTypes);
|
||||
} catch (NoSuchMethodException e) { // NOPMD
|
||||
} catch (final NoSuchMethodException e) { // NOPMD
|
||||
/*
|
||||
* Swallow, if no method is found after the loop then this
|
||||
* method returns null.
|
||||
|
@ -492,19 +492,19 @@ private static Method getAccessibleMethodFromInterfaceNest(Class<?> cls,
|
|||
public static Method getMatchingAccessibleMethod(final Class<?> cls,
|
||||
final String methodName, final Class<?>... parameterTypes) {
|
||||
try {
|
||||
Method method = cls.getMethod(methodName, parameterTypes);
|
||||
final Method method = cls.getMethod(methodName, parameterTypes);
|
||||
MemberUtils.setAccessibleWorkaround(method);
|
||||
return method;
|
||||
} catch (NoSuchMethodException e) { // NOPMD - Swallow the exception
|
||||
} catch (final NoSuchMethodException e) { // NOPMD - Swallow the exception
|
||||
}
|
||||
// search through all methods
|
||||
Method bestMatch = null;
|
||||
Method[] methods = cls.getMethods();
|
||||
for (Method method : methods) {
|
||||
final Method[] methods = cls.getMethods();
|
||||
for (final Method method : methods) {
|
||||
// compare name and parameters
|
||||
if (method.getName().equals(methodName) && ClassUtils.isAssignable(parameterTypes, method.getParameterTypes(), true)) {
|
||||
// get accessible version of method
|
||||
Method accessibleMethod = getAccessibleMethod(method);
|
||||
final Method accessibleMethod = getAccessibleMethod(method);
|
||||
if (accessibleMethod != null && (bestMatch == null || MemberUtils.compareParameterTypes(
|
||||
accessibleMethod.getParameterTypes(),
|
||||
bestMatch.getParameterTypes(),
|
||||
|
|
|
@ -140,7 +140,7 @@ private static boolean isAssignable(final Type type, final Class<?> toClass) {
|
|||
if (type instanceof TypeVariable<?>) {
|
||||
// if any of the bounds are assignable to the class, then the
|
||||
// type is assignable to the class.
|
||||
for (Type bound : ((TypeVariable<?>) type).getBounds()) {
|
||||
for (final Type bound : ((TypeVariable<?>) type).getBounds()) {
|
||||
if (isAssignable(bound, toClass)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -194,10 +194,10 @@ private static boolean isAssignable(final Type type, final ParameterizedType toP
|
|||
}
|
||||
|
||||
// get the target type's raw type
|
||||
Class<?> toClass = getRawType(toParameterizedType);
|
||||
final Class<?> toClass = getRawType(toParameterizedType);
|
||||
// get the subject type's type arguments including owner type arguments
|
||||
// and supertype arguments up to and including the target class.
|
||||
Map<TypeVariable<?>, Type> fromTypeVarAssigns = getTypeArguments(type, toClass, null);
|
||||
final Map<TypeVariable<?>, Type> fromTypeVarAssigns = getTypeArguments(type, toClass, null);
|
||||
|
||||
// null means the two types are not compatible
|
||||
if (fromTypeVarAssigns == null) {
|
||||
|
@ -212,13 +212,13 @@ private static boolean isAssignable(final Type type, final ParameterizedType toP
|
|||
}
|
||||
|
||||
// get the target type's type arguments including owner type arguments
|
||||
Map<TypeVariable<?>, Type> toTypeVarAssigns = getTypeArguments(toParameterizedType,
|
||||
final Map<TypeVariable<?>, Type> toTypeVarAssigns = getTypeArguments(toParameterizedType,
|
||||
toClass, typeVarAssigns);
|
||||
|
||||
// now to check each type argument
|
||||
for (TypeVariable<?> var : toTypeVarAssigns.keySet()) {
|
||||
Type toTypeArg = unrollVariableAssignments(var, toTypeVarAssigns);
|
||||
Type fromTypeArg = unrollVariableAssignments(var, fromTypeVarAssigns);
|
||||
for (final TypeVariable<?> var : toTypeVarAssigns.keySet()) {
|
||||
final Type toTypeArg = unrollVariableAssignments(var, toTypeVarAssigns);
|
||||
final Type fromTypeArg = unrollVariableAssignments(var, fromTypeVarAssigns);
|
||||
|
||||
// parameters must either be absent from the subject type, within
|
||||
// the bounds of the wildcard type, or be an exact match to the
|
||||
|
@ -274,10 +274,10 @@ private static boolean isAssignable(final Type type, final GenericArrayType toGe
|
|||
return true;
|
||||
}
|
||||
|
||||
Type toComponentType = toGenericArrayType.getGenericComponentType();
|
||||
final Type toComponentType = toGenericArrayType.getGenericComponentType();
|
||||
|
||||
if (type instanceof Class<?>) {
|
||||
Class<?> cls = (Class<?>) type;
|
||||
final Class<?> cls = (Class<?>) type;
|
||||
|
||||
// compare the component types
|
||||
return cls.isArray()
|
||||
|
@ -292,7 +292,7 @@ private static boolean isAssignable(final Type type, final GenericArrayType toGe
|
|||
|
||||
if (type instanceof WildcardType) {
|
||||
// so long as one of the upper bounds is assignable, it's good
|
||||
for (Type bound : getImplicitUpperBounds((WildcardType) type)) {
|
||||
for (final Type bound : getImplicitUpperBounds((WildcardType) type)) {
|
||||
if (isAssignable(bound, toGenericArrayType)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -304,7 +304,7 @@ private static boolean isAssignable(final Type type, final GenericArrayType toGe
|
|||
if (type instanceof TypeVariable<?>) {
|
||||
// probably should remove the following logic and just return false.
|
||||
// type variables cannot specify arrays as bounds.
|
||||
for (Type bound : getImplicitBounds((TypeVariable<?>) type)) {
|
||||
for (final Type bound : getImplicitBounds((TypeVariable<?>) type)) {
|
||||
if (isAssignable(bound, toGenericArrayType)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -350,13 +350,13 @@ private static boolean isAssignable(final Type type, final WildcardType toWildca
|
|||
return true;
|
||||
}
|
||||
|
||||
Type[] toUpperBounds = getImplicitUpperBounds(toWildcardType);
|
||||
Type[] toLowerBounds = getImplicitLowerBounds(toWildcardType);
|
||||
final Type[] toUpperBounds = getImplicitUpperBounds(toWildcardType);
|
||||
final Type[] toLowerBounds = getImplicitLowerBounds(toWildcardType);
|
||||
|
||||
if (type instanceof WildcardType) {
|
||||
WildcardType wildcardType = (WildcardType) type;
|
||||
Type[] upperBounds = getImplicitUpperBounds(wildcardType);
|
||||
Type[] lowerBounds = getImplicitLowerBounds(wildcardType);
|
||||
final WildcardType wildcardType = (WildcardType) type;
|
||||
final Type[] upperBounds = getImplicitUpperBounds(wildcardType);
|
||||
final Type[] lowerBounds = getImplicitLowerBounds(wildcardType);
|
||||
|
||||
for (Type toBound : toUpperBounds) {
|
||||
// if there are assignments for unresolved type variables,
|
||||
|
@ -366,7 +366,7 @@ private static boolean isAssignable(final Type type, final WildcardType toWildca
|
|||
// each upper bound of the subject type has to be assignable to
|
||||
// each
|
||||
// upper bound of the target type
|
||||
for (Type bound : upperBounds) {
|
||||
for (final Type bound : upperBounds) {
|
||||
if (!isAssignable(bound, toBound, typeVarAssigns)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -381,7 +381,7 @@ private static boolean isAssignable(final Type type, final WildcardType toWildca
|
|||
// each lower bound of the target type has to be assignable to
|
||||
// each
|
||||
// lower bound of the subject type
|
||||
for (Type bound : lowerBounds) {
|
||||
for (final Type bound : lowerBounds) {
|
||||
if (!isAssignable(toBound, bound, typeVarAssigns)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -391,7 +391,7 @@ private static boolean isAssignable(final Type type, final WildcardType toWildca
|
|||
return true;
|
||||
}
|
||||
|
||||
for (Type toBound : toUpperBounds) {
|
||||
for (final Type toBound : toUpperBounds) {
|
||||
// if there are assignments for unresolved type variables,
|
||||
// now's the time to substitute them.
|
||||
if (!isAssignable(type, substituteTypeVariables(toBound, typeVarAssigns),
|
||||
|
@ -400,7 +400,7 @@ private static boolean isAssignable(final Type type, final WildcardType toWildca
|
|||
}
|
||||
}
|
||||
|
||||
for (Type toBound : toLowerBounds) {
|
||||
for (final Type toBound : toLowerBounds) {
|
||||
// if there are assignments for unresolved type variables,
|
||||
// now's the time to substitute them.
|
||||
if (!isAssignable(substituteTypeVariables(toBound, typeVarAssigns), type,
|
||||
|
@ -443,9 +443,9 @@ private static boolean isAssignable(final Type type, final TypeVariable<?> toTyp
|
|||
// a type variable is assignable to another type variable, if
|
||||
// and only if the former is the latter, extends the latter, or
|
||||
// is otherwise a descendant of the latter.
|
||||
Type[] bounds = getImplicitBounds((TypeVariable<?>) type);
|
||||
final Type[] bounds = getImplicitBounds((TypeVariable<?>) type);
|
||||
|
||||
for (Type bound : bounds) {
|
||||
for (final Type bound : bounds) {
|
||||
if (isAssignable(bound, toTypeVariable, typeVarAssigns)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -470,7 +470,7 @@ private static boolean isAssignable(final Type type, final TypeVariable<?> toTyp
|
|||
*/
|
||||
private static Type substituteTypeVariables(final Type type, final Map<TypeVariable<?>, Type> typeVarAssigns) {
|
||||
if (type instanceof TypeVariable<?> && typeVarAssigns != null) {
|
||||
Type replacementType = typeVarAssigns.get(type);
|
||||
final Type replacementType = typeVarAssigns.get(type);
|
||||
|
||||
if (replacementType == null) {
|
||||
throw new IllegalArgumentException("missing assignment type for type variable "
|
||||
|
@ -560,7 +560,7 @@ private static Map<TypeVariable<?>, Type> getTypeArguments(final Type type, fina
|
|||
// since wildcard types are not assignable to classes, should this just
|
||||
// return null?
|
||||
if (type instanceof WildcardType) {
|
||||
for (Type bound : getImplicitUpperBounds((WildcardType) type)) {
|
||||
for (final Type bound : getImplicitUpperBounds((WildcardType) type)) {
|
||||
// find the first bound that is assignable to the target class
|
||||
if (isAssignable(bound, toClass)) {
|
||||
return getTypeArguments(bound, toClass, subtypeVarAssigns);
|
||||
|
@ -572,7 +572,7 @@ private static Map<TypeVariable<?>, Type> getTypeArguments(final Type type, fina
|
|||
|
||||
// *
|
||||
if (type instanceof TypeVariable<?>) {
|
||||
for (Type bound : getImplicitBounds((TypeVariable<?>) type)) {
|
||||
for (final Type bound : getImplicitBounds((TypeVariable<?>) type)) {
|
||||
// find the first bound that is assignable to the target class
|
||||
if (isAssignable(bound, toClass)) {
|
||||
return getTypeArguments(bound, toClass, subtypeVarAssigns);
|
||||
|
@ -597,19 +597,19 @@ private static Map<TypeVariable<?>, Type> getTypeArguments(final Type type, fina
|
|||
private static Map<TypeVariable<?>, Type> getTypeArguments(
|
||||
final ParameterizedType parameterizedType, final Class<?> toClass,
|
||||
final Map<TypeVariable<?>, Type> subtypeVarAssigns) {
|
||||
Class<?> cls = getRawType(parameterizedType);
|
||||
final Class<?> cls = getRawType(parameterizedType);
|
||||
|
||||
// make sure they're assignable
|
||||
if (!isAssignable(cls, toClass)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Type ownerType = parameterizedType.getOwnerType();
|
||||
final Type ownerType = parameterizedType.getOwnerType();
|
||||
Map<TypeVariable<?>, Type> typeVarAssigns;
|
||||
|
||||
if (ownerType instanceof ParameterizedType) {
|
||||
// get the owner type arguments first
|
||||
ParameterizedType parameterizedOwnerType = (ParameterizedType) ownerType;
|
||||
final ParameterizedType parameterizedOwnerType = (ParameterizedType) ownerType;
|
||||
typeVarAssigns = getTypeArguments(parameterizedOwnerType,
|
||||
getRawType(parameterizedOwnerType), subtypeVarAssigns);
|
||||
} else {
|
||||
|
@ -619,13 +619,13 @@ private static Map<TypeVariable<?>, Type> getTypeArguments(
|
|||
}
|
||||
|
||||
// get the subject parameterized type's arguments
|
||||
Type[] typeArgs = parameterizedType.getActualTypeArguments();
|
||||
final Type[] typeArgs = parameterizedType.getActualTypeArguments();
|
||||
// and get the corresponding type variables from the raw class
|
||||
TypeVariable<?>[] typeParams = cls.getTypeParameters();
|
||||
final TypeVariable<?>[] typeParams = cls.getTypeParameters();
|
||||
|
||||
// map the arguments to their respective type variables
|
||||
for (int i = 0; i < typeParams.length; i++) {
|
||||
Type typeArg = typeArgs[i];
|
||||
final Type typeArg = typeArgs[i];
|
||||
typeVarAssigns.put(typeParams[i], typeVarAssigns.containsKey(typeArg) ? typeVarAssigns
|
||||
.get(typeArg) : typeArg);
|
||||
}
|
||||
|
@ -668,7 +668,7 @@ private static Map<TypeVariable<?>, Type> getTypeArguments(Class<?> cls, final C
|
|||
}
|
||||
|
||||
// create a copy of the incoming map, or an empty one if it's null
|
||||
HashMap<TypeVariable<?>, Type> typeVarAssigns = subtypeVarAssigns == null ? new HashMap<TypeVariable<?>, Type>()
|
||||
final HashMap<TypeVariable<?>, Type> typeVarAssigns = subtypeVarAssigns == null ? new HashMap<TypeVariable<?>, Type>()
|
||||
: new HashMap<TypeVariable<?>, Type>(subtypeVarAssigns);
|
||||
|
||||
// has target class been reached?
|
||||
|
@ -709,7 +709,7 @@ private static Map<TypeVariable<?>, Type> getTypeArguments(Class<?> cls, final C
|
|||
*/
|
||||
public static Map<TypeVariable<?>, Type> determineTypeArguments(final Class<?> cls,
|
||||
final ParameterizedType superType) {
|
||||
Class<?> superClass = getRawType(superType);
|
||||
final Class<?> superClass = getRawType(superType);
|
||||
|
||||
// compatibility check
|
||||
if (!isAssignable(cls, superClass)) {
|
||||
|
@ -721,18 +721,18 @@ public static Map<TypeVariable<?>, Type> determineTypeArguments(final Class<?> c
|
|||
}
|
||||
|
||||
// get the next class in the inheritance hierarchy
|
||||
Type midType = getClosestParentType(cls, superClass);
|
||||
final Type midType = getClosestParentType(cls, superClass);
|
||||
|
||||
// can only be a class or a parameterized type
|
||||
if (midType instanceof Class<?>) {
|
||||
return determineTypeArguments((Class<?>) midType, superType);
|
||||
}
|
||||
|
||||
ParameterizedType midParameterizedType = (ParameterizedType) midType;
|
||||
Class<?> midClass = getRawType(midParameterizedType);
|
||||
final ParameterizedType midParameterizedType = (ParameterizedType) midType;
|
||||
final Class<?> midClass = getRawType(midParameterizedType);
|
||||
// get the type variables of the mid class that map to the type
|
||||
// arguments of the super class
|
||||
Map<TypeVariable<?>, Type> typeVarAssigns = determineTypeArguments(midClass, superType);
|
||||
final Map<TypeVariable<?>, Type> typeVarAssigns = determineTypeArguments(midClass, superType);
|
||||
// map the arguments of the mid type to the class type variables
|
||||
mapTypeVariablesToArguments(cls, midParameterizedType, typeVarAssigns);
|
||||
|
||||
|
@ -750,7 +750,7 @@ public static Map<TypeVariable<?>, Type> determineTypeArguments(final Class<?> c
|
|||
private static <T> void mapTypeVariablesToArguments(final Class<T> cls,
|
||||
final ParameterizedType parameterizedType, final Map<TypeVariable<?>, Type> typeVarAssigns) {
|
||||
// capture the type variables from the owner type that have assignments
|
||||
Type ownerType = parameterizedType.getOwnerType();
|
||||
final Type ownerType = parameterizedType.getOwnerType();
|
||||
|
||||
if (ownerType instanceof ParameterizedType) {
|
||||
// recursion to make sure the owner's owner type gets processed
|
||||
|
@ -761,19 +761,19 @@ private static <T> void mapTypeVariablesToArguments(final Class<T> cls,
|
|||
// hierarchy of said interface/class) implemented/extended by the class
|
||||
// cls. Find out which type variables of cls are type arguments of
|
||||
// parameterizedType:
|
||||
Type[] typeArgs = parameterizedType.getActualTypeArguments();
|
||||
final Type[] typeArgs = parameterizedType.getActualTypeArguments();
|
||||
|
||||
// of the cls's type variables that are arguments of parameterizedType,
|
||||
// find out which ones can be determined from the super type's arguments
|
||||
TypeVariable<?>[] typeVars = getRawType(parameterizedType).getTypeParameters();
|
||||
final TypeVariable<?>[] typeVars = getRawType(parameterizedType).getTypeParameters();
|
||||
|
||||
// use List view of type parameters of cls so the contains() method can be used:
|
||||
List<TypeVariable<Class<T>>> typeVarList = Arrays.asList(cls
|
||||
final List<TypeVariable<Class<T>>> typeVarList = Arrays.asList(cls
|
||||
.getTypeParameters());
|
||||
|
||||
for (int i = 0; i < typeArgs.length; i++) {
|
||||
TypeVariable<?> typeVar = typeVars[i];
|
||||
Type typeArg = typeArgs[i];
|
||||
final TypeVariable<?> typeVar = typeVars[i];
|
||||
final Type typeArg = typeArgs[i];
|
||||
|
||||
// argument of parameterizedType is a type variable of cls
|
||||
if (typeVarList.contains(typeArg)
|
||||
|
@ -798,12 +798,12 @@ private static Type getClosestParentType(final Class<?> cls, final Class<?> supe
|
|||
// only look at the interfaces if the super class is also an interface
|
||||
if (superClass.isInterface()) {
|
||||
// get the generic interfaces of the subject class
|
||||
Type[] interfaceTypes = cls.getGenericInterfaces();
|
||||
final Type[] interfaceTypes = cls.getGenericInterfaces();
|
||||
// will hold the best generic interface match found
|
||||
Type genericInterface = null;
|
||||
|
||||
// find the interface closest to the super class
|
||||
for (Type midType : interfaceTypes) {
|
||||
for (final Type midType : interfaceTypes) {
|
||||
Class<?> midClass = null;
|
||||
|
||||
if (midType instanceof ParameterizedType) {
|
||||
|
@ -878,12 +878,12 @@ public static Type[] normalizeUpperBounds(final Type[] bounds) {
|
|||
return bounds;
|
||||
}
|
||||
|
||||
Set<Type> types = new HashSet<Type>(bounds.length);
|
||||
final Set<Type> types = new HashSet<Type>(bounds.length);
|
||||
|
||||
for (Type type1 : bounds) {
|
||||
for (final Type type1 : bounds) {
|
||||
boolean subtypeFound = false;
|
||||
|
||||
for (Type type2 : bounds) {
|
||||
for (final Type type2 : bounds) {
|
||||
if (type1 != type2 && isAssignable(type2, type1, null)) {
|
||||
subtypeFound = true;
|
||||
break;
|
||||
|
@ -908,7 +908,7 @@ public static Type[] normalizeUpperBounds(final Type[] bounds) {
|
|||
* @return a non-empty array containing the bounds of the type variable.
|
||||
*/
|
||||
public static Type[] getImplicitBounds(final TypeVariable<?> typeVariable) {
|
||||
Type[] bounds = typeVariable.getBounds();
|
||||
final Type[] bounds = typeVariable.getBounds();
|
||||
|
||||
return bounds.length == 0 ? new Type[] { Object.class } : normalizeUpperBounds(bounds);
|
||||
}
|
||||
|
@ -924,7 +924,7 @@ public static Type[] getImplicitBounds(final TypeVariable<?> typeVariable) {
|
|||
* type.
|
||||
*/
|
||||
public static Type[] getImplicitUpperBounds(final WildcardType wildcardType) {
|
||||
Type[] bounds = wildcardType.getUpperBounds();
|
||||
final Type[] bounds = wildcardType.getUpperBounds();
|
||||
|
||||
return bounds.length == 0 ? new Type[] { Object.class } : normalizeUpperBounds(bounds);
|
||||
}
|
||||
|
@ -939,7 +939,7 @@ public static Type[] getImplicitUpperBounds(final WildcardType wildcardType) {
|
|||
* type.
|
||||
*/
|
||||
public static Type[] getImplicitLowerBounds(final WildcardType wildcardType) {
|
||||
Type[] bounds = wildcardType.getLowerBounds();
|
||||
final Type[] bounds = wildcardType.getLowerBounds();
|
||||
|
||||
return bounds.length == 0 ? new Type[] { null } : bounds;
|
||||
}
|
||||
|
@ -960,11 +960,11 @@ public static Type[] getImplicitLowerBounds(final WildcardType wildcardType) {
|
|||
public static boolean typesSatisfyVariables(final Map<TypeVariable<?>, Type> typeVarAssigns) {
|
||||
// all types must be assignable to all the bounds of the their mapped
|
||||
// type variable.
|
||||
for (Map.Entry<TypeVariable<?>, Type> entry : typeVarAssigns.entrySet()) {
|
||||
TypeVariable<?> typeVar = entry.getKey();
|
||||
Type type = entry.getValue();
|
||||
for (final Map.Entry<TypeVariable<?>, Type> entry : typeVarAssigns.entrySet()) {
|
||||
final TypeVariable<?> typeVar = entry.getKey();
|
||||
final Type type = entry.getValue();
|
||||
|
||||
for (Type bound : getImplicitBounds(typeVar)) {
|
||||
for (final Type bound : getImplicitBounds(typeVar)) {
|
||||
if (!isAssignable(type, substituteTypeVariables(bound, typeVarAssigns),
|
||||
typeVarAssigns)) {
|
||||
return false;
|
||||
|
@ -983,7 +983,7 @@ public static boolean typesSatisfyVariables(final Map<TypeVariable<?>, Type> typ
|
|||
* @throws IllegalStateException if the conversion fails
|
||||
*/
|
||||
private static Class<?> getRawType(final ParameterizedType parameterizedType) {
|
||||
Type rawType = parameterizedType.getRawType();
|
||||
final Type rawType = parameterizedType.getRawType();
|
||||
|
||||
// check if raw type is a Class object
|
||||
// not currently necessary, but since the return type is Type instead of
|
||||
|
@ -1026,7 +1026,7 @@ public static Class<?> getRawType(final Type type, final Type assigningType) {
|
|||
}
|
||||
|
||||
// get the entity declaring this type variable
|
||||
Object genericDeclaration = ((TypeVariable<?>) type).getGenericDeclaration();
|
||||
final Object genericDeclaration = ((TypeVariable<?>) type).getGenericDeclaration();
|
||||
|
||||
// can't get the raw type of a method- or constructor-declared type
|
||||
// variable
|
||||
|
@ -1036,7 +1036,7 @@ public static Class<?> getRawType(final Type type, final Type assigningType) {
|
|||
|
||||
// get the type arguments for the declaring class/interface based
|
||||
// on the enclosing type
|
||||
Map<TypeVariable<?>, Type> typeVarAssigns = getTypeArguments(assigningType,
|
||||
final Map<TypeVariable<?>, Type> typeVarAssigns = getTypeArguments(assigningType,
|
||||
(Class<?>) genericDeclaration);
|
||||
|
||||
// enclosingType has to be a subclass (or subinterface) of the
|
||||
|
@ -1046,7 +1046,7 @@ public static Class<?> getRawType(final Type type, final Type assigningType) {
|
|||
}
|
||||
|
||||
// get the argument assigned to this type variable
|
||||
Type typeArgument = typeVarAssigns.get(type);
|
||||
final Type typeArgument = typeVarAssigns.get(type);
|
||||
|
||||
if (typeArgument == null) {
|
||||
return null;
|
||||
|
@ -1058,7 +1058,7 @@ public static Class<?> getRawType(final Type type, final Type assigningType) {
|
|||
|
||||
if (type instanceof GenericArrayType) {
|
||||
// get raw component type
|
||||
Class<?> rawComponentType = getRawType(((GenericArrayType) type)
|
||||
final Class<?> rawComponentType = getRawType(((GenericArrayType) type)
|
||||
.getGenericComponentType(), assigningType);
|
||||
|
||||
// create array type from raw component type and return its class
|
||||
|
@ -1089,7 +1089,7 @@ public static boolean isArrayType(final Type type) {
|
|||
*/
|
||||
public static Type getArrayComponentType(final Type type) {
|
||||
if (type instanceof Class<?>) {
|
||||
Class<?> clazz = (Class<?>) type;
|
||||
final Class<?> clazz = (Class<?>) type;
|
||||
return clazz.isArray() ? clazz.getComponentType() : null;
|
||||
}
|
||||
if (type instanceof GenericArrayType) {
|
||||
|
|
|
@ -148,12 +148,12 @@ public final void applyPattern(final String pattern) {
|
|||
toPattern = super.toPattern();
|
||||
return;
|
||||
}
|
||||
ArrayList<Format> foundFormats = new ArrayList<Format>();
|
||||
ArrayList<String> foundDescriptions = new ArrayList<String>();
|
||||
StringBuilder stripCustom = new StringBuilder(pattern.length());
|
||||
final ArrayList<Format> foundFormats = new ArrayList<Format>();
|
||||
final ArrayList<String> foundDescriptions = new ArrayList<String>();
|
||||
final StringBuilder stripCustom = new StringBuilder(pattern.length());
|
||||
|
||||
ParsePosition pos = new ParsePosition(0);
|
||||
char[] c = pattern.toCharArray();
|
||||
final ParsePosition pos = new ParsePosition(0);
|
||||
final char[] c = pattern.toCharArray();
|
||||
int fmtCount = 0;
|
||||
while (pos.getIndex() < pattern.length()) {
|
||||
switch (c[pos.getIndex()]) {
|
||||
|
@ -163,8 +163,8 @@ public final void applyPattern(final String pattern) {
|
|||
case START_FE:
|
||||
fmtCount++;
|
||||
seekNonWs(pattern, pos);
|
||||
int start = pos.getIndex();
|
||||
int index = readArgumentIndex(pattern, next(pos));
|
||||
final int start = pos.getIndex();
|
||||
final int index = readArgumentIndex(pattern, next(pos));
|
||||
stripCustom.append(START_FE).append(index);
|
||||
seekNonWs(pattern, pos);
|
||||
Format format = null;
|
||||
|
@ -194,12 +194,12 @@ public final void applyPattern(final String pattern) {
|
|||
super.applyPattern(stripCustom.toString());
|
||||
toPattern = insertFormats(super.toPattern(), foundDescriptions);
|
||||
if (containsElements(foundFormats)) {
|
||||
Format[] origFormats = getFormats();
|
||||
final Format[] origFormats = getFormats();
|
||||
// only loop over what we know we have, as MessageFormat on Java 1.3
|
||||
// seems to provide an extra format element:
|
||||
int i = 0;
|
||||
for (Iterator<Format> it = foundFormats.iterator(); it.hasNext(); i++) {
|
||||
Format f = it.next();
|
||||
for (final Iterator<Format> it = foundFormats.iterator(); it.hasNext(); i++) {
|
||||
final Format f = it.next();
|
||||
if (f != null) {
|
||||
origFormats[i] = f;
|
||||
}
|
||||
|
@ -274,7 +274,7 @@ public boolean equals(final Object obj) {
|
|||
if (ObjectUtils.notEqual(getClass(), obj.getClass())) {
|
||||
return false;
|
||||
}
|
||||
ExtendedMessageFormat rhs = (ExtendedMessageFormat)obj;
|
||||
final ExtendedMessageFormat rhs = (ExtendedMessageFormat)obj;
|
||||
if (ObjectUtils.notEqual(toPattern, rhs.toPattern)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -307,12 +307,12 @@ private Format getFormat(final String desc) {
|
|||
if (registry != null) {
|
||||
String name = desc;
|
||||
String args = null;
|
||||
int i = desc.indexOf(START_FMT);
|
||||
final int i = desc.indexOf(START_FMT);
|
||||
if (i > 0) {
|
||||
name = desc.substring(0, i).trim();
|
||||
args = desc.substring(i + 1).trim();
|
||||
}
|
||||
FormatFactory factory = registry.get(name);
|
||||
final FormatFactory factory = registry.get(name);
|
||||
if (factory != null) {
|
||||
return factory.getFormat(name, args, getLocale());
|
||||
}
|
||||
|
@ -328,9 +328,9 @@ private Format getFormat(final String desc) {
|
|||
* @return argument index
|
||||
*/
|
||||
private int readArgumentIndex(final String pattern, final ParsePosition pos) {
|
||||
int start = pos.getIndex();
|
||||
final int start = pos.getIndex();
|
||||
seekNonWs(pattern, pos);
|
||||
StringBuilder result = new StringBuilder();
|
||||
final StringBuilder result = new StringBuilder();
|
||||
boolean error = false;
|
||||
for (; !error && pos.getIndex() < pattern.length(); next(pos)) {
|
||||
char c = pattern.charAt(pos.getIndex());
|
||||
|
@ -345,7 +345,7 @@ private int readArgumentIndex(final String pattern, final ParsePosition pos) {
|
|||
if ((c == START_FMT || c == END_FE) && result.length() > 0) {
|
||||
try {
|
||||
return Integer.parseInt(result.toString());
|
||||
} catch (NumberFormatException e) { // NOPMD
|
||||
} catch (final NumberFormatException e) { // NOPMD
|
||||
// we've already ensured only digits, so unless something
|
||||
// outlandishly large was specified we should be okay.
|
||||
}
|
||||
|
@ -370,9 +370,9 @@ private int readArgumentIndex(final String pattern, final ParsePosition pos) {
|
|||
* @return Format description String
|
||||
*/
|
||||
private String parseFormatDescription(final String pattern, final ParsePosition pos) {
|
||||
int start = pos.getIndex();
|
||||
final int start = pos.getIndex();
|
||||
seekNonWs(pattern, pos);
|
||||
int text = pos.getIndex();
|
||||
final int text = pos.getIndex();
|
||||
int depth = 1;
|
||||
for (; pos.getIndex() < pattern.length(); next(pos)) {
|
||||
switch (pattern.charAt(pos.getIndex())) {
|
||||
|
@ -405,12 +405,12 @@ private String insertFormats(final String pattern, final ArrayList<String> custo
|
|||
if (!containsElements(customPatterns)) {
|
||||
return pattern;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder(pattern.length() * 2);
|
||||
ParsePosition pos = new ParsePosition(0);
|
||||
final StringBuilder sb = new StringBuilder(pattern.length() * 2);
|
||||
final ParsePosition pos = new ParsePosition(0);
|
||||
int fe = -1;
|
||||
int depth = 0;
|
||||
while (pos.getIndex() < pattern.length()) {
|
||||
char c = pattern.charAt(pos.getIndex());
|
||||
final char c = pattern.charAt(pos.getIndex());
|
||||
switch (c) {
|
||||
case QUOTE:
|
||||
appendQuotedString(pattern, pos, sb, false);
|
||||
|
@ -421,7 +421,7 @@ private String insertFormats(final String pattern, final ArrayList<String> custo
|
|||
fe++;
|
||||
sb.append(START_FE).append(
|
||||
readArgumentIndex(pattern, next(pos)));
|
||||
String customPattern = customPatterns.get(fe);
|
||||
final String customPattern = customPatterns.get(fe);
|
||||
if (customPattern != null) {
|
||||
sb.append(START_FMT).append(customPattern);
|
||||
}
|
||||
|
@ -446,7 +446,7 @@ private String insertFormats(final String pattern, final ArrayList<String> custo
|
|||
*/
|
||||
private void seekNonWs(final String pattern, final ParsePosition pos) {
|
||||
int len = 0;
|
||||
char[] buffer = pattern.toCharArray();
|
||||
final char[] buffer = pattern.toCharArray();
|
||||
do {
|
||||
len = StrMatcher.splitMatcher().isMatch(buffer, pos.getIndex());
|
||||
pos.setIndex(pos.getIndex() + len);
|
||||
|
@ -476,8 +476,8 @@ private ParsePosition next(final ParsePosition pos) {
|
|||
*/
|
||||
private StringBuilder appendQuotedString(final String pattern, final ParsePosition pos,
|
||||
final StringBuilder appendTo, final boolean escapingOn) {
|
||||
int start = pos.getIndex();
|
||||
char[] c = pattern.toCharArray();
|
||||
final int start = pos.getIndex();
|
||||
final char[] c = pattern.toCharArray();
|
||||
if (escapingOn && c[start] == QUOTE) {
|
||||
next(pos);
|
||||
return appendTo == null ? null : appendTo.append(QUOTE);
|
||||
|
@ -525,7 +525,7 @@ private boolean containsElements(final Collection<?> coll) {
|
|||
if (coll == null || coll.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
for (Object name : coll) {
|
||||
for (final Object name : coll) {
|
||||
if (name != null) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -135,12 +135,12 @@ public static Formatter append(final CharSequence seq, final Formatter formatter
|
|||
final int precision, final char padChar, final CharSequence ellipsis) {
|
||||
Validate.isTrue(ellipsis == null || precision < 0 || ellipsis.length() <= precision,
|
||||
"Specified ellipsis '%1$s' exceeds precision of %2$s", ellipsis, Integer.valueOf(precision));
|
||||
StringBuilder buf = new StringBuilder(seq);
|
||||
final StringBuilder buf = new StringBuilder(seq);
|
||||
if (precision >= 0 && precision < seq.length()) {
|
||||
CharSequence _ellipsis = ObjectUtils.defaultIfNull(ellipsis, StringUtils.EMPTY);
|
||||
final CharSequence _ellipsis = ObjectUtils.defaultIfNull(ellipsis, StringUtils.EMPTY);
|
||||
buf.replace(precision - _ellipsis.length(), seq.length(), _ellipsis.toString());
|
||||
}
|
||||
boolean leftJustify = (flags & LEFT_JUSTIFY) == LEFT_JUSTIFY;
|
||||
final boolean leftJustify = (flags & LEFT_JUSTIFY) == LEFT_JUSTIFY;
|
||||
for (int i = buf.length(); i < width; i++) {
|
||||
buf.insert(leftJustify ? i : 0, padChar);
|
||||
}
|
||||
|
|
|
@ -204,8 +204,8 @@ public StrBuilder setLength(final int length) {
|
|||
size = length;
|
||||
} else if (length > size) {
|
||||
ensureCapacity(length);
|
||||
int oldEnd = size;
|
||||
int newEnd = length;
|
||||
final int oldEnd = size;
|
||||
final int newEnd = length;
|
||||
size = length;
|
||||
for (int i = oldEnd; i < newEnd; i++) {
|
||||
buffer[i] = '\0';
|
||||
|
@ -232,7 +232,7 @@ public int capacity() {
|
|||
*/
|
||||
public StrBuilder ensureCapacity(final int capacity) {
|
||||
if (capacity > buffer.length) {
|
||||
char[] old = buffer;
|
||||
final char[] old = buffer;
|
||||
buffer = new char[capacity * 2];
|
||||
System.arraycopy(old, 0, buffer, 0, size);
|
||||
}
|
||||
|
@ -246,7 +246,7 @@ public StrBuilder ensureCapacity(final int capacity) {
|
|||
*/
|
||||
public StrBuilder minimizeCapacity() {
|
||||
if (buffer.length > length()) {
|
||||
char[] old = buffer;
|
||||
final char[] old = buffer;
|
||||
buffer = new char[length()];
|
||||
System.arraycopy(old, 0, buffer, 0, size);
|
||||
}
|
||||
|
@ -357,7 +357,7 @@ public char[] toCharArray() {
|
|||
if (size == 0) {
|
||||
return ArrayUtils.EMPTY_CHAR_ARRAY;
|
||||
}
|
||||
char chars[] = new char[size];
|
||||
final char chars[] = new char[size];
|
||||
System.arraycopy(buffer, 0, chars, 0, size);
|
||||
return chars;
|
||||
}
|
||||
|
@ -374,11 +374,11 @@ public char[] toCharArray() {
|
|||
*/
|
||||
public char[] toCharArray(final int startIndex, int endIndex) {
|
||||
endIndex = validateRange(startIndex, endIndex);
|
||||
int len = endIndex - startIndex;
|
||||
final int len = endIndex - startIndex;
|
||||
if (len == 0) {
|
||||
return ArrayUtils.EMPTY_CHAR_ARRAY;
|
||||
}
|
||||
char chars[] = new char[len];
|
||||
final char chars[] = new char[len];
|
||||
System.arraycopy(buffer, startIndex, chars, 0, len);
|
||||
return chars;
|
||||
}
|
||||
|
@ -390,7 +390,7 @@ public char[] toCharArray(final int startIndex, int endIndex) {
|
|||
* @return the input array, unless that was null or too small
|
||||
*/
|
||||
public char[] getChars(char[] destination) {
|
||||
int len = length();
|
||||
final int len = length();
|
||||
if (destination == null || destination.length < len) {
|
||||
destination = new char[len];
|
||||
}
|
||||
|
@ -510,9 +510,9 @@ public StrBuilder append(final String str) {
|
|||
if (str == null) {
|
||||
return appendNull();
|
||||
}
|
||||
int strLen = str.length();
|
||||
final int strLen = str.length();
|
||||
if (strLen > 0) {
|
||||
int len = length();
|
||||
final int len = length();
|
||||
ensureCapacity(len + strLen);
|
||||
str.getChars(0, strLen, buffer, len);
|
||||
size += strLen;
|
||||
|
@ -541,7 +541,7 @@ public StrBuilder append(final String str, final int startIndex, final int lengt
|
|||
throw new StringIndexOutOfBoundsException("length must be valid");
|
||||
}
|
||||
if (length > 0) {
|
||||
int len = length();
|
||||
final int len = length();
|
||||
ensureCapacity(len + length);
|
||||
str.getChars(startIndex, startIndex + length, buffer, len);
|
||||
size += length;
|
||||
|
@ -573,9 +573,9 @@ public StrBuilder append(final StringBuffer str) {
|
|||
if (str == null) {
|
||||
return appendNull();
|
||||
}
|
||||
int strLen = str.length();
|
||||
final int strLen = str.length();
|
||||
if (strLen > 0) {
|
||||
int len = length();
|
||||
final int len = length();
|
||||
ensureCapacity(len + strLen);
|
||||
str.getChars(0, strLen, buffer, len);
|
||||
size += strLen;
|
||||
|
@ -603,7 +603,7 @@ public StrBuilder append(final StringBuffer str, final int startIndex, final int
|
|||
throw new StringIndexOutOfBoundsException("length must be valid");
|
||||
}
|
||||
if (length > 0) {
|
||||
int len = length();
|
||||
final int len = length();
|
||||
ensureCapacity(len + length);
|
||||
str.getChars(startIndex, startIndex + length, buffer, len);
|
||||
size += length;
|
||||
|
@ -623,9 +623,9 @@ public StrBuilder append(final StringBuilder str) {
|
|||
if (str == null) {
|
||||
return appendNull();
|
||||
}
|
||||
int strLen = str.length();
|
||||
final int strLen = str.length();
|
||||
if (strLen > 0) {
|
||||
int len = length();
|
||||
final int len = length();
|
||||
ensureCapacity(len + strLen);
|
||||
str.getChars(0, strLen, buffer, len);
|
||||
size += strLen;
|
||||
|
@ -654,7 +654,7 @@ public StrBuilder append(final StringBuilder str, final int startIndex, final in
|
|||
throw new StringIndexOutOfBoundsException("length must be valid");
|
||||
}
|
||||
if (length > 0) {
|
||||
int len = length();
|
||||
final int len = length();
|
||||
ensureCapacity(len + length);
|
||||
str.getChars(startIndex, startIndex + length, buffer, len);
|
||||
size += length;
|
||||
|
@ -673,9 +673,9 @@ public StrBuilder append(final StrBuilder str) {
|
|||
if (str == null) {
|
||||
return appendNull();
|
||||
}
|
||||
int strLen = str.length();
|
||||
final int strLen = str.length();
|
||||
if (strLen > 0) {
|
||||
int len = length();
|
||||
final int len = length();
|
||||
ensureCapacity(len + strLen);
|
||||
System.arraycopy(str.buffer, 0, buffer, len, strLen);
|
||||
size += strLen;
|
||||
|
@ -703,7 +703,7 @@ public StrBuilder append(final StrBuilder str, final int startIndex, final int l
|
|||
throw new StringIndexOutOfBoundsException("length must be valid");
|
||||
}
|
||||
if (length > 0) {
|
||||
int len = length();
|
||||
final int len = length();
|
||||
ensureCapacity(len + length);
|
||||
str.getChars(startIndex, startIndex + length, buffer, len);
|
||||
size += length;
|
||||
|
@ -722,9 +722,9 @@ public StrBuilder append(final char[] chars) {
|
|||
if (chars == null) {
|
||||
return appendNull();
|
||||
}
|
||||
int strLen = chars.length;
|
||||
final int strLen = chars.length;
|
||||
if (strLen > 0) {
|
||||
int len = length();
|
||||
final int len = length();
|
||||
ensureCapacity(len + strLen);
|
||||
System.arraycopy(chars, 0, buffer, len, strLen);
|
||||
size += strLen;
|
||||
|
@ -752,7 +752,7 @@ public StrBuilder append(final char[] chars, final int startIndex, final int len
|
|||
throw new StringIndexOutOfBoundsException("Invalid length: " + length);
|
||||
}
|
||||
if (length > 0) {
|
||||
int len = length();
|
||||
final int len = length();
|
||||
ensureCapacity(len + length);
|
||||
System.arraycopy(chars, startIndex, buffer, len, length);
|
||||
size += length;
|
||||
|
@ -793,7 +793,7 @@ public StrBuilder append(final boolean value) {
|
|||
*/
|
||||
@Override
|
||||
public StrBuilder append(final char ch) {
|
||||
int len = length();
|
||||
final int len = length();
|
||||
ensureCapacity(len + 1);
|
||||
buffer[size++] = ch;
|
||||
return this;
|
||||
|
@ -1073,7 +1073,7 @@ public StrBuilder appendln(final double value) {
|
|||
*/
|
||||
public <T> StrBuilder appendAll(final T... array) {
|
||||
if (array != null && array.length > 0) {
|
||||
for (Object element : array) {
|
||||
for (final Object element : array) {
|
||||
append(element);
|
||||
}
|
||||
}
|
||||
|
@ -1091,7 +1091,7 @@ public <T> StrBuilder appendAll(final T... array) {
|
|||
*/
|
||||
public StrBuilder appendAll(final Iterable<?> iterable) {
|
||||
if (iterable != null) {
|
||||
for (Object o : iterable) {
|
||||
for (final Object o : iterable) {
|
||||
append(o);
|
||||
}
|
||||
}
|
||||
|
@ -1152,7 +1152,7 @@ public StrBuilder appendWithSeparators(final Object[] array, String separator) {
|
|||
public StrBuilder appendWithSeparators(final Iterable<?> iterable, String separator) {
|
||||
if (iterable != null) {
|
||||
separator = ObjectUtils.toString(separator);
|
||||
Iterator<?> it = iterable.iterator();
|
||||
final Iterator<?> it = iterable.iterator();
|
||||
while (it.hasNext()) {
|
||||
append(it.next());
|
||||
if (it.hasNext()) {
|
||||
|
@ -1239,7 +1239,7 @@ public StrBuilder appendSeparator(final String separator) {
|
|||
* @since 2.5
|
||||
*/
|
||||
public StrBuilder appendSeparator(final String standard, final String defaultIfEmpty) {
|
||||
String str = isEmpty() ? defaultIfEmpty : standard;
|
||||
final String str = isEmpty() ? defaultIfEmpty : standard;
|
||||
if (str != null) {
|
||||
append(str);
|
||||
}
|
||||
|
@ -1383,11 +1383,11 @@ public StrBuilder appendFixedWidthPadLeft(final Object obj, final int width, fin
|
|||
if (str == null) {
|
||||
str = "";
|
||||
}
|
||||
int strLen = str.length();
|
||||
final int strLen = str.length();
|
||||
if (strLen >= width) {
|
||||
str.getChars(strLen - width, strLen, buffer, size);
|
||||
} else {
|
||||
int padLen = width - strLen;
|
||||
final int padLen = width - strLen;
|
||||
for (int i = 0; i < padLen; i++) {
|
||||
buffer[size + i] = padChar;
|
||||
}
|
||||
|
@ -1430,11 +1430,11 @@ public StrBuilder appendFixedWidthPadRight(final Object obj, final int width, fi
|
|||
if (str == null) {
|
||||
str = "";
|
||||
}
|
||||
int strLen = str.length();
|
||||
final int strLen = str.length();
|
||||
if (strLen >= width) {
|
||||
str.getChars(0, width, buffer, size);
|
||||
} else {
|
||||
int padLen = width - strLen;
|
||||
final int padLen = width - strLen;
|
||||
str.getChars(0, strLen, buffer, size);
|
||||
for (int i = 0; i < padLen; i++) {
|
||||
buffer[size + strLen + i] = padChar;
|
||||
|
@ -1491,9 +1491,9 @@ public StrBuilder insert(final int index, String str) {
|
|||
if (str == null) {
|
||||
str = nullText;
|
||||
}
|
||||
int strLen = (str == null ? 0 : str.length());
|
||||
final int strLen = (str == null ? 0 : str.length());
|
||||
if (strLen > 0) {
|
||||
int newSize = size + strLen;
|
||||
final int newSize = size + strLen;
|
||||
ensureCapacity(newSize);
|
||||
System.arraycopy(buffer, index, buffer, index + strLen, size - index);
|
||||
size = newSize;
|
||||
|
@ -1516,7 +1516,7 @@ public StrBuilder insert(final int index, final char chars[]) {
|
|||
if (chars == null) {
|
||||
return insert(index, nullText);
|
||||
}
|
||||
int len = chars.length;
|
||||
final int len = chars.length;
|
||||
if (len > 0) {
|
||||
ensureCapacity(size + len);
|
||||
System.arraycopy(buffer, index, buffer, index + len, size - index);
|
||||
|
@ -1678,7 +1678,7 @@ private void deleteImpl(final int startIndex, final int endIndex, final int len)
|
|||
*/
|
||||
public StrBuilder delete(final int startIndex, int endIndex) {
|
||||
endIndex = validateRange(startIndex, endIndex);
|
||||
int len = endIndex - startIndex;
|
||||
final int len = endIndex - startIndex;
|
||||
if (len > 0) {
|
||||
deleteImpl(startIndex, endIndex, len);
|
||||
}
|
||||
|
@ -1695,13 +1695,13 @@ public StrBuilder delete(final int startIndex, int endIndex) {
|
|||
public StrBuilder deleteAll(final char ch) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (buffer[i] == ch) {
|
||||
int start = i;
|
||||
final int start = i;
|
||||
while (++i < size) {
|
||||
if (buffer[i] != ch) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
int len = i - start;
|
||||
final int len = i - start;
|
||||
deleteImpl(start, i, len);
|
||||
i -= len;
|
||||
}
|
||||
|
@ -1733,7 +1733,7 @@ public StrBuilder deleteFirst(final char ch) {
|
|||
* @return this, to enable chaining
|
||||
*/
|
||||
public StrBuilder deleteAll(final String str) {
|
||||
int len = (str == null ? 0 : str.length());
|
||||
final int len = (str == null ? 0 : str.length());
|
||||
if (len > 0) {
|
||||
int index = indexOf(str, 0);
|
||||
while (index >= 0) {
|
||||
|
@ -1751,9 +1751,9 @@ public StrBuilder deleteAll(final String str) {
|
|||
* @return this, to enable chaining
|
||||
*/
|
||||
public StrBuilder deleteFirst(final String str) {
|
||||
int len = (str == null ? 0 : str.length());
|
||||
final int len = (str == null ? 0 : str.length());
|
||||
if (len > 0) {
|
||||
int index = indexOf(str, 0);
|
||||
final int index = indexOf(str, 0);
|
||||
if (index >= 0) {
|
||||
deleteImpl(index, index + len, len);
|
||||
}
|
||||
|
@ -1802,7 +1802,7 @@ public StrBuilder deleteFirst(final StrMatcher matcher) {
|
|||
* @throws IndexOutOfBoundsException if any index is invalid
|
||||
*/
|
||||
private void replaceImpl(final int startIndex, final int endIndex, final int removeLen, final String insertStr, final int insertLen) {
|
||||
int newSize = size - removeLen + insertLen;
|
||||
final int newSize = size - removeLen + insertLen;
|
||||
if (insertLen != removeLen) {
|
||||
ensureCapacity(newSize);
|
||||
System.arraycopy(buffer, endIndex, buffer, startIndex + insertLen, size - endIndex);
|
||||
|
@ -1826,7 +1826,7 @@ private void replaceImpl(final int startIndex, final int endIndex, final int rem
|
|||
*/
|
||||
public StrBuilder replace(final int startIndex, int endIndex, final String replaceStr) {
|
||||
endIndex = validateRange(startIndex, endIndex);
|
||||
int insertLen = (replaceStr == null ? 0 : replaceStr.length());
|
||||
final int insertLen = (replaceStr == null ? 0 : replaceStr.length());
|
||||
replaceImpl(startIndex, endIndex, endIndex - startIndex, replaceStr, insertLen);
|
||||
return this;
|
||||
}
|
||||
|
@ -1880,9 +1880,9 @@ public StrBuilder replaceFirst(final char search, final char replace) {
|
|||
* @return this, to enable chaining
|
||||
*/
|
||||
public StrBuilder replaceAll(final String searchStr, final String replaceStr) {
|
||||
int searchLen = (searchStr == null ? 0 : searchStr.length());
|
||||
final int searchLen = (searchStr == null ? 0 : searchStr.length());
|
||||
if (searchLen > 0) {
|
||||
int replaceLen = (replaceStr == null ? 0 : replaceStr.length());
|
||||
final int replaceLen = (replaceStr == null ? 0 : replaceStr.length());
|
||||
int index = indexOf(searchStr, 0);
|
||||
while (index >= 0) {
|
||||
replaceImpl(index, index + searchLen, searchLen, replaceStr, replaceLen);
|
||||
|
@ -1900,11 +1900,11 @@ public StrBuilder replaceAll(final String searchStr, final String replaceStr) {
|
|||
* @return this, to enable chaining
|
||||
*/
|
||||
public StrBuilder replaceFirst(final String searchStr, final String replaceStr) {
|
||||
int searchLen = (searchStr == null ? 0 : searchStr.length());
|
||||
final int searchLen = (searchStr == null ? 0 : searchStr.length());
|
||||
if (searchLen > 0) {
|
||||
int index = indexOf(searchStr, 0);
|
||||
final int index = indexOf(searchStr, 0);
|
||||
if (index >= 0) {
|
||||
int replaceLen = (replaceStr == null ? 0 : replaceStr.length());
|
||||
final int replaceLen = (replaceStr == null ? 0 : replaceStr.length());
|
||||
replaceImpl(index, index + searchLen, searchLen, replaceStr, replaceLen);
|
||||
}
|
||||
}
|
||||
|
@ -1987,10 +1987,10 @@ private StrBuilder replaceImpl(
|
|||
if (matcher == null || size == 0) {
|
||||
return this;
|
||||
}
|
||||
int replaceLen = (replaceStr == null ? 0 : replaceStr.length());
|
||||
char[] buf = buffer;
|
||||
final int replaceLen = (replaceStr == null ? 0 : replaceStr.length());
|
||||
final char[] buf = buffer;
|
||||
for (int i = from; i < to && replaceCount != 0; i++) {
|
||||
int removeLen = matcher.isMatch(buf, i, from, to);
|
||||
final int removeLen = matcher.isMatch(buf, i, from, to);
|
||||
if (removeLen > 0) {
|
||||
replaceImpl(i, i + removeLen, removeLen, replaceStr, replaceLen);
|
||||
to = to - removeLen + replaceLen;
|
||||
|
@ -2014,10 +2014,10 @@ public StrBuilder reverse() {
|
|||
return this;
|
||||
}
|
||||
|
||||
int half = size / 2;
|
||||
char[] buf = buffer;
|
||||
final int half = size / 2;
|
||||
final char[] buf = buffer;
|
||||
for (int leftIdx = 0, rightIdx = size - 1; leftIdx < half; leftIdx++,rightIdx--) {
|
||||
char swap = buf[leftIdx];
|
||||
final char swap = buf[leftIdx];
|
||||
buf[leftIdx] = buf[rightIdx];
|
||||
buf[rightIdx] = swap;
|
||||
}
|
||||
|
@ -2036,7 +2036,7 @@ public StrBuilder trim() {
|
|||
return this;
|
||||
}
|
||||
int len = size;
|
||||
char[] buf = buffer;
|
||||
final char[] buf = buffer;
|
||||
int pos = 0;
|
||||
while (pos < len && buf[pos] <= ' ') {
|
||||
pos++;
|
||||
|
@ -2066,7 +2066,7 @@ public boolean startsWith(final String str) {
|
|||
if (str == null) {
|
||||
return false;
|
||||
}
|
||||
int len = str.length();
|
||||
final int len = str.length();
|
||||
if (len == 0) {
|
||||
return true;
|
||||
}
|
||||
|
@ -2093,7 +2093,7 @@ public boolean endsWith(final String str) {
|
|||
if (str == null) {
|
||||
return false;
|
||||
}
|
||||
int len = str.length();
|
||||
final int len = str.length();
|
||||
if (len == 0) {
|
||||
return true;
|
||||
}
|
||||
|
@ -2239,7 +2239,7 @@ public String midString(int index, final int length) {
|
|||
* @return true if the builder contains the character
|
||||
*/
|
||||
public boolean contains(final char ch) {
|
||||
char[] thisBuf = buffer;
|
||||
final char[] thisBuf = buffer;
|
||||
for (int i = 0; i < this.size; i++) {
|
||||
if (thisBuf[i] == ch) {
|
||||
return true;
|
||||
|
@ -2296,7 +2296,7 @@ public int indexOf(final char ch, int startIndex) {
|
|||
if (startIndex >= size) {
|
||||
return -1;
|
||||
}
|
||||
char[] thisBuf = buffer;
|
||||
final char[] thisBuf = buffer;
|
||||
for (int i = startIndex; i < size; i++) {
|
||||
if (thisBuf[i] == ch) {
|
||||
return i;
|
||||
|
@ -2332,7 +2332,7 @@ public int indexOf(final String str, int startIndex) {
|
|||
if (str == null || startIndex >= size) {
|
||||
return -1;
|
||||
}
|
||||
int strLen = str.length();
|
||||
final int strLen = str.length();
|
||||
if (strLen == 1) {
|
||||
return indexOf(str.charAt(0), startIndex);
|
||||
}
|
||||
|
@ -2342,8 +2342,8 @@ public int indexOf(final String str, int startIndex) {
|
|||
if (strLen > size) {
|
||||
return -1;
|
||||
}
|
||||
char[] thisBuf = buffer;
|
||||
int len = size - strLen + 1;
|
||||
final char[] thisBuf = buffer;
|
||||
final int len = size - strLen + 1;
|
||||
outer:
|
||||
for (int i = startIndex; i < len; i++) {
|
||||
for (int j = 0; j < strLen; j++) {
|
||||
|
@ -2387,8 +2387,8 @@ public int indexOf(final StrMatcher matcher, int startIndex) {
|
|||
if (matcher == null || startIndex >= size) {
|
||||
return -1;
|
||||
}
|
||||
int len = size;
|
||||
char[] buf = buffer;
|
||||
final int len = size;
|
||||
final char[] buf = buffer;
|
||||
for (int i = startIndex; i < len; i++) {
|
||||
if (matcher.isMatch(buf, i, startIndex, len) > 0) {
|
||||
return i;
|
||||
|
@ -2455,7 +2455,7 @@ public int lastIndexOf(final String str, int startIndex) {
|
|||
if (str == null || startIndex < 0) {
|
||||
return -1;
|
||||
}
|
||||
int strLen = str.length();
|
||||
final int strLen = str.length();
|
||||
if (strLen > 0 && strLen <= size) {
|
||||
if (strLen == 1) {
|
||||
return lastIndexOf(str.charAt(0), startIndex);
|
||||
|
@ -2508,8 +2508,8 @@ public int lastIndexOf(final StrMatcher matcher, int startIndex) {
|
|||
if (matcher == null || startIndex < 0) {
|
||||
return -1;
|
||||
}
|
||||
char[] buf = buffer;
|
||||
int endIndex = startIndex + 1;
|
||||
final char[] buf = buffer;
|
||||
final int endIndex = startIndex + 1;
|
||||
for (int i = startIndex; i >= 0; i--) {
|
||||
if (matcher.isMatch(buf, i, 0, endIndex) > 0) {
|
||||
return i;
|
||||
|
@ -2649,11 +2649,11 @@ public boolean equalsIgnoreCase(final StrBuilder other) {
|
|||
if (this.size != other.size) {
|
||||
return false;
|
||||
}
|
||||
char thisBuf[] = this.buffer;
|
||||
char otherBuf[] = other.buffer;
|
||||
final char thisBuf[] = this.buffer;
|
||||
final char otherBuf[] = other.buffer;
|
||||
for (int i = size - 1; i >= 0; i--) {
|
||||
char c1 = thisBuf[i];
|
||||
char c2 = otherBuf[i];
|
||||
final char c1 = thisBuf[i];
|
||||
final char c2 = otherBuf[i];
|
||||
if (c1 != c2 && Character.toUpperCase(c1) != Character.toUpperCase(c2)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -2675,8 +2675,8 @@ public boolean equals(final StrBuilder other) {
|
|||
if (this.size != other.size) {
|
||||
return false;
|
||||
}
|
||||
char thisBuf[] = this.buffer;
|
||||
char otherBuf[] = other.buffer;
|
||||
final char thisBuf[] = this.buffer;
|
||||
final char otherBuf[] = other.buffer;
|
||||
for (int i = size - 1; i >= 0; i--) {
|
||||
if (thisBuf[i] != otherBuf[i]) {
|
||||
return false;
|
||||
|
@ -2707,7 +2707,7 @@ public boolean equals(final Object obj) {
|
|||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
char buf[] = buffer;
|
||||
final char buf[] = buffer;
|
||||
int hash = 0;
|
||||
for (int i = size - 1; i >= 0; i--) {
|
||||
hash = 31 * hash + buf[i];
|
||||
|
@ -2823,7 +2823,7 @@ protected List<String> tokenize(final char[] chars, final int offset, final int
|
|||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public String getContent() {
|
||||
String str = super.getContent();
|
||||
final String str = super.getContent();
|
||||
if (str == null) {
|
||||
return StrBuilder.this.toString();
|
||||
} else {
|
||||
|
|
|
@ -52,7 +52,7 @@ public abstract class StrLookup<V> {
|
|||
@SuppressWarnings("unchecked") // System property keys and values are always Strings
|
||||
final Map<String, String> properties = (Map<String, String>) propMap;
|
||||
lookup = new MapStrLookup<String>(properties);
|
||||
} catch (SecurityException ex) {
|
||||
} catch (final SecurityException ex) {
|
||||
lookup = NONE_LOOKUP;
|
||||
}
|
||||
SYSTEM_PROPERTIES_LOOKUP = lookup;
|
||||
|
@ -162,7 +162,7 @@ public String lookup(final String key) {
|
|||
if (map == null) {
|
||||
return null;
|
||||
}
|
||||
Object obj = map.get(key);
|
||||
final Object obj = map.get(key);
|
||||
if (obj == null) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -364,7 +364,7 @@ static final class StringMatcher extends StrMatcher {
|
|||
*/
|
||||
@Override
|
||||
public int isMatch(final char[] buffer, int pos, final int bufferStart, final int bufferEnd) {
|
||||
int len = chars.length;
|
||||
final int len = chars.length;
|
||||
if (pos + len > bufferEnd) {
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -179,11 +179,11 @@ public static String replace(final Object source, final Properties valueProperti
|
|||
if (valueProperties == null) {
|
||||
return source.toString();
|
||||
}
|
||||
Map<String,String> valueMap = new HashMap<String,String>();
|
||||
Enumeration<?> propNames = valueProperties.propertyNames();
|
||||
final Map<String,String> valueMap = new HashMap<String,String>();
|
||||
final Enumeration<?> propNames = valueProperties.propertyNames();
|
||||
while (propNames.hasMoreElements()) {
|
||||
String propName = (String)propNames.nextElement();
|
||||
String propValue = valueProperties.getProperty(propName);
|
||||
final String propName = (String)propNames.nextElement();
|
||||
final String propValue = valueProperties.getProperty(propName);
|
||||
valueMap.put(propName, propValue);
|
||||
}
|
||||
return StrSubstitutor.replace(source, valueMap);
|
||||
|
@ -301,7 +301,7 @@ public String replace(final String source) {
|
|||
if (source == null) {
|
||||
return null;
|
||||
}
|
||||
StrBuilder buf = new StrBuilder(source);
|
||||
final StrBuilder buf = new StrBuilder(source);
|
||||
if (substitute(buf, 0, source.length()) == false) {
|
||||
return source;
|
||||
}
|
||||
|
@ -324,7 +324,7 @@ public String replace(final String source, final int offset, final int length) {
|
|||
if (source == null) {
|
||||
return null;
|
||||
}
|
||||
StrBuilder buf = new StrBuilder(length).append(source, offset, length);
|
||||
final StrBuilder buf = new StrBuilder(length).append(source, offset, length);
|
||||
if (substitute(buf, 0, length) == false) {
|
||||
return source.substring(offset, offset + length);
|
||||
}
|
||||
|
@ -344,7 +344,7 @@ public String replace(final char[] source) {
|
|||
if (source == null) {
|
||||
return null;
|
||||
}
|
||||
StrBuilder buf = new StrBuilder(source.length).append(source);
|
||||
final StrBuilder buf = new StrBuilder(source.length).append(source);
|
||||
substitute(buf, 0, source.length);
|
||||
return buf.toString();
|
||||
}
|
||||
|
@ -366,7 +366,7 @@ public String replace(final char[] source, final int offset, final int length) {
|
|||
if (source == null) {
|
||||
return null;
|
||||
}
|
||||
StrBuilder buf = new StrBuilder(length).append(source, offset, length);
|
||||
final StrBuilder buf = new StrBuilder(length).append(source, offset, length);
|
||||
substitute(buf, 0, length);
|
||||
return buf.toString();
|
||||
}
|
||||
|
@ -384,7 +384,7 @@ public String replace(final StringBuffer source) {
|
|||
if (source == null) {
|
||||
return null;
|
||||
}
|
||||
StrBuilder buf = new StrBuilder(source.length()).append(source);
|
||||
final StrBuilder buf = new StrBuilder(source.length()).append(source);
|
||||
substitute(buf, 0, buf.length());
|
||||
return buf.toString();
|
||||
}
|
||||
|
@ -406,7 +406,7 @@ public String replace(final StringBuffer source, final int offset, final int len
|
|||
if (source == null) {
|
||||
return null;
|
||||
}
|
||||
StrBuilder buf = new StrBuilder(length).append(source, offset, length);
|
||||
final StrBuilder buf = new StrBuilder(length).append(source, offset, length);
|
||||
substitute(buf, 0, length);
|
||||
return buf.toString();
|
||||
}
|
||||
|
@ -424,7 +424,7 @@ public String replace(final StrBuilder source) {
|
|||
if (source == null) {
|
||||
return null;
|
||||
}
|
||||
StrBuilder buf = new StrBuilder(source.length()).append(source);
|
||||
final StrBuilder buf = new StrBuilder(source.length()).append(source);
|
||||
substitute(buf, 0, buf.length());
|
||||
return buf.toString();
|
||||
}
|
||||
|
@ -446,7 +446,7 @@ public String replace(final StrBuilder source, final int offset, final int lengt
|
|||
if (source == null) {
|
||||
return null;
|
||||
}
|
||||
StrBuilder buf = new StrBuilder(length).append(source, offset, length);
|
||||
final StrBuilder buf = new StrBuilder(length).append(source, offset, length);
|
||||
substitute(buf, 0, length);
|
||||
return buf.toString();
|
||||
}
|
||||
|
@ -464,7 +464,7 @@ public String replace(final Object source) {
|
|||
if (source == null) {
|
||||
return null;
|
||||
}
|
||||
StrBuilder buf = new StrBuilder().append(source);
|
||||
final StrBuilder buf = new StrBuilder().append(source);
|
||||
substitute(buf, 0, buf.length());
|
||||
return buf.toString();
|
||||
}
|
||||
|
@ -502,7 +502,7 @@ public boolean replaceIn(final StringBuffer source, final int offset, final int
|
|||
if (source == null) {
|
||||
return false;
|
||||
}
|
||||
StrBuilder buf = new StrBuilder(length).append(source, offset, length);
|
||||
final StrBuilder buf = new StrBuilder(length).append(source, offset, length);
|
||||
if (substitute(buf, 0, length) == false) {
|
||||
return false;
|
||||
}
|
||||
|
@ -576,18 +576,18 @@ protected boolean substitute(final StrBuilder buf, final int offset, final int l
|
|||
* represents a boolean flag as to whether any change occurred.
|
||||
*/
|
||||
private int substitute(final StrBuilder buf, final int offset, final int length, List<String> priorVariables) {
|
||||
StrMatcher prefixMatcher = getVariablePrefixMatcher();
|
||||
StrMatcher suffixMatcher = getVariableSuffixMatcher();
|
||||
char escape = getEscapeChar();
|
||||
final StrMatcher prefixMatcher = getVariablePrefixMatcher();
|
||||
final StrMatcher suffixMatcher = getVariableSuffixMatcher();
|
||||
final char escape = getEscapeChar();
|
||||
|
||||
boolean top = priorVariables == null;
|
||||
final boolean top = priorVariables == null;
|
||||
boolean altered = false;
|
||||
int lengthChange = 0;
|
||||
char[] chars = buf.buffer;
|
||||
int bufEnd = offset + length;
|
||||
int pos = offset;
|
||||
while (pos < bufEnd) {
|
||||
int startMatchLen = prefixMatcher.isMatch(chars, pos, offset,
|
||||
final int startMatchLen = prefixMatcher.isMatch(chars, pos, offset,
|
||||
bufEnd);
|
||||
if (startMatchLen == 0) {
|
||||
pos++;
|
||||
|
@ -602,7 +602,7 @@ private int substitute(final StrBuilder buf, final int offset, final int length,
|
|||
bufEnd--;
|
||||
} else {
|
||||
// find suffix
|
||||
int startPos = pos;
|
||||
final int startPos = pos;
|
||||
pos += startMatchLen;
|
||||
int endMatchLen = 0;
|
||||
int nestedVarCount = 0;
|
||||
|
@ -627,12 +627,12 @@ private int substitute(final StrBuilder buf, final int offset, final int length,
|
|||
+ startMatchLen, pos - startPos
|
||||
- startMatchLen);
|
||||
if (isEnableSubstitutionInVariables()) {
|
||||
StrBuilder bufName = new StrBuilder(varName);
|
||||
final StrBuilder bufName = new StrBuilder(varName);
|
||||
substitute(bufName, 0, bufName.length());
|
||||
varName = bufName.toString();
|
||||
}
|
||||
pos += endMatchLen;
|
||||
int endPos = pos;
|
||||
final int endPos = pos;
|
||||
|
||||
// on the first call initialize priorVariables
|
||||
if (priorVariables == null) {
|
||||
|
@ -646,11 +646,11 @@ private int substitute(final StrBuilder buf, final int offset, final int length,
|
|||
priorVariables.add(varName);
|
||||
|
||||
// resolve the variable
|
||||
String varValue = resolveVariable(varName, buf,
|
||||
final String varValue = resolveVariable(varName, buf,
|
||||
startPos, endPos);
|
||||
if (varValue != null) {
|
||||
// recursive replace
|
||||
int varLen = varValue.length();
|
||||
final int varLen = varValue.length();
|
||||
buf.replace(startPos, endPos, varValue);
|
||||
altered = true;
|
||||
int change = substitute(buf, startPos,
|
||||
|
@ -693,7 +693,7 @@ private void checkCyclicSubstitution(final String varName, final List<String> pr
|
|||
if (priorVariables.contains(varName) == false) {
|
||||
return;
|
||||
}
|
||||
StrBuilder buf = new StrBuilder(256);
|
||||
final StrBuilder buf = new StrBuilder(256);
|
||||
buf.append("Infinite loop in property interpolation of ");
|
||||
buf.append(priorVariables.remove(0));
|
||||
buf.append(": ");
|
||||
|
@ -719,7 +719,7 @@ private void checkCyclicSubstitution(final String varName, final List<String> pr
|
|||
* @return the variable's value or <b>null</b> if the variable is unknown
|
||||
*/
|
||||
protected String resolveVariable(final String variableName, final StrBuilder buf, final int startPos, final int endPos) {
|
||||
StrLookup<?> resolver = getVariableResolver();
|
||||
final StrLookup<?> resolver = getVariableResolver();
|
||||
if (resolver == null) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -162,7 +162,7 @@ public static StrTokenizer getCSVInstance() {
|
|||
* @return a new tokenizer instance which parses Comma Separated Value strings
|
||||
*/
|
||||
public static StrTokenizer getCSVInstance(final String input) {
|
||||
StrTokenizer tok = getCSVClone();
|
||||
final StrTokenizer tok = getCSVClone();
|
||||
tok.reset(input);
|
||||
return tok;
|
||||
}
|
||||
|
@ -177,7 +177,7 @@ public static StrTokenizer getCSVInstance(final String input) {
|
|||
* @return a new tokenizer instance which parses Comma Separated Value strings
|
||||
*/
|
||||
public static StrTokenizer getCSVInstance(final char[] input) {
|
||||
StrTokenizer tok = getCSVClone();
|
||||
final StrTokenizer tok = getCSVClone();
|
||||
tok.reset(input);
|
||||
return tok;
|
||||
}
|
||||
|
@ -212,7 +212,7 @@ public static StrTokenizer getTSVInstance() {
|
|||
* @return a new tokenizer instance which parses Tab Separated Value strings.
|
||||
*/
|
||||
public static StrTokenizer getTSVInstance(final String input) {
|
||||
StrTokenizer tok = getTSVClone();
|
||||
final StrTokenizer tok = getTSVClone();
|
||||
tok.reset(input);
|
||||
return tok;
|
||||
}
|
||||
|
@ -225,7 +225,7 @@ public static StrTokenizer getTSVInstance(final String input) {
|
|||
* @return a new tokenizer instance which parses Tab Separated Value strings.
|
||||
*/
|
||||
public static StrTokenizer getTSVInstance(final char[] input) {
|
||||
StrTokenizer tok = getTSVClone();
|
||||
final StrTokenizer tok = getTSVClone();
|
||||
tok.reset(input);
|
||||
return tok;
|
||||
}
|
||||
|
@ -441,8 +441,8 @@ public String[] getTokenArray() {
|
|||
*/
|
||||
public List<String> getTokenList() {
|
||||
checkTokenized();
|
||||
List<String> list = new ArrayList<String>(tokens.length);
|
||||
for (String element : tokens) {
|
||||
final List<String> list = new ArrayList<String>(tokens.length);
|
||||
for (final String element : tokens) {
|
||||
list.add(element);
|
||||
}
|
||||
return list;
|
||||
|
@ -603,10 +603,10 @@ private void checkTokenized() {
|
|||
if (tokens == null) {
|
||||
if (chars == null) {
|
||||
// still call tokenize as subclass may do some work
|
||||
List<String> split = tokenize(null, 0, 0);
|
||||
final List<String> split = tokenize(null, 0, 0);
|
||||
tokens = split.toArray(new String[split.size()]);
|
||||
} else {
|
||||
List<String> split = tokenize(chars, 0, chars.length);
|
||||
final List<String> split = tokenize(chars, 0, chars.length);
|
||||
tokens = split.toArray(new String[split.size()]);
|
||||
}
|
||||
}
|
||||
|
@ -636,8 +636,8 @@ protected List<String> tokenize(final char[] chars, final int offset, final int
|
|||
if (chars == null || count == 0) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
StrBuilder buf = new StrBuilder();
|
||||
List<String> tokens = new ArrayList<String>();
|
||||
final StrBuilder buf = new StrBuilder();
|
||||
final List<String> tokens = new ArrayList<String>();
|
||||
int pos = offset;
|
||||
|
||||
// loop around the entire buffer
|
||||
|
@ -686,7 +686,7 @@ private int readNextToken(final char[] chars, int start, final int len, final St
|
|||
// skip all leading whitespace, unless it is the
|
||||
// field delimiter or the quote character
|
||||
while (start < len) {
|
||||
int removeLen = Math.max(
|
||||
final int removeLen = Math.max(
|
||||
getIgnoredMatcher().isMatch(chars, start, start, len),
|
||||
getTrimmerMatcher().isMatch(chars, start, start, len));
|
||||
if (removeLen == 0 ||
|
||||
|
@ -704,14 +704,14 @@ private int readNextToken(final char[] chars, int start, final int len, final St
|
|||
}
|
||||
|
||||
// handle empty token
|
||||
int delimLen = getDelimiterMatcher().isMatch(chars, start, start, len);
|
||||
final int delimLen = getDelimiterMatcher().isMatch(chars, start, start, len);
|
||||
if (delimLen > 0) {
|
||||
addToken(tokens, "");
|
||||
return start + delimLen;
|
||||
}
|
||||
|
||||
// handle found token
|
||||
int quoteLen = getQuoteMatcher().isMatch(chars, start, start, len);
|
||||
final int quoteLen = getQuoteMatcher().isMatch(chars, start, start, len);
|
||||
if (quoteLen > 0) {
|
||||
return readWithQuotes(chars, start + quoteLen, len, workArea, tokens, start, quoteLen);
|
||||
}
|
||||
|
@ -775,7 +775,7 @@ private int readWithQuotes(final char[] chars, final int start, final int len, f
|
|||
// Not in quoting mode
|
||||
|
||||
// check for delimiter, and thus end of token
|
||||
int delimLen = getDelimiterMatcher().isMatch(chars, pos, start, len);
|
||||
final int delimLen = getDelimiterMatcher().isMatch(chars, pos, start, len);
|
||||
if (delimLen > 0) {
|
||||
// return condition when end of token found
|
||||
addToken(tokens, workArea.substring(0, trimStart));
|
||||
|
@ -790,7 +790,7 @@ private int readWithQuotes(final char[] chars, final int start, final int len, f
|
|||
}
|
||||
|
||||
// check for ignored (outside quotes), and ignore
|
||||
int ignoredLen = getIgnoredMatcher().isMatch(chars, pos, start, len);
|
||||
final int ignoredLen = getIgnoredMatcher().isMatch(chars, pos, start, len);
|
||||
if (ignoredLen > 0) {
|
||||
pos += ignoredLen;
|
||||
continue;
|
||||
|
@ -799,7 +799,7 @@ private int readWithQuotes(final char[] chars, final int start, final int len, f
|
|||
// check for trimmed character
|
||||
// don't yet know if its at the end, so copy to workArea
|
||||
// use trimStart to keep track of trim at the end
|
||||
int trimmedLen = getTrimmerMatcher().isMatch(chars, pos, start, len);
|
||||
final int trimmedLen = getTrimmerMatcher().isMatch(chars, pos, start, len);
|
||||
if (trimmedLen > 0) {
|
||||
workArea.append(chars, pos, trimmedLen);
|
||||
pos += trimmedLen;
|
||||
|
@ -1075,7 +1075,7 @@ public String getContent() {
|
|||
public Object clone() {
|
||||
try {
|
||||
return cloneReset();
|
||||
} catch (CloneNotSupportedException ex) {
|
||||
} catch (final CloneNotSupportedException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -1089,7 +1089,7 @@ public Object clone() {
|
|||
*/
|
||||
Object cloneReset() throws CloneNotSupportedException {
|
||||
// this method exists to enable 100% test coverage
|
||||
StrTokenizer cloned = (StrTokenizer) super.clone();
|
||||
final StrTokenizer cloned = (StrTokenizer) super.clone();
|
||||
if (cloned.chars != null) {
|
||||
cloned.chars = cloned.chars.clone();
|
||||
}
|
||||
|
|
|
@ -95,9 +95,9 @@ public static String wrap(final String str, int wrapLength, String newLineStr, f
|
|||
if (wrapLength < 1) {
|
||||
wrapLength = 1;
|
||||
}
|
||||
int inputLineLength = str.length();
|
||||
final int inputLineLength = str.length();
|
||||
int offset = 0;
|
||||
StringBuilder wrappedLine = new StringBuilder(inputLineLength + 32);
|
||||
final StringBuilder wrappedLine = new StringBuilder(inputLineLength + 32);
|
||||
|
||||
while (inputLineLength - offset > wrapLength) {
|
||||
if (str.charAt(offset) == ' ') {
|
||||
|
@ -198,14 +198,14 @@ public static String capitalize(final String str) {
|
|||
* @since 2.1
|
||||
*/
|
||||
public static String capitalize(final String str, final char... delimiters) {
|
||||
int delimLen = delimiters == null ? -1 : delimiters.length;
|
||||
final int delimLen = delimiters == null ? -1 : delimiters.length;
|
||||
if (StringUtils.isEmpty(str) || delimLen == 0) {
|
||||
return str;
|
||||
}
|
||||
char[] buffer = str.toCharArray();
|
||||
final char[] buffer = str.toCharArray();
|
||||
boolean capitalizeNext = true;
|
||||
for (int i = 0; i < buffer.length; i++) {
|
||||
char ch = buffer[i];
|
||||
final char ch = buffer[i];
|
||||
if (isDelimiter(ch, delimiters)) {
|
||||
capitalizeNext = true;
|
||||
} else if (capitalizeNext) {
|
||||
|
@ -267,7 +267,7 @@ public static String capitalizeFully(final String str) {
|
|||
* @since 2.1
|
||||
*/
|
||||
public static String capitalizeFully(String str, final char... delimiters) {
|
||||
int delimLen = delimiters == null ? -1 : delimiters.length;
|
||||
final int delimLen = delimiters == null ? -1 : delimiters.length;
|
||||
if (StringUtils.isEmpty(str) || delimLen == 0) {
|
||||
return str;
|
||||
}
|
||||
|
@ -323,14 +323,14 @@ public static String uncapitalize(final String str) {
|
|||
* @since 2.1
|
||||
*/
|
||||
public static String uncapitalize(final String str, final char... delimiters) {
|
||||
int delimLen = delimiters == null ? -1 : delimiters.length;
|
||||
final int delimLen = delimiters == null ? -1 : delimiters.length;
|
||||
if (StringUtils.isEmpty(str) || delimLen == 0) {
|
||||
return str;
|
||||
}
|
||||
char[] buffer = str.toCharArray();
|
||||
final char[] buffer = str.toCharArray();
|
||||
boolean uncapitalizeNext = true;
|
||||
for (int i = 0; i < buffer.length; i++) {
|
||||
char ch = buffer[i];
|
||||
final char ch = buffer[i];
|
||||
if (isDelimiter(ch, delimiters)) {
|
||||
uncapitalizeNext = true;
|
||||
} else if (uncapitalizeNext) {
|
||||
|
@ -368,12 +368,12 @@ public static String swapCase(final String str) {
|
|||
if (StringUtils.isEmpty(str)) {
|
||||
return str;
|
||||
}
|
||||
char[] buffer = str.toCharArray();
|
||||
final char[] buffer = str.toCharArray();
|
||||
|
||||
boolean whitespace = true;
|
||||
|
||||
for (int i = 0; i < buffer.length; i++) {
|
||||
char ch = buffer[i];
|
||||
final char ch = buffer[i];
|
||||
if (Character.isUpperCase(ch)) {
|
||||
buffer[i] = Character.toLowerCase(ch);
|
||||
whitespace = false;
|
||||
|
@ -455,12 +455,12 @@ public static String initials(final String str, final char... delimiters) {
|
|||
if (delimiters != null && delimiters.length == 0) {
|
||||
return "";
|
||||
}
|
||||
int strLen = str.length();
|
||||
char[] buf = new char[strLen / 2 + 1];
|
||||
final int strLen = str.length();
|
||||
final char[] buf = new char[strLen / 2 + 1];
|
||||
int count = 0;
|
||||
boolean lastWasGap = true;
|
||||
for (int i = 0; i < strLen; i++) {
|
||||
char ch = str.charAt(i);
|
||||
final char ch = str.charAt(i);
|
||||
|
||||
if (isDelimiter(ch, delimiters)) {
|
||||
lastWasGap = true;
|
||||
|
@ -486,7 +486,7 @@ private static boolean isDelimiter(final char ch, final char[] delimiters) {
|
|||
if (delimiters == null) {
|
||||
return Character.isWhitespace(ch);
|
||||
}
|
||||
for (char delimiter : delimiters) {
|
||||
for (final char delimiter : delimiters) {
|
||||
if (ch == delimiter) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -48,8 +48,8 @@ public AggregateTranslator(final CharSequenceTranslator... translators) {
|
|||
*/
|
||||
@Override
|
||||
public int translate(final CharSequence input, final int index, final Writer out) throws IOException {
|
||||
for (CharSequenceTranslator translator : translators) {
|
||||
int consumed = translator.translate(input, index, out);
|
||||
for (final CharSequenceTranslator translator : translators) {
|
||||
final int consumed = translator.translate(input, index, out);
|
||||
if(consumed != 0) {
|
||||
return consumed;
|
||||
}
|
||||
|
|
|
@ -55,10 +55,10 @@ public final String translate(final CharSequence input) {
|
|||
return null;
|
||||
}
|
||||
try {
|
||||
StringWriter writer = new StringWriter(input.length() * 2);
|
||||
final StringWriter writer = new StringWriter(input.length() * 2);
|
||||
translate(input, writer);
|
||||
return writer.toString();
|
||||
} catch (IOException ioe) {
|
||||
} catch (final IOException ioe) {
|
||||
// this should never ever happen while writing to a StringWriter
|
||||
throw new RuntimeException(ioe);
|
||||
}
|
||||
|
@ -80,11 +80,11 @@ public final void translate(final CharSequence input, final Writer out) throws I
|
|||
return;
|
||||
}
|
||||
int pos = 0;
|
||||
int len = input.length();
|
||||
final int len = input.length();
|
||||
while (pos < len) {
|
||||
int consumed = translate(input, pos, out);
|
||||
final int consumed = translate(input, pos, out);
|
||||
if (consumed == 0) {
|
||||
char[] c = Character.toChars(Character.codePointAt(input, pos));
|
||||
final char[] c = Character.toChars(Character.codePointAt(input, pos));
|
||||
out.write(c);
|
||||
pos+= c.length;
|
||||
continue;
|
||||
|
@ -105,7 +105,7 @@ public final void translate(final CharSequence input, final Writer out) throws I
|
|||
* @return CharSequenceTranslator merging this translator with the others
|
||||
*/
|
||||
public final CharSequenceTranslator with(final CharSequenceTranslator... translators) {
|
||||
CharSequenceTranslator[] newArray = new CharSequenceTranslator[translators.length + 1];
|
||||
final CharSequenceTranslator[] newArray = new CharSequenceTranslator[translators.length + 1];
|
||||
newArray[0] = this;
|
||||
System.arraycopy(translators, 0, newArray, 1, translators.length);
|
||||
return new AggregateTranslator(newArray);
|
||||
|
|
|
@ -34,8 +34,8 @@ public abstract class CodePointTranslator extends CharSequenceTranslator {
|
|||
*/
|
||||
@Override
|
||||
public final int translate(final CharSequence input, final int index, final Writer out) throws IOException {
|
||||
int codepoint = Character.codePointAt(input, index);
|
||||
boolean consumed = translate(codepoint, out);
|
||||
final int codepoint = Character.codePointAt(input, index);
|
||||
final boolean consumed = translate(codepoint, out);
|
||||
if (consumed) {
|
||||
return 1;
|
||||
} else {
|
||||
|
|
|
@ -414,7 +414,7 @@ public class EntityArrays {
|
|||
* @return String[][] inverted array
|
||||
*/
|
||||
public static String[][] invert(final String[][] array) {
|
||||
String[][] newarray = new String[array.length][2];
|
||||
final String[][] newarray = new String[array.length][2];
|
||||
for(int i = 0; i<array.length; i++) {
|
||||
newarray[i][0] = array[i][1];
|
||||
newarray[i][1] = array[i][0];
|
||||
|
|
|
@ -90,7 +90,7 @@ public JavaUnicodeEscaper(final int below, final int above, final boolean betwee
|
|||
*/
|
||||
@Override
|
||||
protected String toUtf16Escape(final int codepoint) {
|
||||
char[] surrogatePair = Character.toChars(codepoint);
|
||||
final char[] surrogatePair = Character.toChars(codepoint);
|
||||
return "\\u" + hex(surrogatePair[0]) + "\\u" + hex(surrogatePair[1]);
|
||||
}
|
||||
|
||||
|
|
|
@ -42,9 +42,9 @@ public LookupTranslator(final CharSequence[]... lookup) {
|
|||
int _shortest = Integer.MAX_VALUE;
|
||||
int _longest = 0;
|
||||
if (lookup != null) {
|
||||
for (CharSequence[] seq : lookup) {
|
||||
for (final CharSequence[] seq : lookup) {
|
||||
this.lookupMap.put(seq[0], seq[1]);
|
||||
int sz = seq[0].length();
|
||||
final int sz = seq[0].length();
|
||||
if (sz < _shortest) {
|
||||
_shortest = sz;
|
||||
}
|
||||
|
@ -68,8 +68,8 @@ public int translate(final CharSequence input, final int index, final Writer out
|
|||
}
|
||||
// descend so as to get a greedy algorithm
|
||||
for (int i = max; i >= shortest; i--) {
|
||||
CharSequence subSeq = input.subSequence(index, index + i);
|
||||
CharSequence result = lookupMap.get(subSeq);
|
||||
final CharSequence subSeq = input.subSequence(index, index + i);
|
||||
final CharSequence result = lookupMap.get(subSeq);
|
||||
if (result != null) {
|
||||
out.write(result.toString());
|
||||
return i;
|
||||
|
|
|
@ -76,13 +76,13 @@ public boolean isSet(final OPTION option) {
|
|||
*/
|
||||
@Override
|
||||
public int translate(final CharSequence input, final int index, final Writer out) throws IOException {
|
||||
int seqEnd = input.length();
|
||||
final int seqEnd = input.length();
|
||||
// Uses -2 to ensure there is something after the &#
|
||||
if(input.charAt(index) == '&' && index < seqEnd - 2 && input.charAt(index + 1) == '#') {
|
||||
int start = index + 2;
|
||||
boolean isHex = false;
|
||||
|
||||
char firstChar = input.charAt(start);
|
||||
final char firstChar = input.charAt(start);
|
||||
if(firstChar == 'x' || firstChar == 'X') {
|
||||
start++;
|
||||
isHex = true;
|
||||
|
@ -102,7 +102,7 @@ public int translate(final CharSequence input, final int index, final Writer out
|
|||
end++;
|
||||
}
|
||||
|
||||
boolean semiNext = end != seqEnd && input.charAt(end) == ';';
|
||||
final boolean semiNext = end != seqEnd && input.charAt(end) == ';';
|
||||
|
||||
if(!semiNext) {
|
||||
if(isSet(OPTION.semiColonRequired)) {
|
||||
|
@ -120,12 +120,12 @@ public int translate(final CharSequence input, final int index, final Writer out
|
|||
} else {
|
||||
entityValue = Integer.parseInt(input.subSequence(start, end).toString(), 10);
|
||||
}
|
||||
} catch(NumberFormatException nfe) {
|
||||
} catch(final NumberFormatException nfe) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(entityValue > 0xFFFF) {
|
||||
char[] chrs = Character.toChars(entityValue);
|
||||
final char[] chrs = Character.toChars(entityValue);
|
||||
out.write(chrs[0]);
|
||||
out.write(chrs[1]);
|
||||
} else {
|
||||
|
|
|
@ -41,7 +41,7 @@ public class OctalUnescaper extends CharSequenceTranslator {
|
|||
@Override
|
||||
public int translate(final CharSequence input, final int index, final Writer out) throws IOException {
|
||||
if(input.charAt(index) == '\\' && index < (input.length() - 1) && Character.isDigit(input.charAt(index + 1)) ) {
|
||||
int start = index + 1;
|
||||
final int start = index + 1;
|
||||
|
||||
int end = index + 2;
|
||||
while ( end < input.length() && Character.isDigit(input.charAt(end)) ) {
|
||||
|
|
|
@ -47,12 +47,12 @@ public int translate(final CharSequence input, final int index, final Writer out
|
|||
|
||||
if (index + i + 4 <= input.length()) {
|
||||
// Get 4 hex digits
|
||||
CharSequence unicode = input.subSequence(index + i, index + i + 4);
|
||||
final CharSequence unicode = input.subSequence(index + i, index + i + 4);
|
||||
|
||||
try {
|
||||
int value = Integer.parseInt(unicode.toString(), 16);
|
||||
final int value = Integer.parseInt(unicode.toString(), 16);
|
||||
out.write((char) value);
|
||||
} catch (NumberFormatException nfe) {
|
||||
} catch (final NumberFormatException nfe) {
|
||||
throw new IllegalArgumentException("Unable to parse unicode value: " + unicode, nfe);
|
||||
}
|
||||
return i + 4;
|
||||
|
|
|
@ -300,7 +300,7 @@ public static String format(final long millis, final String pattern, final TimeZ
|
|||
* @return the formatted date
|
||||
*/
|
||||
public static String format(final Date date, final String pattern, final TimeZone timeZone, final Locale locale) {
|
||||
FastDateFormat df = FastDateFormat.getInstance(pattern, timeZone, locale);
|
||||
final FastDateFormat df = FastDateFormat.getInstance(pattern, timeZone, locale);
|
||||
return df.format(date);
|
||||
}
|
||||
|
||||
|
@ -316,7 +316,7 @@ public static String format(final Date date, final String pattern, final TimeZon
|
|||
* @since 2.4
|
||||
*/
|
||||
public static String format(final Calendar calendar, final String pattern, final TimeZone timeZone, final Locale locale) {
|
||||
FastDateFormat df = FastDateFormat.getInstance(pattern, timeZone, locale);
|
||||
final FastDateFormat df = FastDateFormat.getInstance(pattern, timeZone, locale);
|
||||
return df.format(calendar);
|
||||
}
|
||||
|
||||
|
|
|
@ -155,9 +155,9 @@ public static boolean isSameDay(final Date date1, final Date date2) {
|
|||
if (date1 == null || date2 == null) {
|
||||
throw new IllegalArgumentException("The date must not be null");
|
||||
}
|
||||
Calendar cal1 = Calendar.getInstance();
|
||||
final Calendar cal1 = Calendar.getInstance();
|
||||
cal1.setTime(date1);
|
||||
Calendar cal2 = Calendar.getInstance();
|
||||
final Calendar cal2 = Calendar.getInstance();
|
||||
cal2.setTime(date2);
|
||||
return isSameDay(cal1, cal2);
|
||||
}
|
||||
|
@ -363,8 +363,8 @@ private static Date parseDateWithLeniency(
|
|||
}
|
||||
|
||||
parser.setLenient(lenient);
|
||||
ParsePosition pos = new ParsePosition(0);
|
||||
for (String parsePattern : parsePatterns) {
|
||||
final ParsePosition pos = new ParsePosition(0);
|
||||
for (final String parsePattern : parsePatterns) {
|
||||
|
||||
String pattern = parsePattern;
|
||||
|
||||
|
@ -382,7 +382,7 @@ private static Date parseDateWithLeniency(
|
|||
str2 = str.replaceAll("([-+][0-9][0-9]):([0-9][0-9])$", "$1$2");
|
||||
}
|
||||
|
||||
Date date = parser.parse(str2, pos);
|
||||
final Date date = parser.parse(str2, pos);
|
||||
if (date != null && pos.getIndex() == str2.length()) {
|
||||
return date;
|
||||
}
|
||||
|
@ -517,7 +517,7 @@ private static Date add(final Date date, final int calendarField, final int amou
|
|||
if (date == null) {
|
||||
throw new IllegalArgumentException("The date must not be null");
|
||||
}
|
||||
Calendar c = Calendar.getInstance();
|
||||
final Calendar c = Calendar.getInstance();
|
||||
c.setTime(date);
|
||||
c.add(calendarField, amount);
|
||||
return c.getTime();
|
||||
|
@ -647,7 +647,7 @@ private static Date set(final Date date, final int calendarField, final int amou
|
|||
throw new IllegalArgumentException("The date must not be null");
|
||||
}
|
||||
// getInstance() returns a new object, so this method is thread safe.
|
||||
Calendar c = Calendar.getInstance();
|
||||
final Calendar c = Calendar.getInstance();
|
||||
c.setLenient(false);
|
||||
c.setTime(date);
|
||||
c.set(calendarField, amount);
|
||||
|
@ -664,7 +664,7 @@ private static Date set(final Date date, final int calendarField, final int amou
|
|||
* @since 3.0
|
||||
*/
|
||||
public static Calendar toCalendar(final Date date) {
|
||||
Calendar c = Calendar.getInstance();
|
||||
final Calendar c = Calendar.getInstance();
|
||||
c.setTime(date);
|
||||
return c;
|
||||
}
|
||||
|
@ -700,7 +700,7 @@ public static Date round(final Date date, final int field) {
|
|||
if (date == null) {
|
||||
throw new IllegalArgumentException("The date must not be null");
|
||||
}
|
||||
Calendar gval = Calendar.getInstance();
|
||||
final Calendar gval = Calendar.getInstance();
|
||||
gval.setTime(date);
|
||||
modify(gval, field, MODIFY_ROUND);
|
||||
return gval.getTime();
|
||||
|
@ -737,7 +737,7 @@ public static Calendar round(final Calendar date, final int field) {
|
|||
if (date == null) {
|
||||
throw new IllegalArgumentException("The date must not be null");
|
||||
}
|
||||
Calendar rounded = (Calendar) date.clone();
|
||||
final Calendar rounded = (Calendar) date.clone();
|
||||
modify(rounded, field, MODIFY_ROUND);
|
||||
return rounded;
|
||||
}
|
||||
|
@ -803,7 +803,7 @@ public static Date truncate(final Date date, final int field) {
|
|||
if (date == null) {
|
||||
throw new IllegalArgumentException("The date must not be null");
|
||||
}
|
||||
Calendar gval = Calendar.getInstance();
|
||||
final Calendar gval = Calendar.getInstance();
|
||||
gval.setTime(date);
|
||||
modify(gval, field, MODIFY_TRUNCATE);
|
||||
return gval.getTime();
|
||||
|
@ -828,7 +828,7 @@ public static Calendar truncate(final Calendar date, final int field) {
|
|||
if (date == null) {
|
||||
throw new IllegalArgumentException("The date must not be null");
|
||||
}
|
||||
Calendar truncated = (Calendar) date.clone();
|
||||
final Calendar truncated = (Calendar) date.clone();
|
||||
modify(truncated, field, MODIFY_TRUNCATE);
|
||||
return truncated;
|
||||
}
|
||||
|
@ -883,7 +883,7 @@ public static Date ceiling(final Date date, final int field) {
|
|||
if (date == null) {
|
||||
throw new IllegalArgumentException("The date must not be null");
|
||||
}
|
||||
Calendar gval = Calendar.getInstance();
|
||||
final Calendar gval = Calendar.getInstance();
|
||||
gval.setTime(date);
|
||||
modify(gval, field, MODIFY_CEILING);
|
||||
return gval.getTime();
|
||||
|
@ -909,7 +909,7 @@ public static Calendar ceiling(final Calendar date, final int field) {
|
|||
if (date == null) {
|
||||
throw new IllegalArgumentException("The date must not be null");
|
||||
}
|
||||
Calendar ceiled = (Calendar) date.clone();
|
||||
final Calendar ceiled = (Calendar) date.clone();
|
||||
modify(ceiled, field, MODIFY_CEILING);
|
||||
return ceiled;
|
||||
}
|
||||
|
@ -968,12 +968,12 @@ private static void modify(final Calendar val, final int field, final int modTyp
|
|||
// Manually truncate milliseconds, seconds and minutes, rather than using
|
||||
// Calendar methods.
|
||||
|
||||
Date date = val.getTime();
|
||||
final Date date = val.getTime();
|
||||
long time = date.getTime();
|
||||
boolean done = false;
|
||||
|
||||
// truncate milliseconds
|
||||
int millisecs = val.get(Calendar.MILLISECOND);
|
||||
final int millisecs = val.get(Calendar.MILLISECOND);
|
||||
if (MODIFY_TRUNCATE == modType || millisecs < 500) {
|
||||
time = time - millisecs;
|
||||
}
|
||||
|
@ -982,7 +982,7 @@ private static void modify(final Calendar val, final int field, final int modTyp
|
|||
}
|
||||
|
||||
// truncate seconds
|
||||
int seconds = val.get(Calendar.SECOND);
|
||||
final int seconds = val.get(Calendar.SECOND);
|
||||
if (!done && (MODIFY_TRUNCATE == modType || seconds < 30)) {
|
||||
time = time - (seconds * 1000L);
|
||||
}
|
||||
|
@ -991,7 +991,7 @@ private static void modify(final Calendar val, final int field, final int modTyp
|
|||
}
|
||||
|
||||
// truncate minutes
|
||||
int minutes = val.get(Calendar.MINUTE);
|
||||
final int minutes = val.get(Calendar.MINUTE);
|
||||
if (!done && (MODIFY_TRUNCATE == modType || minutes < 30)) {
|
||||
time = time - (minutes * 60000L);
|
||||
}
|
||||
|
@ -1004,8 +1004,8 @@ private static void modify(final Calendar val, final int field, final int modTyp
|
|||
// ----------------- Fix for LANG-59 ----------------------- END ----------------
|
||||
|
||||
boolean roundUp = false;
|
||||
for (int[] aField : fields) {
|
||||
for (int element : aField) {
|
||||
for (final int[] aField : fields) {
|
||||
for (final int element : aField) {
|
||||
if (element == field) {
|
||||
//This is our field... we stop looping
|
||||
if (modType == MODIFY_CEILING || (modType == MODIFY_ROUND && roundUp)) {
|
||||
|
@ -1075,8 +1075,8 @@ private static void modify(final Calendar val, final int field, final int modTyp
|
|||
break;
|
||||
}
|
||||
if (!offsetSet) {
|
||||
int min = val.getActualMinimum(aField[0]);
|
||||
int max = val.getActualMaximum(aField[0]);
|
||||
final int min = val.getActualMinimum(aField[0]);
|
||||
final int max = val.getActualMaximum(aField[0]);
|
||||
//Calculate the offset from the minimum allowed value
|
||||
offset = val.get(aField[0]) - min;
|
||||
//Set roundUp if this is more than half way between the minimum and maximum
|
||||
|
@ -1120,7 +1120,7 @@ public static Iterator<Calendar> iterator(final Date focus, final int rangeStyle
|
|||
if (focus == null) {
|
||||
throw new IllegalArgumentException("The date must not be null");
|
||||
}
|
||||
Calendar gval = Calendar.getInstance();
|
||||
final Calendar gval = Calendar.getInstance();
|
||||
gval.setTime(focus);
|
||||
return iterator(gval, rangeStyle);
|
||||
}
|
||||
|
@ -1663,7 +1663,7 @@ private static long getFragment(final Date date, final int fragment, final int u
|
|||
if(date == null) {
|
||||
throw new IllegalArgumentException("The date must not be null");
|
||||
}
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
final Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(date);
|
||||
return getFragment(calendar, fragment, unit);
|
||||
}
|
||||
|
@ -1683,7 +1683,7 @@ private static long getFragment(final Calendar calendar, final int fragment, fin
|
|||
if(calendar == null) {
|
||||
throw new IllegalArgumentException("The date must not be null");
|
||||
}
|
||||
long millisPerUnit = getMillisPerUnit(unit);
|
||||
final long millisPerUnit = getMillisPerUnit(unit);
|
||||
long result = 0;
|
||||
|
||||
// Fragments bigger than a day require a breakdown to days
|
||||
|
@ -1770,8 +1770,8 @@ public static boolean truncatedEquals(final Date date1, final Date date2, final
|
|||
* @since 3.0
|
||||
*/
|
||||
public static int truncatedCompareTo(final Calendar cal1, final Calendar cal2, final int field) {
|
||||
Calendar truncatedCal1 = truncate(cal1, field);
|
||||
Calendar truncatedCal2 = truncate(cal2, field);
|
||||
final Calendar truncatedCal1 = truncate(cal1, field);
|
||||
final Calendar truncatedCal2 = truncate(cal2, field);
|
||||
return truncatedCal1.compareTo(truncatedCal2);
|
||||
}
|
||||
|
||||
|
@ -1790,8 +1790,8 @@ public static int truncatedCompareTo(final Calendar cal1, final Calendar cal2, f
|
|||
* @since 3.0
|
||||
*/
|
||||
public static int truncatedCompareTo(final Date date1, final Date date2, final int field) {
|
||||
Date truncatedDate1 = truncate(date1, field);
|
||||
Date truncatedDate2 = truncate(date2, field);
|
||||
final Date truncatedDate1 = truncate(date1, field);
|
||||
final Date truncatedDate2 = truncate(date2, field);
|
||||
return truncatedDate1.compareTo(truncatedDate2);
|
||||
}
|
||||
|
||||
|
|
|
@ -121,7 +121,7 @@ public static String formatDuration(final long durationMillis, final String form
|
|||
*/
|
||||
public static String formatDuration(long durationMillis, final String format, final boolean padWithZeros) {
|
||||
|
||||
Token[] tokens = lexx(format);
|
||||
final Token[] tokens = lexx(format);
|
||||
|
||||
int days = 0;
|
||||
int hours = 0;
|
||||
|
@ -275,13 +275,13 @@ public static String formatPeriod(final long startMillis, final long endMillis,
|
|||
// TODO: Compare performance to see if anything was lost by
|
||||
// losing this optimisation.
|
||||
|
||||
Token[] tokens = lexx(format);
|
||||
final Token[] tokens = lexx(format);
|
||||
|
||||
// timezones get funky around 0, so normalizing everything to GMT
|
||||
// stops the hours being off
|
||||
Calendar start = Calendar.getInstance(timezone);
|
||||
final Calendar start = Calendar.getInstance(timezone);
|
||||
start.setTime(new Date(startMillis));
|
||||
Calendar end = Calendar.getInstance(timezone);
|
||||
final Calendar end = Calendar.getInstance(timezone);
|
||||
end.setTime(new Date(endMillis));
|
||||
|
||||
// initial estimates
|
||||
|
@ -413,13 +413,13 @@ public static String formatPeriod(final long startMillis, final long endMillis,
|
|||
*/
|
||||
static String format(final Token[] tokens, final int years, final int months, final int days, final int hours, final int minutes, final int seconds,
|
||||
int milliseconds, final boolean padWithZeros) {
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
final StringBuilder buffer = new StringBuilder();
|
||||
boolean lastOutputSeconds = false;
|
||||
int sz = tokens.length;
|
||||
final int sz = tokens.length;
|
||||
for (int i = 0; i < sz; i++) {
|
||||
Token token = tokens[i];
|
||||
Object value = token.getValue();
|
||||
int count = token.getCount();
|
||||
final Token token = tokens[i];
|
||||
final Object value = token.getValue();
|
||||
final int count = token.getCount();
|
||||
if (value instanceof StringBuilder) {
|
||||
buffer.append(value.toString());
|
||||
} else {
|
||||
|
@ -450,7 +450,7 @@ static String format(final Token[] tokens, final int years, final int months, fi
|
|||
} else if (value == S) {
|
||||
if (lastOutputSeconds) {
|
||||
milliseconds += 1000;
|
||||
String str = padWithZeros
|
||||
final String str = padWithZeros
|
||||
? StringUtils.leftPad(Integer.toString(milliseconds), count, '0')
|
||||
: Integer.toString(milliseconds);
|
||||
buffer.append(str.substring(1));
|
||||
|
@ -481,17 +481,17 @@ static String format(final Token[] tokens, final int years, final int months, fi
|
|||
* @return array of Token[]
|
||||
*/
|
||||
static Token[] lexx(final String format) {
|
||||
char[] array = format.toCharArray();
|
||||
ArrayList<Token> list = new ArrayList<Token>(array.length);
|
||||
final char[] array = format.toCharArray();
|
||||
final ArrayList<Token> list = new ArrayList<Token>(array.length);
|
||||
|
||||
boolean inLiteral = false;
|
||||
// Although the buffer is stored in a Token, the Tokens are only
|
||||
// used internally, so cannot be accessed by other threads
|
||||
StringBuilder buffer = null;
|
||||
Token previous = null;
|
||||
int sz = array.length;
|
||||
final int sz = array.length;
|
||||
for(int i=0; i<sz; i++) {
|
||||
char ch = array[i];
|
||||
final char ch = array[i];
|
||||
if(inLiteral && ch != '\'') {
|
||||
buffer.append(ch); // buffer can't be null if inLiteral is true
|
||||
continue;
|
||||
|
@ -528,7 +528,7 @@ static Token[] lexx(final String format) {
|
|||
if(previous != null && previous.getValue() == value) {
|
||||
previous.increment();
|
||||
} else {
|
||||
Token token = new Token(value);
|
||||
final Token token = new Token(value);
|
||||
list.add(token);
|
||||
previous = token;
|
||||
}
|
||||
|
@ -552,7 +552,7 @@ static class Token {
|
|||
* @return boolean <code>true</code> if contained
|
||||
*/
|
||||
static boolean containsTokenWithValue(final Token[] tokens, final Object value) {
|
||||
int sz = tokens.length;
|
||||
final int sz = tokens.length;
|
||||
for (int i = 0; i < sz; i++) {
|
||||
if (tokens[i].getValue() == value) {
|
||||
return true;
|
||||
|
@ -620,7 +620,7 @@ Object getValue() {
|
|||
@Override
|
||||
public boolean equals(final Object obj2) {
|
||||
if (obj2 instanceof Token) {
|
||||
Token tok2 = (Token) obj2;
|
||||
final Token tok2 = (Token) obj2;
|
||||
if (this.value.getClass() != tok2.value.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -548,7 +548,7 @@ public boolean equals(final Object obj) {
|
|||
if (obj instanceof FastDateFormat == false) {
|
||||
return false;
|
||||
}
|
||||
FastDateFormat other = (FastDateFormat) obj;
|
||||
final FastDateFormat other = (FastDateFormat) obj;
|
||||
// no need to check parser, as it has same invariants as printer
|
||||
return printer.equals(other.printer);
|
||||
}
|
||||
|
|
|
@ -106,13 +106,13 @@ protected FastDateParser(final String pattern, final TimeZone timeZone, final Lo
|
|||
* This is called from constructor and from readObject (de-serialization)
|
||||
*/
|
||||
private void init() {
|
||||
Calendar definingCalendar = Calendar.getInstance(timeZone, locale);
|
||||
final Calendar definingCalendar = Calendar.getInstance(timeZone, locale);
|
||||
thisYear= definingCalendar.get(Calendar.YEAR);
|
||||
|
||||
StringBuilder regex= new StringBuilder();
|
||||
List<Strategy> collector = new ArrayList<Strategy>();
|
||||
final StringBuilder regex= new StringBuilder();
|
||||
final List<Strategy> collector = new ArrayList<Strategy>();
|
||||
|
||||
Matcher patternMatcher= formatPattern.matcher(pattern);
|
||||
final Matcher patternMatcher= formatPattern.matcher(pattern);
|
||||
if(!patternMatcher.lookingAt()) {
|
||||
throw new IllegalArgumentException(
|
||||
"Illegal pattern character '" + pattern.charAt(patternMatcher.regionStart()) + "'");
|
||||
|
@ -126,7 +126,7 @@ private void init() {
|
|||
nextStrategy = null;
|
||||
break;
|
||||
}
|
||||
String nextFormatField= patternMatcher.group();
|
||||
final String nextFormatField= patternMatcher.group();
|
||||
nextStrategy = getStrategy(nextFormatField, definingCalendar);
|
||||
if(currentStrategy.addRegex(this, regex)) {
|
||||
collector.add(currentStrategy);
|
||||
|
@ -189,7 +189,7 @@ public boolean equals(final Object obj) {
|
|||
if (! (obj instanceof FastDateParser) ) {
|
||||
return false;
|
||||
}
|
||||
FastDateParser other = (FastDateParser) obj;
|
||||
final FastDateParser other = (FastDateParser) obj;
|
||||
return pattern.equals(other.pattern)
|
||||
&& timeZone.equals(other.timeZone)
|
||||
&& locale.equals(other.locale);
|
||||
|
@ -243,7 +243,7 @@ public Object parseObject(final String source) throws ParseException {
|
|||
*/
|
||||
@Override
|
||||
public Date parse(final String source) throws ParseException {
|
||||
Date date= parse(source, new ParsePosition(0));
|
||||
final Date date= parse(source, new ParsePosition(0));
|
||||
if(date==null) {
|
||||
// Add a note re supported date range
|
||||
if (locale.equals(JAPANESE_IMPERIAL)) {
|
||||
|
@ -269,17 +269,17 @@ public Object parseObject(final String source, final ParsePosition pos) {
|
|||
*/
|
||||
@Override
|
||||
public Date parse(final String source, final ParsePosition pos) {
|
||||
int offset= pos.getIndex();
|
||||
Matcher matcher= parsePattern.matcher(source.substring(offset));
|
||||
final int offset= pos.getIndex();
|
||||
final Matcher matcher= parsePattern.matcher(source.substring(offset));
|
||||
if(!matcher.lookingAt()) {
|
||||
return null;
|
||||
}
|
||||
// timing tests indicate getting new instance is 19% faster than cloning
|
||||
Calendar cal= Calendar.getInstance(timeZone, locale);
|
||||
final Calendar cal= Calendar.getInstance(timeZone, locale);
|
||||
cal.clear();
|
||||
|
||||
for(int i=0; i<strategies.length;) {
|
||||
Strategy strategy= strategies[i++];
|
||||
final Strategy strategy= strategies[i++];
|
||||
strategy.setCalendar(this, cal, matcher.group(i));
|
||||
}
|
||||
pos.setIndex(offset+matcher.end());
|
||||
|
@ -352,7 +352,7 @@ private static Map<String, Integer> getDisplayNames(final int field, final Calen
|
|||
* @return A value within -80 and +20 years from instantiation of this instance
|
||||
*/
|
||||
int adjustYear(final int twoDigitYear) {
|
||||
int trial= twoDigitYear + thisYear - thisYear%100;
|
||||
final int trial= twoDigitYear + thisYear - thisYear%100;
|
||||
if(trial < thisYear+20) {
|
||||
return trial;
|
||||
}
|
||||
|
@ -498,13 +498,13 @@ private static ConcurrentMap<Locale, Strategy> getCache(final int field) {
|
|||
* @return a TextStrategy for the field and Locale
|
||||
*/
|
||||
private Strategy getLocaleSpecificStrategy(final int field, final Calendar definingCalendar) {
|
||||
ConcurrentMap<Locale,Strategy> cache = getCache(field);
|
||||
final ConcurrentMap<Locale,Strategy> cache = getCache(field);
|
||||
Strategy strategy= cache.get(Integer.valueOf(field));
|
||||
if(strategy==null) {
|
||||
strategy= field==Calendar.ZONE_OFFSET
|
||||
? new TimeZoneStrategy(locale)
|
||||
: new TextStrategy(field, definingCalendar, locale);
|
||||
Strategy inCache= cache.putIfAbsent(locale, strategy);
|
||||
final Strategy inCache= cache.putIfAbsent(locale, strategy);
|
||||
if(inCache!=null) {
|
||||
return inCache;
|
||||
}
|
||||
|
@ -570,7 +570,7 @@ private static class TextStrategy extends Strategy {
|
|||
@Override
|
||||
boolean addRegex(final FastDateParser parser, final StringBuilder regex) {
|
||||
regex.append('(');
|
||||
for(String textKeyValue : keyValues.keySet()) {
|
||||
for(final String textKeyValue : keyValues.keySet()) {
|
||||
escapeRegex(regex, textKeyValue, false).append('|');
|
||||
}
|
||||
regex.setCharAt(regex.length()-1, ')');
|
||||
|
@ -582,11 +582,11 @@ boolean addRegex(final FastDateParser parser, final StringBuilder regex) {
|
|||
*/
|
||||
@Override
|
||||
void setCalendar(final FastDateParser parser, final Calendar cal, final String value) {
|
||||
Integer iVal = keyValues.get(value);
|
||||
final Integer iVal = keyValues.get(value);
|
||||
if(iVal == null) {
|
||||
StringBuilder sb= new StringBuilder(value);
|
||||
final StringBuilder sb= new StringBuilder(value);
|
||||
sb.append(" not in (");
|
||||
for(String textKeyValue : keyValues.keySet()) {
|
||||
for(final String textKeyValue : keyValues.keySet()) {
|
||||
sb.append(textKeyValue).append(' ');
|
||||
}
|
||||
sb.setCharAt(sb.length()-1, ')');
|
||||
|
@ -678,11 +678,11 @@ private static class TimeZoneStrategy extends Strategy {
|
|||
* @param locale The Locale
|
||||
*/
|
||||
TimeZoneStrategy(final Locale locale) {
|
||||
for(String id : TimeZone.getAvailableIDs()) {
|
||||
for(final String id : TimeZone.getAvailableIDs()) {
|
||||
if(id.startsWith("GMT")) {
|
||||
continue;
|
||||
}
|
||||
TimeZone tz= TimeZone.getTimeZone(id);
|
||||
final TimeZone tz= TimeZone.getTimeZone(id);
|
||||
tzNames.put(tz.getDisplayName(false, TimeZone.SHORT, locale), tz);
|
||||
tzNames.put(tz.getDisplayName(false, TimeZone.LONG, locale), tz);
|
||||
if(tz.useDaylightTime()) {
|
||||
|
@ -690,9 +690,9 @@ private static class TimeZoneStrategy extends Strategy {
|
|||
tzNames.put(tz.getDisplayName(true, TimeZone.LONG, locale), tz);
|
||||
}
|
||||
}
|
||||
StringBuilder sb= new StringBuilder();
|
||||
final StringBuilder sb= new StringBuilder();
|
||||
sb.append("(GMT[+\\-]\\d{0,1}\\d{2}|[+\\-]\\d{2}:?\\d{2}|");
|
||||
for(String id : tzNames.keySet()) {
|
||||
for(final String id : tzNames.keySet()) {
|
||||
escapeRegex(sb, id, false).append('|');
|
||||
}
|
||||
sb.setCharAt(sb.length()-1, ')');
|
||||
|
|
|
@ -145,7 +145,7 @@ protected FastDatePrinter(final String pattern, final TimeZone timeZone, final L
|
|||
* <p>Initializes the instance for first use.</p>
|
||||
*/
|
||||
private void init() {
|
||||
List<Rule> rulesList = parsePattern();
|
||||
final List<Rule> rulesList = parsePattern();
|
||||
mRules = rulesList.toArray(new Rule[rulesList.size()]);
|
||||
|
||||
int len = 0;
|
||||
|
@ -165,31 +165,31 @@ private void init() {
|
|||
* @throws IllegalArgumentException if pattern is invalid
|
||||
*/
|
||||
protected List<Rule> parsePattern() {
|
||||
DateFormatSymbols symbols = new DateFormatSymbols(mLocale);
|
||||
List<Rule> rules = new ArrayList<Rule>();
|
||||
final DateFormatSymbols symbols = new DateFormatSymbols(mLocale);
|
||||
final List<Rule> rules = new ArrayList<Rule>();
|
||||
|
||||
String[] ERAs = symbols.getEras();
|
||||
String[] months = symbols.getMonths();
|
||||
String[] shortMonths = symbols.getShortMonths();
|
||||
String[] weekdays = symbols.getWeekdays();
|
||||
String[] shortWeekdays = symbols.getShortWeekdays();
|
||||
String[] AmPmStrings = symbols.getAmPmStrings();
|
||||
final String[] ERAs = symbols.getEras();
|
||||
final String[] months = symbols.getMonths();
|
||||
final String[] shortMonths = symbols.getShortMonths();
|
||||
final String[] weekdays = symbols.getWeekdays();
|
||||
final String[] shortWeekdays = symbols.getShortWeekdays();
|
||||
final String[] AmPmStrings = symbols.getAmPmStrings();
|
||||
|
||||
int length = mPattern.length();
|
||||
int[] indexRef = new int[1];
|
||||
final int length = mPattern.length();
|
||||
final int[] indexRef = new int[1];
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
indexRef[0] = i;
|
||||
String token = parseToken(mPattern, indexRef);
|
||||
final String token = parseToken(mPattern, indexRef);
|
||||
i = indexRef[0];
|
||||
|
||||
int tokenLen = token.length();
|
||||
final int tokenLen = token.length();
|
||||
if (tokenLen == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
Rule rule;
|
||||
char c = token.charAt(0);
|
||||
final char c = token.charAt(0);
|
||||
|
||||
switch (c) {
|
||||
case 'G': // era designator (text)
|
||||
|
@ -270,7 +270,7 @@ protected List<Rule> parsePattern() {
|
|||
}
|
||||
break;
|
||||
case '\'': // literal text
|
||||
String sub = token.substring(1);
|
||||
final String sub = token.substring(1);
|
||||
if (sub.length() == 1) {
|
||||
rule = new CharacterLiteral(sub.charAt(0));
|
||||
} else {
|
||||
|
@ -295,10 +295,10 @@ protected List<Rule> parsePattern() {
|
|||
* @return parsed token
|
||||
*/
|
||||
protected String parseToken(final String pattern, final int[] indexRef) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
final StringBuilder buf = new StringBuilder();
|
||||
|
||||
int i = indexRef[0];
|
||||
int length = pattern.length();
|
||||
final int length = pattern.length();
|
||||
|
||||
char c = pattern.charAt(i);
|
||||
if (c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z') {
|
||||
|
@ -307,7 +307,7 @@ protected String parseToken(final String pattern, final int[] indexRef) {
|
|||
buf.append(c);
|
||||
|
||||
while (i + 1 < length) {
|
||||
char peek = pattern.charAt(i + 1);
|
||||
final char peek = pattern.charAt(i + 1);
|
||||
if (peek == c) {
|
||||
buf.append(c);
|
||||
i++;
|
||||
|
@ -394,7 +394,7 @@ public StringBuffer format(final Object obj, final StringBuffer toAppendTo, fina
|
|||
*/
|
||||
@Override
|
||||
public String format(final long millis) {
|
||||
Calendar c = newCalendar(); // hard code GregorianCalendar
|
||||
final Calendar c = newCalendar(); // hard code GregorianCalendar
|
||||
c.setTimeInMillis(millis);
|
||||
return applyRulesToString(c);
|
||||
}
|
||||
|
@ -413,7 +413,7 @@ private GregorianCalendar newCalendar() {
|
|||
*/
|
||||
@Override
|
||||
public String format(final Date date) {
|
||||
Calendar c = newCalendar(); // hard code GregorianCalendar
|
||||
final Calendar c = newCalendar(); // hard code GregorianCalendar
|
||||
c.setTime(date);
|
||||
return applyRulesToString(c);
|
||||
}
|
||||
|
@ -439,7 +439,7 @@ public StringBuffer format(final long millis, final StringBuffer buf) {
|
|||
*/
|
||||
@Override
|
||||
public StringBuffer format(final Date date, final StringBuffer buf) {
|
||||
Calendar c = newCalendar(); // hard code GregorianCalendar
|
||||
final Calendar c = newCalendar(); // hard code GregorianCalendar
|
||||
c.setTime(date);
|
||||
return applyRules(c, buf);
|
||||
}
|
||||
|
@ -461,7 +461,7 @@ public StringBuffer format(final Calendar calendar, final StringBuffer buf) {
|
|||
* @return the specified string buffer
|
||||
*/
|
||||
protected StringBuffer applyRules(final Calendar calendar, final StringBuffer buf) {
|
||||
for (Rule rule : mRules) {
|
||||
for (final Rule rule : mRules) {
|
||||
rule.appendTo(buf, calendar);
|
||||
}
|
||||
return buf;
|
||||
|
@ -519,7 +519,7 @@ public boolean equals(final Object obj) {
|
|||
if (obj instanceof FastDatePrinter == false) {
|
||||
return false;
|
||||
}
|
||||
FastDatePrinter other = (FastDatePrinter) obj;
|
||||
final FastDatePrinter other = (FastDatePrinter) obj;
|
||||
return mPattern.equals(other.mPattern)
|
||||
&& mTimeZone.equals(other.mTimeZone)
|
||||
&& mLocale.equals(other.mLocale);
|
||||
|
@ -687,7 +687,7 @@ private static class TextField implements Rule {
|
|||
public int estimateLength() {
|
||||
int max = 0;
|
||||
for (int i=mValues.length; --i >= 0; ) {
|
||||
int len = mValues[i].length();
|
||||
final int len = mValues[i].length();
|
||||
if (len > max) {
|
||||
max = len;
|
||||
}
|
||||
|
@ -1087,12 +1087,12 @@ public void appendTo(final StringBuffer buffer, final int value) {
|
|||
* @return the textual name of the time zone
|
||||
*/
|
||||
static String getTimeZoneDisplay(final TimeZone tz, final boolean daylight, final int style, final Locale locale) {
|
||||
TimeZoneDisplayKey key = new TimeZoneDisplayKey(tz, daylight, style, locale);
|
||||
final TimeZoneDisplayKey key = new TimeZoneDisplayKey(tz, daylight, style, locale);
|
||||
String value = cTimeZoneDisplayCache.get(key);
|
||||
if (value == null) {
|
||||
// This is a very slow call, so cache the results.
|
||||
value = tz.getDisplayName(daylight, style, locale);
|
||||
String prior = cTimeZoneDisplayCache.putIfAbsent(key, value);
|
||||
final String prior = cTimeZoneDisplayCache.putIfAbsent(key, value);
|
||||
if (prior != null) {
|
||||
value= prior;
|
||||
}
|
||||
|
@ -1140,7 +1140,7 @@ public int estimateLength() {
|
|||
*/
|
||||
@Override
|
||||
public void appendTo(final StringBuffer buffer, final Calendar calendar) {
|
||||
TimeZone zone = calendar.getTimeZone();
|
||||
final TimeZone zone = calendar.getTimeZone();
|
||||
if (zone.useDaylightTime()
|
||||
&& calendar.get(Calendar.DST_OFFSET) != 0) {
|
||||
buffer.append(getTimeZoneDisplay(zone, true, mStyle, mLocale));
|
||||
|
@ -1191,7 +1191,7 @@ public void appendTo(final StringBuffer buffer, final Calendar calendar) {
|
|||
buffer.append('+');
|
||||
}
|
||||
|
||||
int hours = offset / (60 * 60 * 1000);
|
||||
final int hours = offset / (60 * 60 * 1000);
|
||||
buffer.append((char)(hours / 10 + '0'));
|
||||
buffer.append((char)(hours % 10 + '0'));
|
||||
|
||||
|
@ -1199,7 +1199,7 @@ public void appendTo(final StringBuffer buffer, final Calendar calendar) {
|
|||
buffer.append(':');
|
||||
}
|
||||
|
||||
int minutes = offset / (60 * 1000) - 60 * hours;
|
||||
final int minutes = offset / (60 * 1000) - 60 * hours;
|
||||
buffer.append((char)(minutes / 10 + '0'));
|
||||
buffer.append((char)(minutes % 10 + '0'));
|
||||
}
|
||||
|
@ -1249,7 +1249,7 @@ public boolean equals(final Object obj) {
|
|||
return true;
|
||||
}
|
||||
if (obj instanceof TimeZoneDisplayKey) {
|
||||
TimeZoneDisplayKey other = (TimeZoneDisplayKey)obj;
|
||||
final TimeZoneDisplayKey other = (TimeZoneDisplayKey)obj;
|
||||
return
|
||||
mTimeZone.equals(other.mTimeZone) &&
|
||||
mStyle == other.mStyle &&
|
||||
|
|
|
@ -76,11 +76,11 @@ public F getInstance(final String pattern, TimeZone timeZone, Locale locale) {
|
|||
if (locale == null) {
|
||||
locale = Locale.getDefault();
|
||||
}
|
||||
MultipartKey key = new MultipartKey(pattern, timeZone, locale);
|
||||
final MultipartKey key = new MultipartKey(pattern, timeZone, locale);
|
||||
F format = cInstanceCache.get(key);
|
||||
if (format == null) {
|
||||
format = createInstance(pattern, timeZone, locale);
|
||||
F previousValue= cInstanceCache.putIfAbsent(key, format);
|
||||
final F previousValue= cInstanceCache.putIfAbsent(key, format);
|
||||
if (previousValue != null) {
|
||||
// another thread snuck in and did the same work
|
||||
// we should return the instance that is in ConcurrentMap
|
||||
|
@ -120,7 +120,7 @@ public F getDateTimeInstance(final Integer dateStyle, final Integer timeStyle, f
|
|||
if (locale == null) {
|
||||
locale = Locale.getDefault();
|
||||
}
|
||||
String pattern = getPatternForStyle(dateStyle, timeStyle, locale);
|
||||
final String pattern = getPatternForStyle(dateStyle, timeStyle, locale);
|
||||
return getInstance(pattern, timeZone, locale);
|
||||
}
|
||||
|
||||
|
@ -134,7 +134,7 @@ public F getDateTimeInstance(final Integer dateStyle, final Integer timeStyle, f
|
|||
* @throws IllegalArgumentException if the Locale has no date/time pattern defined
|
||||
*/
|
||||
public static String getPatternForStyle(final Integer dateStyle, final Integer timeStyle, final Locale locale) {
|
||||
MultipartKey key = new MultipartKey(dateStyle, timeStyle, locale);
|
||||
final MultipartKey key = new MultipartKey(dateStyle, timeStyle, locale);
|
||||
|
||||
String pattern = cDateTimeInstanceCache.get(key);
|
||||
if (pattern == null) {
|
||||
|
@ -150,14 +150,14 @@ else if (timeStyle == null) {
|
|||
formatter = DateFormat.getDateTimeInstance(dateStyle.intValue(), timeStyle.intValue(), locale);
|
||||
}
|
||||
pattern = ((SimpleDateFormat)formatter).toPattern();
|
||||
String previous = cDateTimeInstanceCache.putIfAbsent(key, pattern);
|
||||
final String previous = cDateTimeInstanceCache.putIfAbsent(key, pattern);
|
||||
if (previous != null) {
|
||||
// even though it doesn't matter if another thread put the pattern
|
||||
// it's still good practice to return the String instance that is
|
||||
// actually in the ConcurrentMap
|
||||
pattern= previous;
|
||||
}
|
||||
} catch (ClassCastException ex) {
|
||||
} catch (final ClassCastException ex) {
|
||||
throw new IllegalArgumentException("No date time pattern for locale: " + locale);
|
||||
}
|
||||
}
|
||||
|
@ -198,7 +198,7 @@ public boolean equals(final Object obj) {
|
|||
public int hashCode() {
|
||||
if(hashCode==0) {
|
||||
int rc= 0;
|
||||
for(Object key : keys) {
|
||||
for(final Object key : keys) {
|
||||
if(key!=null) {
|
||||
rc= rc*7 + key.hashCode();
|
||||
}
|
||||
|
|
|
@ -116,7 +116,7 @@ public void setRight(final R right) {
|
|||
*/
|
||||
@Override
|
||||
public R setValue(final R value) {
|
||||
R result = getRight();
|
||||
final R result = getRight();
|
||||
setRight(value);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -131,7 +131,7 @@ public boolean equals(final Object obj) {
|
|||
return true;
|
||||
}
|
||||
if (obj instanceof Map.Entry<?, ?>) {
|
||||
Map.Entry<?, ?> other = (Map.Entry<?, ?>) obj;
|
||||
final Map.Entry<?, ?> other = (Map.Entry<?, ?>) obj;
|
||||
return ObjectUtils.equals(getKey(), other.getKey())
|
||||
&& ObjectUtils.equals(getValue(), other.getValue());
|
||||
}
|
||||
|
|
|
@ -110,7 +110,7 @@ public boolean equals(final Object obj) {
|
|||
return true;
|
||||
}
|
||||
if (obj instanceof Triple<?, ?, ?>) {
|
||||
Triple<?, ?, ?> other = (Triple<?, ?, ?>) obj;
|
||||
final Triple<?, ?, ?> other = (Triple<?, ?, ?>) obj;
|
||||
return ObjectUtils.equals(getLeft(), other.getLeft())
|
||||
&& ObjectUtils.equals(getMiddle(), other.getMiddle())
|
||||
&& ObjectUtils.equals(getRight(), other.getRight());
|
||||
|
|
|
@ -430,14 +430,14 @@ public void testBothArgsNull() {
|
|||
|
||||
@Test
|
||||
public void testIsValidAnnotationMemberType() {
|
||||
for (Class<?> type : new Class[] { byte.class, short.class, int.class, char.class,
|
||||
for (final Class<?> type : new Class[] { byte.class, short.class, int.class, char.class,
|
||||
long.class, float.class, double.class, boolean.class, String.class, Class.class,
|
||||
NestAnnotation.class, TestAnnotation.class, Stooge.class, ElementType.class }) {
|
||||
assertTrue(AnnotationUtils.isValidAnnotationMemberType(type));
|
||||
assertTrue(AnnotationUtils.isValidAnnotationMemberType(Array.newInstance(type, 0)
|
||||
.getClass()));
|
||||
}
|
||||
for (Class<?> type : new Class[] { Object.class, Map.class, Collection.class }) {
|
||||
for (final Class<?> type : new Class[] { Object.class, Map.class, Collection.class }) {
|
||||
assertFalse(AnnotationUtils.isValidAnnotationMemberType(type));
|
||||
assertFalse(AnnotationUtils.isValidAnnotationMemberType(Array.newInstance(type, 0)
|
||||
.getClass()));
|
||||
|
@ -449,7 +449,7 @@ public void testGeneratedAnnotationEquivalentToRealAnnotation() throws Exception
|
|||
final Test real = getClass().getDeclaredMethod(
|
||||
"testGeneratedAnnotationEquivalentToRealAnnotation").getAnnotation(Test.class);
|
||||
|
||||
InvocationHandler generatedTestInvocationHandler = new InvocationHandler() {
|
||||
final InvocationHandler generatedTestInvocationHandler = new InvocationHandler() {
|
||||
|
||||
@Override
|
||||
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
|
||||
|
@ -466,7 +466,7 @@ public Object invoke(final Object proxy, final Method method, final Object[] arg
|
|||
}
|
||||
};
|
||||
|
||||
Test generated = (Test) Proxy.newProxyInstance(Thread.currentThread()
|
||||
final Test generated = (Test) Proxy.newProxyInstance(Thread.currentThread()
|
||||
.getContextClassLoader(), new Class[] { Test.class },
|
||||
generatedTestInvocationHandler);
|
||||
assertTrue(real.equals(generated));
|
||||
|
@ -474,7 +474,7 @@ public Object invoke(final Object proxy, final Method method, final Object[] arg
|
|||
assertTrue(AnnotationUtils.equals(generated, real));
|
||||
assertTrue(AnnotationUtils.equals(real, generated));
|
||||
|
||||
Test generated2 = (Test) Proxy.newProxyInstance(Thread.currentThread()
|
||||
final Test generated2 = (Test) Proxy.newProxyInstance(Thread.currentThread()
|
||||
.getContextClassLoader(), new Class[] { Test.class },
|
||||
generatedTestInvocationHandler);
|
||||
assertFalse(generated.equals(generated2));
|
||||
|
@ -497,7 +497,7 @@ public void testHashCode() throws Exception {
|
|||
public void testToString() throws Exception {
|
||||
final Test testAnno = getClass().getDeclaredMethod("testToString")
|
||||
.getAnnotation(Test.class);
|
||||
String toString = AnnotationUtils.toString(testAnno);
|
||||
final String toString = AnnotationUtils.toString(testAnno);
|
||||
assertTrue(toString.startsWith("@org.junit.Test("));
|
||||
assertTrue(toString.endsWith(")"));
|
||||
assertTrue(toString.contains("expected=class org.junit.Test$None"));
|
||||
|
|
|
@ -46,7 +46,7 @@ public void testJira567(){
|
|||
// Invalid - can't store Long in Integer array
|
||||
n = ArrayUtils.addAll(new Integer[]{Integer.valueOf(1)}, new Long[]{Long.valueOf(2)});
|
||||
fail("Should have generated IllegalArgumentException");
|
||||
} catch (IllegalArgumentException expected) {
|
||||
} catch (final IllegalArgumentException expected) {
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,7 @@ public void testAddObjectArrayBoolean() {
|
|||
newArray = ArrayUtils.add((boolean[])null, true);
|
||||
assertTrue(Arrays.equals(new boolean[]{true}, newArray));
|
||||
assertEquals(Boolean.TYPE, newArray.getClass().getComponentType());
|
||||
boolean[] array1 = new boolean[]{true, false, true};
|
||||
final boolean[] array1 = new boolean[]{true, false, true};
|
||||
newArray = ArrayUtils.add(array1, false);
|
||||
assertTrue(Arrays.equals(new boolean[]{true, false, true, false}, newArray));
|
||||
assertEquals(Boolean.TYPE, newArray.getClass().getComponentType());
|
||||
|
@ -74,7 +74,7 @@ public void testAddObjectArrayByte() {
|
|||
newArray = ArrayUtils.add((byte[])null, (byte)1);
|
||||
assertTrue(Arrays.equals(new byte[]{1}, newArray));
|
||||
assertEquals(Byte.TYPE, newArray.getClass().getComponentType());
|
||||
byte[] array1 = new byte[]{1, 2, 3};
|
||||
final byte[] array1 = new byte[]{1, 2, 3};
|
||||
newArray = ArrayUtils.add(array1, (byte)0);
|
||||
assertTrue(Arrays.equals(new byte[]{1, 2, 3, 0}, newArray));
|
||||
assertEquals(Byte.TYPE, newArray.getClass().getComponentType());
|
||||
|
@ -92,7 +92,7 @@ public void testAddObjectArrayChar() {
|
|||
newArray = ArrayUtils.add((char[])null, (char)1);
|
||||
assertTrue(Arrays.equals(new char[]{1}, newArray));
|
||||
assertEquals(Character.TYPE, newArray.getClass().getComponentType());
|
||||
char[] array1 = new char[]{1, 2, 3};
|
||||
final char[] array1 = new char[]{1, 2, 3};
|
||||
newArray = ArrayUtils.add(array1, (char)0);
|
||||
assertTrue(Arrays.equals(new char[]{1, 2, 3, 0}, newArray));
|
||||
assertEquals(Character.TYPE, newArray.getClass().getComponentType());
|
||||
|
@ -110,7 +110,7 @@ public void testAddObjectArrayDouble() {
|
|||
newArray = ArrayUtils.add((double[])null, 1);
|
||||
assertTrue(Arrays.equals(new double[]{1}, newArray));
|
||||
assertEquals(Double.TYPE, newArray.getClass().getComponentType());
|
||||
double[] array1 = new double[]{1, 2, 3};
|
||||
final double[] array1 = new double[]{1, 2, 3};
|
||||
newArray = ArrayUtils.add(array1, 0);
|
||||
assertTrue(Arrays.equals(new double[]{1, 2, 3, 0}, newArray));
|
||||
assertEquals(Double.TYPE, newArray.getClass().getComponentType());
|
||||
|
@ -128,7 +128,7 @@ public void testAddObjectArrayFloat() {
|
|||
newArray = ArrayUtils.add((float[])null, 1);
|
||||
assertTrue(Arrays.equals(new float[]{1}, newArray));
|
||||
assertEquals(Float.TYPE, newArray.getClass().getComponentType());
|
||||
float[] array1 = new float[]{1, 2, 3};
|
||||
final float[] array1 = new float[]{1, 2, 3};
|
||||
newArray = ArrayUtils.add(array1, 0);
|
||||
assertTrue(Arrays.equals(new float[]{1, 2, 3, 0}, newArray));
|
||||
assertEquals(Float.TYPE, newArray.getClass().getComponentType());
|
||||
|
@ -146,7 +146,7 @@ public void testAddObjectArrayInt() {
|
|||
newArray = ArrayUtils.add((int[])null, 1);
|
||||
assertTrue(Arrays.equals(new int[]{1}, newArray));
|
||||
assertEquals(Integer.TYPE, newArray.getClass().getComponentType());
|
||||
int[] array1 = new int[]{1, 2, 3};
|
||||
final int[] array1 = new int[]{1, 2, 3};
|
||||
newArray = ArrayUtils.add(array1, 0);
|
||||
assertTrue(Arrays.equals(new int[]{1, 2, 3, 0}, newArray));
|
||||
assertEquals(Integer.TYPE, newArray.getClass().getComponentType());
|
||||
|
@ -164,7 +164,7 @@ public void testAddObjectArrayLong() {
|
|||
newArray = ArrayUtils.add((long[])null, 1);
|
||||
assertTrue(Arrays.equals(new long[]{1}, newArray));
|
||||
assertEquals(Long.TYPE, newArray.getClass().getComponentType());
|
||||
long[] array1 = new long[]{1, 2, 3};
|
||||
final long[] array1 = new long[]{1, 2, 3};
|
||||
newArray = ArrayUtils.add(array1, 0);
|
||||
assertTrue(Arrays.equals(new long[]{1, 2, 3, 0}, newArray));
|
||||
assertEquals(Long.TYPE, newArray.getClass().getComponentType());
|
||||
|
@ -182,7 +182,7 @@ public void testAddObjectArrayShort() {
|
|||
newArray = ArrayUtils.add((short[])null, (short)1);
|
||||
assertTrue(Arrays.equals(new short[]{1}, newArray));
|
||||
assertEquals(Short.TYPE, newArray.getClass().getComponentType());
|
||||
short[] array1 = new short[]{1, 2, 3};
|
||||
final short[] array1 = new short[]{1, 2, 3};
|
||||
newArray = ArrayUtils.add(array1, (short)0);
|
||||
assertTrue(Arrays.equals(new short[]{1, 2, 3, 0}, newArray));
|
||||
assertEquals(Short.TYPE, newArray.getClass().getComponentType());
|
||||
|
@ -202,12 +202,12 @@ public void testAddObjectArrayObject() {
|
|||
assertEquals(String.class, newArray.getClass().getComponentType());
|
||||
|
||||
//show that not casting to Object[] is okay and will assume String based on "a"
|
||||
String[] newStringArray = ArrayUtils.add(null, "a");
|
||||
final String[] newStringArray = ArrayUtils.add(null, "a");
|
||||
assertTrue(Arrays.equals(new String[]{"a"}, newStringArray));
|
||||
assertTrue(Arrays.equals(new Object[]{"a"}, newStringArray));
|
||||
assertEquals(String.class, newStringArray.getClass().getComponentType());
|
||||
|
||||
String[] stringArray1 = new String[]{"a", "b", "c"};
|
||||
final String[] stringArray1 = new String[]{"a", "b", "c"};
|
||||
newArray = ArrayUtils.add(stringArray1, null);
|
||||
assertTrue(Arrays.equals(new String[]{"a", "b", "c", null}, newArray));
|
||||
assertEquals(String.class, newArray.getClass().getComponentType());
|
||||
|
@ -229,20 +229,22 @@ public void testAddObjectArrayObject() {
|
|||
|
||||
@Test
|
||||
public void testLANG571(){
|
||||
String[] stringArray=null;
|
||||
String aString=null;
|
||||
final String[] stringArray=null;
|
||||
final String aString=null;
|
||||
try {
|
||||
@SuppressWarnings("unused")
|
||||
final
|
||||
String[] sa = ArrayUtils.add(stringArray, aString);
|
||||
fail("Should have caused IllegalArgumentException");
|
||||
} catch (IllegalArgumentException iae){
|
||||
} catch (final IllegalArgumentException iae){
|
||||
//expected
|
||||
}
|
||||
try {
|
||||
@SuppressWarnings("unused")
|
||||
final
|
||||
String[] sa = ArrayUtils.add(stringArray, 0, aString);
|
||||
fail("Should have caused IllegalArgumentException");
|
||||
} catch (IllegalArgumentException iae){
|
||||
} catch (final IllegalArgumentException iae){
|
||||
//expected
|
||||
}
|
||||
}
|
||||
|
@ -251,8 +253,8 @@ public void testLANG571(){
|
|||
public void testAddObjectArrayToObjectArray() {
|
||||
assertNull(ArrayUtils.addAll((Object[]) null, (Object[]) null));
|
||||
Object[] newArray;
|
||||
String[] stringArray1 = new String[]{"a", "b", "c"};
|
||||
String[] stringArray2 = new String[]{"1", "2", "3"};
|
||||
final String[] stringArray1 = new String[]{"a", "b", "c"};
|
||||
final String[] stringArray2 = new String[]{"1", "2", "3"};
|
||||
newArray = ArrayUtils.addAll(stringArray1, (String[]) null);
|
||||
assertNotSame(stringArray1, newArray);
|
||||
assertTrue(Arrays.equals(stringArray1, newArray));
|
||||
|
@ -278,7 +280,7 @@ public void testAddObjectArrayToObjectArray() {
|
|||
assertTrue(Arrays.equals(ArrayUtils.EMPTY_STRING_ARRAY, newArray));
|
||||
assertTrue(Arrays.equals(new String[]{}, newArray));
|
||||
assertEquals(String.class, newArray.getClass().getComponentType());
|
||||
String[] stringArrayNull = new String []{null};
|
||||
final String[] stringArrayNull = new String []{null};
|
||||
newArray = ArrayUtils.addAll(stringArrayNull, stringArrayNull);
|
||||
assertTrue(Arrays.equals(new String[]{null, null}, newArray));
|
||||
assertEquals(String.class, newArray.getClass().getComponentType());
|
||||
|
@ -372,7 +374,7 @@ public void testAddObjectAtIndex() {
|
|||
assertTrue(Arrays.equals(new String[]{"a"}, newArray));
|
||||
assertTrue(Arrays.equals(new Object[]{"a"}, newArray));
|
||||
assertEquals(String.class, newArray.getClass().getComponentType());
|
||||
String[] stringArray1 = new String[]{"a", "b", "c"};
|
||||
final String[] stringArray1 = new String[]{"a", "b", "c"};
|
||||
newArray = ArrayUtils.add(stringArray1, 0, null);
|
||||
assertTrue(Arrays.equals(new String[]{null, "a", "b", "c"}, newArray));
|
||||
assertEquals(String.class, newArray.getClass().getComponentType());
|
||||
|
@ -387,9 +389,9 @@ public void testAddObjectAtIndex() {
|
|||
assertEquals(String.class, newArray.getClass().getComponentType());
|
||||
assertEquals(String.class, newArray.getClass().getComponentType());
|
||||
|
||||
Object[] o = new Object[] {"1", "2", "4"};
|
||||
Object[] result = ArrayUtils.add(o, 2, "3");
|
||||
Object[] result2 = ArrayUtils.add(o, 3, "5");
|
||||
final Object[] o = new Object[] {"1", "2", "4"};
|
||||
final Object[] result = ArrayUtils.add(o, 2, "3");
|
||||
final Object[] result2 = ArrayUtils.add(o, 3, "5");
|
||||
|
||||
assertNotNull(result);
|
||||
assertEquals(4, result.length);
|
||||
|
@ -409,7 +411,7 @@ public void testAddObjectAtIndex() {
|
|||
assertTrue( Arrays.equals( new boolean[] { true }, booleanArray ) );
|
||||
try {
|
||||
booleanArray = ArrayUtils.add( null, -1, true );
|
||||
} catch(IndexOutOfBoundsException e) {
|
||||
} catch(final IndexOutOfBoundsException e) {
|
||||
assertEquals("Index: -1, Length: 0", e.getMessage());
|
||||
}
|
||||
booleanArray = ArrayUtils.add( new boolean[] { true }, 0, false);
|
||||
|
@ -420,12 +422,12 @@ public void testAddObjectAtIndex() {
|
|||
assertTrue( Arrays.equals( new boolean[] { true, true, false }, booleanArray ) );
|
||||
try {
|
||||
booleanArray = ArrayUtils.add( new boolean[] { true, false }, 4, true);
|
||||
} catch(IndexOutOfBoundsException e) {
|
||||
} catch(final IndexOutOfBoundsException e) {
|
||||
assertEquals("Index: 4, Length: 2", e.getMessage());
|
||||
}
|
||||
try {
|
||||
booleanArray = ArrayUtils.add( new boolean[] { true, false }, -1, true);
|
||||
} catch(IndexOutOfBoundsException e) {
|
||||
} catch(final IndexOutOfBoundsException e) {
|
||||
assertEquals("Index: -1, Length: 2", e.getMessage());
|
||||
}
|
||||
|
||||
|
@ -434,7 +436,7 @@ public void testAddObjectAtIndex() {
|
|||
assertTrue( Arrays.equals( new char[] { 'a' }, charArray ) );
|
||||
try {
|
||||
charArray = ArrayUtils.add( (char[]) null, -1, 'a' );
|
||||
} catch(IndexOutOfBoundsException e) {
|
||||
} catch(final IndexOutOfBoundsException e) {
|
||||
assertEquals("Index: -1, Length: 0", e.getMessage());
|
||||
}
|
||||
charArray = ArrayUtils.add( new char[] { 'a' }, 0, 'b');
|
||||
|
@ -447,12 +449,12 @@ public void testAddObjectAtIndex() {
|
|||
assertTrue( Arrays.equals( new char[] { 'a', 't', 'b', 'c' }, charArray ) );
|
||||
try {
|
||||
charArray = ArrayUtils.add( new char[] { 'a', 'b' }, 4, 'c');
|
||||
} catch(IndexOutOfBoundsException e) {
|
||||
} catch(final IndexOutOfBoundsException e) {
|
||||
assertEquals("Index: 4, Length: 2", e.getMessage());
|
||||
}
|
||||
try {
|
||||
charArray = ArrayUtils.add( new char[] { 'a', 'b' }, -1, 'c');
|
||||
} catch(IndexOutOfBoundsException e) {
|
||||
} catch(final IndexOutOfBoundsException e) {
|
||||
assertEquals("Index: -1, Length: 2", e.getMessage());
|
||||
}
|
||||
|
||||
|
@ -461,7 +463,7 @@ public void testAddObjectAtIndex() {
|
|||
assertTrue( Arrays.equals( new short[] { 2, 1 }, shortArray ) );
|
||||
try {
|
||||
shortArray = ArrayUtils.add( (short[]) null, -1, (short) 2);
|
||||
} catch(IndexOutOfBoundsException e) {
|
||||
} catch(final IndexOutOfBoundsException e) {
|
||||
assertEquals("Index: -1, Length: 0", e.getMessage());
|
||||
}
|
||||
shortArray = ArrayUtils.add( new short[] { 2, 6 }, 2, (short) 10);
|
||||
|
@ -472,12 +474,12 @@ public void testAddObjectAtIndex() {
|
|||
assertTrue( Arrays.equals( new short[] { 2, 6, 1, 3 }, shortArray ) );
|
||||
try {
|
||||
shortArray = ArrayUtils.add( new short[] { 2, 6 }, 4, (short) 10);
|
||||
} catch(IndexOutOfBoundsException e) {
|
||||
} catch(final IndexOutOfBoundsException e) {
|
||||
assertEquals("Index: 4, Length: 2", e.getMessage());
|
||||
}
|
||||
try {
|
||||
shortArray = ArrayUtils.add( new short[] { 2, 6 }, -1, (short) 10);
|
||||
} catch(IndexOutOfBoundsException e) {
|
||||
} catch(final IndexOutOfBoundsException e) {
|
||||
assertEquals("Index: -1, Length: 2", e.getMessage());
|
||||
}
|
||||
|
||||
|
@ -486,7 +488,7 @@ public void testAddObjectAtIndex() {
|
|||
assertTrue( Arrays.equals( new byte[] { 2, 1 }, byteArray ) );
|
||||
try {
|
||||
byteArray = ArrayUtils.add( (byte[]) null, -1, (byte) 2);
|
||||
} catch(IndexOutOfBoundsException e) {
|
||||
} catch(final IndexOutOfBoundsException e) {
|
||||
assertEquals("Index: -1, Length: 0", e.getMessage());
|
||||
}
|
||||
byteArray = ArrayUtils.add( new byte[] { 2, 6 }, 2, (byte) 3);
|
||||
|
@ -497,12 +499,12 @@ public void testAddObjectAtIndex() {
|
|||
assertTrue( Arrays.equals( new byte[] { 2, 6, 1, 3 }, byteArray ) );
|
||||
try {
|
||||
byteArray = ArrayUtils.add( new byte[] { 2, 6 }, 4, (byte) 3);
|
||||
} catch(IndexOutOfBoundsException e) {
|
||||
} catch(final IndexOutOfBoundsException e) {
|
||||
assertEquals("Index: 4, Length: 2", e.getMessage());
|
||||
}
|
||||
try {
|
||||
byteArray = ArrayUtils.add( new byte[] { 2, 6 }, -1, (byte) 3);
|
||||
} catch(IndexOutOfBoundsException e) {
|
||||
} catch(final IndexOutOfBoundsException e) {
|
||||
assertEquals("Index: -1, Length: 2", e.getMessage());
|
||||
}
|
||||
|
||||
|
@ -511,7 +513,7 @@ public void testAddObjectAtIndex() {
|
|||
assertTrue( Arrays.equals( new int[] { 2, 1 }, intArray ) );
|
||||
try {
|
||||
intArray = ArrayUtils.add( (int[]) null, -1, 2);
|
||||
} catch(IndexOutOfBoundsException e) {
|
||||
} catch(final IndexOutOfBoundsException e) {
|
||||
assertEquals("Index: -1, Length: 0", e.getMessage());
|
||||
}
|
||||
intArray = ArrayUtils.add( new int[] { 2, 6 }, 2, 10);
|
||||
|
@ -522,12 +524,12 @@ public void testAddObjectAtIndex() {
|
|||
assertTrue( Arrays.equals( new int[] { 2, 6, 1, 3 }, intArray ) );
|
||||
try {
|
||||
intArray = ArrayUtils.add( new int[] { 2, 6 }, 4, 10);
|
||||
} catch(IndexOutOfBoundsException e) {
|
||||
} catch(final IndexOutOfBoundsException e) {
|
||||
assertEquals("Index: 4, Length: 2", e.getMessage());
|
||||
}
|
||||
try {
|
||||
intArray = ArrayUtils.add( new int[] { 2, 6 }, -1, 10);
|
||||
} catch(IndexOutOfBoundsException e) {
|
||||
} catch(final IndexOutOfBoundsException e) {
|
||||
assertEquals("Index: -1, Length: 2", e.getMessage());
|
||||
}
|
||||
|
||||
|
@ -536,7 +538,7 @@ public void testAddObjectAtIndex() {
|
|||
assertTrue( Arrays.equals( new long[] { 2L, 1L }, longArray ) );
|
||||
try {
|
||||
longArray = ArrayUtils.add( (long[]) null, -1, 2L);
|
||||
} catch(IndexOutOfBoundsException e) {
|
||||
} catch(final IndexOutOfBoundsException e) {
|
||||
assertEquals("Index: -1, Length: 0", e.getMessage());
|
||||
}
|
||||
longArray = ArrayUtils.add( new long[] { 2L, 6L }, 2, 10L);
|
||||
|
@ -547,12 +549,12 @@ public void testAddObjectAtIndex() {
|
|||
assertTrue( Arrays.equals( new long[] { 2L, 6L, 1L, 3L }, longArray ) );
|
||||
try {
|
||||
longArray = ArrayUtils.add( new long[] { 2L, 6L }, 4, 10L);
|
||||
} catch(IndexOutOfBoundsException e) {
|
||||
} catch(final IndexOutOfBoundsException e) {
|
||||
assertEquals("Index: 4, Length: 2", e.getMessage());
|
||||
}
|
||||
try {
|
||||
longArray = ArrayUtils.add( new long[] { 2L, 6L }, -1, 10L);
|
||||
} catch(IndexOutOfBoundsException e) {
|
||||
} catch(final IndexOutOfBoundsException e) {
|
||||
assertEquals("Index: -1, Length: 2", e.getMessage());
|
||||
}
|
||||
|
||||
|
@ -561,7 +563,7 @@ public void testAddObjectAtIndex() {
|
|||
assertTrue( Arrays.equals( new float[] { 2.2f, 1.1f }, floatArray ) );
|
||||
try {
|
||||
floatArray = ArrayUtils.add( (float[]) null, -1, 2.2f);
|
||||
} catch(IndexOutOfBoundsException e) {
|
||||
} catch(final IndexOutOfBoundsException e) {
|
||||
assertEquals("Index: -1, Length: 0", e.getMessage());
|
||||
}
|
||||
floatArray = ArrayUtils.add( new float[] { 2.3f, 6.4f }, 2, 10.5f);
|
||||
|
@ -572,12 +574,12 @@ public void testAddObjectAtIndex() {
|
|||
assertTrue( Arrays.equals( new float[] { 2.9f, 6.0f, 1.0f, 0.3f }, floatArray ) );
|
||||
try {
|
||||
floatArray = ArrayUtils.add( new float[] { 2.3f, 6.4f }, 4, 10.5f);
|
||||
} catch(IndexOutOfBoundsException e) {
|
||||
} catch(final IndexOutOfBoundsException e) {
|
||||
assertEquals("Index: 4, Length: 2", e.getMessage());
|
||||
}
|
||||
try {
|
||||
floatArray = ArrayUtils.add( new float[] { 2.3f, 6.4f }, -1, 10.5f);
|
||||
} catch(IndexOutOfBoundsException e) {
|
||||
} catch(final IndexOutOfBoundsException e) {
|
||||
assertEquals("Index: -1, Length: 2", e.getMessage());
|
||||
}
|
||||
|
||||
|
@ -586,7 +588,7 @@ public void testAddObjectAtIndex() {
|
|||
assertTrue( Arrays.equals( new double[] { 2.2, 1.1 }, doubleArray ) );
|
||||
try {
|
||||
doubleArray = ArrayUtils.add( (double[]) null, -1, 2.2);
|
||||
} catch(IndexOutOfBoundsException e) {
|
||||
} catch(final IndexOutOfBoundsException e) {
|
||||
assertEquals("Index: -1, Length: 0", e.getMessage());
|
||||
}
|
||||
doubleArray = ArrayUtils.add( new double[] { 2.3, 6.4 }, 2, 10.5);
|
||||
|
@ -597,12 +599,12 @@ public void testAddObjectAtIndex() {
|
|||
assertTrue( Arrays.equals( new double[] { 2.9, 6.0, 1.0, 0.3 }, doubleArray ) );
|
||||
try {
|
||||
doubleArray = ArrayUtils.add( new double[] { 2.3, 6.4 }, 4, 10.5);
|
||||
} catch(IndexOutOfBoundsException e) {
|
||||
} catch(final IndexOutOfBoundsException e) {
|
||||
assertEquals("Index: 4, Length: 2", e.getMessage());
|
||||
}
|
||||
try {
|
||||
doubleArray = ArrayUtils.add( new double[] { 2.3, 6.4 }, -1, 10.5);
|
||||
} catch(IndexOutOfBoundsException e) {
|
||||
} catch(final IndexOutOfBoundsException e) {
|
||||
assertEquals("Index: -1, Length: 2", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,8 +74,8 @@ public void testRemoveAllObjectArray() {
|
|||
|
||||
@Test
|
||||
public void testRemoveAllObjectArrayRemoveNone() {
|
||||
Object[] array1 = new Object[] { "foo", "bar", "baz" };
|
||||
Object[] array2 = ArrayUtils.removeAll(array1);
|
||||
final Object[] array1 = new Object[] { "foo", "bar", "baz" };
|
||||
final Object[] array2 = ArrayUtils.removeAll(array1);
|
||||
assertNotSame(array1, array2);
|
||||
assertArrayEquals(array1, array2);
|
||||
assertEquals(Object.class, array2.getClass().getComponentType());
|
||||
|
@ -98,7 +98,7 @@ public void testRemoveAllNullObjectArray() {
|
|||
|
||||
@Test
|
||||
public void testRemoveAllNumberArray() {
|
||||
Number[] inarray = { Integer.valueOf(1), Long.valueOf(2L), Byte.valueOf((byte) 3) };
|
||||
final Number[] inarray = { Integer.valueOf(1), Long.valueOf(2L), Byte.valueOf((byte) 3) };
|
||||
assertEquals(3, inarray.length);
|
||||
Number[] outarray;
|
||||
outarray = ArrayUtils.removeAll(inarray, 1);
|
||||
|
@ -172,8 +172,8 @@ public void testRemoveAllBooleanArray() {
|
|||
|
||||
@Test
|
||||
public void testRemoveAllBooleanArrayRemoveNone() {
|
||||
boolean[] array1 = new boolean[] { true, false };
|
||||
boolean[] array2 = ArrayUtils.removeAll(array1);
|
||||
final boolean[] array1 = new boolean[] { true, false };
|
||||
final boolean[] array2 = ArrayUtils.removeAll(array1);
|
||||
assertNotSame(array1, array2);
|
||||
assertTrue(Arrays.equals(array1, array2));
|
||||
assertEquals(boolean.class, array2.getClass().getComponentType());
|
||||
|
@ -238,8 +238,8 @@ public void testRemoveAllByteArray() {
|
|||
|
||||
@Test
|
||||
public void testRemoveAllByteArrayRemoveNone() {
|
||||
byte[] array1 = new byte[] { 1, 2 };
|
||||
byte[] array2 = ArrayUtils.removeAll(array1);
|
||||
final byte[] array1 = new byte[] { 1, 2 };
|
||||
final byte[] array2 = ArrayUtils.removeAll(array1);
|
||||
assertNotSame(array1, array2);
|
||||
assertArrayEquals(array1, array2);
|
||||
assertEquals(byte.class, array2.getClass().getComponentType());
|
||||
|
@ -304,8 +304,8 @@ public void testRemoveAllCharArray() {
|
|||
|
||||
@Test
|
||||
public void testRemoveAllCharArrayRemoveNone() {
|
||||
char[] array1 = new char[] { 'a', 'b' };
|
||||
char[] array2 = ArrayUtils.removeAll(array1);
|
||||
final char[] array1 = new char[] { 'a', 'b' };
|
||||
final char[] array2 = ArrayUtils.removeAll(array1);
|
||||
assertNotSame(array1, array2);
|
||||
assertArrayEquals(array1, array2);
|
||||
assertEquals(char.class, array2.getClass().getComponentType());
|
||||
|
@ -370,8 +370,8 @@ public void testRemoveAllDoubleArray() {
|
|||
|
||||
@Test
|
||||
public void testRemoveAllDoubleArrayRemoveNone() {
|
||||
double[] array1 = new double[] { 1, 2 };
|
||||
double[] array2 = ArrayUtils.removeAll(array1);
|
||||
final double[] array1 = new double[] { 1, 2 };
|
||||
final double[] array2 = ArrayUtils.removeAll(array1);
|
||||
assertNotSame(array1, array2);
|
||||
assertTrue(Arrays.equals(array1, array2));
|
||||
assertEquals(double.class, array2.getClass().getComponentType());
|
||||
|
@ -436,8 +436,8 @@ public void testRemoveAllFloatArray() {
|
|||
|
||||
@Test
|
||||
public void testRemoveAllFloatArrayRemoveNone() {
|
||||
float[] array1 = new float[] { 1, 2 };
|
||||
float[] array2 = ArrayUtils.removeAll(array1);
|
||||
final float[] array1 = new float[] { 1, 2 };
|
||||
final float[] array2 = ArrayUtils.removeAll(array1);
|
||||
assertNotSame(array1, array2);
|
||||
assertTrue(Arrays.equals(array1, array2));
|
||||
assertEquals(float.class, array2.getClass().getComponentType());
|
||||
|
@ -506,8 +506,8 @@ public void testRemoveAllIntArray() {
|
|||
|
||||
@Test
|
||||
public void testRemoveAllIntArrayRemoveNone() {
|
||||
int[] array1 = new int[] { 1, 2 };
|
||||
int[] array2 = ArrayUtils.removeAll(array1);
|
||||
final int[] array1 = new int[] { 1, 2 };
|
||||
final int[] array2 = ArrayUtils.removeAll(array1);
|
||||
assertNotSame(array1, array2);
|
||||
assertArrayEquals(array1, array2);
|
||||
assertEquals(int.class, array2.getClass().getComponentType());
|
||||
|
@ -572,8 +572,8 @@ public void testRemoveAllLongArray() {
|
|||
|
||||
@Test
|
||||
public void testRemoveAllLongArrayRemoveNone() {
|
||||
long[] array1 = new long[] { 1, 2 };
|
||||
long[] array2 = ArrayUtils.removeAll(array1);
|
||||
final long[] array1 = new long[] { 1, 2 };
|
||||
final long[] array2 = ArrayUtils.removeAll(array1);
|
||||
assertNotSame(array1, array2);
|
||||
assertArrayEquals(array1, array2);
|
||||
assertEquals(long.class, array2.getClass().getComponentType());
|
||||
|
@ -638,8 +638,8 @@ public void testRemoveAllShortArray() {
|
|||
|
||||
@Test
|
||||
public void testRemoveAllShortArrayRemoveNone() {
|
||||
short[] array1 = new short[] { 1, 2 };
|
||||
short[] array2 = ArrayUtils.removeAll(array1);
|
||||
final short[] array1 = new short[] { 1, 2 };
|
||||
final short[] array2 = ArrayUtils.removeAll(array1);
|
||||
assertNotSame(array1, array2);
|
||||
assertArrayEquals(array1, array2);
|
||||
assertEquals(short.class, array2.getClass().getComponentType());
|
||||
|
|
|
@ -51,20 +51,20 @@ public void testRemoveObjectArray() {
|
|||
try {
|
||||
ArrayUtils.remove(new Object[] {"a", "b"}, -1);
|
||||
fail("IndexOutOfBoundsException expected");
|
||||
} catch (IndexOutOfBoundsException e) {}
|
||||
} catch (final IndexOutOfBoundsException e) {}
|
||||
try {
|
||||
ArrayUtils.remove(new Object[] {"a", "b"}, 2);
|
||||
fail("IndexOutOfBoundsException expected");
|
||||
} catch (IndexOutOfBoundsException e) {}
|
||||
} catch (final IndexOutOfBoundsException e) {}
|
||||
try {
|
||||
ArrayUtils.remove((Object[]) null, 0);
|
||||
fail("IndexOutOfBoundsException expected");
|
||||
} catch (IndexOutOfBoundsException e) {}
|
||||
} catch (final IndexOutOfBoundsException e) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveNumberArray(){
|
||||
Number[] inarray = {Integer.valueOf(1),Long.valueOf(2),Byte.valueOf((byte) 3)};
|
||||
final Number[] inarray = {Integer.valueOf(1),Long.valueOf(2),Byte.valueOf((byte) 3)};
|
||||
assertEquals(3, inarray.length);
|
||||
Number[] outarray;
|
||||
outarray = ArrayUtils.remove(inarray, 1);
|
||||
|
@ -96,15 +96,15 @@ public void testRemoveBooleanArray() {
|
|||
try {
|
||||
ArrayUtils.remove(new boolean[] {true, false}, -1);
|
||||
fail("IndexOutOfBoundsException expected");
|
||||
} catch (IndexOutOfBoundsException e) {}
|
||||
} catch (final IndexOutOfBoundsException e) {}
|
||||
try {
|
||||
ArrayUtils.remove(new boolean[] {true, false}, 2);
|
||||
fail("IndexOutOfBoundsException expected");
|
||||
} catch (IndexOutOfBoundsException e) {}
|
||||
} catch (final IndexOutOfBoundsException e) {}
|
||||
try {
|
||||
ArrayUtils.remove((boolean[]) null, 0);
|
||||
fail("IndexOutOfBoundsException expected");
|
||||
} catch (IndexOutOfBoundsException e) {}
|
||||
} catch (final IndexOutOfBoundsException e) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -125,15 +125,15 @@ public void testRemoveByteArray() {
|
|||
try {
|
||||
ArrayUtils.remove(new byte[] {1, 2}, -1);
|
||||
fail("IndexOutOfBoundsException expected");
|
||||
} catch (IndexOutOfBoundsException e) {}
|
||||
} catch (final IndexOutOfBoundsException e) {}
|
||||
try {
|
||||
ArrayUtils.remove(new byte[] {1, 2}, 2);
|
||||
fail("IndexOutOfBoundsException expected");
|
||||
} catch (IndexOutOfBoundsException e) {}
|
||||
} catch (final IndexOutOfBoundsException e) {}
|
||||
try {
|
||||
ArrayUtils.remove((byte[]) null, 0);
|
||||
fail("IndexOutOfBoundsException expected");
|
||||
} catch (IndexOutOfBoundsException e) {}
|
||||
} catch (final IndexOutOfBoundsException e) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -154,15 +154,15 @@ public void testRemoveCharArray() {
|
|||
try {
|
||||
ArrayUtils.remove(new char[] {'a', 'b'}, -1);
|
||||
fail("IndexOutOfBoundsException expected");
|
||||
} catch (IndexOutOfBoundsException e) {}
|
||||
} catch (final IndexOutOfBoundsException e) {}
|
||||
try {
|
||||
ArrayUtils.remove(new char[] {'a', 'b'}, 2);
|
||||
fail("IndexOutOfBoundsException expected");
|
||||
} catch (IndexOutOfBoundsException e) {}
|
||||
} catch (final IndexOutOfBoundsException e) {}
|
||||
try {
|
||||
ArrayUtils.remove((char[]) null, 0);
|
||||
fail("IndexOutOfBoundsException expected");
|
||||
} catch (IndexOutOfBoundsException e) {}
|
||||
} catch (final IndexOutOfBoundsException e) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -183,15 +183,15 @@ public void testRemoveDoubleArray() {
|
|||
try {
|
||||
ArrayUtils.remove(new double[] {1, 2}, -1);
|
||||
fail("IndexOutOfBoundsException expected");
|
||||
} catch (IndexOutOfBoundsException e) {}
|
||||
} catch (final IndexOutOfBoundsException e) {}
|
||||
try {
|
||||
ArrayUtils.remove(new double[] {1, 2}, 2);
|
||||
fail("IndexOutOfBoundsException expected");
|
||||
} catch (IndexOutOfBoundsException e) {}
|
||||
} catch (final IndexOutOfBoundsException e) {}
|
||||
try {
|
||||
ArrayUtils.remove((double[]) null, 0);
|
||||
fail("IndexOutOfBoundsException expected");
|
||||
} catch (IndexOutOfBoundsException e) {}
|
||||
} catch (final IndexOutOfBoundsException e) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -212,15 +212,15 @@ public void testRemoveFloatArray() {
|
|||
try {
|
||||
ArrayUtils.remove(new float[] {1, 2}, -1);
|
||||
fail("IndexOutOfBoundsException expected");
|
||||
} catch (IndexOutOfBoundsException e) {}
|
||||
} catch (final IndexOutOfBoundsException e) {}
|
||||
try {
|
||||
ArrayUtils.remove(new float[] {1, 2}, 2);
|
||||
fail("IndexOutOfBoundsException expected");
|
||||
} catch (IndexOutOfBoundsException e) {}
|
||||
} catch (final IndexOutOfBoundsException e) {}
|
||||
try {
|
||||
ArrayUtils.remove((float[]) null, 0);
|
||||
fail("IndexOutOfBoundsException expected");
|
||||
} catch (IndexOutOfBoundsException e) {}
|
||||
} catch (final IndexOutOfBoundsException e) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -241,15 +241,15 @@ public void testRemoveIntArray() {
|
|||
try {
|
||||
ArrayUtils.remove(new int[] {1, 2}, -1);
|
||||
fail("IndexOutOfBoundsException expected");
|
||||
} catch (IndexOutOfBoundsException e) {}
|
||||
} catch (final IndexOutOfBoundsException e) {}
|
||||
try {
|
||||
ArrayUtils.remove(new int[] {1, 2}, 2);
|
||||
fail("IndexOutOfBoundsException expected");
|
||||
} catch (IndexOutOfBoundsException e) {}
|
||||
} catch (final IndexOutOfBoundsException e) {}
|
||||
try {
|
||||
ArrayUtils.remove((int[]) null, 0);
|
||||
fail("IndexOutOfBoundsException expected");
|
||||
} catch (IndexOutOfBoundsException e) {}
|
||||
} catch (final IndexOutOfBoundsException e) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -270,15 +270,15 @@ public void testRemoveLongArray() {
|
|||
try {
|
||||
ArrayUtils.remove(new long[] {1, 2}, -1);
|
||||
fail("IndexOutOfBoundsException expected");
|
||||
} catch (IndexOutOfBoundsException e) {}
|
||||
} catch (final IndexOutOfBoundsException e) {}
|
||||
try {
|
||||
ArrayUtils.remove(new long[] {1, 2}, 2);
|
||||
fail("IndexOutOfBoundsException expected");
|
||||
} catch (IndexOutOfBoundsException e) {}
|
||||
} catch (final IndexOutOfBoundsException e) {}
|
||||
try {
|
||||
ArrayUtils.remove((long[]) null, 0);
|
||||
fail("IndexOutOfBoundsException expected");
|
||||
} catch (IndexOutOfBoundsException e) {}
|
||||
} catch (final IndexOutOfBoundsException e) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -299,15 +299,15 @@ public void testRemoveShortArray() {
|
|||
try {
|
||||
ArrayUtils.remove(new short[] {1, 2}, -1);
|
||||
fail("IndexOutOfBoundsException expected");
|
||||
} catch (IndexOutOfBoundsException e) {}
|
||||
} catch (final IndexOutOfBoundsException e) {}
|
||||
try {
|
||||
ArrayUtils.remove(new short[] {1, 2}, 2);
|
||||
fail("IndexOutOfBoundsException expected");
|
||||
} catch (IndexOutOfBoundsException e) {}
|
||||
} catch (final IndexOutOfBoundsException e) {}
|
||||
try {
|
||||
ArrayUtils.remove((short[]) null, 0);
|
||||
fail("IndexOutOfBoundsException expected");
|
||||
} catch (IndexOutOfBoundsException e) {}
|
||||
} catch (final IndexOutOfBoundsException e) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -187,7 +187,7 @@ public void testByte() {
|
|||
assertEquals(0, new BitField(64).setByteBoolean((byte) 64, false));
|
||||
assertEquals(0, new BitField(128).setByteBoolean((byte) 128, false));
|
||||
assertEquals(-2, new BitField(1).setByteBoolean((byte) 255, false));
|
||||
byte clearedBit = new BitField(0x40).setByteBoolean((byte) - 63, false);
|
||||
final byte clearedBit = new BitField(0x40).setByteBoolean((byte) - 63, false);
|
||||
|
||||
assertFalse(new BitField(0x40).isSet(clearedBit));
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ public class BooleanUtilsTest {
|
|||
@Test
|
||||
public void testConstructor() {
|
||||
assertNotNull(new BooleanUtils());
|
||||
Constructor<?>[] cons = BooleanUtils.class.getDeclaredConstructors();
|
||||
final Constructor<?>[] cons = BooleanUtils.class.getDeclaredConstructors();
|
||||
assertEquals(1, cons.length);
|
||||
assertTrue(Modifier.isPublic(cons[0].getModifiers()));
|
||||
assertTrue(Modifier.isPublic(BooleanUtils.class.getModifiers()));
|
||||
|
@ -139,8 +139,8 @@ public void test_toBoolean_int_int_int_noMatch() {
|
|||
|
||||
@Test
|
||||
public void test_toBoolean_Integer_Integer_Integer() {
|
||||
Integer six = Integer.valueOf(6);
|
||||
Integer seven = Integer.valueOf(7);
|
||||
final Integer six = Integer.valueOf(6);
|
||||
final Integer seven = Integer.valueOf(7);
|
||||
|
||||
assertTrue(BooleanUtils.toBoolean((Integer) null, null, seven));
|
||||
assertFalse(BooleanUtils.toBoolean((Integer) null, six, null));
|
||||
|
@ -174,9 +174,9 @@ public void test_toBooleanObject_int_int_int_noMatch() {
|
|||
|
||||
@Test
|
||||
public void test_toBooleanObject_Integer_Integer_Integer_Integer() {
|
||||
Integer six = Integer.valueOf(6);
|
||||
Integer seven = Integer.valueOf(7);
|
||||
Integer eight = Integer.valueOf(8);
|
||||
final Integer six = Integer.valueOf(6);
|
||||
final Integer seven = Integer.valueOf(7);
|
||||
final Integer eight = Integer.valueOf(8);
|
||||
|
||||
assertSame(Boolean.TRUE, BooleanUtils.toBooleanObject((Integer) null, null, seven, eight));
|
||||
assertSame(Boolean.FALSE, BooleanUtils.toBooleanObject((Integer) null, six, null, eight));
|
||||
|
@ -233,17 +233,17 @@ public void test_toInteger_Boolean_int_int_int() {
|
|||
|
||||
@Test
|
||||
public void test_toIntegerObject_boolean_Integer_Integer() {
|
||||
Integer six = Integer.valueOf(6);
|
||||
Integer seven = Integer.valueOf(7);
|
||||
final Integer six = Integer.valueOf(6);
|
||||
final Integer seven = Integer.valueOf(7);
|
||||
assertEquals(six, BooleanUtils.toIntegerObject(true, six, seven));
|
||||
assertEquals(seven, BooleanUtils.toIntegerObject(false, six, seven));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_toIntegerObject_Boolean_Integer_Integer_Integer() {
|
||||
Integer six = Integer.valueOf(6);
|
||||
Integer seven = Integer.valueOf(7);
|
||||
Integer eight = Integer.valueOf(8);
|
||||
final Integer six = Integer.valueOf(6);
|
||||
final Integer seven = Integer.valueOf(7);
|
||||
final Integer eight = Integer.valueOf(8);
|
||||
assertEquals(six, BooleanUtils.toIntegerObject(Boolean.TRUE, six, seven, eight));
|
||||
assertEquals(seven, BooleanUtils.toIntegerObject(Boolean.FALSE, six, seven, eight));
|
||||
assertEquals(eight, BooleanUtils.toIntegerObject((Boolean) null, six, seven, eight));
|
||||
|
|
|
@ -48,7 +48,7 @@ public void testClass() {
|
|||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testConstructorAccessors_is() {
|
||||
CharRange rangea = CharRange.is('a');
|
||||
final CharRange rangea = CharRange.is('a');
|
||||
assertEquals('a', rangea.getStart());
|
||||
assertEquals('a', rangea.getEnd());
|
||||
assertFalse(rangea.isNegated());
|
||||
|
@ -57,7 +57,7 @@ public void testConstructorAccessors_is() {
|
|||
|
||||
@Test
|
||||
public void testConstructorAccessors_isNot() {
|
||||
CharRange rangea = CharRange.isNot('a');
|
||||
final CharRange rangea = CharRange.isNot('a');
|
||||
assertEquals('a', rangea.getStart());
|
||||
assertEquals('a', rangea.getEnd());
|
||||
assertTrue(rangea.isNegated());
|
||||
|
@ -66,7 +66,7 @@ public void testConstructorAccessors_isNot() {
|
|||
|
||||
@Test
|
||||
public void testConstructorAccessors_isIn_Same() {
|
||||
CharRange rangea = CharRange.isIn('a', 'a');
|
||||
final CharRange rangea = CharRange.isIn('a', 'a');
|
||||
assertEquals('a', rangea.getStart());
|
||||
assertEquals('a', rangea.getEnd());
|
||||
assertFalse(rangea.isNegated());
|
||||
|
@ -75,7 +75,7 @@ public void testConstructorAccessors_isIn_Same() {
|
|||
|
||||
@Test
|
||||
public void testConstructorAccessors_isIn_Normal() {
|
||||
CharRange rangea = CharRange.isIn('a', 'e');
|
||||
final CharRange rangea = CharRange.isIn('a', 'e');
|
||||
assertEquals('a', rangea.getStart());
|
||||
assertEquals('e', rangea.getEnd());
|
||||
assertFalse(rangea.isNegated());
|
||||
|
@ -84,7 +84,7 @@ public void testConstructorAccessors_isIn_Normal() {
|
|||
|
||||
@Test
|
||||
public void testConstructorAccessors_isIn_Reversed() {
|
||||
CharRange rangea = CharRange.isIn('e', 'a');
|
||||
final CharRange rangea = CharRange.isIn('e', 'a');
|
||||
assertEquals('a', rangea.getStart());
|
||||
assertEquals('e', rangea.getEnd());
|
||||
assertFalse(rangea.isNegated());
|
||||
|
@ -93,7 +93,7 @@ public void testConstructorAccessors_isIn_Reversed() {
|
|||
|
||||
@Test
|
||||
public void testConstructorAccessors_isNotIn_Same() {
|
||||
CharRange rangea = CharRange.isNotIn('a', 'a');
|
||||
final CharRange rangea = CharRange.isNotIn('a', 'a');
|
||||
assertEquals('a', rangea.getStart());
|
||||
assertEquals('a', rangea.getEnd());
|
||||
assertTrue(rangea.isNegated());
|
||||
|
@ -102,7 +102,7 @@ public void testConstructorAccessors_isNotIn_Same() {
|
|||
|
||||
@Test
|
||||
public void testConstructorAccessors_isNotIn_Normal() {
|
||||
CharRange rangea = CharRange.isNotIn('a', 'e');
|
||||
final CharRange rangea = CharRange.isNotIn('a', 'e');
|
||||
assertEquals('a', rangea.getStart());
|
||||
assertEquals('e', rangea.getEnd());
|
||||
assertTrue(rangea.isNegated());
|
||||
|
@ -111,7 +111,7 @@ public void testConstructorAccessors_isNotIn_Normal() {
|
|||
|
||||
@Test
|
||||
public void testConstructorAccessors_isNotIn_Reversed() {
|
||||
CharRange rangea = CharRange.isNotIn('e', 'a');
|
||||
final CharRange rangea = CharRange.isNotIn('e', 'a');
|
||||
assertEquals('a', rangea.getStart());
|
||||
assertEquals('e', rangea.getEnd());
|
||||
assertTrue(rangea.isNegated());
|
||||
|
@ -121,9 +121,9 @@ public void testConstructorAccessors_isNotIn_Reversed() {
|
|||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testEquals_Object() {
|
||||
CharRange rangea = CharRange.is('a');
|
||||
CharRange rangeae = CharRange.isIn('a', 'e');
|
||||
CharRange rangenotbf = CharRange.isIn('b', 'f');
|
||||
final CharRange rangea = CharRange.is('a');
|
||||
final CharRange rangeae = CharRange.isIn('a', 'e');
|
||||
final CharRange rangenotbf = CharRange.isIn('b', 'f');
|
||||
|
||||
assertFalse(rangea.equals(null));
|
||||
|
||||
|
@ -144,9 +144,9 @@ public void testEquals_Object() {
|
|||
|
||||
@Test
|
||||
public void testHashCode() {
|
||||
CharRange rangea = CharRange.is('a');
|
||||
CharRange rangeae = CharRange.isIn('a', 'e');
|
||||
CharRange rangenotbf = CharRange.isIn('b', 'f');
|
||||
final CharRange rangea = CharRange.is('a');
|
||||
final CharRange rangeae = CharRange.isIn('a', 'e');
|
||||
final CharRange rangenotbf = CharRange.isIn('b', 'f');
|
||||
|
||||
assertTrue(rangea.hashCode() == rangea.hashCode());
|
||||
assertTrue(rangea.hashCode() == CharRange.is('a').hashCode());
|
||||
|
@ -196,19 +196,19 @@ public void testContains_Char() {
|
|||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testContains_Charrange() {
|
||||
CharRange a = CharRange.is('a');
|
||||
CharRange b = CharRange.is('b');
|
||||
CharRange c = CharRange.is('c');
|
||||
CharRange c2 = CharRange.is('c');
|
||||
CharRange d = CharRange.is('d');
|
||||
CharRange e = CharRange.is('e');
|
||||
CharRange cd = CharRange.isIn('c', 'd');
|
||||
CharRange bd = CharRange.isIn('b', 'd');
|
||||
CharRange bc = CharRange.isIn('b', 'c');
|
||||
CharRange ab = CharRange.isIn('a', 'b');
|
||||
CharRange de = CharRange.isIn('d', 'e');
|
||||
CharRange ef = CharRange.isIn('e', 'f');
|
||||
CharRange ae = CharRange.isIn('a', 'e');
|
||||
final CharRange a = CharRange.is('a');
|
||||
final CharRange b = CharRange.is('b');
|
||||
final CharRange c = CharRange.is('c');
|
||||
final CharRange c2 = CharRange.is('c');
|
||||
final CharRange d = CharRange.is('d');
|
||||
final CharRange e = CharRange.is('e');
|
||||
final CharRange cd = CharRange.isIn('c', 'd');
|
||||
final CharRange bd = CharRange.isIn('b', 'd');
|
||||
final CharRange bc = CharRange.isIn('b', 'c');
|
||||
final CharRange ab = CharRange.isIn('a', 'b');
|
||||
final CharRange de = CharRange.isIn('d', 'e');
|
||||
final CharRange ef = CharRange.isIn('e', 'f');
|
||||
final CharRange ae = CharRange.isIn('a', 'e');
|
||||
|
||||
// normal/normal
|
||||
assertFalse(c.contains(b));
|
||||
|
@ -234,17 +234,17 @@ public void testContains_Charrange() {
|
|||
assertTrue(ae.contains(cd));
|
||||
assertTrue(ae.contains(de));
|
||||
|
||||
CharRange notb = CharRange.isNot('b');
|
||||
CharRange notc = CharRange.isNot('c');
|
||||
CharRange notd = CharRange.isNot('d');
|
||||
CharRange notab = CharRange.isNotIn('a', 'b');
|
||||
CharRange notbc = CharRange.isNotIn('b', 'c');
|
||||
CharRange notbd = CharRange.isNotIn('b', 'd');
|
||||
CharRange notcd = CharRange.isNotIn('c', 'd');
|
||||
CharRange notde = CharRange.isNotIn('d', 'e');
|
||||
CharRange notae = CharRange.isNotIn('a', 'e');
|
||||
CharRange all = CharRange.isIn((char) 0, Character.MAX_VALUE);
|
||||
CharRange allbutfirst = CharRange.isIn((char) 1, Character.MAX_VALUE);
|
||||
final CharRange notb = CharRange.isNot('b');
|
||||
final CharRange notc = CharRange.isNot('c');
|
||||
final CharRange notd = CharRange.isNot('d');
|
||||
final CharRange notab = CharRange.isNotIn('a', 'b');
|
||||
final CharRange notbc = CharRange.isNotIn('b', 'c');
|
||||
final CharRange notbd = CharRange.isNotIn('b', 'd');
|
||||
final CharRange notcd = CharRange.isNotIn('c', 'd');
|
||||
final CharRange notde = CharRange.isNotIn('d', 'e');
|
||||
final CharRange notae = CharRange.isNotIn('a', 'e');
|
||||
final CharRange all = CharRange.isIn((char) 0, Character.MAX_VALUE);
|
||||
final CharRange allbutfirst = CharRange.isIn((char) 1, Character.MAX_VALUE);
|
||||
|
||||
// normal/negated
|
||||
assertFalse(c.contains(notc));
|
||||
|
@ -311,31 +311,32 @@ public void testContains_Charrange() {
|
|||
|
||||
@Test
|
||||
public void testContainsNullArg() {
|
||||
CharRange range = CharRange.is('a');
|
||||
final CharRange range = CharRange.is('a');
|
||||
try {
|
||||
@SuppressWarnings("unused")
|
||||
final
|
||||
boolean contains = range.contains(null);
|
||||
} catch(IllegalArgumentException e) {
|
||||
} catch(final IllegalArgumentException e) {
|
||||
assertEquals("The Range must not be null", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIterator() {
|
||||
CharRange a = CharRange.is('a');
|
||||
CharRange ad = CharRange.isIn('a', 'd');
|
||||
CharRange nota = CharRange.isNot('a');
|
||||
CharRange emptySet = CharRange.isNotIn((char) 0, Character.MAX_VALUE);
|
||||
CharRange notFirst = CharRange.isNotIn((char) 1, Character.MAX_VALUE);
|
||||
CharRange notLast = CharRange.isNotIn((char) 0, (char) (Character.MAX_VALUE - 1));
|
||||
final CharRange a = CharRange.is('a');
|
||||
final CharRange ad = CharRange.isIn('a', 'd');
|
||||
final CharRange nota = CharRange.isNot('a');
|
||||
final CharRange emptySet = CharRange.isNotIn((char) 0, Character.MAX_VALUE);
|
||||
final CharRange notFirst = CharRange.isNotIn((char) 1, Character.MAX_VALUE);
|
||||
final CharRange notLast = CharRange.isNotIn((char) 0, (char) (Character.MAX_VALUE - 1));
|
||||
|
||||
Iterator<Character> aIt = a.iterator();
|
||||
final Iterator<Character> aIt = a.iterator();
|
||||
assertNotNull(aIt);
|
||||
assertTrue(aIt.hasNext());
|
||||
assertEquals(Character.valueOf('a'), aIt.next());
|
||||
assertFalse(aIt.hasNext());
|
||||
|
||||
Iterator<Character> adIt = ad.iterator();
|
||||
final Iterator<Character> adIt = ad.iterator();
|
||||
assertNotNull(adIt);
|
||||
assertTrue(adIt.hasNext());
|
||||
assertEquals(Character.valueOf('a'), adIt.next());
|
||||
|
@ -344,25 +345,25 @@ public void testIterator() {
|
|||
assertEquals(Character.valueOf('d'), adIt.next());
|
||||
assertFalse(adIt.hasNext());
|
||||
|
||||
Iterator<Character> notaIt = nota.iterator();
|
||||
final Iterator<Character> notaIt = nota.iterator();
|
||||
assertNotNull(notaIt);
|
||||
assertTrue(notaIt.hasNext());
|
||||
while (notaIt.hasNext()) {
|
||||
Character c = notaIt.next();
|
||||
final Character c = notaIt.next();
|
||||
assertFalse('a' == c.charValue());
|
||||
}
|
||||
|
||||
Iterator<Character> emptySetIt = emptySet.iterator();
|
||||
final Iterator<Character> emptySetIt = emptySet.iterator();
|
||||
assertNotNull(emptySetIt);
|
||||
assertFalse(emptySetIt.hasNext());
|
||||
try {
|
||||
emptySetIt.next();
|
||||
fail("Should throw NoSuchElementException");
|
||||
} catch (NoSuchElementException e) {
|
||||
} catch (final NoSuchElementException e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
Iterator<Character> notFirstIt = notFirst.iterator();
|
||||
final Iterator<Character> notFirstIt = notFirst.iterator();
|
||||
assertNotNull(notFirstIt);
|
||||
assertTrue(notFirstIt.hasNext());
|
||||
assertEquals(Character.valueOf((char) 0), notFirstIt.next());
|
||||
|
@ -370,11 +371,11 @@ public void testIterator() {
|
|||
try {
|
||||
notFirstIt.next();
|
||||
fail("Should throw NoSuchElementException");
|
||||
} catch (NoSuchElementException e) {
|
||||
} catch (final NoSuchElementException e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
Iterator<Character> notLastIt = notLast.iterator();
|
||||
final Iterator<Character> notLastIt = notLast.iterator();
|
||||
assertNotNull(notLastIt);
|
||||
assertTrue(notLastIt.hasNext());
|
||||
assertEquals(Character.valueOf(Character.MAX_VALUE), notLastIt.next());
|
||||
|
@ -382,7 +383,7 @@ public void testIterator() {
|
|||
try {
|
||||
notLastIt.next();
|
||||
fail("Should throw NoSuchElementException");
|
||||
} catch (NoSuchElementException e) {
|
||||
} catch (final NoSuchElementException e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ public class CharSequenceUtilsTest {
|
|||
@Test
|
||||
public void testConstructor() {
|
||||
assertNotNull(new CharSequenceUtils());
|
||||
Constructor<?>[] cons = CharSequenceUtils.class.getDeclaredConstructors();
|
||||
final Constructor<?>[] cons = CharSequenceUtils.class.getDeclaredConstructors();
|
||||
assertEquals(1, cons.length);
|
||||
assertTrue(Modifier.isPublic(cons[0].getModifiers()));
|
||||
assertTrue(Modifier.isPublic(CharSequenceUtils.class.getModifiers()));
|
||||
|
@ -69,13 +69,13 @@ public void testSubSequence() {
|
|||
try {
|
||||
Assert.assertEquals(null, CharSequenceUtils.subSequence(StringUtils.EMPTY, -1));
|
||||
Assert.fail("Expected " + IndexOutOfBoundsException.class.getName());
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
} catch (final IndexOutOfBoundsException e) {
|
||||
// Expected
|
||||
}
|
||||
try {
|
||||
Assert.assertEquals(null, CharSequenceUtils.subSequence(StringUtils.EMPTY, 1));
|
||||
Assert.fail("Expected " + IndexOutOfBoundsException.class.getName());
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
} catch (final IndexOutOfBoundsException e) {
|
||||
// Expected
|
||||
}
|
||||
}
|
||||
|
|
|
@ -343,12 +343,12 @@ public void testConstructor_String_oddCombinations() {
|
|||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testEquals_Object() {
|
||||
CharSet abc = CharSet.getInstance("abc");
|
||||
CharSet abc2 = CharSet.getInstance("abc");
|
||||
CharSet atoc = CharSet.getInstance("a-c");
|
||||
CharSet atoc2 = CharSet.getInstance("a-c");
|
||||
CharSet notatoc = CharSet.getInstance("^a-c");
|
||||
CharSet notatoc2 = CharSet.getInstance("^a-c");
|
||||
final CharSet abc = CharSet.getInstance("abc");
|
||||
final CharSet abc2 = CharSet.getInstance("abc");
|
||||
final CharSet atoc = CharSet.getInstance("a-c");
|
||||
final CharSet atoc2 = CharSet.getInstance("a-c");
|
||||
final CharSet notatoc = CharSet.getInstance("^a-c");
|
||||
final CharSet notatoc2 = CharSet.getInstance("^a-c");
|
||||
|
||||
assertFalse(abc.equals(null));
|
||||
|
||||
|
@ -370,12 +370,12 @@ public void testEquals_Object() {
|
|||
|
||||
@Test
|
||||
public void testHashCode() {
|
||||
CharSet abc = CharSet.getInstance("abc");
|
||||
CharSet abc2 = CharSet.getInstance("abc");
|
||||
CharSet atoc = CharSet.getInstance("a-c");
|
||||
CharSet atoc2 = CharSet.getInstance("a-c");
|
||||
CharSet notatoc = CharSet.getInstance("^a-c");
|
||||
CharSet notatoc2 = CharSet.getInstance("^a-c");
|
||||
final CharSet abc = CharSet.getInstance("abc");
|
||||
final CharSet abc2 = CharSet.getInstance("abc");
|
||||
final CharSet atoc = CharSet.getInstance("a-c");
|
||||
final CharSet atoc2 = CharSet.getInstance("a-c");
|
||||
final CharSet notatoc = CharSet.getInstance("^a-c");
|
||||
final CharSet notatoc2 = CharSet.getInstance("^a-c");
|
||||
|
||||
assertEquals(abc.hashCode(), abc.hashCode());
|
||||
assertEquals(abc.hashCode(), abc2.hashCode());
|
||||
|
@ -388,11 +388,11 @@ public void testHashCode() {
|
|||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testContains_Char() {
|
||||
CharSet btod = CharSet.getInstance("b-d");
|
||||
CharSet dtob = CharSet.getInstance("d-b");
|
||||
CharSet bcd = CharSet.getInstance("bcd");
|
||||
CharSet bd = CharSet.getInstance("bd");
|
||||
CharSet notbtod = CharSet.getInstance("^b-d");
|
||||
final CharSet btod = CharSet.getInstance("b-d");
|
||||
final CharSet dtob = CharSet.getInstance("d-b");
|
||||
final CharSet bcd = CharSet.getInstance("bcd");
|
||||
final CharSet bd = CharSet.getInstance("bd");
|
||||
final CharSet notbtod = CharSet.getInstance("^b-d");
|
||||
|
||||
assertFalse(btod.contains('a'));
|
||||
assertTrue(btod.contains('b'));
|
||||
|
@ -424,7 +424,7 @@ public void testContains_Char() {
|
|||
assertTrue(dtob.contains('d'));
|
||||
assertFalse(dtob.contains('e'));
|
||||
|
||||
CharRange[] array = dtob.getCharRanges();
|
||||
final CharRange[] array = dtob.getCharRanges();
|
||||
assertEquals("[b-d]", dtob.toString());
|
||||
assertEquals(1, array.length);
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ public class CharSetUtilsTest {
|
|||
@Test
|
||||
public void testConstructor() {
|
||||
assertNotNull(new CharSetUtils());
|
||||
Constructor<?>[] cons = CharSetUtils.class.getDeclaredConstructors();
|
||||
final Constructor<?>[] cons = CharSetUtils.class.getDeclaredConstructors();
|
||||
assertEquals(1, cons.length);
|
||||
assertTrue(Modifier.isPublic(cons[0].getModifiers()));
|
||||
assertTrue(Modifier.isPublic(CharSetUtils.class.getModifiers()));
|
||||
|
|
|
@ -125,8 +125,8 @@ private void run() {
|
|||
private int run_CharSet(final int loopCount) {
|
||||
int t = 0;
|
||||
for (int i = 0; i < loopCount; i++) {
|
||||
for (char ch : CHAR_SAMPLES) {
|
||||
boolean b = CharSet.ASCII_NUMERIC.contains(ch);
|
||||
for (final char ch : CHAR_SAMPLES) {
|
||||
final boolean b = CharSet.ASCII_NUMERIC.contains(ch);
|
||||
t += b ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
@ -136,8 +136,8 @@ private int run_CharSet(final int loopCount) {
|
|||
private int run_CharUtils_isAsciiNumeric(final int loopCount) {
|
||||
int t = 0;
|
||||
for (int i = 0; i < loopCount; i++) {
|
||||
for (char ch : CHAR_SAMPLES) {
|
||||
boolean b = CharUtils.isAsciiNumeric(ch);
|
||||
for (final char ch : CHAR_SAMPLES) {
|
||||
final boolean b = CharUtils.isAsciiNumeric(ch);
|
||||
t += b ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
@ -147,8 +147,8 @@ private int run_CharUtils_isAsciiNumeric(final int loopCount) {
|
|||
private int run_inlined_CharUtils_isAsciiNumeric(final int loopCount) {
|
||||
int t = 0;
|
||||
for (int i = 0; i < loopCount; i++) {
|
||||
for (char ch : CHAR_SAMPLES) {
|
||||
boolean b = ch >= '0' && ch <= '9';
|
||||
for (final char ch : CHAR_SAMPLES) {
|
||||
final boolean b = ch >= '0' && ch <= '9';
|
||||
t += b ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
@ -156,7 +156,7 @@ private int run_inlined_CharUtils_isAsciiNumeric(final int loopCount) {
|
|||
}
|
||||
|
||||
private void printlnTotal(final String prefix, final long start) {
|
||||
long total = System.currentTimeMillis() - start;
|
||||
final long total = System.currentTimeMillis() - start;
|
||||
System.out.println(prefix + ": " + NumberFormat.getInstance().format(total) + " milliseconds.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ public class CharUtilsTest {
|
|||
@Test
|
||||
public void testConstructor() {
|
||||
assertNotNull(new CharUtils());
|
||||
Constructor<?>[] cons = CharUtils.class.getDeclaredConstructors();
|
||||
final Constructor<?>[] cons = CharUtils.class.getDeclaredConstructors();
|
||||
assertEquals(1, cons.length);
|
||||
assertTrue(Modifier.isPublic(cons[0].getModifiers()));
|
||||
assertTrue(Modifier.isPublic(BooleanUtils.class.getModifiers()));
|
||||
|
@ -55,14 +55,14 @@ public void testToCharacterObject_char() {
|
|||
assertSame(CharUtils.toCharacterObject('a'), CharUtils.toCharacterObject('a'));
|
||||
|
||||
for (int i = 0; i < 128; i++) {
|
||||
Character ch = CharUtils.toCharacterObject((char) i);
|
||||
Character ch2 = CharUtils.toCharacterObject((char) i);
|
||||
final Character ch = CharUtils.toCharacterObject((char) i);
|
||||
final Character ch2 = CharUtils.toCharacterObject((char) i);
|
||||
assertSame(ch, ch2);
|
||||
assertEquals(i, ch.charValue());
|
||||
}
|
||||
for (int i = 128; i < 196; i++) {
|
||||
Character ch = CharUtils.toCharacterObject((char) i);
|
||||
Character ch2 = CharUtils.toCharacterObject((char) i);
|
||||
final Character ch = CharUtils.toCharacterObject((char) i);
|
||||
final Character ch2 = CharUtils.toCharacterObject((char) i);
|
||||
assertEquals(ch, ch2);
|
||||
assertTrue(ch != ch2);
|
||||
assertEquals(i, ch.charValue());
|
||||
|
@ -86,7 +86,7 @@ public void testToChar_Character() {
|
|||
assertEquals('B', CharUtils.toChar(CHARACTER_B));
|
||||
try {
|
||||
CharUtils.toChar((Character) null);
|
||||
} catch (IllegalArgumentException ex) {}
|
||||
} catch (final IllegalArgumentException ex) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -102,10 +102,10 @@ public void testToChar_String() {
|
|||
assertEquals('B', CharUtils.toChar("BA"));
|
||||
try {
|
||||
CharUtils.toChar((String) null);
|
||||
} catch (IllegalArgumentException ex) {}
|
||||
} catch (final IllegalArgumentException ex) {}
|
||||
try {
|
||||
CharUtils.toChar("");
|
||||
} catch (IllegalArgumentException ex) {}
|
||||
} catch (final IllegalArgumentException ex) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -130,7 +130,7 @@ public void testToIntValue_char() {
|
|||
assertEquals(9, CharUtils.toIntValue('9'));
|
||||
try {
|
||||
CharUtils.toIntValue('a');
|
||||
} catch (IllegalArgumentException ex) {}
|
||||
} catch (final IllegalArgumentException ex) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -146,10 +146,10 @@ public void testToIntValue_Character() {
|
|||
assertEquals(3, CharUtils.toIntValue(new Character('3')));
|
||||
try {
|
||||
CharUtils.toIntValue(null);
|
||||
} catch (IllegalArgumentException ex) {}
|
||||
} catch (final IllegalArgumentException ex) {}
|
||||
try {
|
||||
CharUtils.toIntValue(CHARACTER_A);
|
||||
} catch (IllegalArgumentException ex) {}
|
||||
} catch (final IllegalArgumentException ex) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -166,15 +166,15 @@ public void testToString_char() {
|
|||
assertSame(CharUtils.toString('a'), CharUtils.toString('a'));
|
||||
|
||||
for (int i = 0; i < 128; i++) {
|
||||
String str = CharUtils.toString((char) i);
|
||||
String str2 = CharUtils.toString((char) i);
|
||||
final String str = CharUtils.toString((char) i);
|
||||
final String str2 = CharUtils.toString((char) i);
|
||||
assertSame(str, str2);
|
||||
assertEquals(1, str.length());
|
||||
assertEquals(i, str.charAt(0));
|
||||
}
|
||||
for (int i = 128; i < 196; i++) {
|
||||
String str = CharUtils.toString((char) i);
|
||||
String str2 = CharUtils.toString((char) i);
|
||||
final String str = CharUtils.toString((char) i);
|
||||
final String str2 = CharUtils.toString((char) i);
|
||||
assertEquals(str, str2);
|
||||
assertTrue(str != str2);
|
||||
assertEquals(1, str.length());
|
||||
|
@ -196,9 +196,9 @@ public void testToUnicodeEscaped_char() {
|
|||
assertEquals("\\u0041", CharUtils.unicodeEscaped('A'));
|
||||
|
||||
for (int i = 0; i < 196; i++) {
|
||||
String str = CharUtils.unicodeEscaped((char) i);
|
||||
final String str = CharUtils.unicodeEscaped((char) i);
|
||||
assertEquals(6, str.length());
|
||||
int val = Integer.parseInt(str.substring(2), 16);
|
||||
final int val = Integer.parseInt(str.substring(2), 16);
|
||||
assertEquals(i, val);
|
||||
}
|
||||
assertEquals("\\u0999", CharUtils.unicodeEscaped((char) 0x999));
|
||||
|
|
|
@ -56,7 +56,7 @@ private class DeeplyNested{}
|
|||
@Test
|
||||
public void testConstructor() {
|
||||
assertNotNull(new ClassUtils());
|
||||
Constructor<?>[] cons = ClassUtils.class.getDeclaredConstructors();
|
||||
final Constructor<?>[] cons = ClassUtils.class.getDeclaredConstructors();
|
||||
assertEquals(1, cons.length);
|
||||
assertTrue(Modifier.isPublic(cons[0].getModifiers()));
|
||||
assertTrue(Modifier.isPublic(ClassUtils.class.getModifiers()));
|
||||
|
@ -228,7 +228,7 @@ public void test_getPackageName_String() {
|
|||
// -------------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_getAllSuperclasses_Class() {
|
||||
List<?> list = ClassUtils.getAllSuperclasses(CY.class);
|
||||
final List<?> list = ClassUtils.getAllSuperclasses(CY.class);
|
||||
assertEquals(2, list.size());
|
||||
assertEquals(CX.class, list.get(0));
|
||||
assertEquals(Object.class, list.get(1));
|
||||
|
@ -238,7 +238,7 @@ public void test_getAllSuperclasses_Class() {
|
|||
|
||||
@Test
|
||||
public void test_getAllInterfaces_Class() {
|
||||
List<?> list = ClassUtils.getAllInterfaces(CY.class);
|
||||
final List<?> list = ClassUtils.getAllInterfaces(CY.class);
|
||||
assertEquals(6, list.size());
|
||||
assertEquals(IB.class, list.get(0));
|
||||
assertEquals(IC.class, list.get(1));
|
||||
|
@ -270,7 +270,7 @@ private static class CY extends CX implements IB, IC {
|
|||
// -------------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_convertClassNamesToClasses_List() {
|
||||
List<String> list = new ArrayList<String>();
|
||||
final List<String> list = new ArrayList<String>();
|
||||
List<Class<?>> result = ClassUtils.convertClassNamesToClasses(list);
|
||||
assertEquals(0, result.size());
|
||||
|
||||
|
@ -284,18 +284,19 @@ public void test_convertClassNamesToClasses_List() {
|
|||
assertEquals(Object.class, result.get(2));
|
||||
|
||||
@SuppressWarnings("unchecked") // test what happens when non-generic code adds wrong type of element
|
||||
final
|
||||
List<Object> olist = (List<Object>)(List<?>)list;
|
||||
olist.add(new Object());
|
||||
try {
|
||||
ClassUtils.convertClassNamesToClasses(list);
|
||||
fail("Should not have been able to convert list");
|
||||
} catch (ClassCastException expected) {}
|
||||
} catch (final ClassCastException expected) {}
|
||||
assertEquals(null, ClassUtils.convertClassNamesToClasses(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_convertClassesToClassNames_List() {
|
||||
List<Class<?>> list = new ArrayList<Class<?>>();
|
||||
final List<Class<?>> list = new ArrayList<Class<?>>();
|
||||
List<String> result = ClassUtils.convertClassesToClassNames(list);
|
||||
assertEquals(0, result.size());
|
||||
|
||||
|
@ -309,12 +310,13 @@ public void test_convertClassesToClassNames_List() {
|
|||
assertEquals("java.lang.Object", result.get(2));
|
||||
|
||||
@SuppressWarnings("unchecked") // test what happens when non-generic code adds wrong type of element
|
||||
final
|
||||
List<Object> olist = (List<Object>)(List<?>)list;
|
||||
olist.add(new Object());
|
||||
try {
|
||||
ClassUtils.convertClassesToClassNames(list);
|
||||
fail("Should not have been able to convert list");
|
||||
} catch (ClassCastException expected) {}
|
||||
} catch (final ClassCastException expected) {}
|
||||
assertEquals(null, ClassUtils.convertClassesToClassNames(null));
|
||||
}
|
||||
|
||||
|
@ -333,12 +335,12 @@ public void test_isInnerClass_Class() {
|
|||
// -------------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_isAssignable_ClassArray_ClassArray() throws Exception {
|
||||
Class<?>[] array2 = new Class[] {Object.class, Object.class};
|
||||
Class<?>[] array1 = new Class[] {Object.class};
|
||||
Class<?>[] array1s = new Class[] {String.class};
|
||||
Class<?>[] array0 = new Class[] {};
|
||||
Class<?>[] arrayPrimitives = { Integer.TYPE, Boolean.TYPE };
|
||||
Class<?>[] arrayWrappers = { Integer.class, Boolean.class };
|
||||
final Class<?>[] array2 = new Class[] {Object.class, Object.class};
|
||||
final Class<?>[] array1 = new Class[] {Object.class};
|
||||
final Class<?>[] array1s = new Class[] {String.class};
|
||||
final Class<?>[] array0 = new Class[] {};
|
||||
final Class<?>[] arrayPrimitives = { Integer.TYPE, Boolean.TYPE };
|
||||
final Class<?>[] arrayWrappers = { Integer.class, Boolean.class };
|
||||
|
||||
assertFalse(ClassUtils.isAssignable(array1, array2));
|
||||
assertFalse(ClassUtils.isAssignable(null, array2));
|
||||
|
@ -352,7 +354,7 @@ public void test_isAssignable_ClassArray_ClassArray() throws Exception {
|
|||
assertTrue(ClassUtils.isAssignable(array1s, array1s));
|
||||
assertTrue(ClassUtils.isAssignable(array1s, array1));
|
||||
|
||||
boolean autoboxing = SystemUtils.isJavaVersionAtLeast(JAVA_1_5);
|
||||
final boolean autoboxing = SystemUtils.isJavaVersionAtLeast(JAVA_1_5);
|
||||
|
||||
assertEquals(autoboxing, ClassUtils.isAssignable(arrayPrimitives, arrayWrappers));
|
||||
assertEquals(autoboxing, ClassUtils.isAssignable(arrayWrappers, arrayPrimitives));
|
||||
|
@ -364,12 +366,12 @@ public void test_isAssignable_ClassArray_ClassArray() throws Exception {
|
|||
|
||||
@Test
|
||||
public void test_isAssignable_ClassArray_ClassArray_Autoboxing() throws Exception {
|
||||
Class<?>[] array2 = new Class[] {Object.class, Object.class};
|
||||
Class<?>[] array1 = new Class[] {Object.class};
|
||||
Class<?>[] array1s = new Class[] {String.class};
|
||||
Class<?>[] array0 = new Class[] {};
|
||||
Class<?>[] arrayPrimitives = { Integer.TYPE, Boolean.TYPE };
|
||||
Class<?>[] arrayWrappers = { Integer.class, Boolean.class };
|
||||
final Class<?>[] array2 = new Class[] {Object.class, Object.class};
|
||||
final Class<?>[] array1 = new Class[] {Object.class};
|
||||
final Class<?>[] array1s = new Class[] {String.class};
|
||||
final Class<?>[] array0 = new Class[] {};
|
||||
final Class<?>[] arrayPrimitives = { Integer.TYPE, Boolean.TYPE };
|
||||
final Class<?>[] arrayWrappers = { Integer.class, Boolean.class };
|
||||
|
||||
assertFalse(ClassUtils.isAssignable(array1, array2, true));
|
||||
assertFalse(ClassUtils.isAssignable(null, array2, true));
|
||||
|
@ -392,12 +394,12 @@ public void test_isAssignable_ClassArray_ClassArray_Autoboxing() throws Exceptio
|
|||
|
||||
@Test
|
||||
public void test_isAssignable_ClassArray_ClassArray_NoAutoboxing() throws Exception {
|
||||
Class<?>[] array2 = new Class[] {Object.class, Object.class};
|
||||
Class<?>[] array1 = new Class[] {Object.class};
|
||||
Class<?>[] array1s = new Class[] {String.class};
|
||||
Class<?>[] array0 = new Class[] {};
|
||||
Class<?>[] arrayPrimitives = { Integer.TYPE, Boolean.TYPE };
|
||||
Class<?>[] arrayWrappers = { Integer.class, Boolean.class };
|
||||
final Class<?>[] array2 = new Class[] {Object.class, Object.class};
|
||||
final Class<?>[] array1 = new Class[] {Object.class};
|
||||
final Class<?>[] array1s = new Class[] {String.class};
|
||||
final Class<?>[] array0 = new Class[] {};
|
||||
final Class<?>[] arrayPrimitives = { Integer.TYPE, Boolean.TYPE };
|
||||
final Class<?>[] arrayWrappers = { Integer.class, Boolean.class };
|
||||
|
||||
assertFalse(ClassUtils.isAssignable(array1, array2, false));
|
||||
assertFalse(ClassUtils.isAssignable(null, array2, false));
|
||||
|
@ -430,7 +432,7 @@ public void test_isAssignable() throws Exception {
|
|||
assertTrue(ClassUtils.isAssignable(String.class, String.class));
|
||||
assertFalse(ClassUtils.isAssignable(Object.class, String.class));
|
||||
|
||||
boolean autoboxing = SystemUtils.isJavaVersionAtLeast(JAVA_1_5);
|
||||
final boolean autoboxing = SystemUtils.isJavaVersionAtLeast(JAVA_1_5);
|
||||
|
||||
assertEquals(autoboxing, ClassUtils.isAssignable(Integer.TYPE, Integer.class));
|
||||
assertEquals(autoboxing, ClassUtils.isAssignable(Integer.TYPE, Object.class));
|
||||
|
@ -579,7 +581,7 @@ public void test_isAssignable_Widening() throws Exception {
|
|||
|
||||
@Test
|
||||
public void test_isAssignable_DefaultUnboxing_Widening() throws Exception {
|
||||
boolean autoboxing = SystemUtils.isJavaVersionAtLeast(JAVA_1_5);
|
||||
final boolean autoboxing = SystemUtils.isJavaVersionAtLeast(JAVA_1_5);
|
||||
|
||||
// test byte conversions
|
||||
assertFalse("byte -> char", ClassUtils.isAssignable(Byte.class, Character.TYPE));
|
||||
|
@ -849,7 +851,7 @@ public void testPrimitivesToWrappers() {
|
|||
assertNull("null -> null", ClassUtils.primitivesToWrappers((Class<?>[]) null)); // equivalent cast to avoid warning
|
||||
// Other possible casts for null
|
||||
assertTrue("empty -> empty", Arrays.equals(ArrayUtils.EMPTY_CLASS_ARRAY, ClassUtils.primitivesToWrappers()));
|
||||
Class<?>[] castNull = ClassUtils.primitivesToWrappers((Class<?>)null); // == new Class<?>[]{null}
|
||||
final Class<?>[] castNull = ClassUtils.primitivesToWrappers((Class<?>)null); // == new Class<?>[]{null}
|
||||
assertTrue("(Class<?>)null -> [null]", Arrays.equals(new Class<?>[]{null}, castNull));
|
||||
// test empty array is returned unchanged
|
||||
// TODO this is not documented
|
||||
|
@ -862,12 +864,12 @@ public void testPrimitivesToWrappers() {
|
|||
Integer.TYPE, Long.TYPE, Double.TYPE, Float.TYPE,
|
||||
String.class, ClassUtils.class
|
||||
};
|
||||
Class<?>[] wrappers= ClassUtils.primitivesToWrappers(primitives);
|
||||
final Class<?>[] wrappers= ClassUtils.primitivesToWrappers(primitives);
|
||||
|
||||
for (int i=0; i < primitives.length; i++) {
|
||||
// test each returned wrapper
|
||||
Class<?> primitive = primitives[i];
|
||||
Class<?> expectedWrapper = ClassUtils.primitiveToWrapper(primitive);
|
||||
final Class<?> primitive = primitives[i];
|
||||
final Class<?> expectedWrapper = ClassUtils.primitiveToWrapper(primitive);
|
||||
|
||||
assertEquals(primitive + " -> " + expectedWrapper, expectedWrapper, wrappers[i]);
|
||||
}
|
||||
|
@ -887,8 +889,8 @@ public void testWrapperToPrimitive() {
|
|||
Boolean.TYPE, Byte.TYPE, Character.TYPE, Short.TYPE,
|
||||
Integer.TYPE, Long.TYPE, Float.TYPE, Double.TYPE
|
||||
};
|
||||
for (Class<?> primitive : primitives) {
|
||||
Class<?> wrapperCls = ClassUtils.primitiveToWrapper(primitive);
|
||||
for (final Class<?> primitive : primitives) {
|
||||
final Class<?> wrapperCls = ClassUtils.primitiveToWrapper(primitive);
|
||||
assertFalse("Still primitive", wrapperCls.isPrimitive());
|
||||
assertEquals(wrapperCls + " -> " + primitive, primitive,
|
||||
ClassUtils.wrapperToPrimitive(wrapperCls));
|
||||
|
@ -914,11 +916,11 @@ public void testWrappersToPrimitives() {
|
|||
String.class, ClassUtils.class, null
|
||||
};
|
||||
|
||||
Class<?>[] primitives = ClassUtils.wrappersToPrimitives(classes);
|
||||
final Class<?>[] primitives = ClassUtils.wrappersToPrimitives(classes);
|
||||
// now test the result
|
||||
assertEquals("Wrong length of result array", classes.length, primitives.length);
|
||||
for (int i = 0; i < classes.length; i++) {
|
||||
Class<?> expectedPrimitive = ClassUtils.wrapperToPrimitive(classes[i]);
|
||||
final Class<?> expectedPrimitive = ClassUtils.wrapperToPrimitive(classes[i]);
|
||||
assertEquals(classes[i] + " -> " + expectedPrimitive, expectedPrimitive,
|
||||
primitives[i]);
|
||||
}
|
||||
|
@ -930,13 +932,13 @@ public void testWrappersToPrimitivesNull() {
|
|||
assertNull("Wrong result for null input", ClassUtils.wrappersToPrimitives((Class<?>[]) null)); // equivalent cast
|
||||
// Other possible casts for null
|
||||
assertTrue("empty -> empty", Arrays.equals(ArrayUtils.EMPTY_CLASS_ARRAY, ClassUtils.wrappersToPrimitives()));
|
||||
Class<?>[] castNull = ClassUtils.wrappersToPrimitives((Class<?>)null); // == new Class<?>[]{null}
|
||||
final Class<?>[] castNull = ClassUtils.wrappersToPrimitives((Class<?>)null); // == new Class<?>[]{null}
|
||||
assertTrue("(Class<?>)null -> [null]", Arrays.equals(new Class<?>[]{null}, castNull));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrappersToPrimitivesEmpty() {
|
||||
Class<?>[] empty = new Class[0];
|
||||
final Class<?>[] empty = new Class[0];
|
||||
assertArrayEquals("Wrong result for empty input", empty, ClassUtils.wrappersToPrimitives(empty));
|
||||
}
|
||||
|
||||
|
@ -1051,7 +1053,7 @@ private void assertGetClassThrowsException( final String className, final Class<
|
|||
ClassUtils.getClass( className );
|
||||
fail( "ClassUtils.getClass() should fail with an exception of type " + exceptionType.getName() + " when given class name \"" + className + "\"." );
|
||||
}
|
||||
catch( Exception e ) {
|
||||
catch( final Exception e ) {
|
||||
assertTrue( exceptionType.isAssignableFrom( e.getClass() ) );
|
||||
}
|
||||
}
|
||||
|
@ -1069,12 +1071,12 @@ private void assertGetClassThrowsClassNotFound( final String className ) throws
|
|||
@Test
|
||||
public void testShowJavaBug() throws Exception {
|
||||
// Tests with Collections$UnmodifiableSet
|
||||
Set<?> set = Collections.unmodifiableSet(new HashSet<Object>());
|
||||
Method isEmptyMethod = set.getClass().getMethod("isEmpty", new Class[0]);
|
||||
final Set<?> set = Collections.unmodifiableSet(new HashSet<Object>());
|
||||
final Method isEmptyMethod = set.getClass().getMethod("isEmpty", new Class[0]);
|
||||
try {
|
||||
isEmptyMethod.invoke(set, new Object[0]);
|
||||
fail("Failed to throw IllegalAccessException as expected");
|
||||
} catch(IllegalAccessException iae) {
|
||||
} catch(final IllegalAccessException iae) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
@ -1082,18 +1084,18 @@ public void testShowJavaBug() throws Exception {
|
|||
@Test
|
||||
public void testGetPublicMethod() throws Exception {
|
||||
// Tests with Collections$UnmodifiableSet
|
||||
Set<?> set = Collections.unmodifiableSet(new HashSet<Object>());
|
||||
Method isEmptyMethod = ClassUtils.getPublicMethod(set.getClass(), "isEmpty", new Class[0]);
|
||||
final Set<?> set = Collections.unmodifiableSet(new HashSet<Object>());
|
||||
final Method isEmptyMethod = ClassUtils.getPublicMethod(set.getClass(), "isEmpty", new Class[0]);
|
||||
assertTrue(Modifier.isPublic(isEmptyMethod.getDeclaringClass().getModifiers()));
|
||||
|
||||
try {
|
||||
isEmptyMethod.invoke(set, new Object[0]);
|
||||
} catch(java.lang.IllegalAccessException iae) {
|
||||
} catch(final java.lang.IllegalAccessException iae) {
|
||||
fail("Should not have thrown IllegalAccessException");
|
||||
}
|
||||
|
||||
// Tests with a public Class
|
||||
Method toStringMethod = ClassUtils.getPublicMethod(Object.class, "toString", new Class[0]);
|
||||
final Method toStringMethod = ClassUtils.getPublicMethod(Object.class, "toString", new Class[0]);
|
||||
assertEquals(Object.class.getMethod("toString", new Class[0]), toStringMethod);
|
||||
}
|
||||
|
||||
|
@ -1104,7 +1106,7 @@ public void testToClass_object() {
|
|||
|
||||
// Additional varargs tests
|
||||
assertTrue("empty -> empty", Arrays.equals(ArrayUtils.EMPTY_CLASS_ARRAY, ClassUtils.toClass()));
|
||||
Class<?>[] castNull = ClassUtils.toClass((Object) null); // == new Object[]{null}
|
||||
final Class<?>[] castNull = ClassUtils.toClass((Object) null); // == new Object[]{null}
|
||||
assertTrue("(Object)null -> [null]", Arrays.equals(new Object[]{null}, castNull));
|
||||
|
||||
assertSame(ArrayUtils.EMPTY_CLASS_ARRAY, ClassUtils.toClass(ArrayUtils.EMPTY_OBJECT_ARRAY));
|
||||
|
|
|
@ -256,11 +256,11 @@ public void testBinaryToHexDigit() {
|
|||
*/
|
||||
@Test
|
||||
public void testBinaryToHexDigit_2args() {
|
||||
boolean[] shortArray = new boolean[]{false, true, true};
|
||||
final boolean[] shortArray = new boolean[]{false, true, true};
|
||||
assertEquals('6', Conversion.binaryToHexDigit(shortArray, 0));
|
||||
assertEquals('3', Conversion.binaryToHexDigit(shortArray, 1));
|
||||
assertEquals('1', Conversion.binaryToHexDigit(shortArray, 2));
|
||||
boolean[] longArray = new boolean[]{true, false, true, false, false, true, true};
|
||||
final boolean[] longArray = new boolean[]{true, false, true, false, false, true, true};
|
||||
assertEquals('5', Conversion.binaryToHexDigit(longArray, 0));
|
||||
assertEquals('2', Conversion.binaryToHexDigit(longArray, 1));
|
||||
assertEquals('9', Conversion.binaryToHexDigit(longArray, 2));
|
||||
|
@ -329,9 +329,9 @@ public void testBinaryToHexDigitMsb0_4bits_2args() {
|
|||
// assertEquals('6', Conversion.BinaryToHexDigitMsb0(shortArray,0));
|
||||
// assertEquals('3', Conversion.BinaryToHexDigitMsb0(shortArray,1));
|
||||
// assertEquals('1', Conversion.BinaryToHexDigitMsb0(shortArray,2));
|
||||
boolean[] shortArray = new boolean[]{true, true, false, true};
|
||||
final boolean[] shortArray = new boolean[]{true, true, false, true};
|
||||
assertEquals('d', Conversion.binaryToHexDigitMsb0_4bits(shortArray, 0));
|
||||
boolean[] longArray = new boolean[]{true, false, true, false, false, true, true};
|
||||
final boolean[] longArray = new boolean[]{true, false, true, false, false, true, true};
|
||||
assertEquals('a', Conversion.binaryToHexDigitMsb0_4bits(longArray, 0));
|
||||
assertEquals('4', Conversion.binaryToHexDigitMsb0_4bits(longArray, 1));
|
||||
assertEquals('9', Conversion.binaryToHexDigitMsb0_4bits(longArray, 2));
|
||||
|
@ -339,7 +339,7 @@ public void testBinaryToHexDigitMsb0_4bits_2args() {
|
|||
// assertEquals('6', Conversion.BinaryToHexDigitMsb0(longArray,4));
|
||||
// assertEquals('3', Conversion.BinaryToHexDigitMsb0(longArray,5));
|
||||
// assertEquals('1', Conversion.BinaryToHexDigitMsb0(longArray,6));
|
||||
boolean[] maxLengthArray = new boolean[]{
|
||||
final boolean[] maxLengthArray = new boolean[]{
|
||||
true, false, true, false, false, true, true, true};
|
||||
assertEquals('a', Conversion.binaryToHexDigitMsb0_4bits(maxLengthArray, 0));
|
||||
assertEquals('4', Conversion.binaryToHexDigitMsb0_4bits(maxLengthArray, 1));
|
||||
|
@ -349,7 +349,7 @@ public void testBinaryToHexDigitMsb0_4bits_2args() {
|
|||
// assertEquals('7', Conversion.BinaryToHexDigitMsb0(longArray,5));
|
||||
// assertEquals('3', Conversion.BinaryToHexDigitMsb0(longArray,6));
|
||||
// assertEquals('1', Conversion.BinaryToHexDigitMsb0(longArray,7));
|
||||
boolean[] javaDocCheck = new boolean[]{
|
||||
final boolean[] javaDocCheck = new boolean[]{
|
||||
true, false, false, true, true, false, true, false};
|
||||
assertEquals('d', Conversion.binaryToHexDigitMsb0_4bits(javaDocCheck, 3));
|
||||
|
||||
|
@ -416,11 +416,11 @@ public void testBinaryBeMsb0ToHexDigit_2args() {
|
|||
true, false, false, false, false, false, false, false, false, false, false,
|
||||
true, false, true, false, false}, 2));
|
||||
|
||||
boolean[] shortArray = new boolean[]{true, true, false};
|
||||
final boolean[] shortArray = new boolean[]{true, true, false};
|
||||
assertEquals('6', Conversion.binaryBeMsb0ToHexDigit(shortArray, 0));
|
||||
assertEquals('3', Conversion.binaryBeMsb0ToHexDigit(shortArray, 1));
|
||||
assertEquals('1', Conversion.binaryBeMsb0ToHexDigit(shortArray, 2));
|
||||
boolean[] shortArray2 = new boolean[]{true, true, true, false, false, true, false, true};
|
||||
final boolean[] shortArray2 = new boolean[]{true, true, true, false, false, true, false, true};
|
||||
assertEquals('5', Conversion.binaryBeMsb0ToHexDigit(shortArray2, 0));
|
||||
assertEquals('2', Conversion.binaryBeMsb0ToHexDigit(shortArray2, 1));
|
||||
assertEquals('9', Conversion.binaryBeMsb0ToHexDigit(shortArray2, 2));
|
||||
|
@ -429,7 +429,7 @@ public void testBinaryBeMsb0ToHexDigit_2args() {
|
|||
assertEquals('7', Conversion.binaryBeMsb0ToHexDigit(shortArray2, 5));
|
||||
assertEquals('3', Conversion.binaryBeMsb0ToHexDigit(shortArray2, 6));
|
||||
assertEquals('1', Conversion.binaryBeMsb0ToHexDigit(shortArray2, 7));
|
||||
boolean[] multiBytesArray = new boolean[]{
|
||||
final boolean[] multiBytesArray = new boolean[]{
|
||||
true, true, false, false, true, false, true, false, true, true, true, false, false,
|
||||
true, false, true};
|
||||
assertEquals('5', Conversion.binaryBeMsb0ToHexDigit(multiBytesArray, 0));
|
||||
|
@ -511,15 +511,15 @@ public void testIntToHexDigitMsb0() {
|
|||
}
|
||||
|
||||
static String dbgPrint(final boolean[] src) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (boolean e : src) {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
for (final boolean e : src) {
|
||||
if (e) {
|
||||
sb.append("1,");
|
||||
} else {
|
||||
sb.append("0,");
|
||||
}
|
||||
}
|
||||
String out = sb.toString();
|
||||
final String out = sb.toString();
|
||||
return out.substring(0, out.length() - 1);
|
||||
}
|
||||
|
||||
|
@ -529,8 +529,8 @@ static void assertBinaryEquals(final boolean[] expected, final boolean[] actual)
|
|||
for (int i = 0; i < expected.length; i++ ) {
|
||||
try {
|
||||
assertEquals(expected[i], actual[i]);
|
||||
} catch (Throwable e) {
|
||||
String msg = "Mismatch at index "
|
||||
} catch (final Throwable e) {
|
||||
final String msg = "Mismatch at index "
|
||||
+ i
|
||||
+ " between:\n"
|
||||
+ dbgPrint(expected)
|
||||
|
@ -546,7 +546,7 @@ static void assertBinaryEquals(final boolean[] expected, final boolean[] actual)
|
|||
*/
|
||||
@Test
|
||||
public void testIntArrayToLong() {
|
||||
int[] src = new int[]{0xCDF1F0C1, 0x0F123456, 0x78000000};
|
||||
final int[] src = new int[]{0xCDF1F0C1, 0x0F123456, 0x78000000};
|
||||
assertEquals(0x0000000000000000L, Conversion.intArrayToLong(src, 0, 0L, 0, 0));
|
||||
assertEquals(0x0000000000000000L, Conversion.intArrayToLong(src, 1, 0L, 0, 0));
|
||||
assertEquals(0x00000000CDF1F0C1L, Conversion.intArrayToLong(src, 0, 0L, 0, 1));
|
||||
|
@ -564,7 +564,7 @@ public void testIntArrayToLong() {
|
|||
*/
|
||||
@Test
|
||||
public void testShortArrayToLong() {
|
||||
short[] src = new short[]{
|
||||
final short[] src = new short[]{
|
||||
(short)0xCDF1, (short)0xF0C1, (short)0x0F12, (short)0x3456, (short)0x7800};
|
||||
assertEquals(0x0000000000000000L, Conversion.shortArrayToLong(src, 0, 0L, 0, 0));
|
||||
assertEquals(0x000000000000CDF1L, Conversion.shortArrayToLong(src, 0, 0L, 0, 1));
|
||||
|
@ -585,7 +585,7 @@ public void testShortArrayToLong() {
|
|||
*/
|
||||
@Test
|
||||
public void testByteArrayToLong() {
|
||||
byte[] src = new byte[]{
|
||||
final byte[] src = new byte[]{
|
||||
(byte)0xCD, (byte)0xF1, (byte)0xF0, (byte)0xC1, (byte)0x0F, (byte)0x12, (byte)0x34,
|
||||
(byte)0x56, (byte)0x78};
|
||||
assertEquals(0x0000000000000000L, Conversion.byteArrayToLong(src, 0, 0L, 0, 0));
|
||||
|
@ -605,7 +605,7 @@ public void testByteArrayToLong() {
|
|||
*/
|
||||
@Test
|
||||
public void testShortArrayToInt() {
|
||||
short[] src = new short[]{
|
||||
final short[] src = new short[]{
|
||||
(short)0xCDF1, (short)0xF0C1, (short)0x0F12, (short)0x3456, (short)0x7800};
|
||||
assertEquals(0x00000000, Conversion.shortArrayToInt(src, 0, 0, 0, 0));
|
||||
assertEquals(0x0000CDF1, Conversion.shortArrayToInt(src, 0, 0, 0, 1));
|
||||
|
@ -621,7 +621,7 @@ public void testShortArrayToInt() {
|
|||
*/
|
||||
@Test
|
||||
public void testByteArrayToInt() {
|
||||
byte[] src = new byte[]{
|
||||
final byte[] src = new byte[]{
|
||||
(byte)0xCD, (byte)0xF1, (byte)0xF0, (byte)0xC1, (byte)0x0F, (byte)0x12, (byte)0x34,
|
||||
(byte)0x56, (byte)0x78};
|
||||
assertEquals(0x00000000, Conversion.byteArrayToInt(src, 0, 0, 0, 0));
|
||||
|
@ -638,7 +638,7 @@ public void testByteArrayToInt() {
|
|||
*/
|
||||
@Test
|
||||
public void testByteArrayToShort() {
|
||||
byte[] src = new byte[]{
|
||||
final byte[] src = new byte[]{
|
||||
(byte)0xCD, (byte)0xF1, (byte)0xF0, (byte)0xC1, (byte)0x0F, (byte)0x12, (byte)0x34,
|
||||
(byte)0x56, (byte)0x78};
|
||||
assertEquals((short)0x0000, Conversion.byteArrayToShort(src, 0, (short)0, 0, 0));
|
||||
|
@ -656,7 +656,7 @@ public void testByteArrayToShort() {
|
|||
*/
|
||||
@Test
|
||||
public void testHexToLong() {
|
||||
String src = "CDF1F0C10F12345678";
|
||||
final String src = "CDF1F0C10F12345678";
|
||||
assertEquals(0x0000000000000000L, Conversion.hexToLong(src, 0, 0L, 0, 0));
|
||||
assertEquals(0x000000000000000CL, Conversion.hexToLong(src, 0, 0L, 0, 1));
|
||||
assertEquals(0x000000001C0F1FDCL, Conversion.hexToLong(src, 0, 0L, 0, 8));
|
||||
|
@ -672,7 +672,7 @@ public void testHexToLong() {
|
|||
*/
|
||||
@Test
|
||||
public void testHexToInt() {
|
||||
String src = "CDF1F0C10F12345678";
|
||||
final String src = "CDF1F0C10F12345678";
|
||||
assertEquals(0x00000000, Conversion.hexToInt(src, 0, 0, 0, 0));
|
||||
assertEquals(0x0000000C, Conversion.hexToInt(src, 0, 0, 0, 1));
|
||||
assertEquals(0x1C0F1FDC, Conversion.hexToInt(src, 0, 0, 0, 8));
|
||||
|
@ -686,7 +686,7 @@ public void testHexToInt() {
|
|||
*/
|
||||
@Test
|
||||
public void testHexToShort() {
|
||||
String src = "CDF1F0C10F12345678";
|
||||
final String src = "CDF1F0C10F12345678";
|
||||
assertEquals((short)0x0000, Conversion.hexToShort(src, 0, (short)0, 0, 0));
|
||||
assertEquals((short)0x000C, Conversion.hexToShort(src, 0, (short)0, 0, 1));
|
||||
assertEquals((short)0x1FDC, Conversion.hexToShort(src, 0, (short)0, 0, 4));
|
||||
|
@ -700,7 +700,7 @@ public void testHexToShort() {
|
|||
*/
|
||||
@Test
|
||||
public void testHexToByte() {
|
||||
String src = "CDF1F0C10F12345678";
|
||||
final String src = "CDF1F0C10F12345678";
|
||||
assertEquals((byte)0x00, Conversion.hexToByte(src, 0, (byte)0, 0, 0));
|
||||
assertEquals((byte)0x0C, Conversion.hexToByte(src, 0, (byte)0, 0, 1));
|
||||
assertEquals((byte)0xDC, Conversion.hexToByte(src, 0, (byte)0, 0, 2));
|
||||
|
@ -714,7 +714,7 @@ public void testHexToByte() {
|
|||
*/
|
||||
@Test
|
||||
public void testBinaryToLong() {
|
||||
boolean[] src = new boolean[]{
|
||||
final boolean[] src = new boolean[]{
|
||||
false, false, true, true, true, false, true, true, true, true, true, true, true,
|
||||
false, false, false, true, true, true, true, false, false, false, false, false,
|
||||
false, true, true, true, false, false, false, false, false, false, false, true,
|
||||
|
@ -738,7 +738,7 @@ public void testBinaryToLong() {
|
|||
*/
|
||||
@Test
|
||||
public void testBinaryToInt() {
|
||||
boolean[] src = new boolean[]{
|
||||
final boolean[] src = new boolean[]{
|
||||
false, false, true, true, true, false, true, true, true, true, true, true, true,
|
||||
false, false, false, true, true, true, true, false, false, false, false, false,
|
||||
false, true, true, true, false, false, false, false, false, false, false, true,
|
||||
|
@ -759,7 +759,7 @@ public void testBinaryToInt() {
|
|||
*/
|
||||
@Test
|
||||
public void testBinaryToShort() {
|
||||
boolean[] src = new boolean[]{
|
||||
final boolean[] src = new boolean[]{
|
||||
false, false, true, true, true, false, true, true, true, true, true, true, true,
|
||||
false, false, false, true, true, true, true, false, false, false, false, false,
|
||||
false, true, true, true, false, false, false, false, false, false, false, true,
|
||||
|
@ -782,7 +782,7 @@ public void testBinaryToShort() {
|
|||
*/
|
||||
@Test
|
||||
public void testBinaryToByte() {
|
||||
boolean[] src = new boolean[]{
|
||||
final boolean[] src = new boolean[]{
|
||||
false, false, true, true, true, false, true, true, true, true, true, true, true,
|
||||
false, false, false, true, true, true, true, false, false, false, false, false,
|
||||
false, true, true, true, false, false, false, false, false, false, false, true,
|
||||
|
|
|
@ -45,7 +45,7 @@ public void testConstructable() {
|
|||
|
||||
@Test
|
||||
public void test_getEnumMap() {
|
||||
Map<String, Traffic> test = EnumUtils.getEnumMap(Traffic.class);
|
||||
final Map<String, Traffic> test = EnumUtils.getEnumMap(Traffic.class);
|
||||
assertEquals( "getEnumMap not created correctly", "{RED=RED, AMBER=AMBER, GREEN=GREEN}", test.toString());
|
||||
assertEquals(3, test.size());
|
||||
assertTrue(test.containsKey("RED"));
|
||||
|
@ -59,7 +59,7 @@ public void test_getEnumMap() {
|
|||
|
||||
@Test
|
||||
public void test_getEnumList() {
|
||||
List<Traffic> test = EnumUtils.getEnumList(Traffic.class);
|
||||
final List<Traffic> test = EnumUtils.getEnumList(Traffic.class);
|
||||
assertEquals(3, test.size());
|
||||
assertEquals(Traffic.RED, test.get(0));
|
||||
assertEquals(Traffic.AMBER, test.get(1));
|
||||
|
@ -168,8 +168,10 @@ public void test_generateBitVector_longClassWithArray() {
|
|||
@Test(expected=IllegalArgumentException.class)
|
||||
public void test_generateBitVector_nonEnumClass() {
|
||||
@SuppressWarnings("rawtypes")
|
||||
final
|
||||
Class rawType = Object.class;
|
||||
@SuppressWarnings("rawtypes")
|
||||
final
|
||||
List rawList = new ArrayList();
|
||||
EnumUtils.generateBitVector(rawType, rawList);
|
||||
}
|
||||
|
@ -178,8 +180,10 @@ public void test_generateBitVector_nonEnumClass() {
|
|||
@Test(expected=IllegalArgumentException.class)
|
||||
public void test_generateBitVectors_nonEnumClass() {
|
||||
@SuppressWarnings("rawtypes")
|
||||
final
|
||||
Class rawType = Object.class;
|
||||
@SuppressWarnings("rawtypes")
|
||||
final
|
||||
List rawList = new ArrayList();
|
||||
EnumUtils.generateBitVectors(rawType, rawList);
|
||||
}
|
||||
|
@ -188,6 +192,7 @@ public void test_generateBitVectors_nonEnumClass() {
|
|||
@Test(expected=IllegalArgumentException.class)
|
||||
public void test_generateBitVector_nonEnumClassWithArray() {
|
||||
@SuppressWarnings("rawtypes")
|
||||
final
|
||||
Class rawType = Object.class;
|
||||
EnumUtils.generateBitVector(rawType);
|
||||
}
|
||||
|
@ -196,6 +201,7 @@ public void test_generateBitVector_nonEnumClassWithArray() {
|
|||
@Test(expected=IllegalArgumentException.class)
|
||||
public void test_generateBitVectors_nonEnumClassWithArray() {
|
||||
@SuppressWarnings("rawtypes")
|
||||
final
|
||||
Class rawType = Object.class;
|
||||
EnumUtils.generateBitVectors(rawType);
|
||||
}
|
||||
|
|
|
@ -49,8 +49,8 @@ public void testTimes() {
|
|||
* @return bitSet - HashSet
|
||||
*/
|
||||
private long printTimes(final int count) {
|
||||
long hashSet = timeHashSet(count);
|
||||
long bitSet = timeBitSet(count);
|
||||
final long hashSet = timeHashSet(count);
|
||||
final long bitSet = timeBitSet(count);
|
||||
// If percent is less than 100, then bitset is faster
|
||||
System.out.println("Ratio="+(bitSet*100/hashSet)+"% count="+count+" hash="+hashSet+" bits="+bitSet);
|
||||
return bitSet - hashSet;
|
||||
|
@ -58,29 +58,29 @@ private long printTimes(final int count) {
|
|||
|
||||
private static long timeHashSet(final int count) {
|
||||
int [] result = new int[0];
|
||||
long start = System.nanoTime();
|
||||
final long start = System.nanoTime();
|
||||
for (int i = 0; i < LOOPS; i++) {
|
||||
result = testHashSet(count);
|
||||
}
|
||||
long elapsed = System.nanoTime() - start;
|
||||
final long elapsed = System.nanoTime() - start;
|
||||
Assert.assertEquals(count, result.length);
|
||||
return elapsed;
|
||||
}
|
||||
|
||||
private static long timeBitSet(final int count) {
|
||||
int [] result = new int[0];
|
||||
long start = System.nanoTime();
|
||||
final long start = System.nanoTime();
|
||||
for (int i = 0; i < LOOPS; i++) {
|
||||
result = testBitSet(count);
|
||||
}
|
||||
long elapsed = System.nanoTime() - start;
|
||||
final long elapsed = System.nanoTime() - start;
|
||||
Assert.assertEquals(count, result.length);
|
||||
return elapsed;
|
||||
}
|
||||
|
||||
@SuppressWarnings("boxing")
|
||||
private static int[] testHashSet(final int count) {
|
||||
HashSet<Integer> toRemove = new HashSet<Integer>();
|
||||
final HashSet<Integer> toRemove = new HashSet<Integer>();
|
||||
int found = 0;
|
||||
for (int i = 0; i < count; i++) {
|
||||
toRemove.add(found++);
|
||||
|
@ -89,7 +89,7 @@ private static int[] testHashSet(final int count) {
|
|||
}
|
||||
|
||||
private static int[] testBitSet(final int count) {
|
||||
BitSet toRemove = new BitSet();
|
||||
final BitSet toRemove = new BitSet();
|
||||
int found = 0;
|
||||
for (int i = 0; i < count; i++) {
|
||||
toRemove.set(found++);
|
||||
|
@ -99,16 +99,16 @@ private static int[] testBitSet(final int count) {
|
|||
|
||||
|
||||
private static int[] extractIndices(final HashSet<Integer> coll) {
|
||||
int[] result = new int[coll.size()];
|
||||
final int[] result = new int[coll.size()];
|
||||
int i = 0;
|
||||
for (Integer index : coll) {
|
||||
for (final Integer index : coll) {
|
||||
result[i++] = index.intValue();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static int[] extractIndices(final BitSet coll) {
|
||||
int[] result = new int[coll.cardinality()];
|
||||
final int[] result = new int[coll.cardinality()];
|
||||
int i = 0;
|
||||
int j=0;
|
||||
while((j=coll.nextSetBit(j)) != -1) {
|
||||
|
@ -136,13 +136,13 @@ public void testTimesExtractOrBitset() {
|
|||
}
|
||||
|
||||
private long printTimes(final int arraySize, final int bitSetSize) {
|
||||
int[] array = new int[arraySize];
|
||||
BitSet remove = new BitSet();
|
||||
final int[] array = new int[arraySize];
|
||||
final BitSet remove = new BitSet();
|
||||
for (int i = 0; i < bitSetSize; i++) {
|
||||
remove.set(i);
|
||||
}
|
||||
long bitSet = timeBitSetRemoveAll(array, remove );
|
||||
long extract = timeExtractRemoveAll(array, remove);
|
||||
final long bitSet = timeBitSetRemoveAll(array, remove );
|
||||
final long extract = timeExtractRemoveAll(array, remove);
|
||||
// If percent is less than 100, then direct use of bitset is faster
|
||||
System.out.println("Ratio="+(bitSet*100/extract)+"% array="+array.length+" count="+remove.cardinality()+" extract="+extract+" bitset="+bitSet);
|
||||
return bitSet - extract;
|
||||
|
@ -150,23 +150,23 @@ private long printTimes(final int arraySize, final int bitSetSize) {
|
|||
|
||||
private long timeBitSetRemoveAll(final int[] array, final BitSet toRemove) {
|
||||
int[] output = new int[0];
|
||||
long start = System.nanoTime();
|
||||
final long start = System.nanoTime();
|
||||
for(int i = 0; i < LOOPS2; i++){
|
||||
output = (int[]) ArrayUtils.removeAll(array, toRemove);
|
||||
}
|
||||
long end = System.nanoTime();
|
||||
final long end = System.nanoTime();
|
||||
Assert.assertEquals(array.length-toRemove.cardinality(), output.length);
|
||||
return end - start;
|
||||
}
|
||||
|
||||
private long timeExtractRemoveAll(final int[] array, final BitSet toRemove) {
|
||||
int[] output = new int[0];
|
||||
long start = System.nanoTime();
|
||||
final long start = System.nanoTime();
|
||||
for(int i = 0; i < LOOPS2; i++){
|
||||
final int[] extractIndices = extractIndices(toRemove);
|
||||
output = (int[]) ArrayUtils.removeAll((Object)array, extractIndices);
|
||||
}
|
||||
long end = System.nanoTime();
|
||||
final long end = System.nanoTime();
|
||||
Assert.assertEquals(array.length-toRemove.cardinality(), output.length);
|
||||
return end - start;
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ public void setUp() throws Exception {
|
|||
@Test
|
||||
public void testConstructor() {
|
||||
assertNotNull(new LocaleUtils());
|
||||
Constructor<?>[] cons = LocaleUtils.class.getDeclaredConstructors();
|
||||
final Constructor<?>[] cons = LocaleUtils.class.getDeclaredConstructors();
|
||||
assertEquals(1, cons.length);
|
||||
assertTrue(Modifier.isPublic(cons[0].getModifiers()));
|
||||
assertTrue(Modifier.isPublic(LocaleUtils.class.getModifiers()));
|
||||
|
@ -81,7 +81,7 @@ public void testConstructor() {
|
|||
* @param language the language string
|
||||
*/
|
||||
private void assertValidToLocale(final String language) {
|
||||
Locale locale = LocaleUtils.toLocale(language);
|
||||
final Locale locale = LocaleUtils.toLocale(language);
|
||||
assertNotNull("valid locale", locale);
|
||||
assertEquals(language, locale.getLanguage());
|
||||
//country and variant are empty
|
||||
|
@ -97,7 +97,7 @@ private void assertValidToLocale(final String language) {
|
|||
* @param country of the resulting Locale
|
||||
*/
|
||||
private void assertValidToLocale(final String localeString, final String language, final String country) {
|
||||
Locale locale = LocaleUtils.toLocale(localeString);
|
||||
final Locale locale = LocaleUtils.toLocale(localeString);
|
||||
assertNotNull("valid locale", locale);
|
||||
assertEquals(language, locale.getLanguage());
|
||||
assertEquals(country, locale.getCountry());
|
||||
|
@ -116,7 +116,7 @@ private void assertValidToLocale(final String localeString, final String languag
|
|||
private void assertValidToLocale(
|
||||
final String localeString, final String language,
|
||||
final String country, final String variant) {
|
||||
Locale locale = LocaleUtils.toLocale(localeString);
|
||||
final Locale locale = LocaleUtils.toLocale(localeString);
|
||||
assertNotNull("valid locale", locale);
|
||||
assertEquals(language, locale.getLanguage());
|
||||
assertEquals(country, locale.getCountry());
|
||||
|
@ -141,34 +141,34 @@ public void testToLocale_1Part() {
|
|||
try {
|
||||
LocaleUtils.toLocale("Us");
|
||||
fail("Should fail if not lowercase");
|
||||
} catch (IllegalArgumentException iae) {}
|
||||
} catch (final IllegalArgumentException iae) {}
|
||||
try {
|
||||
LocaleUtils.toLocale("US");
|
||||
fail("Should fail if not lowercase");
|
||||
} catch (IllegalArgumentException iae) {}
|
||||
} catch (final IllegalArgumentException iae) {}
|
||||
try {
|
||||
LocaleUtils.toLocale("uS");
|
||||
fail("Should fail if not lowercase");
|
||||
} catch (IllegalArgumentException iae) {}
|
||||
} catch (final IllegalArgumentException iae) {}
|
||||
try {
|
||||
LocaleUtils.toLocale("u#");
|
||||
fail("Should fail if not lowercase");
|
||||
} catch (IllegalArgumentException iae) {}
|
||||
} catch (final IllegalArgumentException iae) {}
|
||||
|
||||
try {
|
||||
LocaleUtils.toLocale("u");
|
||||
fail("Must be 2 chars if less than 5");
|
||||
} catch (IllegalArgumentException iae) {}
|
||||
} catch (final IllegalArgumentException iae) {}
|
||||
|
||||
try {
|
||||
LocaleUtils.toLocale("uuu");
|
||||
fail("Must be 2 chars if less than 5");
|
||||
} catch (IllegalArgumentException iae) {}
|
||||
} catch (final IllegalArgumentException iae) {}
|
||||
|
||||
try {
|
||||
LocaleUtils.toLocale("uu_U");
|
||||
fail("Must be 2 chars if less than 5");
|
||||
} catch (IllegalArgumentException iae) {}
|
||||
} catch (final IllegalArgumentException iae) {}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -183,27 +183,27 @@ public void testToLocale_2Part() {
|
|||
try {
|
||||
LocaleUtils.toLocale("us-EN");
|
||||
fail("Should fail as not underscore");
|
||||
} catch (IllegalArgumentException iae) {}
|
||||
} catch (final IllegalArgumentException iae) {}
|
||||
try {
|
||||
LocaleUtils.toLocale("us_En");
|
||||
fail("Should fail second part not uppercase");
|
||||
} catch (IllegalArgumentException iae) {}
|
||||
} catch (final IllegalArgumentException iae) {}
|
||||
try {
|
||||
LocaleUtils.toLocale("us_en");
|
||||
fail("Should fail second part not uppercase");
|
||||
} catch (IllegalArgumentException iae) {}
|
||||
} catch (final IllegalArgumentException iae) {}
|
||||
try {
|
||||
LocaleUtils.toLocale("us_eN");
|
||||
fail("Should fail second part not uppercase");
|
||||
} catch (IllegalArgumentException iae) {}
|
||||
} catch (final IllegalArgumentException iae) {}
|
||||
try {
|
||||
LocaleUtils.toLocale("uS_EN");
|
||||
fail("Should fail first part not lowercase");
|
||||
} catch (IllegalArgumentException iae) {}
|
||||
} catch (final IllegalArgumentException iae) {}
|
||||
try {
|
||||
LocaleUtils.toLocale("us_E3");
|
||||
fail("Should fail second part not uppercase");
|
||||
} catch (IllegalArgumentException iae) {}
|
||||
} catch (final IllegalArgumentException iae) {}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -225,11 +225,11 @@ public void testToLocale_3Part() {
|
|||
try {
|
||||
LocaleUtils.toLocale("us_EN-a");
|
||||
fail("Should fail as not underscore");
|
||||
} catch (IllegalArgumentException iae) {}
|
||||
} catch (final IllegalArgumentException iae) {}
|
||||
try {
|
||||
LocaleUtils.toLocale("uu_UU_");
|
||||
fail("Must be 3, 5 or 7+ in length");
|
||||
} catch (IllegalArgumentException iae) {}
|
||||
} catch (final IllegalArgumentException iae) {}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
@ -241,7 +241,7 @@ public void testToLocale_3Part() {
|
|||
* @param expected expected results
|
||||
*/
|
||||
private void assertLocaleLookupList(final Locale locale, final Locale defaultLocale, final Locale[] expected) {
|
||||
List<Locale> localeList = defaultLocale == null ?
|
||||
final List<Locale> localeList = defaultLocale == null ?
|
||||
LocaleUtils.localeLookupList(locale) :
|
||||
LocaleUtils.localeLookupList(locale, defaultLocale);
|
||||
|
||||
|
@ -331,14 +331,14 @@ public void testLocaleLookupList_LocaleLocale() {
|
|||
*/
|
||||
@Test
|
||||
public void testAvailableLocaleList() {
|
||||
List<Locale> list = LocaleUtils.availableLocaleList();
|
||||
List<Locale> list2 = LocaleUtils.availableLocaleList();
|
||||
final List<Locale> list = LocaleUtils.availableLocaleList();
|
||||
final List<Locale> list2 = LocaleUtils.availableLocaleList();
|
||||
assertNotNull(list);
|
||||
assertSame(list, list2);
|
||||
assertUnmodifiableCollection(list);
|
||||
|
||||
Locale[] jdkLocaleArray = Locale.getAvailableLocales();
|
||||
List<Locale> jdkLocaleList = Arrays.asList(jdkLocaleArray);
|
||||
final Locale[] jdkLocaleArray = Locale.getAvailableLocales();
|
||||
final List<Locale> jdkLocaleList = Arrays.asList(jdkLocaleArray);
|
||||
assertEquals(jdkLocaleList, list);
|
||||
}
|
||||
|
||||
|
@ -348,15 +348,15 @@ public void testAvailableLocaleList() {
|
|||
*/
|
||||
@Test
|
||||
public void testAvailableLocaleSet() {
|
||||
Set<Locale> set = LocaleUtils.availableLocaleSet();
|
||||
Set<Locale> set2 = LocaleUtils.availableLocaleSet();
|
||||
final Set<Locale> set = LocaleUtils.availableLocaleSet();
|
||||
final Set<Locale> set2 = LocaleUtils.availableLocaleSet();
|
||||
assertNotNull(set);
|
||||
assertSame(set, set2);
|
||||
assertUnmodifiableCollection(set);
|
||||
|
||||
Locale[] jdkLocaleArray = Locale.getAvailableLocales();
|
||||
List<Locale> jdkLocaleList = Arrays.asList(jdkLocaleArray);
|
||||
Set<Locale> jdkLocaleSet = new HashSet<Locale>(jdkLocaleList);
|
||||
final Locale[] jdkLocaleArray = Locale.getAvailableLocales();
|
||||
final List<Locale> jdkLocaleList = Arrays.asList(jdkLocaleArray);
|
||||
final Set<Locale> jdkLocaleSet = new HashSet<Locale>(jdkLocaleList);
|
||||
assertEquals(jdkLocaleSet, set);
|
||||
}
|
||||
|
||||
|
@ -367,7 +367,7 @@ public void testAvailableLocaleSet() {
|
|||
@SuppressWarnings("boxing") // JUnit4 does not support primitive equality testing apart from long
|
||||
@Test
|
||||
public void testIsAvailableLocale() {
|
||||
Set<Locale> set = LocaleUtils.availableLocaleSet();
|
||||
final Set<Locale> set = LocaleUtils.availableLocaleSet();
|
||||
assertEquals(set.contains(LOCALE_EN), LocaleUtils.isAvailableLocale(LOCALE_EN));
|
||||
assertEquals(set.contains(LOCALE_EN_US), LocaleUtils.isAvailableLocale(LOCALE_EN_US));
|
||||
assertEquals(set.contains(LOCALE_EN_US_ZZZZ), LocaleUtils.isAvailableLocale(LOCALE_EN_US_ZZZZ));
|
||||
|
@ -388,17 +388,17 @@ public void testIsAvailableLocale() {
|
|||
* @param languages array of languages that should be returned
|
||||
*/
|
||||
private void assertLanguageByCountry(final String country, final String[] languages) {
|
||||
List<Locale> list = LocaleUtils.languagesByCountry(country);
|
||||
List<Locale> list2 = LocaleUtils.languagesByCountry(country);
|
||||
final List<Locale> list = LocaleUtils.languagesByCountry(country);
|
||||
final List<Locale> list2 = LocaleUtils.languagesByCountry(country);
|
||||
assertNotNull(list);
|
||||
assertSame(list, list2);
|
||||
//search through langauges
|
||||
for (String language : languages) {
|
||||
Iterator<Locale> iterator = list.iterator();
|
||||
for (final String language : languages) {
|
||||
final Iterator<Locale> iterator = list.iterator();
|
||||
boolean found = false;
|
||||
// see if it was returned by the set
|
||||
while (iterator.hasNext()) {
|
||||
Locale locale = iterator.next();
|
||||
final Locale locale = iterator.next();
|
||||
// should have an en empty variant
|
||||
assertTrue(locale.getVariant() == null
|
||||
|| locale.getVariant().isEmpty());
|
||||
|
@ -439,17 +439,17 @@ public void testLanguagesByCountry() {
|
|||
* @param countries array of countries that should be returned
|
||||
*/
|
||||
private void assertCountriesByLanguage(final String language, final String[] countries) {
|
||||
List<Locale> list = LocaleUtils.countriesByLanguage(language);
|
||||
List<Locale> list2 = LocaleUtils.countriesByLanguage(language);
|
||||
final List<Locale> list = LocaleUtils.countriesByLanguage(language);
|
||||
final List<Locale> list2 = LocaleUtils.countriesByLanguage(language);
|
||||
assertNotNull(list);
|
||||
assertSame(list, list2);
|
||||
//search through langauges
|
||||
for (String countrie : countries) {
|
||||
Iterator<Locale> iterator = list.iterator();
|
||||
for (final String countrie : countries) {
|
||||
final Iterator<Locale> iterator = list.iterator();
|
||||
boolean found = false;
|
||||
// see if it was returned by the set
|
||||
while (iterator.hasNext()) {
|
||||
Locale locale = iterator.next();
|
||||
final Locale locale = iterator.next();
|
||||
// should have an en empty variant
|
||||
assertTrue(locale.getVariant() == null
|
||||
|| locale.getVariant().isEmpty());
|
||||
|
@ -485,7 +485,7 @@ private static void assertUnmodifiableCollection(final Collection<?> coll) {
|
|||
try {
|
||||
coll.add(null);
|
||||
fail();
|
||||
} catch (UnsupportedOperationException ex) {}
|
||||
} catch (final UnsupportedOperationException ex) {}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -51,7 +51,7 @@ public class ObjectUtilsTest {
|
|||
@Test
|
||||
public void testConstructor() {
|
||||
assertNotNull(new ObjectUtils());
|
||||
Constructor<?>[] cons = ObjectUtils.class.getDeclaredConstructors();
|
||||
final Constructor<?>[] cons = ObjectUtils.class.getDeclaredConstructors();
|
||||
assertEquals(1, cons.length);
|
||||
assertTrue(Modifier.isPublic(cons[0].getModifiers()));
|
||||
assertTrue(Modifier.isPublic(ObjectUtils.class.getModifiers()));
|
||||
|
@ -61,8 +61,8 @@ public void testConstructor() {
|
|||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testIsNull() {
|
||||
Object o = FOO;
|
||||
Object dflt = BAR;
|
||||
final Object o = FOO;
|
||||
final Object dflt = BAR;
|
||||
assertSame("dflt was not returned when o was null", dflt, ObjectUtils.defaultIfNull(null, dflt));
|
||||
assertSame("dflt was returned when o was not null", o, ObjectUtils.defaultIfNull(o, dflt));
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ public void testIsNull() {
|
|||
public void testFirstNonNull() {
|
||||
assertEquals(null, ObjectUtils.firstNonNull(null, null));
|
||||
assertEquals("", ObjectUtils.firstNonNull(null, ""));
|
||||
String firstNonNullGenerics = ObjectUtils.firstNonNull(null, null, "123", "456");
|
||||
final String firstNonNullGenerics = ObjectUtils.firstNonNull(null, null, "123", "456");
|
||||
assertEquals("123", firstNonNullGenerics);
|
||||
assertEquals("123", ObjectUtils.firstNonNull("123", null, "456", null));
|
||||
assertEquals(null, ObjectUtils.firstNonNull());
|
||||
|
@ -112,28 +112,28 @@ public void testHashCode() {
|
|||
|
||||
@Test
|
||||
public void testHashCodeMulti_multiple_emptyArray() {
|
||||
Object[] array = new Object[0];
|
||||
final Object[] array = new Object[0];
|
||||
assertEquals(1, ObjectUtils.hashCodeMulti(array));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashCodeMulti_multiple_nullArray() {
|
||||
Object[] array = null;
|
||||
final Object[] array = null;
|
||||
assertEquals(1, ObjectUtils.hashCodeMulti(array));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashCodeMulti_multiple_likeList() {
|
||||
List<Object> list0 = new ArrayList<Object>(Arrays.asList());
|
||||
final List<Object> list0 = new ArrayList<Object>(Arrays.asList());
|
||||
assertEquals(list0.hashCode(), ObjectUtils.hashCodeMulti());
|
||||
|
||||
List<Object> list1 = new ArrayList<Object>(Arrays.asList("a"));
|
||||
final List<Object> list1 = new ArrayList<Object>(Arrays.asList("a"));
|
||||
assertEquals(list1.hashCode(), ObjectUtils.hashCodeMulti("a"));
|
||||
|
||||
List<Object> list2 = new ArrayList<Object>(Arrays.asList("a", "b"));
|
||||
final List<Object> list2 = new ArrayList<Object>(Arrays.asList("a", "b"));
|
||||
assertEquals(list2.hashCode(), ObjectUtils.hashCodeMulti("a", "b"));
|
||||
|
||||
List<Object> list3 = new ArrayList<Object>(Arrays.asList("a", "b", "c"));
|
||||
final List<Object> list3 = new ArrayList<Object>(Arrays.asList("a", "b", "c"));
|
||||
assertEquals(list3.hashCode(), ObjectUtils.hashCodeMulti("a", "b", "c"));
|
||||
}
|
||||
|
||||
|
@ -184,22 +184,22 @@ public void testIdentityToString() {
|
|||
assertEquals(
|
||||
"java.lang.String@" + Integer.toHexString(System.identityHashCode(FOO)),
|
||||
ObjectUtils.identityToString(FOO));
|
||||
Integer i = Integer.valueOf(90);
|
||||
String expected = "java.lang.Integer@" + Integer.toHexString(System.identityHashCode(i));
|
||||
final Integer i = Integer.valueOf(90);
|
||||
final String expected = "java.lang.Integer@" + Integer.toHexString(System.identityHashCode(i));
|
||||
assertEquals(expected, ObjectUtils.identityToString(i));
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
final StringBuffer buffer = new StringBuffer();
|
||||
ObjectUtils.identityToString(buffer, i);
|
||||
assertEquals(expected, buffer.toString());
|
||||
|
||||
try {
|
||||
ObjectUtils.identityToString(null, "tmp");
|
||||
fail("NullPointerException expected");
|
||||
} catch(NullPointerException npe) {
|
||||
} catch(final NullPointerException npe) {
|
||||
}
|
||||
try {
|
||||
ObjectUtils.identityToString(new StringBuffer(), null);
|
||||
fail("NullPointerException expected");
|
||||
} catch(NullPointerException npe) {
|
||||
} catch(final NullPointerException npe) {
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -226,13 +226,13 @@ public void testNull() {
|
|||
|
||||
@Test
|
||||
public void testMax() {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
Date nonNullComparable1 = calendar.getTime();
|
||||
Date nonNullComparable2 = calendar.getTime();
|
||||
String[] nullAray = null;
|
||||
final Calendar calendar = Calendar.getInstance();
|
||||
final Date nonNullComparable1 = calendar.getTime();
|
||||
final Date nonNullComparable2 = calendar.getTime();
|
||||
final String[] nullAray = null;
|
||||
|
||||
calendar.set( Calendar.YEAR, calendar.get( Calendar.YEAR ) -1 );
|
||||
Date minComparable = calendar.getTime();
|
||||
final Date minComparable = calendar.getTime();
|
||||
|
||||
assertNotSame( nonNullComparable1, nonNullComparable2 );
|
||||
|
||||
|
@ -252,13 +252,13 @@ public void testMax() {
|
|||
|
||||
@Test
|
||||
public void testMin() {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
Date nonNullComparable1 = calendar.getTime();
|
||||
Date nonNullComparable2 = calendar.getTime();
|
||||
String[] nullAray = null;
|
||||
final Calendar calendar = Calendar.getInstance();
|
||||
final Date nonNullComparable1 = calendar.getTime();
|
||||
final Date nonNullComparable2 = calendar.getTime();
|
||||
final String[] nullAray = null;
|
||||
|
||||
calendar.set( Calendar.YEAR, calendar.get( Calendar.YEAR ) -1 );
|
||||
Date minComparable = calendar.getTime();
|
||||
final Date minComparable = calendar.getTime();
|
||||
|
||||
assertNotSame( nonNullComparable1, nonNullComparable2 );
|
||||
|
||||
|
@ -281,9 +281,9 @@ public void testMin() {
|
|||
*/
|
||||
@Test
|
||||
public void testCompare() {
|
||||
Integer one = Integer.valueOf(1);
|
||||
Integer two = Integer.valueOf(2);
|
||||
Integer nullValue = null;
|
||||
final Integer one = Integer.valueOf(1);
|
||||
final Integer two = Integer.valueOf(2);
|
||||
final Integer nullValue = null;
|
||||
|
||||
assertEquals("Null Null false", 0, ObjectUtils.compare(nullValue, nullValue));
|
||||
assertEquals("Null Null true", 0, ObjectUtils.compare(nullValue, nullValue, true));
|
||||
|
@ -327,12 +327,12 @@ public void testMedian_emptyItems() {
|
|||
|
||||
@Test
|
||||
public void testComparatorMedian() {
|
||||
CharSequenceComparator cmp = new CharSequenceComparator();
|
||||
NonComparableCharSequence foo = new NonComparableCharSequence("foo");
|
||||
NonComparableCharSequence bar = new NonComparableCharSequence("bar");
|
||||
NonComparableCharSequence baz = new NonComparableCharSequence("baz");
|
||||
NonComparableCharSequence blah = new NonComparableCharSequence("blah");
|
||||
NonComparableCharSequence wah = new NonComparableCharSequence("wah");
|
||||
final CharSequenceComparator cmp = new CharSequenceComparator();
|
||||
final NonComparableCharSequence foo = new NonComparableCharSequence("foo");
|
||||
final NonComparableCharSequence bar = new NonComparableCharSequence("bar");
|
||||
final NonComparableCharSequence baz = new NonComparableCharSequence("baz");
|
||||
final NonComparableCharSequence blah = new NonComparableCharSequence("blah");
|
||||
final NonComparableCharSequence wah = new NonComparableCharSequence("wah");
|
||||
assertSame(foo, ObjectUtils.median(cmp, foo));
|
||||
assertSame(bar, ObjectUtils.median(cmp, foo, bar));
|
||||
assertSame(baz, ObjectUtils.median(cmp, foo, bar, baz));
|
||||
|
@ -474,18 +474,18 @@ public void testConstMethods() {
|
|||
// for "Can you screw this up?" The answer is, yes,
|
||||
// you can even screw this up. (When you == Julius)
|
||||
// .
|
||||
boolean MAGIC_FLAG = ObjectUtils.CONST(true);
|
||||
byte MAGIC_BYTE1 = ObjectUtils.CONST((byte) 127);
|
||||
byte MAGIC_BYTE2 = ObjectUtils.CONST_BYTE(127);
|
||||
char MAGIC_CHAR = ObjectUtils.CONST('a');
|
||||
short MAGIC_SHORT1 = ObjectUtils.CONST((short) 123);
|
||||
short MAGIC_SHORT2 = ObjectUtils.CONST_SHORT(127);
|
||||
int MAGIC_INT = ObjectUtils.CONST(123);
|
||||
long MAGIC_LONG1 = ObjectUtils.CONST(123L);
|
||||
long MAGIC_LONG2 = ObjectUtils.CONST(3);
|
||||
float MAGIC_FLOAT = ObjectUtils.CONST(1.0f);
|
||||
double MAGIC_DOUBLE = ObjectUtils.CONST(1.0);
|
||||
String MAGIC_STRING = ObjectUtils.CONST("abc");
|
||||
final boolean MAGIC_FLAG = ObjectUtils.CONST(true);
|
||||
final byte MAGIC_BYTE1 = ObjectUtils.CONST((byte) 127);
|
||||
final byte MAGIC_BYTE2 = ObjectUtils.CONST_BYTE(127);
|
||||
final char MAGIC_CHAR = ObjectUtils.CONST('a');
|
||||
final short MAGIC_SHORT1 = ObjectUtils.CONST((short) 123);
|
||||
final short MAGIC_SHORT2 = ObjectUtils.CONST_SHORT(127);
|
||||
final int MAGIC_INT = ObjectUtils.CONST(123);
|
||||
final long MAGIC_LONG1 = ObjectUtils.CONST(123L);
|
||||
final long MAGIC_LONG2 = ObjectUtils.CONST(3);
|
||||
final float MAGIC_FLOAT = ObjectUtils.CONST(1.0f);
|
||||
final double MAGIC_DOUBLE = ObjectUtils.CONST(1.0);
|
||||
final String MAGIC_STRING = ObjectUtils.CONST("abc");
|
||||
|
||||
assertTrue(MAGIC_FLAG);
|
||||
assertEquals(127, MAGIC_BYTE1);
|
||||
|
@ -503,25 +503,25 @@ public void testConstMethods() {
|
|||
try {
|
||||
ObjectUtils.CONST_BYTE(-129);
|
||||
fail("CONST_BYTE(-129): IllegalArgumentException should have been thrown.");
|
||||
} catch (IllegalArgumentException iae) {
|
||||
} catch (final IllegalArgumentException iae) {
|
||||
|
||||
}
|
||||
try {
|
||||
ObjectUtils.CONST_BYTE(128);
|
||||
fail("CONST_BYTE(128): IllegalArgumentException should have been thrown.");
|
||||
} catch (IllegalArgumentException iae) {
|
||||
} catch (final IllegalArgumentException iae) {
|
||||
|
||||
}
|
||||
try {
|
||||
ObjectUtils.CONST_SHORT(-32769);
|
||||
fail("CONST_SHORT(-32769): IllegalArgumentException should have been thrown.");
|
||||
} catch (IllegalArgumentException iae) {
|
||||
} catch (final IllegalArgumentException iae) {
|
||||
|
||||
}
|
||||
try {
|
||||
ObjectUtils.CONST_BYTE(32768);
|
||||
fail("CONST_SHORT(32768): IllegalArgumentException should have been thrown.");
|
||||
} catch (IllegalArgumentException iae) {
|
||||
} catch (final IllegalArgumentException iae) {
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ public class RandomStringUtilsTest {
|
|||
@Test
|
||||
public void testConstructor() {
|
||||
assertNotNull(new RandomStringUtils());
|
||||
Constructor<?>[] cons = RandomStringUtils.class.getDeclaredConstructors();
|
||||
final Constructor<?>[] cons = RandomStringUtils.class.getDeclaredConstructors();
|
||||
assertEquals(1, cons.length);
|
||||
assertTrue(Modifier.isPublic(cons[0].getModifiers()));
|
||||
assertTrue(Modifier.isPublic(RandomStringUtils.class.getModifiers()));
|
||||
|
@ -120,7 +120,7 @@ public void testRandomStringUtils() {
|
|||
assertEquals("random(50) length", 50, r2.length());
|
||||
assertTrue("!r1.equals(r2)", !r1.equals(r2));
|
||||
|
||||
long seed = System.currentTimeMillis();
|
||||
final long seed = System.currentTimeMillis();
|
||||
r1 = RandomStringUtils.random(50,0,0,true,true,null,new Random(seed));
|
||||
r2 = RandomStringUtils.random(50,0,0,true,true,null,new Random(seed));
|
||||
assertEquals("r1.equals(r2)", r1, r2);
|
||||
|
@ -131,7 +131,7 @@ public void testRandomStringUtils() {
|
|||
|
||||
@Test
|
||||
public void testLANG805() {
|
||||
long seed = System.currentTimeMillis();
|
||||
final long seed = System.currentTimeMillis();
|
||||
assertEquals("aaa", RandomStringUtils.random(3,0,0,false,false,new char[]{'a'},new Random(seed)));
|
||||
}
|
||||
|
||||
|
@ -140,7 +140,7 @@ public void testLANG807() {
|
|||
try {
|
||||
RandomStringUtils.random(3,5,5,false,false);
|
||||
fail("Expected IllegalArgumentException");
|
||||
} catch (IllegalArgumentException ex) { // distinguish from Random#nextInt message
|
||||
} catch (final IllegalArgumentException ex) { // distinguish from Random#nextInt message
|
||||
final String msg = ex.getMessage();
|
||||
assertTrue("Message (" + msg + ") must contain 'start'", msg.contains("start"));
|
||||
assertTrue("Message (" + msg + ") must contain 'end'", msg.contains("end"));
|
||||
|
@ -153,39 +153,39 @@ public void testExceptions() {
|
|||
try {
|
||||
RandomStringUtils.random(-1);
|
||||
fail();
|
||||
} catch (IllegalArgumentException ex) {}
|
||||
} catch (final IllegalArgumentException ex) {}
|
||||
try {
|
||||
RandomStringUtils.random(-1, true, true);
|
||||
fail();
|
||||
} catch (IllegalArgumentException ex) {}
|
||||
} catch (final IllegalArgumentException ex) {}
|
||||
try {
|
||||
RandomStringUtils.random(-1, DUMMY);
|
||||
fail();
|
||||
} catch (IllegalArgumentException ex) {}
|
||||
} catch (final IllegalArgumentException ex) {}
|
||||
try {
|
||||
RandomStringUtils.random(1, new char[0]); // must not provide empty array => IAE
|
||||
fail();
|
||||
} catch (IllegalArgumentException ex) {}
|
||||
} catch (final IllegalArgumentException ex) {}
|
||||
try {
|
||||
RandomStringUtils.random(-1, "");
|
||||
fail();
|
||||
} catch (IllegalArgumentException ex) {}
|
||||
} catch (final IllegalArgumentException ex) {}
|
||||
try {
|
||||
RandomStringUtils.random(-1, (String)null);
|
||||
fail();
|
||||
} catch (IllegalArgumentException ex) {}
|
||||
} catch (final IllegalArgumentException ex) {}
|
||||
try {
|
||||
RandomStringUtils.random(-1, 'a', 'z', false, false);
|
||||
fail();
|
||||
} catch (IllegalArgumentException ex) {}
|
||||
} catch (final IllegalArgumentException ex) {}
|
||||
try {
|
||||
RandomStringUtils.random(-1, 'a', 'z', false, false, DUMMY);
|
||||
fail();
|
||||
} catch (IllegalArgumentException ex) {}
|
||||
} catch (final IllegalArgumentException ex) {}
|
||||
try {
|
||||
RandomStringUtils.random(-1, 'a', 'z', false, false, DUMMY, new Random());
|
||||
fail();
|
||||
} catch (IllegalArgumentException ex) {}
|
||||
} catch (final IllegalArgumentException ex) {}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -194,10 +194,10 @@ public void testExceptions() {
|
|||
*/
|
||||
@Test
|
||||
public void testRandomAlphaNumeric() {
|
||||
char[] testChars = {'a', 'z', 'A', 'Z', '0', '9'};
|
||||
boolean[] found = {false, false, false, false, false, false};
|
||||
final char[] testChars = {'a', 'z', 'A', 'Z', '0', '9'};
|
||||
final boolean[] found = {false, false, false, false, false, false};
|
||||
for (int i = 0; i < 100; i++) {
|
||||
String randString = RandomStringUtils.randomAlphanumeric(10);
|
||||
final String randString = RandomStringUtils.randomAlphanumeric(10);
|
||||
for (int j = 0; j < testChars.length; j++) {
|
||||
if (randString.indexOf(testChars[j]) > 0) {
|
||||
found[j] = true;
|
||||
|
@ -218,10 +218,10 @@ public void testRandomAlphaNumeric() {
|
|||
*/
|
||||
@Test
|
||||
public void testRandomNumeric() {
|
||||
char[] testChars = {'0','9'};
|
||||
boolean[] found = {false, false};
|
||||
final char[] testChars = {'0','9'};
|
||||
final boolean[] found = {false, false};
|
||||
for (int i = 0; i < 100; i++) {
|
||||
String randString = RandomStringUtils.randomNumeric(10);
|
||||
final String randString = RandomStringUtils.randomNumeric(10);
|
||||
for (int j = 0; j < testChars.length; j++) {
|
||||
if (randString.indexOf(testChars[j]) > 0) {
|
||||
found[j] = true;
|
||||
|
@ -242,10 +242,10 @@ public void testRandomNumeric() {
|
|||
*/
|
||||
@Test
|
||||
public void testRandomAlphabetic() {
|
||||
char[] testChars = {'a', 'z', 'A', 'Z'};
|
||||
boolean[] found = {false, false, false, false};
|
||||
final char[] testChars = {'a', 'z', 'A', 'Z'};
|
||||
final boolean[] found = {false, false, false, false};
|
||||
for (int i = 0; i < 100; i++) {
|
||||
String randString = RandomStringUtils.randomAlphabetic(10);
|
||||
final String randString = RandomStringUtils.randomAlphabetic(10);
|
||||
for (int j = 0; j < testChars.length; j++) {
|
||||
if (randString.indexOf(testChars[j]) > 0) {
|
||||
found[j] = true;
|
||||
|
@ -266,10 +266,10 @@ public void testRandomAlphabetic() {
|
|||
*/
|
||||
@Test
|
||||
public void testRandomAscii() {
|
||||
char[] testChars = {(char) 32, (char) 126};
|
||||
boolean[] found = {false, false};
|
||||
final char[] testChars = {(char) 32, (char) 126};
|
||||
final boolean[] found = {false, false};
|
||||
for (int i = 0; i < 100; i++) {
|
||||
String randString = RandomStringUtils.randomAscii(10);
|
||||
final String randString = RandomStringUtils.randomAscii(10);
|
||||
for (int j = 0; j < testChars.length; j++) {
|
||||
if (randString.indexOf(testChars[j]) > 0) {
|
||||
found[j] = true;
|
||||
|
@ -293,11 +293,11 @@ public void testRandomAscii() {
|
|||
*/
|
||||
@Test
|
||||
public void testRandomStringUtilsHomog() {
|
||||
String set = "abc";
|
||||
char[] chars = set.toCharArray();
|
||||
final String set = "abc";
|
||||
final char[] chars = set.toCharArray();
|
||||
String gen = "";
|
||||
int[] counts = {0,0,0};
|
||||
int[] expected = {200,200,200};
|
||||
final int[] counts = {0,0,0};
|
||||
final int[] expected = {200,200,200};
|
||||
for (int i = 0; i< 100; i++) {
|
||||
gen = RandomStringUtils.random(6,chars);
|
||||
for (int j = 0; j < 6; j++) {
|
||||
|
@ -339,16 +339,16 @@ private double chiSquare(final int[] expected, final int[] observed) {
|
|||
*/
|
||||
@Test
|
||||
public void testLang100() throws Exception {
|
||||
int size = 5000;
|
||||
String encoding = "UTF-8";
|
||||
String orig = RandomStringUtils.random(size);
|
||||
byte[] bytes = orig.getBytes(encoding);
|
||||
String copy = new String(bytes, encoding);
|
||||
final int size = 5000;
|
||||
final String encoding = "UTF-8";
|
||||
final String orig = RandomStringUtils.random(size);
|
||||
final byte[] bytes = orig.getBytes(encoding);
|
||||
final String copy = new String(bytes, encoding);
|
||||
|
||||
// for a verbose compare:
|
||||
for (int i=0; i < orig.length() && i < copy.length(); i++) {
|
||||
char o = orig.charAt(i);
|
||||
char c = copy.charAt(i);
|
||||
final char o = orig.charAt(i);
|
||||
final char c = copy.charAt(i);
|
||||
assertEquals("differs at " + i + "(" + Integer.toHexString(new Character(o).hashCode()) + "," +
|
||||
Integer.toHexString(new Character(c).hashCode()) + ")", o, c);
|
||||
}
|
||||
|
|
|
@ -65,22 +65,22 @@ public void setUp() {
|
|||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@Test
|
||||
public void testComparableConstructors() {
|
||||
Comparable c =
|
||||
final Comparable c =
|
||||
new Comparable() {
|
||||
@Override
|
||||
public int compareTo(final Object other) {
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
Range r1 = Range.is(c);
|
||||
Range r2 = Range.between(c, c);
|
||||
final Range r1 = Range.is(c);
|
||||
final Range r2 = Range.between(c, c);
|
||||
assertEquals(true, r1.isNaturalOrdering());
|
||||
assertEquals(true, r2.isNaturalOrdering());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsWithCompare(){
|
||||
Comparator<Integer> c = new Comparator<Integer>(){
|
||||
final Comparator<Integer> c = new Comparator<Integer>(){
|
||||
@Override
|
||||
public int compare(final Integer o1, final Integer o2) {
|
||||
return 0; // all integers are equal
|
||||
|
@ -99,7 +99,7 @@ public int compare(final Integer o1, final Integer o2) {
|
|||
@Test
|
||||
public void testBetweenWithCompare(){
|
||||
// TODO add tests with a better comparator
|
||||
Comparator<Integer> c = new Comparator<Integer>(){
|
||||
final Comparator<Integer> c = new Comparator<Integer>(){
|
||||
@Override
|
||||
public int compare(final Integer o1, final Integer o2) {
|
||||
return 0; // all integers are equal
|
||||
|
@ -122,7 +122,7 @@ public int compare(final Integer o1, final Integer o2) {
|
|||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testRangeOfChars() {
|
||||
Range<Character> chars = Range.between('a', 'z');
|
||||
final Range<Character> chars = Range.between('a', 'z');
|
||||
assertTrue(chars.contains('b'));
|
||||
assertFalse(chars.contains('B'));
|
||||
}
|
||||
|
@ -154,14 +154,14 @@ public void testHashCode() {
|
|||
public void testToString() {
|
||||
assertNotNull(byteRange.toString());
|
||||
|
||||
String str = intRange.toString();
|
||||
final String str = intRange.toString();
|
||||
assertEquals("[10..20]", str);
|
||||
assertEquals("[-20..-10]", Range.between(-20, -10).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToStringFormat() {
|
||||
String str = intRange.toString("From %1$s to %2$s");
|
||||
final String str = intRange.toString("From %1$s to %2$s");
|
||||
assertEquals("From 10 to 20", str);
|
||||
}
|
||||
|
||||
|
@ -242,7 +242,7 @@ public void testElementCompareTo() {
|
|||
try {
|
||||
intRange.elementCompareTo(null);
|
||||
fail("NullPointerException should have been thrown");
|
||||
} catch(NullPointerException npe) {
|
||||
} catch(final NullPointerException npe) {
|
||||
// expected
|
||||
}
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ public void setUp() {
|
|||
@Test
|
||||
public void testConstructor() {
|
||||
assertNotNull(new SerializationUtils());
|
||||
Constructor<?>[] cons = SerializationUtils.class.getDeclaredConstructors();
|
||||
final Constructor<?>[] cons = SerializationUtils.class.getDeclaredConstructors();
|
||||
assertEquals(1, cons.length);
|
||||
assertTrue(Modifier.isPublic(cons[0].getModifiers()));
|
||||
assertTrue(Modifier.isPublic(SerializationUtils.class.getModifiers()));
|
||||
|
@ -78,7 +78,7 @@ public void testConstructor() {
|
|||
@Test
|
||||
public void testException() {
|
||||
SerializationException serEx;
|
||||
Exception ex = new Exception();
|
||||
final Exception ex = new Exception();
|
||||
|
||||
serEx = new SerializationException();
|
||||
assertSame(null, serEx.getMessage());
|
||||
|
@ -101,17 +101,17 @@ public void testException() {
|
|||
|
||||
@Test
|
||||
public void testSerializeStream() throws Exception {
|
||||
ByteArrayOutputStream streamTest = new ByteArrayOutputStream();
|
||||
final ByteArrayOutputStream streamTest = new ByteArrayOutputStream();
|
||||
SerializationUtils.serialize(iMap, streamTest);
|
||||
|
||||
ByteArrayOutputStream streamReal = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos = new ObjectOutputStream(streamReal);
|
||||
final ByteArrayOutputStream streamReal = new ByteArrayOutputStream();
|
||||
final ObjectOutputStream oos = new ObjectOutputStream(streamReal);
|
||||
oos.writeObject(iMap);
|
||||
oos.flush();
|
||||
oos.close();
|
||||
|
||||
byte[] testBytes = streamTest.toByteArray();
|
||||
byte[] realBytes = streamReal.toByteArray();
|
||||
final byte[] testBytes = streamTest.toByteArray();
|
||||
final byte[] realBytes = streamReal.toByteArray();
|
||||
assertEquals(testBytes.length, realBytes.length);
|
||||
for (int i = 0; i < realBytes.length; i++) {
|
||||
assertEquals(realBytes[i], testBytes[i]);
|
||||
|
@ -120,11 +120,11 @@ public void testSerializeStream() throws Exception {
|
|||
|
||||
@Test
|
||||
public void testSerializeStreamUnserializable() throws Exception {
|
||||
ByteArrayOutputStream streamTest = new ByteArrayOutputStream();
|
||||
final ByteArrayOutputStream streamTest = new ByteArrayOutputStream();
|
||||
try {
|
||||
iMap.put(new Object(), new Object());
|
||||
SerializationUtils.serialize(iMap, streamTest);
|
||||
} catch (SerializationException ex) {
|
||||
} catch (final SerializationException ex) {
|
||||
return;
|
||||
}
|
||||
fail();
|
||||
|
@ -132,17 +132,17 @@ public void testSerializeStreamUnserializable() throws Exception {
|
|||
|
||||
@Test
|
||||
public void testSerializeStreamNullObj() throws Exception {
|
||||
ByteArrayOutputStream streamTest = new ByteArrayOutputStream();
|
||||
final ByteArrayOutputStream streamTest = new ByteArrayOutputStream();
|
||||
SerializationUtils.serialize(null, streamTest);
|
||||
|
||||
ByteArrayOutputStream streamReal = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos = new ObjectOutputStream(streamReal);
|
||||
final ByteArrayOutputStream streamReal = new ByteArrayOutputStream();
|
||||
final ObjectOutputStream oos = new ObjectOutputStream(streamReal);
|
||||
oos.writeObject(null);
|
||||
oos.flush();
|
||||
oos.close();
|
||||
|
||||
byte[] testBytes = streamTest.toByteArray();
|
||||
byte[] realBytes = streamReal.toByteArray();
|
||||
final byte[] testBytes = streamTest.toByteArray();
|
||||
final byte[] realBytes = streamReal.toByteArray();
|
||||
assertEquals(testBytes.length, realBytes.length);
|
||||
for (int i = 0; i < realBytes.length; i++) {
|
||||
assertEquals(realBytes[i], testBytes[i]);
|
||||
|
@ -153,7 +153,7 @@ public void testSerializeStreamNullObj() throws Exception {
|
|||
public void testSerializeStreamObjNull() throws Exception {
|
||||
try {
|
||||
SerializationUtils.serialize(iMap, null);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
} catch (final IllegalArgumentException ex) {
|
||||
return;
|
||||
}
|
||||
fail();
|
||||
|
@ -163,7 +163,7 @@ public void testSerializeStreamObjNull() throws Exception {
|
|||
public void testSerializeStreamNullNull() throws Exception {
|
||||
try {
|
||||
SerializationUtils.serialize(null, null);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
} catch (final IllegalArgumentException ex) {
|
||||
return;
|
||||
}
|
||||
fail();
|
||||
|
@ -173,7 +173,7 @@ public void testSerializeStreamNullNull() throws Exception {
|
|||
public void testSerializeIOException() throws Exception {
|
||||
// forces an IOException when the ObjectOutputStream is created, to test not closing the stream
|
||||
// in the finally block
|
||||
OutputStream streamTest = new OutputStream() {
|
||||
final OutputStream streamTest = new OutputStream() {
|
||||
@Override
|
||||
public void write(final int arg0) throws IOException {
|
||||
throw new IOException(SERIALIZE_IO_EXCEPTION_MESSAGE);
|
||||
|
@ -182,7 +182,7 @@ public void write(final int arg0) throws IOException {
|
|||
try {
|
||||
SerializationUtils.serialize(iMap, streamTest);
|
||||
}
|
||||
catch(SerializationException e) {
|
||||
catch(final SerializationException e) {
|
||||
assertEquals("java.io.IOException: " + SERIALIZE_IO_EXCEPTION_MESSAGE, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
@ -191,18 +191,18 @@ public void write(final int arg0) throws IOException {
|
|||
|
||||
@Test
|
||||
public void testDeserializeStream() throws Exception {
|
||||
ByteArrayOutputStream streamReal = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos = new ObjectOutputStream(streamReal);
|
||||
final ByteArrayOutputStream streamReal = new ByteArrayOutputStream();
|
||||
final ObjectOutputStream oos = new ObjectOutputStream(streamReal);
|
||||
oos.writeObject(iMap);
|
||||
oos.flush();
|
||||
oos.close();
|
||||
|
||||
ByteArrayInputStream inTest = new ByteArrayInputStream(streamReal.toByteArray());
|
||||
Object test = SerializationUtils.deserialize(inTest);
|
||||
final ByteArrayInputStream inTest = new ByteArrayInputStream(streamReal.toByteArray());
|
||||
final Object test = SerializationUtils.deserialize(inTest);
|
||||
assertNotNull(test);
|
||||
assertTrue(test instanceof HashMap<?, ?>);
|
||||
assertTrue(test != iMap);
|
||||
HashMap<?, ?> testMap = (HashMap<?, ?>) test;
|
||||
final HashMap<?, ?> testMap = (HashMap<?, ?>) test;
|
||||
assertEquals(iString, testMap.get("FOO"));
|
||||
assertTrue(iString != testMap.get("FOO"));
|
||||
assertEquals(iInteger, testMap.get("BAR"));
|
||||
|
@ -213,22 +213,22 @@ public void testDeserializeStream() throws Exception {
|
|||
@Test(expected=ClassCastException.class)
|
||||
public void testDeserializeClassCastException() {
|
||||
final String value = "Hello";
|
||||
byte[] serialized = SerializationUtils.serialize(value);
|
||||
final byte[] serialized = SerializationUtils.serialize(value);
|
||||
Assert.assertEquals(value, SerializationUtils.deserialize(serialized));
|
||||
// Causes ClassCastException in call site, not in SerializationUtils.deserialize
|
||||
Integer i = SerializationUtils.deserialize(serialized);
|
||||
final Integer i = SerializationUtils.deserialize(serialized);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserializeStreamOfNull() throws Exception {
|
||||
ByteArrayOutputStream streamReal = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos = new ObjectOutputStream(streamReal);
|
||||
final ByteArrayOutputStream streamReal = new ByteArrayOutputStream();
|
||||
final ObjectOutputStream oos = new ObjectOutputStream(streamReal);
|
||||
oos.writeObject(null);
|
||||
oos.flush();
|
||||
oos.close();
|
||||
|
||||
ByteArrayInputStream inTest = new ByteArrayInputStream(streamReal.toByteArray());
|
||||
Object test = SerializationUtils.deserialize(inTest);
|
||||
final ByteArrayInputStream inTest = new ByteArrayInputStream(streamReal.toByteArray());
|
||||
final Object test = SerializationUtils.deserialize(inTest);
|
||||
assertNull(test);
|
||||
}
|
||||
|
||||
|
@ -236,7 +236,7 @@ public void testDeserializeStreamOfNull() throws Exception {
|
|||
public void testDeserializeStreamNull() throws Exception {
|
||||
try {
|
||||
SerializationUtils.deserialize((InputStream) null);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
} catch (final IllegalArgumentException ex) {
|
||||
return;
|
||||
}
|
||||
fail();
|
||||
|
@ -246,7 +246,7 @@ public void testDeserializeStreamNull() throws Exception {
|
|||
public void testDeserializeStreamBadStream() throws Exception {
|
||||
try {
|
||||
SerializationUtils.deserialize(new ByteArrayInputStream(new byte[0]));
|
||||
} catch (SerializationException ex) {
|
||||
} catch (final SerializationException ex) {
|
||||
return;
|
||||
}
|
||||
fail();
|
||||
|
@ -254,17 +254,18 @@ public void testDeserializeStreamBadStream() throws Exception {
|
|||
|
||||
@Test
|
||||
public void testDeserializeStreamClassNotFound() throws Exception {
|
||||
ByteArrayOutputStream streamReal = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos = new ObjectOutputStream(streamReal);
|
||||
final ByteArrayOutputStream streamReal = new ByteArrayOutputStream();
|
||||
final ObjectOutputStream oos = new ObjectOutputStream(streamReal);
|
||||
oos.writeObject(new ClassNotFoundSerialization());
|
||||
oos.flush();
|
||||
oos.close();
|
||||
|
||||
ByteArrayInputStream inTest = new ByteArrayInputStream(streamReal.toByteArray());
|
||||
final ByteArrayInputStream inTest = new ByteArrayInputStream(streamReal.toByteArray());
|
||||
try {
|
||||
@SuppressWarnings("unused")
|
||||
final
|
||||
Object test = SerializationUtils.deserialize(inTest);
|
||||
} catch(SerializationException se) {
|
||||
} catch(final SerializationException se) {
|
||||
assertEquals("java.lang.ClassNotFoundException: " + CLASS_NOT_FOUND_MESSAGE, se.getMessage());
|
||||
}
|
||||
}
|
||||
|
@ -273,15 +274,15 @@ public void testDeserializeStreamClassNotFound() throws Exception {
|
|||
|
||||
@Test
|
||||
public void testSerializeBytes() throws Exception {
|
||||
byte[] testBytes = SerializationUtils.serialize(iMap);
|
||||
final byte[] testBytes = SerializationUtils.serialize(iMap);
|
||||
|
||||
ByteArrayOutputStream streamReal = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos = new ObjectOutputStream(streamReal);
|
||||
final ByteArrayOutputStream streamReal = new ByteArrayOutputStream();
|
||||
final ObjectOutputStream oos = new ObjectOutputStream(streamReal);
|
||||
oos.writeObject(iMap);
|
||||
oos.flush();
|
||||
oos.close();
|
||||
|
||||
byte[] realBytes = streamReal.toByteArray();
|
||||
final byte[] realBytes = streamReal.toByteArray();
|
||||
assertEquals(testBytes.length, realBytes.length);
|
||||
for (int i = 0; i < realBytes.length; i++) {
|
||||
assertEquals(realBytes[i], testBytes[i]);
|
||||
|
@ -293,7 +294,7 @@ public void testSerializeBytesUnserializable() throws Exception {
|
|||
try {
|
||||
iMap.put(new Object(), new Object());
|
||||
SerializationUtils.serialize(iMap);
|
||||
} catch (SerializationException ex) {
|
||||
} catch (final SerializationException ex) {
|
||||
return;
|
||||
}
|
||||
fail();
|
||||
|
@ -301,15 +302,15 @@ public void testSerializeBytesUnserializable() throws Exception {
|
|||
|
||||
@Test
|
||||
public void testSerializeBytesNull() throws Exception {
|
||||
byte[] testBytes = SerializationUtils.serialize(null);
|
||||
final byte[] testBytes = SerializationUtils.serialize(null);
|
||||
|
||||
ByteArrayOutputStream streamReal = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos = new ObjectOutputStream(streamReal);
|
||||
final ByteArrayOutputStream streamReal = new ByteArrayOutputStream();
|
||||
final ObjectOutputStream oos = new ObjectOutputStream(streamReal);
|
||||
oos.writeObject(null);
|
||||
oos.flush();
|
||||
oos.close();
|
||||
|
||||
byte[] realBytes = streamReal.toByteArray();
|
||||
final byte[] realBytes = streamReal.toByteArray();
|
||||
assertEquals(testBytes.length, realBytes.length);
|
||||
for (int i = 0; i < realBytes.length; i++) {
|
||||
assertEquals(realBytes[i], testBytes[i]);
|
||||
|
@ -320,17 +321,17 @@ public void testSerializeBytesNull() throws Exception {
|
|||
|
||||
@Test
|
||||
public void testDeserializeBytes() throws Exception {
|
||||
ByteArrayOutputStream streamReal = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos = new ObjectOutputStream(streamReal);
|
||||
final ByteArrayOutputStream streamReal = new ByteArrayOutputStream();
|
||||
final ObjectOutputStream oos = new ObjectOutputStream(streamReal);
|
||||
oos.writeObject(iMap);
|
||||
oos.flush();
|
||||
oos.close();
|
||||
|
||||
Object test = SerializationUtils.deserialize(streamReal.toByteArray());
|
||||
final Object test = SerializationUtils.deserialize(streamReal.toByteArray());
|
||||
assertNotNull(test);
|
||||
assertTrue(test instanceof HashMap<?, ?>);
|
||||
assertTrue(test != iMap);
|
||||
HashMap<?, ?> testMap = (HashMap<?, ?>) test;
|
||||
final HashMap<?, ?> testMap = (HashMap<?, ?>) test;
|
||||
assertEquals(iString, testMap.get("FOO"));
|
||||
assertTrue(iString != testMap.get("FOO"));
|
||||
assertEquals(iInteger, testMap.get("BAR"));
|
||||
|
@ -340,13 +341,13 @@ public void testDeserializeBytes() throws Exception {
|
|||
|
||||
@Test
|
||||
public void testDeserializeBytesOfNull() throws Exception {
|
||||
ByteArrayOutputStream streamReal = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos = new ObjectOutputStream(streamReal);
|
||||
final ByteArrayOutputStream streamReal = new ByteArrayOutputStream();
|
||||
final ObjectOutputStream oos = new ObjectOutputStream(streamReal);
|
||||
oos.writeObject(null);
|
||||
oos.flush();
|
||||
oos.close();
|
||||
|
||||
Object test = SerializationUtils.deserialize(streamReal.toByteArray());
|
||||
final Object test = SerializationUtils.deserialize(streamReal.toByteArray());
|
||||
assertNull(test);
|
||||
}
|
||||
|
||||
|
@ -354,7 +355,7 @@ public void testDeserializeBytesOfNull() throws Exception {
|
|||
public void testDeserializeBytesNull() throws Exception {
|
||||
try {
|
||||
SerializationUtils.deserialize((byte[]) null);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
} catch (final IllegalArgumentException ex) {
|
||||
return;
|
||||
}
|
||||
fail();
|
||||
|
@ -364,7 +365,7 @@ public void testDeserializeBytesNull() throws Exception {
|
|||
public void testDeserializeBytesBadStream() throws Exception {
|
||||
try {
|
||||
SerializationUtils.deserialize(new byte[0]);
|
||||
} catch (SerializationException ex) {
|
||||
} catch (final SerializationException ex) {
|
||||
return;
|
||||
}
|
||||
fail();
|
||||
|
@ -374,11 +375,11 @@ public void testDeserializeBytesBadStream() throws Exception {
|
|||
|
||||
@Test
|
||||
public void testClone() throws Exception {
|
||||
Object test = SerializationUtils.clone(iMap);
|
||||
final Object test = SerializationUtils.clone(iMap);
|
||||
assertNotNull(test);
|
||||
assertTrue(test instanceof HashMap<?,?>);
|
||||
assertTrue(test != iMap);
|
||||
HashMap<?, ?> testMap = (HashMap<?, ?>) test;
|
||||
final HashMap<?, ?> testMap = (HashMap<?, ?>) test;
|
||||
assertEquals(iString, testMap.get("FOO"));
|
||||
assertTrue(iString != testMap.get("FOO"));
|
||||
assertEquals(iInteger, testMap.get("BAR"));
|
||||
|
@ -388,7 +389,7 @@ public void testClone() throws Exception {
|
|||
|
||||
@Test
|
||||
public void testCloneNull() throws Exception {
|
||||
Object test = SerializationUtils.clone(null);
|
||||
final Object test = SerializationUtils.clone(null);
|
||||
assertNull(test);
|
||||
}
|
||||
|
||||
|
@ -397,7 +398,7 @@ public void testCloneUnserializable() throws Exception {
|
|||
try {
|
||||
iMap.put(new Object(), new Object());
|
||||
SerializationUtils.clone(iMap);
|
||||
} catch (SerializationException ex) {
|
||||
} catch (final SerializationException ex) {
|
||||
return;
|
||||
}
|
||||
fail();
|
||||
|
@ -405,11 +406,11 @@ public void testCloneUnserializable() throws Exception {
|
|||
|
||||
@Test
|
||||
public void testPrimitiveTypeClassSerialization() {
|
||||
Class<?>[] primitiveTypes = { byte.class, short.class, int.class, long.class, float.class, double.class,
|
||||
final Class<?>[] primitiveTypes = { byte.class, short.class, int.class, long.class, float.class, double.class,
|
||||
boolean.class, char.class, void.class };
|
||||
|
||||
for (Class<?> primitiveType : primitiveTypes) {
|
||||
Class<?> clone = SerializationUtils.clone(primitiveType);
|
||||
for (final Class<?> primitiveType : primitiveTypes) {
|
||||
final Class<?> clone = SerializationUtils.clone(primitiveType);
|
||||
assertEquals(primitiveType, clone);
|
||||
}
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue