commons-lang3-3.1

16:34:48.824 INFO  jd.cli.Main - Decompiling commons-lang3-3.1.jar
package org.apache.commons.lang3;

class CharRange$1 {}

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

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;

public class ClassUtils
{
  public static final char PACKAGE_SEPARATOR_CHAR = '.';
  public static final String PACKAGE_SEPARATOR = String.valueOf('.');
  public static final char INNER_CLASS_SEPARATOR_CHAR = '$';
  public static final String INNER_CLASS_SEPARATOR = String.valueOf('$');
  private static final Map<Class<?>, Class<?>> primitiveWrapperMap = new HashMap();
  private static final Map<Class<?>, Class<?>> wrapperPrimitiveMap;
  private static final Map<String, String> abbreviationMap;
  private static final Map<String, String> reverseAbbreviationMap;
  
  private static void addAbbreviation(String primitive, String abbreviation)
  {
    abbreviationMap.put(primitive, abbreviation);
    reverseAbbreviationMap.put(abbreviation, primitive);
  }
  
  static
  {
    primitiveWrapperMap.put(Boolean.TYPE, Boolean.class);
    primitiveWrapperMap.put(Byte.TYPE, Byte.class);
    primitiveWrapperMap.put(Character.TYPE, Character.class);
    primitiveWrapperMap.put(Short.TYPE, Short.class);
    primitiveWrapperMap.put(Integer.TYPE, Integer.class);
    primitiveWrapperMap.put(Long.TYPE, Long.class);
    primitiveWrapperMap.put(Double.TYPE, Double.class);
    primitiveWrapperMap.put(Float.TYPE, Float.class);
    primitiveWrapperMap.put(Void.TYPE, Void.TYPE);
    
    wrapperPrimitiveMap = new HashMap();
    for (Class<?> primitiveClass : primitiveWrapperMap.keySet())
    {
      Class<?> wrapperClass = (Class)primitiveWrapperMap.get(primitiveClass);
      if (!primitiveClass.equals(wrapperClass)) {
        wrapperPrimitiveMap.put(wrapperClass, primitiveClass);
      }
    }
    abbreviationMap = new HashMap();
    
    reverseAbbreviationMap = new HashMap();
    
    addAbbreviation("int", "I");
    addAbbreviation("boolean", "Z");
    addAbbreviation("float", "F");
    addAbbreviation("long", "J");
    addAbbreviation("short", "S");
    addAbbreviation("byte", "B");
    addAbbreviation("double", "D");
    addAbbreviation("char", "C");
  }
  
  public static String getShortClassName(Object object, String valueIfNull)
  {
    if (object == null) {
      return valueIfNull;
    }
    return getShortClassName(object.getClass());
  }
  
  public static String getShortClassName(Class<?> cls)
  {
    if (cls == null) {
      return "";
    }
    return getShortClassName(cls.getName());
  }
  
  public static String getShortClassName(String className)
  {
    if (className == null) {
      return "";
    }
    if (className.length() == 0) {
      return "";
    }
    StringBuilder arrayPrefix = new StringBuilder();
    if (className.startsWith("["))
    {
      while (className.charAt(0) == '[')
      {
        className = className.substring(1);
        arrayPrefix.append("[]");
      }
      if ((className.charAt(0) == 'L') && (className.charAt(className.length() - 1) == ';')) {
        className = className.substring(1, className.length() - 1);
      }
    }
    if (reverseAbbreviationMap.containsKey(className)) {
      className = (String)reverseAbbreviationMap.get(className);
    }
    int lastDotIdx = className.lastIndexOf('.');
    int innerIdx = className.indexOf('$', lastDotIdx == -1 ? 0 : lastDotIdx + 1);
    
    String out = className.substring(lastDotIdx + 1);
    if (innerIdx != -1) {
      out = out.replace('$', '.');
    }
    return out + arrayPrefix;
  }
  
  public static String getSimpleName(Class<?> cls)
  {
    if (cls == null) {
      return "";
    }
    return cls.getSimpleName();
  }
  
  public static String getSimpleName(Object object, String valueIfNull)
  {
    if (object == null) {
      return valueIfNull;
    }
    return getSimpleName(object.getClass());
  }
  
  public static String getPackageName(Object object, String valueIfNull)
  {
    if (object == null) {
      return valueIfNull;
    }
    return getPackageName(object.getClass());
  }
  
  public static String getPackageName(Class<?> cls)
  {
    if (cls == null) {
      return "";
    }
    return getPackageName(cls.getName());
  }
  
  public static String getPackageName(String className)
  {
    if ((className == null) || (className.length() == 0)) {
      return "";
    }
    while (className.charAt(0) == '[') {
      className = className.substring(1);
    }
    if ((className.charAt(0) == 'L') && (className.charAt(className.length() - 1) == ';')) {
      className = className.substring(1);
    }
    int i = className.lastIndexOf('.');
    if (i == -1) {
      return "";
    }
    return className.substring(0, i);
  }
  
