Back to project page ZorbsCity.
The source code is released under:
GNU General Public License
If you think the Android project ZorbsCity listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package jonathan.geoffroy.zorbscity.model; /*from w w w. j ava 2 s.c o m*/ import jonathan.geoffroy.zorbscity.model.cityObjects.buildings.Construction; /** * A SimulatorEvent is an event that will be triggered when the Simulator time-lime reach the handlerTime time. * When that's happening, the method onTrigger is called, i.e. the method ontriggeredEvent from creator is called. * * @author Jonathan GEOFFROY * @version 0.1 */ public abstract class SimulatorEvent implements Comparable<Long> { /** * The building which has emitted this event from the Simulator */ private Construction creator; /** * The time when this event should be triggered */ private long handlerTime; public SimulatorEvent(Construction creator, long handlerTime) { super(); this.creator = creator; this.handlerTime = handlerTime; } public Construction getCreator() { return creator; } public void setCreator(Construction creator) { this.creator = creator; } public long getHandlerTime() { return handlerTime; } public void setHandlerTime(long handlerTime) { this.handlerTime = handlerTime; } public void incHandlerTime(int handlerInc) { handlerTime += handlerInc; } @Override /** * Compare the handlerTime between this and e * It's the result of handlerTime - other * Means that if handlerTime is triggered after e, the result is positive */ public int compareTo(Long other) { return (int) (handlerTime - other); } public int compareTo(SimulatorEvent other) { return (int)(handlerTime - other.handlerTime); } /** * Should be called when the simulator time-line has reached the handlerTime time. * @param sim */ public void onTrigger(Simulator sim) { creator.onTriggeredEvent(this, sim); } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((creator == null) ? 0 : creator.hashCode()); result = prime * result + (int) (handlerTime ^ (handlerTime >>> 32)); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; SimulatorEvent other = (SimulatorEvent) obj; if (creator == null) { if (other.creator != null) return false; } else if (!creator.equals(other.creator)) return false; if (handlerTime != other.handlerTime) return false; return true; } }