Class Digit
- java.lang.Object
-
- Digit
-
- All Implemented Interfaces:
Comparable<Digit>
public class Digit extends Object implements Comparable<Digit>
A digit whose value is always in the range 0 to 9.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static List<Digit>
allDigits()
Returns a new list containing all 10 digits (from 0 to 9).int
compareTo(Digit other)
Compares this digit to another digit for order.boolean
equals(Object obj)
Compares this digit to an object for equality.static Digit
get(int i)
Returns the digit having the specified value.int
hashCode()
Returns a hash code for this digit;Digit
set(int value)
Sets this digit to the specified value.String
toString()
Returns the string representation of this digit.int
value()
Get the value of this 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 interfaceComparable<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;
-
equals
public boolean equals(Object obj)
Compares this digit to an object for equality. Returns true if and only ifobj
is aDigit
with the same value as this digit.
-
-