/**
* A component of a library for
* GENESIS
* Copyright (C) 2008
* Andy Turner,
* University of Leeds.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
package uk.ac.leeds.ccg.andyt.projects.genesis.society.organisations;
import uk.ac.leeds.ccg.andyt.projects.genesis.society.persons.Person;
import java.util.HashSet;
import java.util.Iterator;
/**
* A family is individual to a person. It is made up of indivuals and
* collections of people with special roles or relationships to the individual.
* A family includes parents. These may also be guardians, but guardians are
* represented separately and these may change, but parents do not. There may be
* siblings who can share all, one or no parents or guardians. There may also be
* children who reciprocate the parent relationship. Often these are dependents,
* although dependents are represented separately. (Every guardian does not
* necessarily have the same set of dependents.) Next of kin relationships for
* the individual is stored here. Spouse relationship is also stored here (this
* is reciprocal).
*
* Family history is stored with dates of changes in the relationships.
*
* Every person has a family even if it is not defined.
*/
public class Family {
private Person _Person;
private HashSet _People;
private HashSet _Parents;
private HashSet _Guardians;
private HashSet _Siblings;
private HashSet _Dependents;
private HashSet _Children;
private Person _NextOfKin;
private Person _Spouse;
/**
* _Order = 0 means this is not completely initialised
* _Order = 1 means this is initialised such that all relevant members have
* been added.
* _Order = 2 means all Family members have been initialised to order 1
* _Order = 3 means there is a full and complete family history
*/
private int _Order;
/**
* A record of the date and changes in Family for _Person. Inlcuding;
* Births, deaths, marriages, changes of dependent/guardian status.
*/
private Object _FamilyHistory;
public Family(Person _Person) {
this._Person = _Person;
this._People = new HashSet();
this._People.add(_Person);
_Parents = new HashSet();
}
/**
* Parents are not necessarily guardians. A parent is biological/genetic
* provider.
* A parent is not to be removed from a family in simulation though they
* may die or divorce/decohabit.
*/
public void _Add_Parent(Person _Parent) {
get_Parents().add(_Parent);
get_People().add(_Parent);
_Parent._Family._Add_Child(_Person);
}
/**
* Children are not necessarily dependents, but are biological/genetic
* inheritors.
* A child should be added to a parent.
* It is possible through genetic engineering that a person has only one
* parent or has more than two parents. It is usual that a person has two
* parents, a male and a female.
* One case of three parents can be a doner egg used in fertility treatment.
* A child is not to be removed from a family. So when a child becomes adult
* or non-dependent they are still a child.
*/
private void _Add_Child(Person _Child) {
if (get_Children() == null){
set_Children(new HashSet());
}
get_Children().add(_Child);
get_People().add(_Child);
}
/**
* Once a sibling, always a sibling. A sibling is not strictly biological/
* genetic in that siblings do not have to share a common parent. To
* identify those that do then the parents of siblings should be tested for
* equality.
*
* All siblings are common, however it might be desirable to distinguish
* the steps of siblings.
*
* Should sibling divorce be allowed?
*
* Siblings that do not share a common parent can legally have children.
*
* Legality is not well defined yet.
*
* After a family is initilised, a sibling may be added during simulation
* when there is a birth, or a marriage/cohabitation.
*
* @param _Sibling
*/
public void _Add_Sibling(
Person _Sibling) {
if (get_Siblings() == null) {
if (_Sibling._Family.get_Siblings() == null){
set_Siblings(new HashSet());
get_Siblings().add(_Sibling);
get_Siblings().add(_Person);
get_People().add(_Sibling);
_Sibling._Family.set_Siblings(get_Siblings());
_Sibling._Family.get_People().add(_Person);
} else {
set_Siblings(_Sibling._Family.get_Siblings());
Iterator _Iterator = get_Siblings().iterator();
while(_Iterator.hasNext()){
Person _A_Sibling = (Person) _Iterator.next();
_A_Sibling._Family.get_People().add(_Person);
}
get_Siblings().add(_Person);
}
} else {
if (_Sibling._Family.get_Siblings() == null){
get_Siblings().add(_Sibling);
get_People().add(_Sibling);
_Sibling._Family.set_Siblings(get_Siblings());
_Sibling._Family.get_People().addAll(get_Siblings());
} else {
Iterator _Iterator = get_Siblings().iterator();
while(_Iterator.hasNext()){
Person _A_Sibling = (Person) _Iterator.next();
_A_Sibling._Family.get_People().addAll(_Person._Family.get_Siblings());
}
get_Siblings().addAll(_Sibling._Family.get_Siblings());
get_People().addAll(_Sibling._Family.get_Siblings());
_Iterator = _Sibling._Family.get_Siblings().iterator();
while(_Iterator.hasNext()){
Person _A_Sibling = (Person) _Iterator.next();
_A_Sibling._Family.set_Siblings(_Person._Family.get_Siblings());
}
}
}
}
/**
* After an individuals family is initilised, a guardian may be added during
* simulation. This is usually when there is a marriage/cohabitation change.
* Cohabitation is not necessary for a guardian relationship, but it is
* perhaps usual.
* @param _Guardian
*/
public void _Add_Guardian(
Person _Guardian){
if (get_Guardians() == null ){
set_Guardians(new HashSet());
}
get_Guardians().add(_Guardian);
get_People().add(_Guardian);
_Guardian._Family._Add_Dependent(_Person);
}
/**
* A guardian may be removed during simulation. Removing a guardian
* does not remove the guardian from _People.
* @param _Guardian
*/
public void _Remove_Guardian(
Person _Guardian) {
get_Guardians().remove(_Guardian);
if (get_Guardians().size() == 0){
set_Guardians(null);
}
_Guardian._Family._Remove_Dependent(_Person);
}
/**
* Dependents may be old or young related genetically or not. This is a
* reciprocal relationship to guardianship. If somone is a persons guardian,
* then that person is a dependent of the guardian. The dependency is
* established via the _Add_Guardian(Person,boolean) method.
* @param _Dependent
*/
private void _Add_Dependent(Person _Dependent) {
if (get_Dependents() == null) {
set_Dependents(new HashSet());
}
get_Dependents().add(_Dependent);
get_People().add(_Dependent);
}
// public void _Add_Dependents(HashSet _Dependents) {
// this._Dependents.addAll(_Dependents);
// _People.addAll(_Dependents);
// }
/**
* Dependents may be removed during simulation when there is a divorce/
* decohabitation. The dependency is removed via the
* _Remove_Guardian(Person,boolean) method.
* @param _Dependent
*/
private void _Remove_Dependent(Person _Dependent) {
get_Dependents().remove(_Dependent);
if (get_Dependents().size() == 0) {
set_Dependents(null);
}
}
/**
* @param _Spouse
*/
public void _Add_Spouse(
Person _Spouse){
if (_Spouse != null ){
System.out.println("_Family._Spouse exists and is being overwritten for Person.ID " + _Person._ID);
}
this.set_Spouse(_Spouse);
get_People().add(_Spouse);
_Spouse._Family.set_Spouse(_Person);
_Spouse._Family.get_People().add(_Person);
}
/**
* This is like divorce, but that could be more complicated?
* @param _Spouse
*/
public void _Remove_Spouse(
Person _Spouse) {
_Spouse = null;
_Spouse._Family.set_Spouse(null);
}
/**
* @return description of this.
*/
public String toString() {
String _String = new String("Family: ");
_String += "; _People.size() " + get_People().size();
_String += "; _Parents.size() " + get_Parents().size();
if (get_Siblings() == null ){
_String += "; Siblings undefined or non existant";
} else {
_String += "; _Siblings.size() " + get_Siblings().size();
}
if (get_Guardians() == null ){
_String += "; Guardians undefined or non existant";
} else {
_String += "; _Guardians.size() " + get_Guardians().size();
}
if (get_Dependents() == null ){
_String += "; Dependents undefined or non existant";
} else {
_String += "; _Dependents.size() " + get_Dependents().size();
}
if (get_Children() == null ){
_String += "; _Children undefined or non existant";
} else {
_String += "; _Children.size() " + get_Children().size();
}
if (get_Spouse() == null){
_String += "; _Spouse undefined or non existant";
} else {
_String += "; _Spouse._ID " + get_Spouse()._ID;
}
if (get_NextOfKin() == null){
_String += "; _NextOfKin undefined or non existant";
} else {
_String += "; _NextOfKin._ID " + get_NextOfKin()._ID;
}
return _String;
}
public HashSet get_People() {
return _People;
}
public HashSet get_Parents() {
return _Parents;
}
public void set_Parents(HashSet _Parents) {
this._Parents = _Parents;
}
public HashSet get_Guardians() {
return _Guardians;
}
public void set_Guardians(HashSet _Guardians) {
this._Guardians = _Guardians;
}
public HashSet get_Siblings() {
return _Siblings;
}
public void set_Siblings(HashSet _Siblings) {
this._Siblings = _Siblings;
}
public HashSet get_Dependents() {
return _Dependents;
}
public void set_Dependents(HashSet _Dependents) {
this._Dependents = _Dependents;
}
public HashSet get_Children() {
return _Children;
}
public void set_Children(HashSet _Children) {
this._Children = _Children;
}
public Person get_NextOfKin() {
return _NextOfKin;
}
public void set_NextOfKin(Person _NextOfKin) {
this._NextOfKin = _NextOfKin;
}
public Person get_Spouse() {
return _Spouse;
}
public void set_Spouse(Person _Spouse) {
this._Spouse = _Spouse;
}
public int get_Order() {
return _Order;
}
public void set_Order(int _Order) {
this._Order = _Order;
}
}