public final class PhoneNumber extends Object implements Comparable<PhoneNumber>
The class ensures that there is only one PhoneNumber
instance
for each unique phone number. Clients should use the getInstance
method to obtain a PhoneNumber
instance.
Modifier and Type | Method and Description |
---|---|
int |
compareTo(PhoneNumber other)
Compares two phone numbers for order.
|
boolean |
equals(Object obj)
Compares two phone numbers for equality.
|
short |
getAreaCode()
Returns the area code.
|
short |
getExchangeCode()
Returns the exchange code.
|
static PhoneNumber |
getInstance(int areaCode,
int exchangeCode,
int stationCode)
Get a phone number having the given area code, exchange code, and station
code.
|
short |
getStationCode()
Returns the station code.
|
int |
hashCode()
Returns a hash code for this phone number.
|
String |
toString()
Returns a string representation of this phone number.
|
public static PhoneNumber getInstance(int areaCode, int exchangeCode, int stationCode)
areaCode
- the area code; must be in the range 0-999exchangeCode
- the exchange code; must be in the range 0-999stationCode
- the station code; must be in the range 0-9999IllegalArgumentException
- if any of the area code, exchange code or station code are
out of rangepublic short getAreaCode()
public short getExchangeCode()
public short getStationCode()
public String toString()
public int hashCode()
public boolean equals(Object obj)
public int compareTo(PhoneNumber other)
compareTo
in interface Comparable<PhoneNumber>
other
- the phone number to be compared