Пример #1
0
 public String toString() {
   String string = "event set, policy:" + suspendPolicy + ", count:" + this.size() + " = {";
   boolean first = true;
   for (Event event : this) {
     if (!first) {
       string += ", ";
     }
     string += event.toString();
     first = false;
   }
   string += "}";
   return string;
 }
Пример #2
0
  private void viewCalendar(String event_indicator) {
    if (event_indicator.equals("event")) {
      // Uniquely identify the event from user input
      ArrayList eventInfo = uniquelyIdentifyEvent();
      String eventTitle = (String) eventInfo.get(0);
      LocalDateTime eventDateTime = (LocalDateTime) eventInfo.get(1);

      // Fetch the event from the calendar
      Event event = calendar.findEvent(eventTitle, eventDateTime);
      if (event == null) {
        System.out.println("    Event not found. Try again");
      } else {
        System.out.println(event.toString());
      }
    } else if (event_indicator.equals("events")) {
      // Just print out the entire calendar for now. Add functionality for
      // range search later.
      System.out.println(calendar);
    }
  }
  private void initialize() {

    Person JohnLennon = newPerson("John", "Lennon", Person.Gender.MALE);
    JohnLennon.setNotes("Famous songwriter and member of the Beatles musical group.");

    Person yoko = newPerson("Yoko", "Ono", Person.Gender.FEMALE);
    Person cynthia = newPerson("Cynthia", "Powell", Person.Gender.FEMALE);
    Person julian = newPerson("Julian", "Lennon", Person.Gender.MALE);

    Birth b = new Birth();
    b.setEventDate(new GregorianCalendar(1963, 3, 8).getTime());
    b.setPerson(julian);
    b.addParent(JohnLennon);
    b.addParent(cynthia);
    b.setTown("Liverpool");
    b.setCountry("England");
    addBirth(b);

    Person sean = newPerson("Sean", "Lennon", Person.Gender.MALE);
    b = new Birth();
    b.setEventDate(new GregorianCalendar(1975, 9, 9).getTime());
    b.setPerson(sean);
    b.setTown("Liverpool");
    b.setCountry("England");
    b.addParent(JohnLennon);
    b.addParent(yoko);
    addBirth(b);

    Person mimi = newPerson("Mary Elizabeth", "Smith", Person.Gender.FEMALE);

    mimi.setMiddle("Mimi");
    mimi.setNotes("Mimi became nephew John's guardian");

    Person Isoko = newPerson("Isoko", "Ono", Person.Gender.FEMALE);
    Person Yeisuke = newPerson("Yeisuke", "Ono", Person.Gender.MALE);

    // Get person JohnLennon
    Person person = getPerson(JohnLennon.getId());
    person.setMiddle("Winston");
    mydisplay(person.toString());

    mydisplay(JohnLennon.getMiddle());

    // birth = October 9, 1940
    // death = December 8, 1980
    b = new Birth();
    b.setEventDate(new GregorianCalendar(1940, 9, 9).getTime());
    b.setPerson(JohnLennon);
    b.setTown("Liverpool");
    b.setCountry("England");
    addBirth(b);

    Death dd = new Death();
    dd.setPerson(JohnLennon);
    dd.setEventDate(new GregorianCalendar(1980, 11, 8).getTime());
    dd.setTown("New York");
    dd.setState_province("New York");
    dd.setCountry("USA");
    addDeath(dd);

    // add more people to John Lennon's ancestry
    Person julia = newPerson("Julia", "Stanley", Person.Gender.FEMALE);

    Person alf = newPerson("Alfred", "Lennon", Person.Gender.MALE);
    addParent(JohnLennon, alf);
    addParent(JohnLennon, julia);

    Adoption a = new Adoption();
    a.setEventDate(new GregorianCalendar(1946, 6, 1).getTime());
    a.setPerson(JohnLennon);
    a.setTown("Liverpool");
    a.setCountry("England");
    // a.addParent(mimi);
    addAdoption(a);
    addAdoptedParent(JohnLennon, mimi);

    dd = new Death();
    dd.setPerson(mimi);
    dd.setEventDate(new GregorianCalendar(1991, 11, 6).getTime());
    dd.setTown("Poole");
    dd.setState_province("Dorset");
    dd.setCountry("England");
    addDeath(dd);

    b = new Birth();
    b.setEventDate(new GregorianCalendar(1933, 1, 18).getTime());
    b.setPerson(yoko);
    b.setTown("Tokyo");
    b.setCountry("Japan");
    addBirth(b);

    Marriage m = new Marriage();
    m.setEventDate(new GregorianCalendar(1969, 2, 20).getTime());
    m.setPerson(JohnLennon);
    m.setSpouse(yoko);
    m.setTown("Gilbraltar");
    m.setCountry("Gibraltar");
    addMarriage(m);

    addParent(yoko, Isoko);
    addParent(yoko, Yeisuke);
    List<Person> thesepeople = getAllPeople();
    mydisplay("\nGetting All People");
    for (Person p : thesepeople) {
      mydisplay(p.toString());
    }

    Set<Person> thesechildren = getChildren(JohnLennon);
    mydisplay("\nGetting Children of " + JohnLennon);
    for (Person p : thesechildren) {
      mydisplay(p.toString());
    }

    thesechildren = getChildren(JohnLennon, yoko);
    mydisplay("\nGetting Children of both " + JohnLennon + " and " + yoko);
    for (Person p : thesechildren) {
      mydisplay(p.toString());
    }

    thesechildren = getChildrenAll(JohnLennon, yoko);
    mydisplay("\nGetting Children of either " + JohnLennon + " and " + yoko);
    for (Person p : thesechildren) {
      mydisplay(p.toString());
    }

    // Events stuff
    List<Event> events = findAllEvents(JohnLennon);
    mydisplay("Finding all events for " + JohnLennon);
    for (Event e : events) {
      if (e != null) {
        mydisplay(e.toString());
      }
    }

    events = findAllEvents(yoko);
    mydisplay("Finding all events for " + yoko);
    for (Event e : events) {
      if (e != null) {
        mydisplay(e.toString());
      }
    }

    events = findAllEvents(cynthia);

    mydisplay("Finding all events for " + cynthia);
    for (Event e : events) {
      if (e != null) {
        mydisplay(e.toString());
      }
    }
  }