  public static List<Class<?>> getAllSuperclasses(Class<?> cls)
  {
    if (cls == null) {
      return null;
    }
    List<Class<?>> classes = new ArrayList();
    Class<?> superclass = cls.getSuperclass();
    while (superclass != null)
    {
      classes.add(superclass);
      superclass = superclass.getSuperclass();
    }
    return classes;
  }
  
  public static List<Class<?>> getAllInterfaces(Class<?> cls)
  {
    if (cls == null) {
      return null;
    }
    LinkedHashSet<Class<?>> interfacesFound = new LinkedHashSet();
    getAllInterfaces(cls, interfacesFound);
    
    return new ArrayList(interfacesFound);
  }
  
  private static void getAllInterfaces(Class<?> cls, HashSet<Class<?>> interfacesFound)
  {
    while (cls != null)
    {
      Class<?>[] interfaces = cls.getInterfaces();
      for (Class<?> i : interfaces) {
        if (interfacesFound.add(i)) {
          getAllInterfaces(i, interfacesFound);
        }
      }
      cls = cls.getSuperclass();
    }
  }
  
  public static List<Class<?>> convertClassNamesToClasses(List<String> classNames)
  {
    if (classNames == null) {
      return null;
    }
    List<Class<?>> classes = new ArrayList(classNames.size());
    for (String className : classNames) {
      try
      {
        classes.add(Class.forName(className));
      }
      catch (Exception ex)
      {
        classes.add(null);
      }
    }
    return classes;
  }
  
  public static List<String> convertClassesToClassNames(List<Class<?>> classes)
  {
    if (classes == null) {
      return null;
    }
    List<String> classNames = new ArrayList(classes.size());
    for (Class<?> cls : classes) {
      if (cls == null) {
        classNames.add(null);
      } else {
        classNames.add(cls.getName());
      }
    }
    return classNames;
  }
  
