K - This parameter is a generic for the type of key each element must have.
Please note that K must implement the Comparable interface, or
a super class of K must implement the Comparable interface.public class Person<K extends java.lang.Comparable<? super K>> extends java.lang.Object implements KeyedElementInterface<K>
| Modifier and Type | Field and Description |
|---|---|
private int |
birthDay |
private int |
birthMonth |
private int |
birthYear |
private java.lang.String |
firstName |
private K |
key |
private java.lang.String |
lastName |
private static int |
NAME_LENGTH |
private static java.util.Random |
randomNumberGenerator |
| Modifier | Constructor and Description |
|---|---|
|
Person(K key)
This is the constructor for the class.
|
private |
Person(java.lang.String firstName,
java.lang.String lastName,
int birthYear,
int birthMonth,
int birthDay,
K key)
This constructor is used by the copy method of this class
|
| Modifier and Type | Method and Description |
|---|---|
KeyedElementInterface<K> |
copy()
This method makes a deep copy of the KeyedElement.
|
private static int |
createRandomBirthDay(int month,
int year) |
private static int |
createRandomBirthMonth() |
private static int |
createRandomBirthYear() |
private static java.lang.String |
createRandomName(int length) |
boolean |
equals(java.lang.Object obj) |
int |
getBirthDay() |
int |
getBirthMonth() |
int |
getBirthYear() |
java.lang.String |
getFirstName() |
K |
getKey()
This method is the implementation of the KeyedElement interface
|
java.lang.String |
getLastName() |
int |
hashCode() |
private static boolean |
isLeapYear(int year) |
void |
setBirthDay(int birthDay) |
void |
setBirthMonth(int birthMonth) |
void |
setBirthYear(int birthYear) |
void |
setFirstName(java.lang.String firstName) |
void |
setLastName(java.lang.String lastName) |
java.lang.String |
toString() |
private static final int NAME_LENGTH
private static final java.util.Random randomNumberGenerator
private java.lang.String firstName
private java.lang.String lastName
private int birthYear
private int birthMonth
private int birthDay
private Person(java.lang.String firstName,
java.lang.String lastName,
int birthYear,
int birthMonth,
int birthDay,
K key)
firstName - The person's first namelastName - The person's last namebirthYear - The person's birth yearbirthMonth - The person's birth monthbirthDay - The person's birth daykey - The person's unique keypublic Person(K key)
id - This parameter will be specified by the user. It is intended to be a
unique Key for each instance of the Person class. It is up to the user
to assure the uniqueness of the Key.public K getKey()
getKey in interface KeyedElementInterface<K extends java.lang.Comparable<? super K>>public KeyedElementInterface<K> copy()
KeyedElementInterfacecopy in interface KeyedElementInterface<K extends java.lang.Comparable<? super K>>public java.lang.String toString()
toString in class java.lang.Objectpublic java.lang.String getFirstName()
public void setFirstName(java.lang.String firstName)
public java.lang.String getLastName()
public void setLastName(java.lang.String lastName)
public int getBirthYear()
public void setBirthYear(int birthYear)
public int getBirthMonth()
public void setBirthMonth(int birthMonth)
public int getBirthDay()
public void setBirthDay(int birthDay)
public int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object obj)
equals in class java.lang.Objectprivate static java.lang.String createRandomName(int length)
private static int createRandomBirthYear()
private static int createRandomBirthMonth()
private static int createRandomBirthDay(int month,
int year)
private static boolean isLeapYear(int year)