Class Digit

    • Constructor Detail

      • Digit

        public Digit​(int value)
        Initialize this digit to the specified value.
        Parameters:
        value - the value of this digit
        Throws:
        IllegalArgumentException - if value is not in the range 0 to 9
      • Digit

        public Digit​(Digit other)
        Initialize this digit by copying another digit.
        Parameters:
        other - the digit to copy
    • Method Detail

      • value

        public int value()
        Get the value of this digit
        Returns:
        the value of this digit
      • get

        public static Digit get​(int i)
        Returns the digit having the specified value.
        Parameters:
        i - the value of the digit
        Returns:
        the digit having the specified value
        Throws:
        IllegalArgumentException - if value is not in the range 0 to 9
      • set

        public final Digit set​(int value)
        Sets this digit to the specified value.
        Parameters:
        value - the value of this digit
        Returns:
        a reference to this Digit
        Throws:
        IllegalArgumentException - if value is not in the range 0 to 9
      • allDigits

        public static List<Digit> allDigits()
        Returns a new list containing all 10 digits (from 0 to 9).
        Returns:
        a new list containing all 10 digits (from 0 to 9)
      • compareTo

        public int compareTo​(Digit other)
        Compares this digit to another digit for order. The result is:
        • a positive integer if the value of this digit is greater than the value of the other digit
        • a negative integer if the value of this digit is less than the value of the other digit
        • zero if the values of the two digits are equal
        Specified by:
        compareTo in interface Comparable<Digit>
        Parameters:
        other - a digit
        Returns:
        a positive integer, negative integer, or zero if the value of this digit is greater than, less than, or equal to the value of the other digit
      • hashCode

        public int hashCode()
        Returns a hash code for this digit;
        Overrides:
        hashCode in class Object
        Returns:
        a hash code for this digit
      • equals

        public boolean equals​(Object obj)
        Compares this digit to an object for equality. Returns true if and only if obj is a Digit with the same value as this digit.
        Overrides:
        equals in class Object
        Parameters:
        obj - the object to compare
        Returns:
        true if this digit is equal to obj, false otherwise
      • toString

        public String toString()
        Returns the string representation of this digit.
        Overrides:
        toString in class Object
        Returns:
        a string representation of this digit