  public static boolean isAssignable(Class<?>[] classArray, Class<?>... toClassArray)
  {
    return isAssignable(classArray, toClassArray, SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_1_5));
  }
  
  public static boolean isAssignable(Class<?>[] classArray, Class<?>[] toClassArray, boolean autoboxing)
  {
    if (!ArrayUtils.isSameLength(classArray, toClassArray)) {
      return false;
    }
    if (classArray == null) {
      classArray = ArrayUtils.EMPTY_CLASS_ARRAY;
    }
    if (toClassArray == null) {
      toClassArray = ArrayUtils.EMPTY_CLASS_ARRAY;
    }
    for (int i = 0; i < classArray.length; i++) {
      if (!isAssignable(classArray[i], toClassArray[i], autoboxing)) {
        return false;
      }
    }
    return true;
  }
  
  public static boolean isPrimitiveOrWrapper(Class<?> type)
  {
    if (type == null) {
      return false;
    }
    return (type.isPrimitive()) || (isPrimitiveWrapper(type));
  }
  
  public static boolean isPrimitiveWrapper(Class<?> type)
  {
    return wrapperPrimitiveMap.containsKey(type);
  }
  
  public static boolean isAssignable(Class<?> cls, Class<?> toClass)
  {
    return isAssignable(cls, toClass, SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_1_5));
  }
  
  public static boolean isAssignable(Class<?> cls, Class<?> toClass, boolean autoboxing)
  {
    if (toClass == null) {
      return false;
    }
    if (cls == null) {
      return !toClass.isPrimitive();
    }
    if (autoboxing)
    {
      if ((cls.isPrimitive()) && (!toClass.isPrimitive()))
      {
        cls = primitiveToWrapper(cls);
        if (cls == null) {
          return false;
        }
      }
      if ((toClass.isPrimitive()) && (!cls.isPrimitive()))
      {
        cls = wrapperToPrimitive(cls);
        if (cls == null) {
          return false;
        }
      }
    }
    if (cls.equals(toClass)) {
      return true;
    }
    if (cls.isPrimitive())
    {
      if (!toClass.isPrimitive()) {
        return false;
      }
      if (Integer.TYPE.equals(cls)) {
        return (Long.TYPE.equals(toClass)) || (Float.TYPE.equals(toClass)) || (Double.TYPE.equals(toClass));
      }
      if (Long.TYPE.equals(cls)) {
        return (Float.TYPE.equals(toClass)) || (Double.TYPE.equals(toClass));
      }
      if (Boolean.TYPE.equals(cls)) {
        return false;
      }
      if (Double.TYPE.equals(cls)) {
        return false;
      }
      if (Float.TYPE.equals(cls)) {
        return Double.TYPE.equals(toClass);
      }
      if (Character.TYPE.equals(cls)) {
        return (Integer.TYPE.equals(toClass)) || (Long.TYPE.equals(toClass)) || (Float.TYPE.equals(toClass)) || (Double.TYPE.equals(toClass));
      }
      if (Short.TYPE.equals(cls)) {
        return (Integer.TYPE.equals(toClass)) || (Long.TYPE.equals(toClass)) || (Float.TYPE.equals(toClass)) || (Double.TYPE.equals(toClass));
      }
      if (Byte.TYPE.equals(cls)) {
        return (Short.TYPE.equals(toClass)) || (Integer.TYPE.equals(toClass)) || (Long.TYPE.equals(toClass)) || (Float.TYPE.equals(toClass)) || (Double.TYPE.equals(toClass));
      }
      return false;
    }
    return toClass.isAssignableFrom(cls);
  }
  
  public static Class<?> primitiveToWrapper(Class<?> cls)
  {
    Class<?> convertedClass = cls;
    if ((cls != null) && (cls.isPrimitive())) {
      convertedClass = (Class)primitiveWrapperMap.get(cls);
    }
    return convertedClass;
  }
  
  public static Class<?>[] primitivesToWrappers(Class<?>... classes)
  {
    if (classes == null) {
      return null;
    }
    if (classes.length == 0) {
      return classes;
    }
    Class<?>[] convertedClasses = new Class[classes.length];
    for (int i = 0; i < classes.length; i++) {
      convertedClasses[i] = primitiveToWrapper(classes[i]);
    }
    return convertedClasses;
  }
  
  public static Class<?> wrapperToPrimitive(Class<?> cls)
  {
    return (Class)wrapperPrimitiveMap.get(cls);
  }
  
  public static Class<?>[] wrappersToPrimitives(Class<?>... classes)
  {
    if (classes == null) {
      return null;
    }
    if (classes.length == 0) {
      return classes;
    }
    Class<?>[] convertedClasses = new Class[classes.length];
    for (int i = 0; i < classes.length; i++) {
      convertedClasses[i] = wrapperToPrimitive(classes[i]);
    }
    return convertedClasses;
  }
  
  public static boolean isInnerClass(Class<?> cls)
  {
    return (cls != null) && (cls.getEnclosingClass() != null);
  }
  
  public static Class<?> getClass(ClassLoader classLoader, String className, boolean initialize)
    throws ClassNotFoundException
  {
    try
    {
      Class<?> clazz;
      if (abbreviationMap.containsKey(className))
      {
        String clsName = "[" + (String)abbreviationMap.get(className);
        clazz = Class.forName(clsName, initialize, classLoader).getComponentType();
      }
      return Class.forName(toCanonicalName(className), initialize, classLoader);
    }
    catch (ClassNotFoundException ex)
    {
      int lastDotIndex = className.lastIndexOf('.');
      if (lastDotIndex != -1) {
        try
        {
          return getClass(classLoader, className.substring(0, lastDotIndex) + '$' + className.substring(lastDotIndex + 1), initialize);
        }
        catch (ClassNotFoundException ex2) {}
      }
      throw ex;
    }
  }
  
  public static Class<?> getClass(ClassLoader classLoader, String className)
    throws ClassNotFoundException
  {
    return getClass(classLoader, className, true);
  }
  
  public static Class<?> getClass(String className)
    throws ClassNotFoundException
  {
    return getClass(className, true);
  }
  
  public static Class<?> getClass(String className, boolean initialize)
    throws ClassNotFoundException
  {
    ClassLoader contextCL = Thread.currentThread().getContextClassLoader();
    ClassLoader loader = contextCL == null ? ClassUtils.class.getClassLoader() : contextCL;
    return getClass(loader, className, initialize);
  }
  
  public static Method getPublicMethod(Class<?> cls, String methodName, Class<?>... parameterTypes)
    throws SecurityException, NoSuchMethodException
  {
    Method declaredMethod = cls.getMethod(methodName, parameterTypes);
    if (Modifier.isPublic(declaredMethod.getDeclaringClass().getModifiers())) {
      return declaredMethod;
    }
    List<Class<?>> candidateClasses = new ArrayList();
    candidateClasses.addAll(getAllInterfaces(cls));
    candidateClasses.addAll(getAllSuperclasses(cls));
    for (Class<?> candidateClass : candidateClasses) {
      if (Modifier.isPublic(candidateClass.getModifiers()))
      {
        Method candidateMethod;
        try
        {
          candidateMethod = candidateClass.getMethod(methodName, parameterTypes);
        }
        catch (NoSuchMethodException ex) {}
        continue;
        if (Modifier.isPublic(candidateMethod.getDeclaringClass().getModifiers())) {
          return candidateMethod;
        }
      }
    }
    throw new NoSuchMethodException("Can't find a public method for " + methodName + " " + ArrayUtils.toString(parameterTypes));
  }
  
  private static String toCanonicalName(String className)
  {
    className = StringUtils.deleteWhitespace(className);
    if (className == null) {
      throw new NullPointerException("className must not be null.");
    }
    if (className.endsWith("[]"))
    {
      StringBuilder classNameBuffer = new StringBuilder();
      while (className.endsWith("[]"))
      {
        className = className.substring(0, className.length() - 2);
        classNameBuffer.append("[");
      }
      String abbreviation = (String)abbreviationMap.get(className);
      if (abbreviation != null) {
        classNameBuffer.append(abbreviation);
      } else {
        classNameBuffer.append("L").append(className).append(";");
      }
      className = classNameBuffer.toString();
    }
    return className;
  }
  
  public static Class<?>[] toClass(Object... array)
  {
    if (array == null) {
      return null;
    }
    if (array.length == 0) {
      return ArrayUtils.EMPTY_CLASS_ARRAY;
    }
    Class<?>[] classes = new Class[array.length];
    for (int i = 0; i < array.length; i++) {
      classes[i] = (array[i] == null ? null : array[i].getClass());
    }
    return classes;
  }
  
  public static String getShortCanonicalName(Object object, String valueIfNull)
  {
    if (object == null) {
      return valueIfNull;
    }
    return getShortCanonicalName(object.getClass().getName());
  }
  
  public static String getShortCanonicalName(Class<?> cls)
  {
    if (cls == null) {
      return "";
    }
    return getShortCanonicalName(cls.getName());
  }
  
  public static String getShortCanonicalName(String canonicalName)
  {
    return getShortClassName(getCanonicalName(canonicalName));
  }
  
  public static String getPackageCanonicalName(Object object, String valueIfNull)
  {
    if (object == null) {
      return valueIfNull;
    }
    return getPackageCanonicalName(object.getClass().getName());
  }
  
  public static String getPackageCanonicalName(Class<?> cls)
  {
    if (cls == null) {
      return "";
    }
    return getPackageCanonicalName(cls.getName());
  }
  
  public static String getPackageCanonicalName(String canonicalName)
  {
    return getPackageName(getCanonicalName(canonicalName));
  }
  
  private static String getCanonicalName(String className)
  {
    className = StringUtils.deleteWhitespace(className);
    if (className == null) {
      return null;
    }
    int dim = 0;
    while (className.startsWith("["))
    {
      dim++;
      className = className.substring(1);
    }
    if (dim < 1) {
      return className;
    }
    if (className.startsWith("L")) {
      className = className.substring(1, className.endsWith(";") ? className.length() - 1 : className.length());
    } else if (className.length() > 0) {
      className = (String)reverseAbbreviationMap.get(className.substring(0, 1));
    }
    StringBuilder canonicalClassNameBuffer = new StringBuilder(className);
    for (int i = 0; i < dim; i++) {
      canonicalClassNameBuffer.append("[]");
    }
    return canonicalClassNameBuffer.toString();
  }
}

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

