Class Range

  • All Implemented Interfaces:
    java.lang.Comparable<Range>, java.lang.Iterable<java.lang.Integer>

    public class Range
    extends java.lang.Object
    implements java.lang.Comparable<Range>, java.lang.Iterable<java.lang.Integer>
    A class for holding a minimum and maximum signed int values that define a range.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      int max
      The range's maximum extent (inclusive).
      int min
      The range's minimum extent.
    • Constructor Summary

      Constructors 
      Constructor Description
      Range​(int min, int max)
      Creates a range whose extent is from min to max.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compareTo​(Range other)  
      boolean contains​(int value)
      Returns true if the value is within the ranges extent.
      boolean equals​(java.lang.Object obj)  
      int hashCode()  
      java.util.Iterator<java.lang.Integer> iterator()  
      long size()
      Returns the range's size.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Field Detail

      • min

        public int min
        The range's minimum extent.
      • max

        public int max
        The range's maximum extent (inclusive).
    • Constructor Detail

      • Range

        public Range​(int min,
                     int max)
        Creates a range whose extent is from min to max.
        Parameters:
        min - the minimum extent.
        max - the maximum extent (inclusive).
        Throws:
        java.lang.IllegalArgumentException - if max is less than min.
    • Method Detail

      • compareTo

        public int compareTo​(Range other)
        Specified by:
        compareTo in interface java.lang.Comparable<Range>
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • contains

        public boolean contains​(int value)
        Returns true if the value is within the ranges extent.
        Parameters:
        value - the value to check.
        Returns:
        true if the value is within the ranges extent.
      • size

        public long size()
        Returns the range's size.
        Returns:
        the size
      • iterator

        public java.util.Iterator<java.lang.Integer> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<java.lang.Integer>