Class NumberRange

java.lang.Object
fc.util.Range
fc.util.NumberRange

public class NumberRange extends Range
A range of integral values.

Note, many methods in this particular class have the same signatures as in the apache commons.lang package but the implementation was strictly clean-room.

Thread Safety: This class is not thread safe in the face of any concurrent modification (via changing the start/end numbers or union/intersection operations).

  • Constructor Summary

    Constructors
    Constructor
    Description
    NumberRange(long start, long end)
    Constructs a number range between the specified start and end numbers (both inclusive).
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
     
    long
    Get the end number for this number range.
    long
    Returns the size of this range which is calculated as the (endnumber - startnumber) + 1 - i.e., the number of slots in this range, start and end inclusive.
    long
    Get the start number for this number range
    int
     
    boolean
    inRange(long c)
    Is the passed in number inside this range
    static void
    main(String[] args)
     
    void
    setEnd(long c)
    Sets the end number for this number range
    void
    setStart(long c)
    Set the start number for this number range
    Output a string representation of the number range

    Methods inherited from class Range

    isNegated, setNegated

    Methods inherited from class Object

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

    • NumberRange

      public NumberRange(long start, long end)
      Constructs a number range between the specified start and end numbers (both inclusive).
      Throws:
      IllegalArgumentException - if the end number is lesser (via a < comparison) than the start number (equal to the start number is ok)
  • Method Details

    • getStart

      public long getStart()
      Get the start number for this number range
    • getEnd

      public long getEnd()
      Get the end number for this number range.
    • inRange

      public boolean inRange(long c)
      Is the passed in number inside this range
    • setEnd

      public void setEnd(long c)
      Sets the end number for this number range
      Parameters:
      c - the end number
      Throws:
      IllegalArgumentException - if the end number is lesser (via a < comparison) than the current start number (equal to the start number is ok)
    • setStart

      public void setStart(long c)
      Set the start number for this number range
      Throws:
      IllegalArgumentException - if the start number is greater (via a > comparison) than the current end number (equal to the end number is ok)
    • getSize

      public long getSize()
      Returns the size of this range which is calculated as the (endnumber - startnumber) + 1 - i.e., the number of slots in this range, start and end inclusive.
    • toString

      public String toString()
      Output a string representation of the number range
      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
    • main

      public static void main(String[] args)