import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public class EnumUtils
{
  public static <E extends Enum<E>> Map<String, E> getEnumMap(Class<E> enumClass)
  {
    Map<String, E> map = new LinkedHashMap();
    for (E e : (Enum[])enumClass.getEnumConstants()) {
      map.put(e.name(), e);
    }
    return map;
  }
  
  public static <E extends Enum<E>> List<E> getEnumList(Class<E> enumClass)
  {
    return new ArrayList(Arrays.asList(enumClass.getEnumConstants()));
  }
  
  public static <E extends Enum<E>> boolean isValidEnum(Class<E> enumClass, String enumName)
  {
    if (enumName == null) {
      return false;
    }
    try
    {
      Enum.valueOf(enumClass, enumName);
      return true;
    }
    catch (IllegalArgumentException ex) {}
    return false;
  }
  
  public static <E extends Enum<E>> E getEnum(Class<E> enumClass, String enumName)
  {
    if (enumName == null) {
      return null;
    }
    try
    {
      return Enum.valueOf(enumClass, enumName);
    }
    catch (IllegalArgumentException ex) {}
    return null;
  }
  
  public static <E extends Enum<E>> long generateBitVector(Class<E> enumClass, Iterable<E> values)
  {
    checkBitVectorable(enumClass);
    Validate.notNull(values);
    long total = 0L;
    for (E constant : values) {
      total |= 1 << constant.ordinal();
    }
    return total;
  }
  
  public static <E extends Enum<E>> long generateBitVector(Class<E> enumClass, E... values)
  {
    Validate.noNullElements(values);
    return generateBitVector(enumClass, Arrays.asList(values));
  }
  
  public static <E extends Enum<E>> EnumSet<E> processBitVector(Class<E> enumClass, long value)
  {
    E[] constants = (Enum[])checkBitVectorable(enumClass).getEnumConstants();
    EnumSet<E> results = EnumSet.noneOf(enumClass);
    for (E constant : constants) {
      if ((value & 1 << constant.ordinal()) != 0L) {
        results.add(constant);
      }
    }
    return results;
  }
  
  private static <E extends Enum<E>> Class<E> checkBitVectorable(Class<E> enumClass)
  {
    Validate.notNull(enumClass, "EnumClass must be defined.", new Object[0]);
    
    E[] constants = (Enum[])enumClass.getEnumConstants();
    Validate.isTrue(constants != null, "%s does not seem to be an Enum type", new Object[] { enumClass });
    Validate.isTrue(constants.length <= 64, "Cannot store %s %s values in %s bits", new Object[] { Integer.valueOf(constants.length), enumClass.getSimpleName(), Integer.valueOf(64) });
    
    return enumClass;
  }
}

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

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.ObjectStreamClass;
import java.io.OutputStream;
import java.io.Serializable;

