FileDocCategorySizeDatePackage
Family.javaAPI DocExample13691Tue Dec 08 01:21:00 GMT 1998ProblemDomain

Family

public class Family extends Object
version
0.2
author
Tim Shelley
note
The Family class is the main class in the Problem Domain, and is made up of Individuals.

Fields Summary
Marriage
ceremony
Divorce
decree
Individual
wife
Individual
husband
private int
reference
private String
displayName
private boolean
notSolemnised
private Vector
children
private Vector
notes
private static int
lastReference
private static Hashtable
All
Constructors Summary
public Family()
CONSTRUCTORS

    this(Family.getNextReference());
public Family(int reference)
CONSTRUCTORS

    this.reference = reference;
    //Put in hash table
    Family.All.put(new Integer(reference), this);
    
public Family(int reference, Individual husband, Individual wife, Marriage ceremony, Divorce decree)
CONSTRUCTORS

    this(reference);
    this.setHusband(husband);
    this.setWife(wife);
    this.setMarriage(ceremony);
    this.setDivorce(decree);
    lastReference++;
    
Methods Summary
public voidaddChild(ProblemDomain.Individual p)

note
Add the passed Individual as a child to this family.
param
Individual - the child to be added

    if (this.children == null) children = new Vector(1);
    this.children.addElement(p);
    // link from other end
    p.linkAsChild(this);
  
public voidaddNote(ProblemDomain.Note comments)

note
Add notes about the family

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

note
Method to remove itself from the Hashtable of Families

    // Remove from hash table
    Family.All.remove(new Integer(this.getReference()));
public java.util.VectorgetAncestors(int spaces)

note
Create a list of ancestors for the family.
return
Vector - compiled list of ancestors

    Vector storage = null;
    Vector temp;
    Enumeration list;
    Family family;
    String name;
    String gap = new String();

    for(int i=0;i<spaces;i++) gap = gap + "     ";
    if(spaces == 0) {
      if(storage == null) storage = new Vector();
      storage.addElement("Fathers Side:\n");
    }
    if(getHusband() != null) {
      if(storage == null) storage = new Vector();
      name = gap + getHusband().getName();
      if(getHusband().getName().equals("null null")) name = gap + "Unknown";
      storage.addElement(name);
      if(getHusband().getChildOf() != null) {
        temp = getHusband().getChildOf().getAncestors(spaces+1);
        if(temp != null) {
          list = temp.elements();
          while(list.hasMoreElements()) {
            storage.addElement(list.nextElement());
          }
        }
      }
    }
    if(spaces == 0) {
      if(storage ==  null) storage = new Vector();
      storage.addElement("\n\nMothers Side:\n");
    }
    if(getWife() != null) {
      if(storage == null) storage = new Vector();
      name = gap + getWife().getName();
      if(getWife().getName().equals("null null")) name = gap + "Unknown";
      storage.addElement(name);
      if(getWife().getChildOf() != null) {
        temp = getWife().getChildOf().getAncestors(spaces+1);
        if(temp != null) {
          list = temp.elements();
          while(list.hasMoreElements()) {
            storage.addElement(list.nextElement());
          }
        }
      }
    }
    return storage;
  
public java.util.EnumerationgetChildren()

note
Return all the children linked to this family as an Enumeration.


           
     
    return this.children.elements();
  
public java.util.VectorgetDescendants(java.lang.String parentsName, int spaces, boolean showSpouse)

note
Create a list of descendents for the family.
return
Vector - compiled list of ancestors

    Enumeration kids;
    Enumeration subkids;
    Individual person;
    Individual child;
    Vector descendantList = null;
    Vector subList = null;
    String individualsName = new String();
    String childsName = new String();
    String gaps = new String();

    for(int i=0;i<spaces;i++) {
      gaps = gaps + "    ";
    }

    if(children != null) {
      kids = getChildren();
      while(kids.hasMoreElements()) {
        if(descendantList == null) descendantList = new Vector();
        person = (Individual)kids.nextElement();
        individualsName = gaps + person.getGivenNames() + " " + person.getFamilyName();
        if(showSpouse) {
          individualsName = individualsName + " = " + parentsName;
        }
        descendantList.addElement(individualsName);
        if(person.isParent()) {
          subkids = person.getSpouseInList();
          if(subkids != null)
          {
            while(subkids.hasMoreElements()) {
              if(subList == null) subList = new Vector();
              subList = ((Family)subkids.nextElement()).getDescendants(person.getName(),spaces+1,showSpouse);
              if(subList != null) {
                Enumeration l = subList.elements();
                while(l.hasMoreElements()) {
                  childsName = (String)l.nextElement();
                  descendantList.addElement(childsName);
                }
              }
            }
          }
        }
      }
    }
    return descendantList;
  
public java.lang.StringgetDetails()

note
Return the family details as a String with the /n character to show where a carriage return should be.
return
String - details of the family

    String s = new String();

    s = s + "Reference No.:" + Integer.toString(this.reference) + "\n";
    if (this.husband != null) s = s + "Huband: " + this.husband.getName() + "\n";
    if (this.wife != null) s = s + "Wife: " + this.wife.getName() + "\n";
    if(this.children != null) {
      Enumeration kids = this.getChildren();
      s = s + "Children: \n";
      while (kids.hasMoreElements()) {
        s = s + "     " + ((Individual)kids.nextElement()).getName() + "\n";
      }
    }
    if (this.ceremony != null) s = s + "\nMarriage: \n     " + this.ceremony.getDetails();
    if (this.decree != null) s = s + "\nDivorce: \n     " + this.decree.getDetails();
    return s;
  
