/* ************************
* Name : Eugene Krapivin *
* ID : 306255084 *
* ***********************/
package person;
import java.io.Serializable;
import java.util.List;
import java.util.Stack;
import java.util.Vector;
import nodes.MileStone;
import trees.MileStoneTree;
public class Person implements Serializable
{
private static final long serialVersionUID = 9163027217354401625L;
private String firstName;
private String lastName;
public MileStoneTree lifeHistory;
/**
* Class constructor
* <p>
* This constructor allows to build the person with a specific milestone at
* root, which is not necessarily his birthday.
*
* @param firstName
* The first name of the person
* @param lastName
* the last name of the person
* @param m
* the root milestone of this person
*/
public Person(String firstName, String lastName, MileStone m)
{
this.firstName = firstName;
this.lastName = lastName;
this.lifeHistory = new MileStoneTree(m);
}
public Person(String firstName, String lastName, Vector<MileStone> list)
{
this.firstName = firstName;
this.lastName = lastName;
this.lifeHistory = new MileStoneTree(list);
}
/**
* Insertion method
* <p>
* this method inserts a new milestone in to the person. Since the
* lifeHistory is an extended Interval Tree, this method uses the insertion
* methods of IntervalTree
*
* @param low
* The lower boundary of the milestone
* @param high
* The higher boundary of the milestone
* @param place
* The place the milestone took place at
* @param description
* The description of this milestone
*/
public void addMilestone(int low, int high, MileStonePlace place,
String description)
{
lifeHistory.insert(new MileStone(low, high, place, description));
}
/**
* Insertion method
* <p>
* This method receives a milestone to insert to the person It uses the
* interval tree insertion method.
*
* @param m
* The milestone to insert to the Person
*/
public void addMilestone(MileStone m)
{
lifeHistory.insert(m);
}
public void addMileStone(Vector<MileStone> list)
{
synchronized (this)
{
lifeHistory.insert(list);
}
}
/**
* Removal method.
* <p>
* This method users the interval tree removal method and delegates to it
* the low boundary to remove from the tree
*
* @param low
* The year to remove from the tree
*/
public void removeMilestone(int low)
{
if (lifeHistory != null)
{
lifeHistory.remove(low);
}
}
/**
* Getter method for first name
*
* @return first name
*/
public String getFirstName()
{
return firstName;
}
/**
* Setter method for first name
*
* @param firstName
* The first name to set
*/
public void setFirstName(String firstName)
{
this.firstName = firstName;
}
/**
* Getter method for the last name
*
* @return The last name
*/
public String getLastName()
{
return lastName;
}
/**
* Setter method for last name
*
* @param lastName
* The last name to set
*/
public void setLastName(String lastName)
{
this.lastName = lastName;
}
/**
* Getter method for the full name
*
* @return Full name of the person
*/
public String getName()
{
return getFirstName() + " " + getLastName();
}
/**
* to String method
*
* @return the name in format of "lastname, firstname"
*/
@Override
public String toString()
{
return lastName + ", " + firstName;// + "\n" + lifeHistory.toString();
}
/**
* return the whole life history of the person
*
* @return the string representing the persons information
*/
public String lifeHistoryToString()
{
return lastName + ", " + firstName + "\n" + lifeHistory.toString();
}
public Vector<MileStone> returnMileStoneList()
{
return lifeHistory.returnNodes();
}
}