public class SerializationUtils
{
  public static <T extends Serializable> T clone(T object)
  {
    if (object == null) {
      return null;
    }
    byte[] objectData = serialize(object);
    ByteArrayInputStream bais = new ByteArrayInputStream(objectData);
    
    ClassLoaderAwareObjectInputStream in = null;
    try
    {
      in = new ClassLoaderAwareObjectInputStream(bais, object.getClass().getClassLoader());
      
      T readObject = (Serializable)in.readObject();
      return readObject;
    }
    catch (ClassNotFoundException ex)
    {
      throw new SerializationException("ClassNotFoundException while reading cloned object data", ex);
    }
    catch (IOException ex)
    {
      throw new SerializationException("IOException while reading cloned object data", ex);
    }
    finally
    {
      try
      {
        if (in != null) {
          in.close();
        }
      }
      catch (IOException ex)
      {
        throw new SerializationException("IOException on closing cloned object data InputStream.", ex);
      }
    }
  }
  
  public static void serialize(Serializable obj, OutputStream outputStream)
  {
    if (outputStream == null) {
      throw new IllegalArgumentException("The OutputStream must not be null");
    }
    ObjectOutputStream out = null;
    try
    {
      out = new ObjectOutputStream(outputStream);
      out.writeObject(obj); return;
    }
    catch (IOException ex)
    {
      throw new SerializationException(ex);
    }
    finally
    {
      try
      {
        if (out != null) {
          out.close();
        }
      }
      catch (IOException ex) {}
    }
  }
  
  public static byte[] serialize(Serializable obj)
  {
    ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
    serialize(obj, baos);
    return baos.toByteArray();
  }
  
  public static Object deserialize(InputStream inputStream)
  {
    if (inputStream == null) {
      throw new IllegalArgumentException("The InputStream must not be null");
    }
    ObjectInputStream in = null;
    try
    {
      in = new ObjectInputStream(inputStream);
      return in.readObject();
    }
    catch (ClassNotFoundException ex)
    {
      throw new SerializationException(ex);
    }
    catch (IOException ex)
    {
      throw new SerializationException(ex);
    }
    finally
    {
      try
      {
        if (in != null) {
          in.close();
        }
      }
      catch (IOException ex) {}
    }
  }
  
  public static Object deserialize(byte[] objectData)
  {
    if (objectData == null) {
      throw new IllegalArgumentException("The byte[] must not be null");
    }
    ByteArrayInputStream bais = new ByteArrayInputStream(objectData);
    return deserialize(bais);
  }
  
  static class ClassLoaderAwareObjectInputStream
    extends ObjectInputStream
  {
    private ClassLoader classLoader;
    
    public ClassLoaderAwareObjectInputStream(InputStream in, ClassLoader classLoader)
      throws IOException
    {
      super();
      this.classLoader = classLoader;
    }
    
    protected Class<?> resolveClass(ObjectStreamClass desc)
      throws IOException, ClassNotFoundException
    {
      String name = desc.getName();
      try
      {
        return Class.forName(name, false, classLoader);
      }
      catch (ClassNotFoundException ex) {}
      return Class.forName(name, false, Thread.currentThread().getContextClassLoader());
    }
  }
}

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

public class StopWatch
{
  private static final long NANO_2_MILLIS = 1000000L;
  private static final int STATE_UNSTARTED = 0;
  private static final int STATE_RUNNING = 1;
  private static final int STATE_STOPPED = 2;
  private static final int STATE_SUSPENDED = 3;
  private static final int STATE_UNSPLIT = 10;
  private static final int STATE_SPLIT = 11;
  private int runningState = 0;
  private int splitState = 10;
  private long startTime;
  private long startTimeMillis;
  private long stopTime;
  
  public void start()
  {
    if (runningState == 2) {
      throw new IllegalStateException("Stopwatch must be reset before being restarted. ");
    }
    if (runningState != 0) {
      throw new IllegalStateException("Stopwatch already started. ");
    }
    startTime = System.nanoTime();
    startTimeMillis = System.currentTimeMillis();
    runningState = 1;
  }
  
  public void stop()
  {
    if ((runningState != 1) && (runningState != 3)) {
      throw new IllegalStateException("Stopwatch is not running. ");
    }
    if (runningState == 1) {
      stopTime = System.nanoTime();
    }
    runningState = 2;
  }
  
  public void reset()
  {
    runningState = 0;
    splitState = 10;
  }
  