public java.lang.StringgetDisplayName()

note
Return the display name of the family - i.e. family name

    return this.displayName;
  
public DivorcegetDivorce()

note
Return the divorce associated with this family.
return
Divorce - associated divorce or null

    return this.decree; 
  
public static ProblemDomain.FamilygetFamily(int reference)

note
Return the family with the given reference, using the reference to directly access its location in the Hashtable.


                  
       
    return (Family)(Family.All.get(new Integer(reference)));
  
public IndividualgetHusband()

note
Return the husband linked to this family.

    return this.husband;
  
public MarriagegetMarriage()

note
Return the marriage associated with this family.
return
Marriage - associated marriage or null

    return this.ceremony;
  
protected static intgetNextReference()

note
Static method to allow unique reference numbers to be gerenrated from the static variable - lastReference.


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

note
Return all the notes associated with this family as an Enumeration.

    return notes.elements();
  
public intgetReference()

note
Return the unique reference no. for the Family object.

    return this.reference;
  
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 "@F" + java.lang.Integer.toString(this.reference) + "@ FAM";
public IndividualgetWife()

note
Return the wife linked to this family.

    return this.wife;
  
public booleanhasAsChild(ProblemDomain.Individual c)

note
Check to see if the passed individual is part of the children of this family.
return
boolean - true if individual is a child of this family, else false

    return this.children.contains(c);
  
public booleanhasAsSpouse(ProblemDomain.Individual p)

note
Check to see if the passed individual is the spouse of this family.
return
boolean - true if individual is a spouse of this family, else false

    return (this.husband == p | this.wife == p);
  
public booleanisNotSolemnised()

    return this.notSolemnised;
  
public voidremoveChild(ProblemDomain.Individual p)

note
Remove the Individual, passed to this method, from the list of children.

    this.children.removeElement(p);
    // unlink other end
    p.unlinkAsChild(this);
  
public voidremoveNote(ProblemDomain.Note comments)

note
Remove note from family, by locating the note object passed to it and removing it.

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

note
Remove note from family, by using the index of the note passed to it and removing it.

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

 lastReference = 0; 
public voidsetDivorce(ProblemDomain.Divorce p)

note
Set the divorce associated with this family.

    this.decree = p; return;
  
public voidsetHusband(ProblemDomain.Individual p)

note
Link the individual passed as the husband to this family.

    // unlink other end
    if (husband != null) {
      husband.unlinkAsSpouse(this);}
    // set
    this.husband = p;
    // link other end
    husband.linkAsSpouse(this);
    // update display name
    this.displayName = this.husband.getFamilyName() + " = ";
    if (this.wife != null) this.displayName = this.displayName
      + this.wife.getFamilyName();
    return;
  
public voidsetMarriage(ProblemDomain.Marriage p)

note
Set the marriage associated with this family.

  this.ceremony = p; return;
  
protected static voidsetNextReference(int n)

    if (lastReference < n) lastReference = n-1; return;
  
public voidsetNotSolemnised(boolean b)

    this.notSolemnised = b;
  
public voidsetNoteAt(int i, ProblemDomain.Note s)

note
Replace a specific note object with a new one.

    notes.setElementAt(s,i); return;
  
public voidsetWife(ProblemDomain.Individual p)

note
Link the individual passed as the wife to this family.
param
p - the Individual object that represents the wife.

    // unlink other end
    if (wife != null) {
      wife.unlinkAsSpouse(this);}
    // set
    this.wife = p;
    // link other end
    wife.linkAsSpouse(this);
    // update display name
    this.displayName = " = " + this.wife.getFamilyName();
    if (this.husband != null) this.displayName = this.husband.getFamilyName() + this.displayName;
    return;
  
public static ProblemDomain.FamilytestObject()

note
Simple method to create test data for a family object.

    Family f = new Family(1,
      Individual.testObject(), Individual.testObject2(),
      Marriage.testObject(), Divorce.testObject());
    f.addChild(Individual.testObject3());
    f.addChild(Individual.testObject4());
    f.addNote(new Note("A fine family there now."));
    f.addNote(new Note("And that's the truth!"));
    return f;
  
public java.lang.StringtoString(java.lang.String sn)

note
Outputs string for the LifeEvent. 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 F" + Integer.toString(this.reference) + "\n";
    if (this.husband != null) s = s + sn + " " + "HUSB @I" + Integer.toString(this.husband.getReference()) + "@\n";
    if (this.wife != null) s = s + sn + " " + "WIFE @I" + Integer.toString(this.wife.getReference()) + "@\n";
    if(this.children != null) {
      Enumeration kids = this.getChildren();
      while (kids.hasMoreElements()) {
        s = s + sn + " " + "CHIL @I" + Integer.toString(((Individual)kids.nextElement()).getReference()) + "@\n";
      }
    }
    if (this.ceremony != null) s = s + this.ceremony.toString(sn);
    if (this.decree != null) s = s + this.decree.toString(sn);
    s = s + sn + " " + "_PCODE F" + Integer.toString(this.reference) + "\n";
    s = s + sn + " " + "_PNAME " + this.displayName + "\n";
    s = s + sn + " " + "_FRECT " + "\n";    
    return s;