Range.java 5.53 KB
package org.apache.commons.lang3;

import java.io.Serializable;
import java.util.Comparator;

public final class Range<T>
  implements Serializable
{
  private static final long serialVersionUID = 1L;
  private final Comparator<T> a;
  private final T b;
  private final T c;
  private transient int d;
  private transient String e;
  
  private Range(T paramT1, T paramT2, Comparator<T> paramComparator)
  {
    if ((paramT1 == null) || (paramT2 == null)) {
      throw new IllegalArgumentException("Elements in a range must not be null: element1=" + paramT1 + ", element2=" + paramT2);
    }
    if (paramComparator == null) {}
    for (this.a = a.a; this.a.compare(paramT1, paramT2) <= 0; this.a = paramComparator)
    {
      this.b = paramT1;
      this.c = paramT2;
      return;
    }
    this.b = paramT2;
    this.c = paramT1;
  }
  
  public static <T extends Comparable<T>> Range<T> between(T paramT1, T paramT2)
  {
    return between(paramT1, paramT2, null);
  }
  
  public static <T> Range<T> between(T paramT1, T paramT2, Comparator<T> paramComparator)
  {
    return new Range(paramT1, paramT2, paramComparator);
  }
  
  public static <T extends Comparable<T>> Range<T> is(T paramT)
  {
    return between(paramT, paramT, null);
  }
  
  public static <T> Range<T> is(T paramT, Comparator<T> paramComparator)
  {
    return between(paramT, paramT, paramComparator);
  }
  
  public final boolean contains(T paramT)
  {
    if (paramT == null) {}
    while ((this.a.compare(paramT, this.b) < 0) || (this.a.compare(paramT, this.c) > 0)) {
      return false;
    }
    return true;
  }
  
  public final boolean containsRange(Range<T> paramRange)
  {
    if (paramRange == null) {}
    while ((!contains(paramRange.b)) || (!contains(paramRange.c))) {
      return false;
    }
    return true;
  }
  
  public final int elementCompareTo(T paramT)
  {
    if (paramT == null) {
      throw new NullPointerException("Element is null");
    }
    if (isAfter(paramT)) {
      return -1;
    }
    if (isBefore(paramT)) {
      return 1;
    }
    return 0;
  }
  
  public final boolean equals(Object paramObject)
  {
    if (paramObject == this) {}
    do
    {
      return true;
      if ((paramObject == null) || (paramObject.getClass() != getClass())) {
        return false;
      }
      paramObject = (Range)paramObject;
    } while ((this.b.equals(((Range)paramObject).b)) && (this.c.equals(((Range)paramObject).c)));
    return false;
  }
  
  public final Comparator<T> getComparator()
  {
    return this.a;
  }
  
  public final T getMaximum()
  {
    return (T)this.c;
  }
  
  public final T getMinimum()
  {
    return (T)this.b;
  }
  
  public final int hashCode()
  {
    int i = this.d;
    if (this.d == 0)
    {
      i = ((getClass().hashCode() + 629) * 37 + this.b.hashCode()) * 37 + this.c.hashCode();
      this.d = i;
    }
    return i;
  }
  
  public final Range<T> intersectionWith(Range<T> paramRange)
  {
    if (!isOverlappedBy(paramRange)) {
      throw new IllegalArgumentException(String.format("Cannot calculate intersection with non-overlapping range %s", new Object[] { paramRange }));
    }
    if (equals(paramRange)) {
      return this;
    }
    Object localObject;
    if (getComparator().compare(this.b, paramRange.b) < 0)
    {
      localObject = paramRange.b;
      if (getComparator().compare(this.c, paramRange.c) >= 0) {
        break label107;
      }
    }
    label107:
    for (paramRange = this.c;; paramRange = paramRange.c)
    {
      return between(localObject, paramRange, getComparator());
      localObject = this.b;
      break;
    }
  }
  
  public final boolean isAfter(T paramT)
  {
    if (paramT == null) {}
    while (this.a.compare(paramT, this.b) >= 0) {
      return false;
    }
    return true;
  }
  
  public final boolean isAfterRange(Range<T> paramRange)
  {
    if (paramRange == null) {
      return false;
    }
    return isAfter(paramRange.c);
  }
  
  public final boolean isBefore(T paramT)
  {
    if (paramT == null) {}
    while (this.a.compare(paramT, this.c) <= 0) {
      return false;
    }
    return true;
  }
  
  public final boolean isBeforeRange(Range<T> paramRange)
  {
    if (paramRange == null) {
      return false;
    }
    return isBefore(paramRange.b);
  }
  
  public final boolean isEndedBy(T paramT)
  {
    if (paramT == null) {}
    while (this.a.compare(paramT, this.c) != 0) {
      return false;
    }
    return true;
  }
  
  public final boolean isNaturalOrdering()
  {
    return this.a == a.a;
  }
  
  public final boolean isOverlappedBy(Range<T> paramRange)
  {
    if (paramRange == null) {}
    while ((!paramRange.contains(this.b)) && (!paramRange.contains(this.c)) && (!contains(paramRange.b))) {
      return false;
    }
    return true;
  }
  
  public final boolean isStartedBy(T paramT)
  {
    if (paramT == null) {}
    while (this.a.compare(paramT, this.b) != 0) {
      return false;
    }
    return true;
  }
  
  public final String toString()
  {
    if (this.e == null) {
      this.e = ("[" + this.b + ".." + this.c + "]");
    }
    return this.e;
  }
  
  public final String toString(String paramString)
  {
    return String.format(paramString, new Object[] { this.b, this.c, this.a });
  }
  
  static enum a
    implements Comparator
  {
    private a() {}
    
    public final int compare(Object paramObject1, Object paramObject2)
    {
      return ((Comparable)paramObject1).compareTo(paramObject2);
    }
  }
}


/* Location:              /home/merong/decompile/hackery-dex2jar.jar!/org/apache/commons/lang3/Range.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */