Class FloatRange

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

public class FloatRange extends Object
A range between 2 positive floats.
  • Field Details

    • from

      public float from
    • to

      public float to
    • EMPTY_FLOAT_RANGE

      public static final FloatRange EMPTY_FLOAT_RANGE
      The special shared instance for the empty range.

      EMPTY_FLOAT_RANGE.size() returns 0.

  • Constructor Details

    • FloatRange

      public FloatRange(float from, float to)
      A range representing [from; to].

      Use the EMPTY_FLOAT_RANGE instance for empty range.

      Parameters:
      from - Must be >= 0
      to - Must be > from
      Throws:
      IllegalArgumentException - If from==to
  • Method Details

    • isEmpty

      public boolean isEmpty()
    • size

      public float size()
      Get the size of the range.
      Returns:
      (to - from), or 0 for the EMPTY_RANGE.
    • getCenter

      public float getCenter()
      The center of the range.
      Returns:
      (to-from)/2 + from
    • contains

      public boolean contains(float x, boolean excludeUpperBound)
      Check if value is within the range.
      Parameters:
      x -
      excludeUpperBound - If true, return false if x == this.to.
      Returns:
    • contains

      public boolean contains(FloatRange fr, boolean excludeUpperBound)
      Check if specified range is within this float range.
      Parameters:
      fr -
      excludeUpperBound - If true, fr.to must be < this.to to be considered as contained.
      Returns:
    • getIntersectRange

      public FloatRange getIntersectRange(FloatRange rg)
      Parameters:
      rg -
      Returns:
      Can return the EMPTY_RANGE if no intersection.
    • intersects

      public boolean intersects(FloatRange rg)
      Check if specified range intersects with this range.

      Note: [2;4] and [4;7] does NOT intersect.

      Parameters:
      rg -
      Returns:
    • getTransformed

      public FloatRange getTransformed(float fromOffset, float toOffset)
      Get a new range with bounds modified.

      Modifying the empty range returns the empty range.

      Parameters:
      fromOffset -
      toOffset -
      Returns:
    • getTransformed

      public FloatRange getTransformed(float offset)
      Get a new range with bounds modified by adding offset.

      Modifying the empty range returns the empty range.

      Parameters:
      offset -
      Returns:
    • getUnion

      public FloatRange getUnion(FloatRange r)
      Get a new range made from the lowest and highest bounds from this object and r.

      If one of the range is empty, return the empty range.

      Parameters:
      r -
      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