FileDocCategorySizeDatePackage
Individual.javaAPI DocExample11928Tue Dec 08 01:21:00 GMT 1998ProblemDomain

Individual

public class Individual extends Object
stereotype
role
note
Individuals are the core components that make up the Family objects and record details about the Individual.

Fields Summary
Birth
birth
Death
death
Family
childOf
private int
reference
private String
givenNames
private String
familyName
private String
sex
public static final String
MALE
public static final String
FEMALE
public static final String
INDETERMINATE
private Vector
notes
private Vector
spouseInList
private static int
lastReference
private static Hashtable
All
Constructors Summary
public Individual()

    this(Individual.getNextReference());
public Individual(int reference)

    this.reference = reference;
    //Put in hash table
    Individual.All.put(new Integer(reference), this);
    
public Individual(int reference, String FamilyName, String GivenNames, String sex, Birth birth, Death death)

    this(reference);
    this.setFamilyName(FamilyName);
    this.setGivenNames(GivenNames);
    this.setSex(sex);
    this.setBirth(birth);
    this.setDeath(death);
    ++lastReference;
    
Methods Summary
public voidaddNote(ProblemDomain.Note comments)

note
Add a note to the Individual.

    if (this.notes == null) notes = new Vector(1);
    notes.addElement(comments); return;
public voiddelete()

note
Deletes itself from the main list of Individuals by removing the record identified by its own reference id.

    //Remove from hash table
    Individual.All.remove(new Integer(this.getReference()));
public static java.util.EnumerationgetAll()

note
A static method to return all the Individual records as an Enumeration.

            
      return All.elements();
public BirthgetBirth()

note
Return the Birth object that records the birth of the Individual.

return this.birth;
public FamilygetChildOf()

note
Return the Family to which this Individual is a child of.

return this.childOf;
public DeathgetDeath()

note
Return the Death object that records the death of the Individual.

return this.death;
public java.lang.StringgetDetails()

note
Returns the details of the Individual as one string, with '\n' denoting carriage returnss - this method is used to display the Individual to the screen,

    String s = new String();
    s = s + "Reference No.: " + Integer.toString(this.reference) + "\n";
    if ((this.familyName + this.givenNames) != "")
      s = s + " NAME " + this.givenNames + " " + this.familyName + "\n";
    if (this.birth != null) s = s + "\nBirth: \n     " + this.birth.getDetails();
    if (this.death != null) s = s + "\nDeath: \n     " + this.death.getDetails();
    if (this.childOf != null) s = s + "Child of Family: " + this.childOf.getDisplayName() + "\n";
    if (this.spouseInList != null) {
      Enumeration e = this.spouseInList.elements();
      Family f;
      s = s + "Parent of families: \n";
      while (e.hasMoreElements()) {
        f = (Family)(e.nextElement());
        s = s + f.getDisplayName() + "\n";}
    }
    return s;
  
public java.lang.StringgetFamilyName()

note
Return the family name - the family name is usually the surname of the husband of the family.

return this.familyName;
public java.lang.StringgetGivenNames()

note
Returns the given names of the individual - a string of names they are or were known by.

return this.givenNames;
public static ProblemDomain.IndividualgetIndividual(int reference)

note
Static method to return an Individual at the specific place in the Individual hashtable.

    return (Individual)(Individual.All.get(new Integer(reference)));
public java.lang.StringgetName()

note
Returns the Individuals name.

    return givenNames + " " + familyName;
  
protected static intgetNextReference()

note
Static method to return a number to be used as the reference number for the new Individual.

                 
      return ++lastReference;
public java.util.EnumerationgetNotes()

note
Return all the notes for this Individual as an Enumeration

    return notes.elements();
public intgetReference()

note
Returns the reference number of this Individual.

return this.reference;
public java.lang.StringgetSex()

note
Returns the sex of the Individual.

      
     return this.sex;
public java.util.EnumerationgetSpouseInList()

note
Return the Families that this Individual is or has been a spouse of.


             
     
    return this.spouseInList.elements();
  
public java.lang.StringgetTextRecordIdentifier()

note
Returns the text record identifier required for the data field to be recognised when read back in from file.

    return "@I" + java.lang.Integer.toString(this.reference) + "@ INDI";
public booleanisParent()

note
Return whether or not the Individual is a parent of a Family.

    if(spouseInList == null) return false;
    else return true;
  
protected voidlinkAsChild(ProblemDomain.Family f)

note
Link this Individual to a Family. Must be called after Individual added as child to Family

    // check it has already been added at other end
    if (f.hasAsChild(this)) {
      // Remove this from current family if there is one
      if (this.childOf != null) this.childOf.removeChild(this);
      // link
      this.childOf = f;}
    else {
      // 'this' is not a child of the family f.
      throw new InvalidParameterException();}
    return;
protected voidlinkAsSpouse(ProblemDomain.Family f)

