commons-lang3-3.x

16:34:49.665 INFO  jd.cli.Main - Decompiling commons-lang3-3.x.jar
package org.apache.commons.lang3;

import java.lang.annotation.Annotation;
import org.apache.commons.lang3.builder.ToStringStyle;

final class AnnotationUtils$1
  extends ToStringStyle
{
  private static final long serialVersionUID = 1L;
  
  AnnotationUtils$1()
  {
    setDefaultFullDetail(true);
    setArrayContentDetail(true);
    setUseClassName(true);
    setUseShortClassName(true);
    setUseIdentityHashCode(false);
    setContentStart("(");
    setContentEnd(")");
    setFieldSeparator(", ");
    setArrayStart("[");
    setArrayEnd("]");
  }
  
  protected String getShortClassName(Class<?> cls)
  {
    Class<? extends Annotation> annotationType = null;
    for (Class<?> iface : ClassUtils.getAllInterfaces(cls)) {
      if (Annotation.class.isAssignableFrom(iface))
      {
        Class<? extends Annotation> found = iface;
        annotationType = found;
        break;
      }
    }
    return new StringBuilder(annotationType == null ? "" : annotationType.getName()).insert(0, '@').toString();
  }
  
  protected void appendDetail(StringBuffer buffer, String fieldName, Object value)
  {
    if ((value instanceof Annotation)) {
      value = AnnotationUtils.toString((Annotation)value);
    }
    super.appendDetail(buffer, fieldName, value);
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.lang3.AnnotationUtils.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.lang3;

import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

public class AnnotationUtils
{
  private static final ToStringStyle TO_STRING_STYLE = new ToStringStyle()
  {
    private static final long serialVersionUID = 1L;
    
    protected String getShortClassName(Class<?> cls)
    {
      Class<? extends Annotation> annotationType = null;
      for (Class<?> iface : ClassUtils.getAllInterfaces(cls)) {
        if (Annotation.class.isAssignableFrom(iface))
        {
          Class<? extends Annotation> found = iface;
          annotationType = found;
          break;
        }
      }
      return new StringBuilder(annotationType == null ? "" : annotationType.getName()).insert(0, '@').toString();
    }
    
    protected void appendDetail(StringBuffer buffer, String fieldName, Object value)
    {
      if ((value instanceof Annotation)) {
        value = AnnotationUtils.toString((Annotation)value);
      }
      super.appendDetail(buffer, fieldName, value);
    }
  };
  
  public static boolean equals(Annotation a1, Annotation a2)
  {
    if (a1 == a2) {
      return true;
    }
    if ((a1 == null) || (a2 == null)) {
      return false;
    }
    Class<? extends Annotation> type = a1.annotationType();
    Class<? extends Annotation> type2 = a2.annotationType();
    Validate.notNull(type, "Annotation %s with null annotationType()", new Object[] { a1 });
    Validate.notNull(type2, "Annotation %s with null annotationType()", new Object[] { a2 });
    if (!type.equals(type2)) {
      return false;
    }
    try
    {
      for (Method m : type.getDeclaredMethods()) {
        if ((m.getParameterTypes().length == 0) && (isValidAnnotationMemberType(m.getReturnType())))
        {
          Object v1 = m.invoke(a1, new Object[0]);
          Object v2 = m.invoke(a2, new Object[0]);
          if (!memberEquals(m.getReturnType(), v1, v2)) {
            return false;
          }
        }
      }
    }
    catch (IllegalAccessException ex)
    {
      return false;
    }
    catch (InvocationTargetException ex)
    {
      return false;
    }
    return true;
  }
  
  public static int hashCode(Annotation a)
  {
    int result = 0;
    Class<? extends Annotation> type = a.annotationType();
    for (Method m : type.getDeclaredMethods()) {
      try
      {
        Object value = m.invoke(a, new Object[0]);
        if (value == null) {
          throw new IllegalStateException(String.format("Annotation method %s returned null", new Object[] { m }));
        }
        result += hashMember(m.getName(), value);
      }
      catch (RuntimeException ex)
      {
        throw ex;
      }
      catch (Exception ex)
      {
        throw new RuntimeException(ex);
      }
    }
    return result;
  }
  
  public static String toString(Annotation a)
  {
    ToStringBuilder builder = new ToStringBuilder(a, TO_STRING_STYLE);
    for (Method m : a.annotationType().getDeclaredMethods()) {
      if (m.getParameterTypes().length <= 0) {
        try
        {
          builder.append(m.getName(), m.invoke(a, new Object[0]));
        }
        catch (RuntimeException ex)
        {
          throw ex;
        }
        catch (Exception ex)
        {
          throw new RuntimeException(ex);
        }
      }
    }
    return builder.build();
  }
  
  public static boolean isValidAnnotationMemberType(Class<?> type)
  {
    if (type == null) {
      return false;
    }
    if (type.isArray()) {
      type = type.getComponentType();
    }
    return (type.isPrimitive()) || (type.isEnum()) || (type.isAnnotation()) || (String.class.equals(type)) || (Class.class.equals(type));
  }
  
  private static int hashMember(String name, Object value)
  {
    int part1 = name.hashCode() * 127;
    if (value.getClass().isArray()) {
      return part1 ^ arrayMemberHash(value.getClass().getComponentType(), value);
    }
    if ((value instanceof Annotation)) {
      return part1 ^ hashCode((Annotation)value);
    }
    return part1 ^ value.hashCode();
  }
  
  private static boolean memberEquals(Class<?> type, Object o1, Object o2)
  {
    if (o1 == o2) {
      return true;
    }
    if ((o1 == null) || (o2 == null)) {
      return false;
    }
    if (type.isArray()) {
      return arrayMemberEquals(type.getComponentType(), o1, o2);
    }
    if (type.isAnnotation()) {
      return equals((Annotation)o1, (Annotation)o2);
    }
    return o1.equals(o2);
  }
  
  private static boolean arrayMemberEquals(Class<?> componentType, Object o1, Object o2)
  {
    if (componentType.isAnnotation()) {
      return annotationArrayMemberEquals((Annotation[])o1, (Annotation[])o2);
    }
    if (componentType.equals(Byte.TYPE)) {
      return Arrays.equals((byte[])o1, (byte[])o2);
    }
    if (componentType.equals(Short.TYPE)) {
      return Arrays.equals((short[])o1, (short[])o2);
    }
    if (componentType.equals(Integer.TYPE)) {
      return Arrays.equals((int[])o1, (int[])o2);
    }
    if (componentType.equals(Character.TYPE)) {
      return Arrays.equals((char[])o1, (char[])o2);
    }
    if (componentType.equals(Long.TYPE)) {
      return Arrays.equals((long[])o1, (long[])o2);
    }
    if (componentType.equals(Float.TYPE)) {
      return Arrays.equals((float[])o1, (float[])o2);
    }
    if (componentType.equals(Double.TYPE)) {
      return Arrays.equals((double[])o1, (double[])o2);
    }
    if (componentType.equals(Boolean.TYPE)) {
      return Arrays.equals((boolean[])o1, (boolean[])o2);
    }
    return Arrays.equals((Object[])o1, (Object[])o2);
  }
  
  private static boolean annotationArrayMemberEquals(Annotation[] a1, Annotation[] a2)
  {
    if (a1.length != a2.length) {
      return false;
    }
    for (int i = 0; i < a1.length; i++) {
      if (!equals(a1[i], a2[i])) {
        return false;
      }
    }
    return true;
  }
  
  private static int arrayMemberHash(Class<?> componentType, Object o)
  {
    if (componentType.equals(Byte.TYPE)) {
      return Arrays.hashCode((byte[])o);
    }
    if (componentType.equals(Short.TYPE)) {
      return Arrays.hashCode((short[])o);
    }
    if (componentType.equals(Integer.TYPE)) {
      return Arrays.hashCode((int[])o);
    }
    if (componentType.equals(Character.TYPE)) {
      return Arrays.hashCode((char[])o);
    }
    if (componentType.equals(Long.TYPE)) {
      return Arrays.hashCode((long[])o);
    }
    if (componentType.equals(Float.TYPE)) {
      return Arrays.hashCode((float[])o);
    }
    if (componentType.equals(Double.TYPE)) {
      return Arrays.hashCode((double[])o);
    }
    if (componentType.equals(Boolean.TYPE)) {
      return Arrays.hashCode((boolean[])o);
    }
    return Arrays.hashCode((Object[])o);
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.lang3.AnnotationUtils
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.lang3;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.apache.commons.lang3.mutable.MutableInt;

public class ArrayUtils
{
  public static final Object[] EMPTY_OBJECT_ARRAY = new Object[0];
  public static final Class<?>[] EMPTY_CLASS_ARRAY = new Class[0];
  public static final String[] EMPTY_STRING_ARRAY = new String[0];
  public static final long[] EMPTY_LONG_ARRAY = new long[0];
  public static final Long[] EMPTY_LONG_OBJECT_ARRAY = new Long[0];
  public static final int[] EMPTY_INT_ARRAY = new int[0];
  public static final Integer[] EMPTY_INTEGER_OBJECT_ARRAY = new Integer[0];
  public static final short[] EMPTY_SHORT_ARRAY = new short[0];
  public static final Short[] EMPTY_SHORT_OBJECT_ARRAY = new Short[0];
  public static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
  public static final Byte[] EMPTY_BYTE_OBJECT_ARRAY = new Byte[0];
  public static final double[] EMPTY_DOUBLE_ARRAY = new double[0];
  public static final Double[] EMPTY_DOUBLE_OBJECT_ARRAY = new Double[0];
  public static final float[] EMPTY_FLOAT_ARRAY = new float[0];
  public static final Float[] EMPTY_FLOAT_OBJECT_ARRAY = new Float[0];
  public static final boolean[] EMPTY_BOOLEAN_ARRAY = new boolean[0];
  public static final Boolean[] EMPTY_BOOLEAN_OBJECT_ARRAY = new Boolean[0];
  public static final char[] EMPTY_CHAR_ARRAY = new char[0];
  public static final Character[] EMPTY_CHARACTER_OBJECT_ARRAY = new Character[0];
  public static final int INDEX_NOT_FOUND = -1;
  
  public static String toString(Object array)
  {
    return toString(array, "{}");
  }
  
  public static String toString(Object array, String stringIfNull)
  {
    if (array == null) {
      return stringIfNull;
    }
    return new ToStringBuilder(array, ToStringStyle.SIMPLE_STYLE).append(array).toString();
  }
  
  public static int hashCode(Object array)
  {
    return new HashCodeBuilder().append(array).toHashCode();
  }
  
  public static boolean isEquals(Object array1, Object array2)
  {
    return new EqualsBuilder().append(array1, array2).isEquals();
  }
  
  public static Map<Object, Object> toMap(Object[] array)
  {
    if (array == null) {
      return null;
    }
    Map<Object, Object> map = new HashMap((int)(array.length * 1.5D));
    for (int i = 0; i < array.length; i++)
    {
      Object object = array[i];
      if ((object instanceof Map.Entry))
      {
        Map.Entry<?, ?> entry = (Map.Entry)object;
        map.put(entry.getKey(), entry.getValue());
      }
      else if ((object instanceof Object[]))
      {
        Object[] entry = (Object[])object;
        if (entry.length < 2) {
          throw new IllegalArgumentException("Array element " + i + ", '" + object + "', has a length less than 2");
        }
        map.put(entry[0], entry[1]);
      }
      else
      {
        throw new IllegalArgumentException("Array element " + i + ", '" + object + "', is neither of type Map.Entry nor an Array");
      }
    }
    return map;
  }
  
  public static <T> T[] toArray(T... items)
  {
    return items;
  }
  
  public static <T> T[] clone(T[] array)
  {
    if (array == null) {
      return null;
    }
    return (Object[])array.clone();
  }
  
  public static long[] clone(long[] array)
  {
    if (array == null) {
      return null;
    }
    return (long[])array.clone();
  }
  
  public static int[] clone(int[] array)
  {
    if (array == null) {
      return null;
    }
    return (int[])array.clone();
  }
  
  public static short[] clone(short[] array)
  {
    if (array == null) {
      return null;
    }
    return (short[])array.clone();
  }
  
  public static char[] clone(char[] array)
  {
    if (array == null) {
      return null;
    }
    return (char[])array.clone();
  }
  
  public static byte[] clone(byte[] array)
  {
    if (array == null) {
      return null;
    }
    return (byte[])array.clone();
  }
  
  public static double[] clone(double[] array)
  {
    if (array == null) {
      return null;
    }
    return (double[])array.clone();
  }
  
  public static float[] clone(float[] array)
  {
    if (array == null) {
      return null;
    }
    return (float[])array.clone();
  }
  
  public static boolean[] clone(boolean[] array)
  {
    if (array == null) {
      return null;
    }
    return (boolean[])array.clone();
  }
  
  public static Object[] nullToEmpty(Object[] array)
  {
    if ((array == null) || (array.length == 0)) {
      return EMPTY_OBJECT_ARRAY;
    }
    return array;
  }
  
  public static String[] nullToEmpty(String[] array)
  {
    if ((array == null) || (array.length == 0)) {
      return EMPTY_STRING_ARRAY;
    }
    return array;
  }
  
  public static long[] nullToEmpty(long[] array)
  {
    if ((array == null) || (array.length == 0)) {
      return EMPTY_LONG_ARRAY;
    }
    return array;
  }
  
  public static int[] nullToEmpty(int[] array)
  {
    if ((array == null) || (array.length == 0)) {
      return EMPTY_INT_ARRAY;
    }
    return array;
  }
  
  public static short[] nullToEmpty(short[] array)
  {
    if ((array == null) || (array.length == 0)) {
      return EMPTY_SHORT_ARRAY;
    }
    return array;
  }
  
  public static char[] nullToEmpty(char[] array)
  {
    if ((array == null) || (array.length == 0)) {
      return EMPTY_CHAR_ARRAY;
    }
    return array;
  }
  
  public static byte[] nullToEmpty(byte[] array)
  {
    if ((array == null) || (array.length == 0)) {
      return EMPTY_BYTE_ARRAY;
    }
    return array;
  }
  
  public static double[] nullToEmpty(double[] array)
  {
    if ((array == null) || (array.length == 0)) {
      return EMPTY_DOUBLE_ARRAY;
    }
    return array;
  }
  
  public static float[] nullToEmpty(float[] array)
  {
    if ((array == null) || (array.length == 0)) {
      return EMPTY_FLOAT_ARRAY;
    }
    return array;
  }
  
  public static boolean[] nullToEmpty(boolean[] array)
  {
    if ((array == null) || (array.length == 0)) {
      return EMPTY_BOOLEAN_ARRAY;
    }
    return array;
  }
  
  public static Long[] nullToEmpty(Long[] array)
  {
    if ((array == null) || (array.length == 0)) {
      return EMPTY_LONG_OBJECT_ARRAY;
    }
    return array;
  }
  
  public static Integer[] nullToEmpty(Integer[] array)
  {
    if ((array == null) || (array.length == 0)) {
      return EMPTY_INTEGER_OBJECT_ARRAY;
    }
    return array;
  }
  
  public static Short[] nullToEmpty(Short[] array)
  {
    if ((array == null) || (array.length == 0)) {
      return EMPTY_SHORT_OBJECT_ARRAY;
    }
    return array;
  }
  
  public static Character[] nullToEmpty(Character[] array)
  {
    if ((array == null) || (array.length == 0)) {
      return EMPTY_CHARACTER_OBJECT_ARRAY;
    }
    return array;
  }
  
  public static Byte[] nullToEmpty(Byte[] array)
  {
    if ((array == null) || (array.length == 0)) {
      return EMPTY_BYTE_OBJECT_ARRAY;
    }
    return array;
  }
  
  public static Double[] nullToEmpty(Double[] array)
  {
    if ((array == null) || (array.length == 0)) {
      return EMPTY_DOUBLE_OBJECT_ARRAY;
    }
    return array;
  }
  
  public static Float[] nullToEmpty(Float[] array)
  {
    if ((array == null) || (array.length == 0)) {
      return EMPTY_FLOAT_OBJECT_ARRAY;
    }
    return array;
  }
  
  public static Boolean[] nullToEmpty(Boolean[] array)
  {
    if ((array == null) || (array.length == 0)) {
      return EMPTY_BOOLEAN_OBJECT_ARRAY;
    }
    return array;
  }
  
  public static <T> T[] subarray(T[] array, int startIndexInclusive, int endIndexExclusive)
  {
    if (array == null) {
      return null;
    }
    if (startIndexInclusive < 0) {
      startIndexInclusive = 0;
    }
    if (endIndexExclusive > array.length) {
      endIndexExclusive = array.length;
    }
    int newSize = endIndexExclusive - startIndexInclusive;
    Class<?> type = array.getClass().getComponentType();
    if (newSize <= 0)
    {
      T[] emptyArray = (Object[])Array.newInstance(type, 0);
      return emptyArray;
    }
    T[] subarray = (Object[])Array.newInstance(type, newSize);
    System.arraycopy(array, startIndexInclusive, subarray, 0, newSize);
    return subarray;
  }
  
  public static long[] subarray(long[] array, int startIndexInclusive, int endIndexExclusive)
  {
    if (array == null) {
      return null;
    }
    if (startIndexInclusive < 0) {
      startIndexInclusive = 0;
    }
    if (endIndexExclusive > array.length) {
      endIndexExclusive = array.length;
    }
    int newSize = endIndexExclusive - startIndexInclusive;
    if (newSize <= 0) {
      return EMPTY_LONG_ARRAY;
    }
    long[] subarray = new long[newSize];
    System.arraycopy(array, startIndexInclusive, subarray, 0, newSize);
    return subarray;
  }
  
  public static int[] subarray(int[] array, int startIndexInclusive, int endIndexExclusive)
  {
    if (array == null) {
      return null;
    }
    if (startIndexInclusive < 0) {
      startIndexInclusive = 0;
    }
    if (endIndexExclusive > array.length) {
      endIndexExclusive = array.length;
    }
    int newSize = endIndexExclusive - startIndexInclusive;
    if (newSize <= 0) {
      return EMPTY_INT_ARRAY;
    }
    int[] subarray = new int[newSize];
    System.arraycopy(array, startIndexInclusive, subarray, 0, newSize);
    return subarray;
  }
  
  public static short[] subarray(short[] array, int startIndexInclusive, int endIndexExclusive)
  {
    if (array == null) {
      return null;
    }
    if (startIndexInclusive < 0) {
      startIndexInclusive = 0;
    }
    if (endIndexExclusive > array.length) {
      endIndexExclusive = array.length;
    }
    int newSize = endIndexExclusive - startIndexInclusive;
    if (newSize <= 0) {
      return EMPTY_SHORT_ARRAY;
    }
    short[] subarray = new short[newSize];
    System.arraycopy(array, startIndexInclusive, subarray, 0, newSize);
    return subarray;
  }
  
  public static char[] subarray(char[] array, int startIndexInclusive, int endIndexExclusive)
  {
    if (array == null) {
      return null;
    }
    if (startIndexInclusive < 0) {
      startIndexInclusive = 0;
    }
    if (endIndexExclusive > array.length) {
      endIndexExclusive = array.length;
    }
    int newSize = endIndexExclusive - startIndexInclusive;
    if (newSize <= 0) {
      return EMPTY_CHAR_ARRAY;
    }
    char[] subarray = new char[newSize];
    System.arraycopy(array, startIndexInclusive, subarray, 0, newSize);
    return subarray;
  }
  
  public static byte[] subarray(byte[] array, int startIndexInclusive, int endIndexExclusive)
  {
    if (array == null) {
      return null;
    }
    if (startIndexInclusive < 0) {
      startIndexInclusive = 0;
    }
    if (endIndexExclusive > array.length) {
      endIndexExclusive = array.length;
    }
    int newSize = endIndexExclusive - startIndexInclusive;
    if (newSize <= 0) {
      return EMPTY_BYTE_ARRAY;
    }
    byte[] subarray = new byte[newSize];
    System.arraycopy(array, startIndexInclusive, subarray, 0, newSize);
    return subarray;
  }
  
  public static double[] subarray(double[] array, int startIndexInclusive, int endIndexExclusive)
  {
    if (array == null) {
      return null;
    }
    if (startIndexInclusive < 0) {
      startIndexInclusive = 0;
    }
    if (endIndexExclusive > array.length) {
      endIndexExclusive = array.length;
    }
    int newSize = endIndexExclusive - startIndexInclusive;
    if (newSize <= 0) {
      return EMPTY_DOUBLE_ARRAY;
    }
    double[] subarray = new double[newSize];
    System.arraycopy(array, startIndexInclusive, subarray, 0, newSize);
    return subarray;
  }
  
  public static float[] subarray(float[] array, int startIndexInclusive, int endIndexExclusive)
  {
    if (array == null) {
      return null;
    }
    if (startIndexInclusive < 0) {
      startIndexInclusive = 0;
    }
    if (endIndexExclusive > array.length) {
      endIndexExclusive = array.length;
    }
    int newSize = endIndexExclusive - startIndexInclusive;
    if (newSize <= 0) {
      return EMPTY_FLOAT_ARRAY;
    }
    float[] subarray = new float[newSize];
    System.arraycopy(array, startIndexInclusive, subarray, 0, newSize);
    return subarray;
  }
  
  public static boolean[] subarray(boolean[] array, int startIndexInclusive, int endIndexExclusive)
  {
    if (array == null) {
      return null;
    }
    if (startIndexInclusive < 0) {
      startIndexInclusive = 0;
    }
    if (endIndexExclusive > array.length) {
      endIndexExclusive = array.length;
    }
    int newSize = endIndexExclusive - startIndexInclusive;
    if (newSize <= 0) {
      return EMPTY_BOOLEAN_ARRAY;
    }
    boolean[] subarray = new boolean[newSize];
    System.arraycopy(array, startIndexInclusive, subarray, 0, newSize);
    return subarray;
  }
  
  public static boolean isSameLength(Object[] array1, Object[] array2)
  {
    if (((array1 == null) && (array2 != null) && (array2.length > 0)) || ((array2 == null) && (array1 != null) && (array1.length > 0)) || ((array1 != null) && (array2 != null) && (array1.length != array2.length))) {
      return false;
    }
    return true;
  }
  
  public static boolean isSameLength(long[] array1, long[] array2)
  {
    if (((array1 == null) && (array2 != null) && (array2.length > 0)) || ((array2 == null) && (array1 != null) && (array1.length > 0)) || ((array1 != null) && (array2 != null) && (array1.length != array2.length))) {
      return false;
    }
    return true;
  }
  
  public static boolean isSameLength(int[] array1, int[] array2)
  {
    if (((array1 == null) && (array2 != null) && (array2.length > 0)) || ((array2 == null) && (array1 != null) && (array1.length > 0)) || ((array1 != null) && (array2 != null) && (array1.length != array2.length))) {
      return false;
    }
    return true;
  }
  
  public static boolean isSameLength(short[] array1, short[] array2)
  {
    if (((array1 == null) && (array2 != null) && (array2.length > 0)) || ((array2 == null) && (array1 != null) && (array1.length > 0)) || ((array1 != null) && (array2 != null) && (array1.length != array2.length))) {
      return false;
    }
    return true;
  }
  
  public static boolean isSameLength(char[] array1, char[] array2)
  {
    if (((array1 == null) && (array2 != null) && (array2.length > 0)) || ((array2 == null) && (array1 != null) && (array1.length > 0)) || ((array1 != null) && (array2 != null) && (array1.length != array2.length))) {
      return false;
    }
    return true;
  }
  
  public static boolean isSameLength(byte[] array1, byte[] array2)
  {
    if (((array1 == null) && (array2 != null) && (array2.length > 0)) || ((array2 == null) && (array1 != null) && (array1.length > 0)) || ((array1 != null) && (array2 != null) && (array1.length != array2.length))) {
      return false;
    }
    return true;
  }
  
  public static boolean isSameLength(double[] array1, double[] array2)
  {
    if (((array1 == null) && (array2 != null) && (array2.length > 0)) || ((array2 == null) && (array1 != null) && (array1.length > 0)) || ((array1 != null) && (array2 != null) && (array1.length != array2.length))) {
      return false;
    }
    return true;
  }
  
  public static boolean isSameLength(float[] array1, float[] array2)
  {
    if (((array1 == null) && (array2 != null) && (array2.length > 0)) || ((array2 == null) && (array1 != null) && (array1.length > 0)) || ((array1 != null) && (array2 != null) && (array1.length != array2.length))) {
      return false;
    }
    return true;
  }
  
  public static boolean isSameLength(boolean[] array1, boolean[] array2)
  {
    if (((array1 == null) && (array2 != null) && (array2.length > 0)) || ((array2 == null) && (array1 != null) && (array1.length > 0)) || ((array1 != null) && (array2 != null) && (array1.length != array2.length))) {
      return false;
    }
    return true;
  }
  
  public static int getLength(Object array)
  {
    if (array == null) {
      return 0;
    }
    return Array.getLength(array);
  }
  
  public static boolean isSameType(Object array1, Object array2)
  {
    if ((array1 == null) || (array2 == null)) {
      throw new IllegalArgumentException("The Array must not be null");
    }
    return array1.getClass().getName().equals(array2.getClass().getName());
  }
  
  public static void reverse(Object[] array)
  {
    if (array == null) {
      return;
    }
    int i = 0;
    int j = array.length - 1;
    while (j > i)
    {
      Object tmp = array[j];
      array[j] = array[i];
      array[i] = tmp;
      j--;
      i++;
    }
  }
  
  public static void reverse(long[] array)
  {
    if (array == null) {
      return;
    }
    int i = 0;
    int j = array.length - 1;
    while (j > i)
    {
      long tmp = array[j];
      array[j] = array[i];
      array[i] = tmp;
      j--;
      i++;
    }
  }
  
  public static void reverse(int[] array)
  {
    if (array == null) {
      return;
    }
    int i = 0;
    int j = array.length - 1;
    while (j > i)
    {
      int tmp = array[j];
      array[j] = array[i];
      array[i] = tmp;
      j--;
      i++;
    }
  }
  
  public static void reverse(short[] array)
  {
    if (array == null) {
      return;
    }
    int i = 0;
    int j = array.length - 1;
    while (j > i)
    {
      short tmp = array[j];
      array[j] = array[i];
      array[i] = tmp;
      j--;
      i++;
    }
  }
  
  public static void reverse(char[] array)
  {
    if (array == null) {
      return;
    }
    int i = 0;
    int j = array.length - 1;
    while (j > i)
    {
      char tmp = array[j];
      array[j] = array[i];
      array[i] = tmp;
      j--;
      i++;
    }
  }
  
  public static void reverse(byte[] array)
  {
    if (array == null) {
      return;
    }
    int i = 0;
    int j = array.length - 1;
    while (j > i)
    {
      byte tmp = array[j];
      array[j] = array[i];
      array[i] = tmp;
      j--;
      i++;
    }
  }
  
  public static void reverse(double[] array)
  {
    if (array == null) {
      return;
    }
    int i = 0;
    int j = array.length - 1;
    while (j > i)
    {
      double tmp = array[j];
      array[j] = array[i];
      array[i] = tmp;
      j--;
      i++;
    }
  }
  
  public static void reverse(float[] array)
  {
    if (array == null) {
      return;
    }
    int i = 0;
    int j = array.length - 1;
    while (j > i)
    {
      float tmp = array[j];
      array[j] = array[i];
      array[i] = tmp;
      j--;
      i++;
    }
  }
  
  public static void reverse(boolean[] array)
  {
    if (array == null) {
      return;
    }
    int i = 0;
    int j = array.length - 1;
    while (j > i)
    {
      boolean tmp = array[j];
      array[j] = array[i];
      array[i] = tmp;
      j--;
      i++;
    }
  }
  
  public static int indexOf(Object[] array, Object objectToFind)
  {
    return indexOf(array, objectToFind, 0);
  }
  
  public static int indexOf(Object[] array, Object objectToFind, int startIndex)
  {
    if (array == null) {
      return -1;
    }
    if (startIndex < 0) {
      startIndex = 0;
    }
    if (objectToFind == null) {
      for (int i = startIndex; i < array.length; i++) {
        if (array[i] == null) {
          return i;
        }
      }
    } else if (array.getClass().getComponentType().isInstance(objectToFind)) {
      for (int i = startIndex; i < array.length; i++) {
        if (objectToFind.equals(array[i])) {
          return i;
        }
      }
    }
    return -1;
  }
  
  public static int lastIndexOf(Object[] array, Object objectToFind)
  {
    return lastIndexOf(array, objectToFind, Integer.MAX_VALUE);
  }
  
  public static int lastIndexOf(Object[] array, Object objectToFind, int startIndex)
  {
    if (array == null) {
      return -1;
    }
    if (startIndex < 0) {
      return -1;
    }
    if (startIndex >= array.length) {
      startIndex = array.length - 1;
    }
    if (objectToFind == null) {
      for (int i = startIndex; i >= 0; i--) {
        if (array[i] == null) {
          return i;
        }
      }
    } else if (array.getClass().getComponentType().isInstance(objectToFind)) {
      for (int i = startIndex; i >= 0; i--) {
        if (objectToFind.equals(array[i])) {
          return i;
        }
      }
    }
    return -1;
  }
  
  public static boolean contains(Object[] array, Object objectToFind)
  {
    return indexOf(array, objectToFind) != -1;
  }
  
  public static int indexOf(long[] array, long valueToFind)
  {
    return indexOf(array, valueToFind, 0);
  }
  
  public static int indexOf(long[] array, long valueToFind, int startIndex)
  {
    if (array == null) {
      return -1;
    }
    if (startIndex < 0) {
      startIndex = 0;
    }
    for (int i = startIndex; i < array.length; i++) {
      if (valueToFind == array[i]) {
        return i;
      }
    }
    return -1;
  }
  
  public static int lastIndexOf(long[] array, long valueToFind)
  {
    return lastIndexOf(array, valueToFind, Integer.MAX_VALUE);
  }
  
  public static int lastIndexOf(long[] array, long valueToFind, int startIndex)
  {
    if (array == null) {
      return -1;
    }
    if (startIndex < 0) {
      return -1;
    }
    if (startIndex >= array.length) {
      startIndex = array.length - 1;
    }
    for (int i = startIndex; i >= 0; i--) {
      if (valueToFind == array[i]) {
        return i;
      }
    }
    return -1;
  }
  
  public static boolean contains(long[] array, long valueToFind)
  {
    return indexOf(array, valueToFind) != -1;
  }
  
  public static int indexOf(int[] array, int valueToFind)
  {
    return indexOf(array, valueToFind, 0);
  }
  
  public static int indexOf(int[] array, int valueToFind, int startIndex)
  {
    if (array == null) {
      return -1;
    }
    if (startIndex < 0) {
      startIndex = 0;
    }
    for (int i = startIndex; i < array.length; i++) {
      if (valueToFind == array[i]) {
        return i;
      }
    }
    return -1;
  }
  
  public static int lastIndexOf(int[] array, int valueToFind)
  {
    return lastIndexOf(array, valueToFind, Integer.MAX_VALUE);
  }
  
  public static int lastIndexOf(int[] array, int valueToFind, int startIndex)
  {
    if (array == null) {
      return -1;
    }
    if (startIndex < 0) {
      return -1;
    }
    if (startIndex >= array.length) {
      startIndex = array.length - 1;
    }
    for (int i = startIndex; i >= 0; i--) {
      if (valueToFind == array[i]) {
        return i;
      }
    }
    return -1;
  }
  
  public static boolean contains(int[] array, int valueToFind)
  {
    return indexOf(array, valueToFind) != -1;
  }
  
  public static int indexOf(short[] array, short valueToFind)
  {
    return indexOf(array, valueToFind, 0);
  }
  
  public static int indexOf(short[] array, short valueToFind, int startIndex)
  {
    if (array == null) {
      return -1;
    }
    if (startIndex < 0) {
      startIndex = 0;
    }
    for (int i = startIndex; i < array.length; i++) {
      if (valueToFind == array[i]) {
        return i;
      }
    }
    return -1;
  }
  
  public static int lastIndexOf(short[] array, short valueToFind)
  {
    return lastIndexOf(array, valueToFind, Integer.MAX_VALUE);
  }
  
  public static int lastIndexOf(short[] array, short valueToFind, int startIndex)
  {
    if (array == null) {
      return -1;
    }
    if (startIndex < 0) {
      return -1;
    }
    if (startIndex >= array.length) {
      startIndex = array.length - 1;
    }
    for (int i = startIndex; i >= 0; i--) {
      if (valueToFind == array[i]) {
        return i;
      }
    }
    return -1;
  }
  
  public static boolean contains(short[] array, short valueToFind)
  {
    return indexOf(array, valueToFind) != -1;
  }
  
  public static int indexOf(char[] array, char valueToFind)
  {
    return indexOf(array, valueToFind, 0);
  }
  
  public static int indexOf(char[] array, char valueToFind, int startIndex)
  {
    if (array == null) {
      return -1;
    }
    if (startIndex < 0) {
      startIndex = 0;
    }
    for (int i = startIndex; i < array.length; i++) {
      if (valueToFind == array[i]) {
        return i;
      }
    }
    return -1;
  }
  
  public static int lastIndexOf(char[] array, char valueToFind)
  {
    return lastIndexOf(array, valueToFind, Integer.MAX_VALUE);
  }
  
  public static int lastIndexOf(char[] array, char valueToFind, int startIndex)
  {
    if (array == null) {
      return -1;
    }
    if (startIndex < 0) {
      return -1;
    }
    if (startIndex >= array.length) {
      startIndex = array.length - 1;
    }
    for (int i = startIndex; i >= 0; i--) {
      if (valueToFind == array[i]) {
        return i;
      }
    }
    return -1;
  }
  
  public static boolean contains(char[] array, char valueToFind)
  {
    return indexOf(array, valueToFind) != -1;
  }
  
  public static int indexOf(byte[] array, byte valueToFind)
  {
    return indexOf(array, valueToFind, 0);
  }
  
  public static int indexOf(byte[] array, byte valueToFind, int startIndex)
  {
    if (array == null) {
      return -1;
    }
    if (startIndex < 0) {
      startIndex = 0;
    }
    for (int i = startIndex; i < array.length; i++) {
      if (valueToFind == array[i]) {
        return i;
      }
    }
    return -1;
  }
  
  public static int lastIndexOf(byte[] array, byte valueToFind)
  {
    return lastIndexOf(array, valueToFind, Integer.MAX_VALUE);
  }
  
  public static int lastIndexOf(byte[] array, byte valueToFind, int startIndex)
  {
    if (array == null) {
      return -1;
    }
    if (startIndex < 0) {
      return -1;
    }
    if (startIndex >= array.length) {
      startIndex = array.length - 1;
    }
    for (int i = startIndex; i >= 0; i--) {
      if (valueToFind == array[i]) {
        return i;
      }
    }
    return -1;
  }
  
  public static boolean contains(byte[] array, byte valueToFind)
  {
    return indexOf(array, valueToFind) != -1;
  }
  
  public static int indexOf(double[] array, double valueToFind)
  {
    return indexOf(array, valueToFind, 0);
  }
  
  public static int indexOf(double[] array, double valueToFind, double tolerance)
  {
    return indexOf(array, valueToFind, 0, tolerance);
  }
  
  public static int indexOf(double[] array, double valueToFind, int startIndex)
  {
    if (isEmpty(array)) {
      return -1;
    }
    if (startIndex < 0) {
      startIndex = 0;
    }
    for (int i = startIndex; i < array.length; i++) {
      if (valueToFind == array[i]) {
        return i;
      }
    }
    return -1;
  }
  
  public static int indexOf(double[] array, double valueToFind, int startIndex, double tolerance)
  {
    if (isEmpty(array)) {
      return -1;
    }
    if (startIndex < 0) {
      startIndex = 0;
    }
    double min = valueToFind - tolerance;
    double max = valueToFind + tolerance;
    for (int i = startIndex; i < array.length; i++) {
      if ((array[i] >= min) && (array[i] <= max)) {
        return i;
      }
    }
    return -1;
  }
  
  public static int lastIndexOf(double[] array, double valueToFind)
  {
    return lastIndexOf(array, valueToFind, Integer.MAX_VALUE);
  }
  
  public static int lastIndexOf(double[] array, double valueToFind, double tolerance)
  {
    return lastIndexOf(array, valueToFind, Integer.MAX_VALUE, tolerance);
  }
  
  public static int lastIndexOf(double[] array, double valueToFind, int startIndex)
  {
    if (isEmpty(array)) {
      return -1;
    }
    if (startIndex < 0) {
      return -1;
    }
    if (startIndex >= array.length) {
      startIndex = array.length - 1;
    }
    for (int i = startIndex; i >= 0; i--) {
      if (valueToFind == array[i]) {
        return i;
      }
    }
    return -1;
  }
  
  public static int lastIndexOf(double[] array, double valueToFind, int startIndex, double tolerance)
  {
    if (isEmpty(array)) {
      return -1;
    }
    if (startIndex < 0) {
      return -1;
    }
    if (startIndex >= array.length) {
      startIndex = array.length - 1;
    }
    double min = valueToFind - tolerance;
    double max = valueToFind + tolerance;
    for (int i = startIndex; i >= 0; i--) {
      if ((array[i] >= min) && (array[i] <= max)) {
        return i;
      }
    }
    return -1;
  }
  
  public static boolean contains(double[] array, double valueToFind)
  {
    return indexOf(array, valueToFind) != -1;
  }
  
  public static boolean contains(double[] array, double valueToFind, double tolerance)
  {
    return indexOf(array, valueToFind, 0, tolerance) != -1;
  }
  
  public static int indexOf(float[] array, float valueToFind)
  {
    return indexOf(array, valueToFind, 0);
  }
  
  public static int indexOf(float[] array, float valueToFind, int startIndex)
  {
    if (isEmpty(array)) {
      return -1;
    }
    if (startIndex < 0) {
      startIndex = 0;
    }
    for (int i = startIndex; i < array.length; i++) {
      if (valueToFind == array[i]) {
        return i;
      }
    }
    return -1;
  }
  
  public static int lastIndexOf(float[] array, float valueToFind)
  {
    return lastIndexOf(array, valueToFind, Integer.MAX_VALUE);
  }
  
  public static int lastIndexOf(float[] array, float valueToFind, int startIndex)
  {
    if (isEmpty(array)) {
      return -1;
    }
    if (startIndex < 0) {
      return -1;
    }
    if (startIndex >= array.length) {
      startIndex = array.length - 1;
    }
    for (int i = startIndex; i >= 0; i--) {
      if (valueToFind == array[i]) {
        return i;
      }
    }
    return -1;
  }
  
  public static boolean contains(float[] array, float valueToFind)
  {
    return indexOf(array, valueToFind) != -1;
  }
  
  public static int indexOf(boolean[] array, boolean valueToFind)
  {
    return indexOf(array, valueToFind, 0);
  }
  
  public static int indexOf(boolean[] array, boolean valueToFind, int startIndex)
  {
    if (isEmpty(array)) {
      return -1;
    }
    if (startIndex < 0) {
      startIndex = 0;
    }
    for (int i = startIndex; i < array.length; i++) {
      if (valueToFind == array[i]) {
        return i;
      }
    }
    return -1;
  }
  
  public static int lastIndexOf(boolean[] array, boolean valueToFind)
  {
    return lastIndexOf(array, valueToFind, Integer.MAX_VALUE);
  }
  
  public static int lastIndexOf(boolean[] array, boolean valueToFind, int startIndex)
  {
    if (isEmpty(array)) {
      return -1;
    }
    if (startIndex < 0) {
      return -1;
    }
    if (startIndex >= array.length) {
      startIndex = array.length - 1;
    }
    for (int i = startIndex; i >= 0; i--) {
      if (valueToFind == array[i]) {
        return i;
      }
    }
    return -1;
  }
  
  public static boolean contains(boolean[] array, boolean valueToFind)
  {
    return indexOf(array, valueToFind) != -1;
  }
  
  public static char[] toPrimitive(Character[] array)
  {
    if (array == null) {
      return null;
    }
    if (array.length == 0) {
      return EMPTY_CHAR_ARRAY;
    }
    char[] result = new char[array.length];
    for (int i = 0; i < array.length; i++) {
      result[i] = array[i].charValue();
    }
    return result;
  }
  
  public static char[] toPrimitive(Character[] array, char valueForNull)
  {
    if (array == null) {
      return null;
    }
    if (array.length == 0) {
      return EMPTY_CHAR_ARRAY;
    }
    char[] result = new
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2019. Infinite Loop Ltd