Class Range<T extends Comparable<T>>

java.lang.Object
org.jppf.utils.Range<T>
Type Parameters:
T - the type of values handled by this object.

public class Range<T extends Comparable<T>> extends Object
Instances of this class represent a range of values.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Range(T value)
    Initialize this range with the specified single value used as both lower and upper bounds.
    Range(T lower, T upper)
    Initialize this range with the specified lower and upper bounds.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
     
    Get the lower bound.
    Get the upper bound.
    int
     
    boolean
    includes(Range<T> other)
    Determine whether this range is a superset of the specified other.
    More formally, this method returns true if other.lower >= this.lower and other.upper <= this.upper.
    Construct a Range that represents the intersection of this range and the other specified one.
    This is equivalent to building a range object with its lower bound equal to max(this.lower, other.lower) and its upper bound equal to min(this.upper, other.upper)
    boolean
    intersects(Range<T> other)
    Determine whether this range and the specified one have at least one value in common.
    boolean
    intersects(Range<T> other, boolean includeBounds)
    Determine whether this range and the specified one have at least one value in common.
    boolean
    Determine if the specified value is included in this range.
    boolean
    isValueInRange(T value, boolean includeBounds)
    Determine if the specified value is included in this range.
    merge(Range<T> other)
    Construct a Range that is made of all values between the lowest lower bound and the highest upper bound of this range and the other specified range.
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Range

      public Range(T value)
      Initialize this range with the specified single value used as both lower and upper bounds.
      Parameters:
      value - the value to use for the bounds.
    • Range

      public Range(T lower, T upper)
      Initialize this range with the specified lower and upper bounds.
      Parameters:
      lower - the lower bound.
      upper - the upper bound.
  • Method Details

    • isValueInRange

      public boolean isValueInRange(T value)
      Determine if the specified value is included in this range.
      Parameters:
      value - the value to check.
      Returns:
      true if the value is in range, false otherwise.
    • isValueInRange

      public boolean isValueInRange(T value, boolean includeBounds)
      Determine if the specified value is included in this range.
      Parameters:
      value - the value to check.
      includeBounds - specifies whether the bounds of this range shoud be included in the comparisons.
      Returns:
      true if the value is in range, false otherwise.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getLower

      public T getLower()
      Get the lower bound.
      Returns:
      the lower bound.
    • getUpper

      public T getUpper()
      Get the upper bound.
      Returns:
      the upper bound.
    • intersects

      public boolean intersects(Range<T> other)
      Determine whether this range and the specified one have at least one value in common.
      Parameters:
      other - the range to check against.
      Returns:
      true if and only if part of other overlaps this range.
    • intersects

      public boolean intersects(Range<T> other, boolean includeBounds)
      Determine whether this range and the specified one have at least one value in common.
      Parameters:
      other - the range to check against.
      includeBounds - specifies whether the bounds of each range shoud be included in the comparisons.
      Returns:
      true if and only if part of other overlaps this range.
    • includes

      public boolean includes(Range<T> other)
      Determine whether this range is a superset of the specified other.
      More formally, this method returns true if other.lower >= this.lower and other.upper <= this.upper.
      Parameters:
      other - the range to check against.
      Returns:
      true if and only if this range includes all the values from other.
    • merge

      public Range<T> merge(Range<T> other)
      Construct a Range that is made of all values between the lowest lower bound and the highest upper bound of this range and the other specified range. This works even if the ranges are completely disjointed (i.e if this.intersects(other) == false)
      This is equivalent to building a range object with its lower bound equal to min(this.lower, other.lower) and its upper bound equal to max(this.upper, other.upper)
      Parameters:
      other - the range to merge with.
      Returns:
      a new Range object that encompasses all values between the lowest lower bound and the highest upper bound, or a copy of this range if the other is null.
    • intersection

      public Range<T> intersection(Range<T> other)
      Construct a Range that represents the intersection of this range and the other specified one.
      This is equivalent to building a range object with its lower bound equal to max(this.lower, other.lower) and its upper bound equal to min(this.upper, other.upper)
      Parameters:
      other - the range to check against.
      Returns:
      a Range object representing the intersection of 2 ranges, or null if other is null or the ranges are disjointed (i.e if this.intersects(other) == false).
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object