  public void split()
  {
    if (runningState != 1) {
      throw new IllegalStateException("Stopwatch is not running. ");
    }
    stopTime = System.nanoTime();
    splitState = 11;
  }
  
  public void unsplit()
  {
    if (splitState != 11) {
      throw new IllegalStateException("Stopwatch has not been split. ");
    }
    splitState = 10;
  }
  
  public void suspend()
  {
    if (runningState != 1) {
      throw new IllegalStateException("Stopwatch must be running to suspend. ");
    }
    stopTime = System.nanoTime();
    runningState = 3;
  }
  
  public void resume()
  {
    if (runningState != 3) {
      throw new IllegalStateException("Stopwatch must be suspended to resume. ");
    }
    startTime += System.nanoTime() - stopTime;
    runningState = 1;
  }
  
  public long getTime()
  {
    return getNanoTime() / 1000000L;
  }
  
  public long getNanoTime()
  {
    if ((runningState == 2) || (runningState == 3)) {
      return stopTime - startTime;
    }
    if (runningState == 0) {
      return 0L;
    }
    if (runningState == 1) {
      return System.nanoTime() - startTime;
    }
    throw new RuntimeException("Illegal running state has occured. ");
  }
  
  public long getSplitTime()
  {
    return getSplitNanoTime() / 1000000L;
  }
  
  public long getSplitNanoTime()
  {
    if (splitState != 11) {
      throw new IllegalStateException("Stopwatch must be split to get the split time. ");
    }
    return stopTime - startTime;
  }
  
  public long getStartTime()
  {
    if (runningState == 0) {
      throw new IllegalStateException("Stopwatch has not been started");
    }
    return startTimeMillis;
  }
  
  public String toString()
  {
    return DurationFormatUtils.formatDurationHMS(getTime());
  }
  
  public String toSplitString()
  {
    return DurationFormatUtils.formatDurationHMS(getSplitTime());
  }
}

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

import org.apache.commons.lang3.StringUtils;

class DurationFormatUtils$Token
{
  private final Object value;
  private int count;
  
  static boolean containsTokenWithValue(Token[] tokens, Object value)
  {
    int sz = tokens.length;
    for (int i = 0; i < sz; i++) {
      if (tokens[i].getValue() == value) {
        return true;
      }
    }
    return false;
  }
  
  DurationFormatUtils$Token(Object value)
  {
    this.value = value;
    count = 1;
  }
  
  DurationFormatUtils$Token(Object value, int count)
  {
    this.value = value;
    this.count = count;
  }
  
  void increment()
  {
    count += 1;
  }
  
  int getCount()
  {
    return count;
  }
  
  Object getValue()
  {
    return value;
  }
  
  public boolean equals(Object obj2)
  {
    if ((obj2 instanceof Token))
    {
      Token tok2 = (Token)obj2;
      if (value.getClass() != value.getClass()) {
        return false;
      }
      if (count != count) {
        return false;
      }
      if ((value instanceof StringBuffer)) {
        return value.toString().equals(value.toString());
      }
      if ((value instanceof Number)) {
        return value.equals(value);
      }
      return value == value;
    }
    return false;
  }
  
  public int hashCode()
  {
    return value.hashCode();
  }
  
  public String toString()
  {
    return StringUtils.repeat(value.toString(), count);
  }
}

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

import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.NoSuchElementException;

public class DateUtils
{
  public static final long MILLIS_PER_SECOND = 1000L;
  public static final long MILLIS_PER_MINUTE = 60000L;
  public static final long MILLIS_PER_HOUR = 3600000L;
  public static final long MILLIS_PER_DAY = 86400000L;
  public static final int SEMI_MONTH = 1001;
  private static final int[][] fields = { { 14 }, { 13 }, { 12 }, { 11, 10 }, { 5, 5, 9 }, { 2, 1001 }, { 1 }, { 0 } };
  public static final int RANGE_WEEK_SUNDAY = 1;
  public static final int RANGE_WEEK_MONDAY = 2;
  public static final int RANGE_WEEK_RELATIVE = 3;
  public static final int RANGE_WEEK_CENTER = 4;
  public static final int RANGE_MONTH_SUNDAY = 5;
  public static final int RANGE_MONTH_MONDAY = 6;
  private static final int MODIFY_TRUNCATE = 0;
  private static final int MODIFY_ROUND = 1;
  private static final int MODIFY_CEILING = 2;
  
  public static boolean isSameDay(Date date1, Date date2)
  {
    if ((date1 == null) || (date2 == null)) {
      throw new IllegalArgumentException("The date must not be null");
    }
    Calendar cal1 = Calendar.getInstance();
    cal1.setTime(date1);
    Calendar cal2 = Calendar.getInstance();
    cal2.setTime(date2);
    return isSameDay(cal1, cal2);
  }
  
