示例#1
0
  public static void main(String[] args) {
    EventManager mgr = new EventManager();

    if (args[0].equals("store")) {
      mgr.createAndStoreEvent("My Event", new Date());
    } else if (args[0].equals("list")) {
      List events = mgr.listEvents();
      for (int i = 0; i < events.size(); i++) {
        Event theEvent = (Event) events.get(i);
        System.out.println("Event: " + theEvent.getTitle() + " Time: " + theEvent.getDate());
      }
    } else if (args[0].equals("addpersontoevent")) {
      Long eventId = mgr.createAndStoreEvent("My Event", new Date());
      Long personId = mgr.createAndStorePerson("Foo", "Bar");
      mgr.addPersonToEvent(personId, eventId);
      System.out.println("Added person " + personId + " to event " + eventId);
    } else if (args[0].equals("addemailtoperson")) {
      Long personId = mgr.createAndStorePerson("Foozy", "Beary");
      mgr.addEmailToPerson(personId, "foo@bar");
      mgr.addEmailToPerson(personId, "bar@foo");
      System.out.println(
          "Added two email addresses (value typed objects) to person entity : " + personId);
    }

    HibernateUtil.getSessionFactory().close();
  }
示例#2
0
  public void printBuffer() {
    ArrayList<Event> copy = (ArrayList<Event>) this.buffer.clone();

    for (Event e : copy) {
      System.out.println(e.toString());
      this.buffer.remove(e);
    }
  }
示例#3
0
 private void updateTime() {
   timeLeap = 0;
   for (Event e : events.getAddBuffer()) {
     if (e.getSpeed() != 0) timeLeap += 100 / e.getSpeed();
   }
   time += timeLeap;
   if (time >= DAY_LENGTH) {
     day++;
     time -= DAY_LENGTH;
   }
 }
示例#4
0
 public void newTurn() {
   turn++;
   updateTime();
   currentMap.update(timeLeap);
   if (previousMapTimer > 0) {
     previousMap.update(timeLeap);
     previousMapTimer -= timeLeap;
   }
   player.update();
   for (Event e : events.getAddBuffer()) {
     addMessage(e.getMessage());
   }
   events.update(); // TODO: optimize double looping
 }
示例#5
0
  private Long createAndStoreEvent(String title, Date theDate) {

    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();

    Event theEvent = new Event();
    theEvent.setTitle(title);
    theEvent.setDate(theDate);

    session.save(theEvent);

    session.getTransaction().commit();

    return theEvent.getId();
  }
示例#6
0
  @Override
  public void eventRecieved(Event event) throws RemoteException {

    switch (this.status) {
      case AUTO:
        System.out.println(event.toString());
        break;
      case HIDE:
        this.buffer.add(event);
        break;
    }
  }