org.starhope.appius.game.intangible
Class Event

java.lang.Object
  extended by org.starhope.appius.util.ManagedReferenceHolder
      extended by org.starhope.appius.util.BaseDatum
          extended by org.starhope.appius.game.intangible.Event
All Implemented Interfaces:
com.sun.sgs.app.ManagedObject, Externalizable, Serializable, CastsToJSON

public class Event
extends BaseDatum

An Event is anything in-game which has a time reference (both a beginning and ending time are recorded, but they can be equal) and earns or costs currency. Earning currency is by virtue of earning points at a specific event type.

Author:
brpocock
See Also:
Serialized Form

Field Summary
private  Date begin
           
private  Date end
           
private  BigDecimal points
           
private  com.sun.sgs.app.ManagedReference<EventType> reason
           
private static long serialVersionUID
           
 
Fields inherited from class org.starhope.appius.util.BaseDatum
database_id
 
Constructor Summary
Event(EventType reason)
          Create an event starting now (which can be changed) but with no points, not finished.
Event(EventType reason, BigDecimal points)
          This is for an event where the number of points earned is already known (instantly) by the time that the event gets registered.
Event(EventType reason, int points)
          Creates an event; syntactic sugar for Event(EventType, BigDecimal)
Event(String reason)
          Syntactic sugar for Event(EventType)
Event(String reason, BigDecimal points)
          Creates an event; syntactic sugar for Event(EventType, BigDecimal)
Event(String reason, int points)
          Syntactic sugar for Event(EventType, BigDecimal)
 
Method Summary
 Date getBegin()
           
 Date getEnd()
           
 BigDecimal getPoints()
          Gets the number of points earned at an event.
 EventType getReason()
          Gets the event type
 void set(org.json.JSONObject o)
          This method will attempt to set the data contents of this object to the values derived from the JSON object being passed-in.
 void setBegin(Date begin)
           
 void setEnd(Date end)
           
 void setPoints(BigDecimal points)
          Set the number of points earned at this Event
 void setPoints(int points)
          Syntactic sugar for setPoints(BigDecimal) using an integer
 void setReason(EventType newReason)
          Set the reason for the event
 org.json.JSONObject toJSON()
          Creates a JSON representation of this object
 
Methods inherited from class org.starhope.appius.util.BaseDatum
changed, commitToDatabase, delete, equals, flush, get, get, getID, getUniqueBoundName, readExternal, refJSON, setID, sqlDateTime, writeExternal
 
Methods inherited from class org.starhope.appius.util.ManagedReferenceHolder
deref, setRef
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

begin

private Date begin

end

private Date end

points

private BigDecimal points

reason

private com.sun.sgs.app.ManagedReference<EventType> reason
Constructor Detail

Event

public Event(EventType reason)
Create an event starting now (which can be changed) but with no points, not finished.

Parameters:
reason - The type of event

Event

public Event(EventType reason,
             BigDecimal points)
This is for an event where the number of points earned is already known (instantly) by the time that the event gets registered. This constructor might reasonably be used like a static method, without even storing the constructed object, so it commits a flush itself to be safe.

Parameters:
reason - The type of event (e.g. game)
points - The number of points earned

Event

public Event(EventType reason,
             int points)
Creates an event; syntactic sugar for Event(EventType, BigDecimal)

Parameters:
reason - reason for earning points
points - points earned

Event

public Event(String reason)
      throws NotFoundException
Syntactic sugar for Event(EventType)

Parameters:
reason - the reason code string
Throws:
NotFoundException - if the reason specified is not defined

Event

public Event(String reason,
             BigDecimal points)
      throws NotFoundException
Creates an event; syntactic sugar for Event(EventType, BigDecimal)

Parameters:
reason - the reason string for the event type
points - the number of points earned
Throws:
NotFoundException - if the specified EventType reason can't be found

Event

public Event(String reason,
             int points)
      throws NotFoundException
Syntactic sugar for Event(EventType, BigDecimal)

Parameters:
reason - reason string
points - points earned
Throws:
NotFoundException - if the specified reason isn't a known EventType
Method Detail

getBegin

public Date getBegin()
Returns:
the begin

getEnd

public Date getEnd()
Returns:
the end

getPoints

public BigDecimal getPoints()
Gets the number of points earned at an event. Note that this can exceed the range of an integer.

Returns:
the number of points earned

getReason

public EventType getReason()
Gets the event type

Returns:
the event type

set

public void set(org.json.JSONObject o)
Description copied from interface: CastsToJSON
This method will attempt to set the data contents of this object to the values derived from the JSON object being passed-in. All exceptions are ignored, but any errors in the JSON data could cause the command to fail, completely or partially.

Specified by:
set in interface CastsToJSON
Overrides:
set in class BaseDatum
Parameters:
o - The JSON object containing a the new data for this object.
See Also:
CastsToJSON.set(org.json.JSONObject)

setBegin

public void setBegin(Date begin)
Parameters:
begin - the begin to set

setEnd

public void setEnd(Date end)
Parameters:
end - the end to set

setPoints

public void setPoints(BigDecimal points)
Set the number of points earned at this Event

Parameters:
points - the number of points earned

setPoints

public void setPoints(int points)
Syntactic sugar for setPoints(BigDecimal) using an integer

Parameters:
points - the number of points earned

setReason

public void setReason(EventType newReason)
Set the reason for the event

Parameters:
newReason - the EventType

toJSON

public org.json.JSONObject toJSON()
Creates a JSON representation of this object

Specified by:
toJSON in interface CastsToJSON
Overrides:
toJSON in class BaseDatum
Returns:
The string representing this object in JSON format
See Also:
BaseDatum.toJSON()