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(); }
public void printBuffer() { ArrayList<Event> copy = (ArrayList<Event>) this.buffer.clone(); for (Event e : copy) { System.out.println(e.toString()); this.buffer.remove(e); } }
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; } }
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 }
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(); }
@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; } }