  public static boolean isSameDay(Calendar cal1, Calendar cal2)
  {
    if ((cal1 == null) || (cal2 == null)) {
      throw new IllegalArgumentException("The date must not be null");
    }
    return (cal1.get(0) == cal2.get(0)) && (cal1.get(1) == cal2.get(1)) && (cal1.get(6) == cal2.get(6));
  }
  
  public static boolean isSameInstant(Date date1, Date date2)
  {
    if ((date1 == null) || (date2 == null)) {
      throw new IllegalArgumentException("The date must not be null");
    }
    return date1.getTime() == date2.getTime();
  }
  
  public static boolean isSameInstant(Calendar cal1, Calendar cal2)
  {
    if ((cal1 == null) || (cal2 == null)) {
      throw new IllegalArgumentException("The date must not be null");
    }
    return cal1.getTime().getTime() == cal2.getTime().getTime();
  }
  
  public static boolean isSameLocalTime(Calendar cal1, Calendar cal2)
  {
    if ((cal1 == null) || (cal2 == null)) {
      throw new IllegalArgumentException("The date must not be null");
    }
    return (cal1.get(14) == cal2.get(14)) && (cal1.get(13) == cal2.get(13)) && (cal1.get(12) == cal2.get(12)) && (cal1.get(11) == cal2.get(11)) && (cal1.get(6) == cal2.get(6)) && (cal1.get(1) == cal2.get(1)) && (cal1.get(0) == cal2.get(0)) && (cal1.getClass() == cal2.getClass());
  }
  
  public static Date parseDate(String str, String... parsePatterns)
    throws ParseException
  {
    return parseDateWithLeniency(str, parsePatterns, true);
  }
  
  public static Date parseDateStrictly(String str, String... parsePatterns)
    throws ParseException
  {
    return parseDateWithLeniency(str, parsePatterns, false);
  }
  
  private static Date parseDateWithLeniency(String str, String[] parsePatterns, boolean lenient)
    throws ParseException
  {
    if ((str == null) || (parsePatterns == null)) {
      throw new IllegalArgumentException("Date and Patterns must not be null");
    }
    SimpleDateFormat parser = new SimpleDateFormat();
    parser.setLenient(lenient);
    ParsePosition pos = new ParsePosition(0);
    for (String parsePattern : parsePatterns)
    {
      String pattern = parsePattern;
      if (parsePattern.endsWith("ZZ")) {
        pattern = pattern.substring(0, pattern.length() - 1);
      }
      parser.applyPattern(pattern);
      pos.setIndex(0);
      
      String str2 = str;
      if (parsePattern.endsWith("ZZ")) {
        str2 = str.replaceAll("([-+][0-9][0-9]):([0-9][0-9])$", "$1$2");
      }
      Date date = parser.parse(str2, pos);
      if ((date != null) && (pos.getIndex() == str2.length())) {
        return date;
      }
    }
    throw new ParseException("Unable to parse the date: " + str, -1);
  }
  
  public static Date addYears(Date date, int amount)
  {
    return add(date, 1, amount);
  }
  
  public static Date addMonths(Date date, int amount)
  {
    return add(date, 2, amount);
  }
  
  public static Date addWeeks(Date date, int amount)
  {
    return add(date, 3, amount);
  }
  
  public static Date addDays(Date date, int amount)
  {
    return add(date, 5, amount);
  }
  
  public static Date addHours(Date date, int amount)
  {
    return add(date, 11, amount);
  }
  
  public static Date addMinutes(Date date, int amount)
  {
    return add(date, 12, amount);
  }
  
  public static Date addSeconds(Date date, int amount)
  {
    return add(date, 13, amount);
  }
  
  public static Date addMilliseconds(Date date, int amount)
  {
    return add(date, 14, amount);
  }
  
  private static Date add(Date date, int calendarField, int amount)
  {
    if (date == null) {
      throw new IllegalArgumentException("The date must not be null");
    }
    Calendar c = Calendar.getInstance();
    c.setTime(date);
    c.add(calendarField, amount);
    return c.getTime();
  }
  
  public static Date setYears(Date date, int amount)
  {
    return set(date, 1, amount);
  }
  
  public static Date setMonths(Date date, int amount)
  {
    return set(date, 2, amount);
  }
  
  public static Date setDays(Date date, int amount)
  {
    return set(date, 5, amount);
  }
  
  public static Date setHours(Date date, int amount)
  {
    return set(date, 11, amount);
  }
  
  public static Date setMinutes(Date date, int amount)
  {
    return set(date, 12, amount);
  }
  
  public static Date setSeconds(Date date, int amount)
  {
    return set(date, 13, amount);
  }
  
  public static Date setMilliseconds(Date date, int amount)
  {
    return set(date, 14, amount);
  }
  
  private static Date set(Date date, int calendarField, int amount)
  {
    if (date == null) {
      throw new IllegalArgumentException("The date must not be null");
    }
    Calendar c = Calendar.getInstance();
    c.setLenient(false);
    c.setTime(date);
    c.set(calendarField, amount);
    return c.getTime();
  }
  