note
Link the Inidividual as a spouse of the Family that is passed to the method. Must be called after Individual added as spouse to Family

    if (f.hasAsSpouse(this)) {
      if (this.spouseInList == null) this.spouseInList = new Vector(1);
      this.spouseInList.addElement(f);}
    else {
      // 'this' is not a spouse of the family f.
      throw new InvalidParameterException();}
    return;
public voidremoveNote(ProblemDomain.Note comments)

note
Remove the note if you know the actual object to remove.

    notes.removeElement(comments); return;
public voidremoveNoteAt(int i)

note
Remove the note at a specific position.

    notes.removeElementAt(i); return;
public voidreset()

 lastReference = 0; 
public voidsetBirth(ProblemDomain.Birth b)

note
Set up the Birth object for this Individual.

this.birth = b; return;
public voidsetDeath(ProblemDomain.Death d)

note
Set up the Death object for this Individual.

this.death = d; return;
public voidsetFamilyName(java.lang.String s)

note
Set the family name.

this.familyName = s; return;
public voidsetGivenNames(java.lang.String s)

note
Set the given names for this Individual, the different names are seperated by spaces.

this.givenNames = s; return;
protected static voidsetNextReference(int n)

note
Static method to reset or change the reference number.

    if (lastReference < n) lastReference = n-1; return;
public voidsetNoteAt(int i, ProblemDomain.Note s)

note
Add/change the note in the comments at the index passed to the method.

    notes.setElementAt(s,i); return;
public voidsetSex(java.lang.String s)

note
Set the sex of the Inidividual. There is the flexibility that if you do not know the sex and you canot tell the sex by the name, you can enter I for Indeterminate.

    if (s.equals("M") || s.equals("F") || s.equals("I"))
      this.sex = s;
    else
      throw new InvalidParameterException();
    return;
public static ProblemDomain.IndividualtestObject()

    return new Individual(
      1,
      "Bloggs",
      "Joe",
      MALE,
      Birth.testObject(),
      null);
  
public static ProblemDomain.IndividualtestObject2()

    return new Individual(
      2,
      "Smith",
      "Mary",
      FEMALE,
      Birth.testObject(),
      null);
  
public static ProblemDomain.IndividualtestObject3()

    return new Individual(
      3,
      "Bloggs",
      "John",
      MALE,
      Birth.testObject(),
      null);
  
public static ProblemDomain.IndividualtestObject4()

    return new Individual(
      4,
      "Bloggs",
      "Jane",
      FEMALE,
      Birth.testObject(),
      null);
  
public static ProblemDomain.IndividualtestObject5()

    return new Individual(
      5,
      "Winters",
      "Susan",
      FEMALE,
      Birth.testObject(),
      null);
  
public static ProblemDomain.IndividualtestObject6()

    return new Individual(
      6,
      "Bloggs",
      "Robert",
      MALE,
      Birth.testObject(),
      null);
  
public java.lang.StringtoString()

    return this.toString("");
public java.lang.StringtoString(java.lang.String sn)

note
Outputs string for the Individual. Each line begins with a String defined by the parameter. If this string converts to an integer, the prefix for contained objects will be incremented by 1.

    String s = sn + " " + getTextRecordIdentifier() + "\n";
    try {
      sn = Integer.toString(Integer.parseInt(sn)+1);}
    catch (NumberFormatException e) {
      sn = sn + "  ";}
    s = s + sn + " " + "REFN P" + Integer.toString(this.reference) + "\n";
    if ((this.familyName + this.givenNames) != "")
      s = s + sn + " " + "NAME " + this.givenNames + " /" + this.familyName + "/\n";
    s = s + sn + " " + "SEX " + getSex() + "\n";
    if (this.birth != null) s = s + this.birth.toString(sn);
    if (this.death != null) s = s + this.death.toString(sn);
    if (this.childOf != null) s = s + sn + " " + "FAMC @F" + Integer.toString(this.childOf.getReference()) + "@\n";
    if (this.spouseInList != null) {
      Enumeration e = this.spouseInList.elements();
      Family f;
      while (e.hasMoreElements()) {
        f = (Family)(e.nextElement());
        s = s + sn + " " + "FAMS @F" + Integer.toString(f.getReference()) + "@\n";}
    }
    return s;
  
protected voidunlinkAsChild(ProblemDomain.Family f)

note
Remove the link between this Individual and the Family it is a child of. Must be called after Individual removed as child of Family

    if (!f.hasAsChild(this)) {
      if (this.childOf == f) {
        this.childOf = null;}
      else
        // childOf references different family
        throw new InvalidParameterException();}
    else {
      // 'this' is still a child of the family f.
      throw new InvalidParameterException();}
    return;
protected voidunlinkAsSpouse(ProblemDomain.Family f)

note
Remove the Individual from the Family that they are a spouse of. Must be called after Individual removed as spouse to Family

    // check 'this' is not still a spouse
    if (!f.hasAsSpouse(this)) {
      this.spouseInList.removeElement(f);}
    else {
      // 'this' is still a spouse of the family f.
      throw new InvalidParameterException();}
    return;