Class LongRange

java.lang.Object
org.jjazz.utilities.api.LongRange

public class LongRange extends Object
A basic long integer (zero or positive) interval.

This is an immutable class.

  • Field Details

    • EMPTY_LONG_RANGE

      public static final LongRange EMPTY_LONG_RANGE
      The special shared instance for the empty range.
    • from

      public final long from
    • to

      public final long to
  • Constructor Details

    • LongRange

      public LongRange(long from, long to)
      A range representing [from; to].
      Parameters:
      from - Must be >= 0
      to - Must be >= from
  • Method Details

    • isEmpty

      public boolean isEmpty()
    • size

      public long size()
      Get the size of the range.
      Returns:
      (to - from + 1), or 0 for the EMPTY_LONG_RANGE.
    • contains

      public boolean contains(long x)
      Check if value is within the range.
      Parameters:
      x -
      Returns:
    • contains

      public boolean contains(LongRange r)
      Check if specified range is contained in this range.
      Parameters:
      r -
      Returns:
    • getIntersectRange

      public LongRange getIntersectRange(LongRange r)
      Parameters:
      r -
      Returns:
      Return the EMPTY_LONG_RANGE if no intersection.
    • intersects

      public boolean intersects(LongRange r)
      Check if specified range intersects with this range.

      Note: [2;4] and [4;7] intersects.

      Parameters:
      r -
      Returns:
    • getTransformed

      public LongRange getTransformed(long fromOffset, long toOffset)
      Get a new range with bounds modified by adding fromOffset and toOffset.

      If this object is the the empty range, just return the empty range.

      Parameters:
      fromOffset -
      toOffset -
      Returns:
    • getTransformed

      public LongRange getTransformed(long offset)
      Get a new range with bounds modified by adding offset.

      If this object is the the empty range, just return the empty range.

      Parameters:
      offset -
      Returns:
    • toString

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

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

      public int hashCode()
      Overrides:
      hashCode in class Object