  public static Calendar toCalendar(Date date)
  {
    Calendar c = Calendar.getInstance();
    c.setTime(date);
    return c;
  }
  
  public static Date round(Date date, int field)
  {
    if (date == null) {
      throw new IllegalArgumentException("The date must not be null");
    }
    Calendar gval = Calendar.getInstance();
    gval.setTime(date);
    modify(gval, field, 1);
    return gval.getTime();
  }
  
  public static Calendar round(Calendar date, int field)
  {
    if (date == null) {
      throw new IllegalArgumentException("The date must not be null");
    }
    Calendar rounded = (Calendar)date.clone();
    modify(rounded, field, 1);
    return rounded;
  }
  
  public static Date round(Object date, int field)
  {
    if (date == null) {
      throw new IllegalArgumentException("The date must not be null");
    }
    if ((date instanceof Date)) {
      return round((Date)date, field);
    }
    if ((date instanceof Calendar)) {
      return round((Calendar)date, field).getTime();
    }
    throw new ClassCastException("Could not round " + date);
  }
  
  public static Date truncate(Date date, int field)
  {
    if (date == null) {
      throw new IllegalArgumentException("The date must not be null");
    }
    Calendar gval = Calendar.getInstance();
    gval.setTime(date);
    modify(gval, field, 0);
    return gval.getTime();
  }
  
  public static Calendar truncate(Calendar date, int field)
  {
    if (date == null) {
      throw new IllegalArgumentException("The date must not be null");
    }
    Calendar truncated = (Calendar)date.clone();
    modify(truncated, field, 0);
    return truncated;
  }
  
  public static Date truncate(Object date, int field)
  {
    if (date == null) {
      throw new IllegalArgumentException("The date must not be null");
    }
    if ((date instanceof Date)) {
      return truncate((Date)date, field);
    }
    if ((date instanceof Calendar)) {
      return truncate((Calendar)date, field).getTime();
    }
    throw new ClassCastException("Could not truncate " + date);
  }
  
  public static Date ceiling(Date date, int field)
  {
    if (date == null) {
      throw new IllegalArgumentException("The date must not be null");
    }
    Calendar gval = Calendar.getInstance();
    gval.setTime(date);
    modify(gval, field, 2);
    return gval.getTime();
  }
  
  public static Calendar ceiling(Calendar date, int field)
  {
    if (date == null) {
      throw new IllegalArgumentException("The date must not be null");
    }
    Calendar ceiled = (Calendar)date.clone();
    modify(ceiled, field, 2);
    return ceiled;
  }
  
  public static Date ceiling(Object date, int field)
  {
    if (date == null) {
      throw new IllegalArgumentException("The date must not be null");
    }
    if ((date instanceof Date)) {
      return ceiling((Date)date, field);
    }
    if ((date instanceof Calendar)) {
      return ceiling((Calendar)date, field).getTime();
    }
    throw new ClassCastException("Could not find ceiling of for type: " + date.getClass());
  }
  
  private static void modify(Calendar val, int field, int modType)
  {
    if (val.get(1) > 280000000) {
      throw new ArithmeticException("Calendar value too large for accurate calculations");
    }
    if (field == 14) {
      return;
    }
    Date date = val.getTime();
    long time = date.getTime();
    boolean done = false;
    
    int millisecs = val.get(14);
    if ((0 == modType) || (millisecs < 500)) {
      time -= millisecs;
    }
    if (field == 13) {
      done = true;
    }
    int seconds = val.get(13);
    if ((!done) && ((0 == modType) || (seconds < 30))) {
      time -= seconds * 1000L;
    }
    if (field == 12) {
      done = true;
    }
    int minutes = val.get(12);
    if ((!done) && ((0 == modType) || (minutes < 30))) {
      time -= minutes * 60000L;
    }
    if (date.getTime() != time)
    {
      date.setTime(time);
      val.setTime(date);
    }
    boolean roundUp = false;
    for (int[] aField : fields)
    {
      for (int element : aField) {
        if (element == field)
        {
          if ((modType == 2) || ((modType == 1) && (roundUp))) {
            if (field == 1001)
            {
              if (val.get(5) == 1)
              {
                val.add(5, 15);
              }
              else
              {
                val.add(5, -15);
                val.add(2, 1);
              }
            }
            else if (field == 9)
            {
              if (val.get(11) == 0)
              {
                val.add(11, 12);
              }
              else
              {
                val.add(11, -12);
                val.add(5, 1);
              }
            }
            else {
              val.add(aField[0], 1);
            }
          }
          return;
        }
      }
      int offset = 0;
      boolean offsetSet = false;
      switch (field)
      {
      case 1001: 
        if (aField[0] == 5)
        {
          offset = val.get(5) - 1;
          if (offset >= 15) {
            offset -= 15;
          }
          roundUp = offset > 7;
          offsetSet = true;
        }
        break;
      case 9: 
        if (aField[0] == 11)
        {
          of
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