Package model

Source Code of model.Person

/**
*
*/
package model;

import java.util.Date;
import java.util.GregorianCalendar;
import java.util.LinkedList;
import java.util.ListIterator;

import controller.enums.Group;
import controller.exceptions.EmptyNameException;

/**
* @author Mister Creeper
*
*/
public class Person {
  private LinkedList<String> firstName = new LinkedList<String>();
  private String lastName = "";
  private Date birthday = new GregorianCalendar(0, 0, 0).getTime();
  private LinkedList<TelephoneNumber> mobilNumber = new LinkedList<TelephoneNumber>();
  private LinkedList<Email> email = new LinkedList<Email>();
  private Group group = Group.NO_GROUP;
  private LinkedList<PositionInformation> positionInformation = new LinkedList<PositionInformation>();
 
  private <T> T getListElement(LinkedList<T> ll, int index){
    if (index < 0 || index > ll.size() - 1){
      return null;            //<== EXIT
    }
    int i = 0;
    ListIterator<T> listIterator = ll.listIterator();
    while (true){
      i++;
      if (i == index){
        return listIterator.next();    //<== EXIT
      }
      listIterator.next();
    }
  }
 
  public Person(LinkedList<String> firstName, String lastName) throws EmptyNameException{
    this(firstName, lastName, null, null, null, null, null);
  }
 
  public Person(LinkedList<String> firstName, String lastName, Date birthday,
      LinkedList<TelephoneNumber> mobilNumber, LinkedList<Email> email,
      Group group, LinkedList<PositionInformation> positionInformation) throws EmptyNameException{
    if (firstName == null || lastName == null || firstName.isEmpty() ||
        firstName.getFirst().equals("") || lastName.equals("")){
      throw new EmptyNameException();        //<== EXIT
    }
    this.firstName = firstName;
    this.lastName = lastName;
    if (birthday != null){
      this.birthday = birthday;
    }
    if (mobilNumber != null){
      this.mobilNumber = mobilNumber;
    }
    if (email != null){
      this.email = email;
    }
    if (group != null){
      this.group = group;
    }
    if (positionInformation != null){
      this.positionInformation = positionInformation;
    }
  }
 
  public boolean setLastName(String lastName){
    if (lastName == null || lastName.equals("")){
      return false;
    }
    this.lastName = lastName;
    return true;
  }
 
  public boolean setMobilNumber(TelephoneNumber mobilNumber, int index){
    if (mobilNumber == null || index < 0){
      return false;                  //<== EXIT
    }
    if (index > this.mobilNumber.size() - 1){
      return this.addMobilNumber(mobilNumber);    //<== EXIT
    }
    ListIterator<TelephoneNumber> listIterator = this.mobilNumber.listIterator();
    int i = 0;
    listIterator.next();
    while (i != index){
      listIterator.next();
      i++;
    }
    listIterator.set(mobilNumber);
    return true;
  }
 
  public boolean setMobilNumber(LinkedList<TelephoneNumber> mobilNumber){
    if (mobilNumber != null){
      return false;
    }
    this.mobilNumber = mobilNumber;
    return true;
  }
 
  public boolean addMobilNumber(TelephoneNumber mobilNumber){
    if (mobilNumber == null){
      return false;
    }
    this.mobilNumber.push(mobilNumber);
    return true;
  }

  public boolean setEmail(Email email, int index){
    if (email == null || index < 0){
      return false;                  //<== EXIT
    }
    if (index > this.email.size() - 1){
      return this.addEmail(email);    //<== EXIT
    }
    ListIterator<Email> listIterator = this.email.listIterator();
    int i = 0;
    listIterator.next();
    while (i != index){
      listIterator.next();
      i++;
    }
    listIterator.set(email);
    return true;
  }
 
  public boolean setEmail(LinkedList<Email> email){
    if (email != null){
      return false;
    }
    this.email = email;
    return true;
  }
 
  public boolean addEmail(Email email){
    if (email == null){
      return false;
    }
    this.email.push(email);
    return true;
  }
 
  public boolean setGroup(Group group){
    if (group == null){
      return false;
    }
    this.group = group;
    return true;
  }

  public boolean setPositionInformation(PositionInformation positionInformation, int index){
    if (positionInformation == null || index < 0){
      return false;                  //<== EXIT
    }
    if (index > this.positionInformation.size() - 1){
      return this.addPositionInformation(positionInformation);    //<== EXIT
    }
    ListIterator<PositionInformation> listIterator = this.positionInformation.listIterator();
    int i = 0;
    listIterator.next();
    while (i != index){
      listIterator.next();
      i++;
    }
    listIterator.set(positionInformation);
    return true;
  }
 
  public boolean setPositionInformation(LinkedList<PositionInformation> positionInformation){
    if (positionInformation != null){
      return false;
    }
    this.positionInformation = positionInformation;
    return true;
  }
 
  public boolean addPositionInformation(PositionInformation positionInformation){
    if (positionInformation == null){
      return false;
    }
    this.positionInformation.push(positionInformation);
    return true;
  }
 
  public String getFirstName(int index){
    return this.getListElement(this.firstName, index);
  }
 
  public LinkedList<String> getFirstName(){
    return this.firstName;
  }
 
  public String getLastName(){
    return this.lastName;
  }
 
  public Date getBirthday(){
    return this.birthday;
  }
 
  public TelephoneNumber getMobilNumber(int index){
    return this.getListElement(this.mobilNumber, index);
  }
 
  public LinkedList<TelephoneNumber> getMobilNumber(){
    return this.mobilNumber;
  }
 
  public Email getEmail(int index){
    return this.getListElement(this.email, index);
  }
 
  public LinkedList<Email> getEmail(){
    return this.email;
  }
 
  public Group getGroup(){
    return this.group;
  }
 
  public PositionInformation getPositionInformation(int index){
    return this.getListElement(this.positionInformation, index);
  }
 
  public LinkedList<PositionInformation> getPositionInformation(){
    return this.positionInformation;
  }
}
TOP

Related Classes of model.Person

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.