|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectdip.order.Order
This is the base class for all Order objects.
When referring to an Order subclass, it is best to refer to an object
as an "Orderable" object rather than an "Order" object.
For example:
GUIOrderFactory gof = new GUIOrderFactory(); Order order = OrderFactory.getDefault().createHold(a,b,c); // ok Orderable order = OrderFactory.getDefault().createHold(a,b,c); // dangerous Order order = gof.createHold(a,b,c); // this may fail!! Orderable order = gof.createHold(a,b,c); // ok
This class provides default implementations for many Order interface methods, as well as protected convenience methods.
A note on serialization: provided are several internal fields which can be used to 'upgrade' objects as needed. These fields are for future use, but their presence enables future upgradibility.
Field Summary | |
protected static java.lang.String |
ORD_VAL_BORDER
|
protected Power |
power
Power who gave the order to the unit |
protected Location |
src
Location of the ordered unit |
protected Unit.Type |
srcUnitType
Type of the ordered unit |
Constructor Summary | |
protected |
Order()
No-arg constructor |
protected |
Order(Power power,
Location src,
Unit.Type srcUnit)
Constructor for the Order object |
Method Summary | |
protected void |
addSupportsOfAndMovesToSource(Adjudicator adjudicator)
Convenience method typically used in determineDependencies(); this method gets all Support and Move orders to this space and adds them to the dependency list. |
protected void |
appendBrief(java.lang.StringBuffer sb)
Convenience Method: prints the beginning of an order in a brief format. |
protected void |
appendFull(java.lang.StringBuffer sb)
Convenience Method: prints the beginning of an order in a verbose format. |
protected void |
checkPower(Power power,
TurnState turnState,
boolean checkIfActive)
Validates the given Power |
protected void |
checkSeasonAdjustment(TurnState state,
java.lang.String orderName)
Convenience method to check that we are in the Adjustment phase |
protected void |
checkSeasonMovement(TurnState state,
java.lang.String orderName)
Convenience method to check that we are in the Movement phase |
protected void |
checkSeasonRetreat(TurnState state,
java.lang.String orderName)
Convenience method to check that we are in the Retreat phase |
boolean |
equals(java.lang.Object obj)
Determines if the orders are equal. |
Power |
getPower()
Gets the Power ordering the ordered Source unit |
Location |
getSource()
Gets the Location of the ordered unit |
Unit.Type |
getSourceUnitType()
Gets the Type of the ordered unit |
protected Unit.Type |
getValidatedUnitType(Province province,
Unit.Type unitType,
Unit unit)
Convenience method for matching unit types. |
java.lang.String |
toFormattedString(OrderFormatOptions ofo)
Formats the order using the OrderFormat format string. |
java.lang.String |
toString()
For debugging: calls toBriefString(). |
void |
validate(TurnState state,
ValidationOptions valOpts,
RuleOptions ruleOpts)
Validate the order. |
protected void |
validate(ValidationOptions valOpts,
Unit unit)
Validates a dislodged or non-dislodged unit, depending upon what type of unit is specified |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface dip.order.Orderable |
determineDependencies, evaluate, getBriefName, getDefaultFormat, getFullName, toBriefString, toFullString, verify |
Field Detail |
protected static final java.lang.String ORD_VAL_BORDER
protected Power power
protected Location src
protected Unit.Type srcUnitType
Constructor Detail |
protected Order()
protected Order(Power power, Location src, Unit.Type srcUnit)
power
- Power giving the Ordersrc
- Location of the ordered unitsrcUnit
- Unit typeMethod Detail |
public final Location getSource()
Orderable
getSource
in interface Orderable
public final Unit.Type getSourceUnitType()
Orderable
getSourceUnitType
in interface Orderable
public final Power getPower()
Orderable
getPower
in interface Orderable
public java.lang.String toFormattedString(OrderFormatOptions ofo)
Orderable
Note that this is equivalent to calling OrderFormat.format(ofo, this, getDefaultFormat())
To print with default (not user-specified) options, use
OrderFormat.format(OrderFormatOptions.DEFAULT, this, getDefaultFormat())
While this enables better formatting, it is slower than using the toBriefString() and toFullString() methods.
toFormattedString
in interface Orderable
public void validate(TurnState state, ValidationOptions valOpts, RuleOptions ruleOpts) throws OrderException
This checks the order for legality. An order is not considered to be well-formed until it has been validated. It validates locations (at the least), and other order syntax as appropriate, throwing exceptions if there is a conflict.
This is used by the UI to flag bad orders, as well as by the adjudicator to eliminate bad orders before processing.
Important Note:
The only state that should be assumed is the following: 1) orders for this power (if entered) 2) the positions of all units. Thus, the orders of units not controlled by this power may not be known (in multiplayer games, this information would not be available until adjudication took place). DO NOT assume order information for the units of any power other than that of this unit/order!
Usage Notes:
Subclasses should generally call super.validate() before performing additional validation.
There should be no side effects of calling validate() multiple times, nor should behavior differ between multiple calls of validate(), given the same order.
validate
in interface Orderable
state
- Current turn statevalOpts
- Current validation options
OrderException
protected final void addSupportsOfAndMovesToSource(Adjudicator adjudicator)
Only "hold" supports are added. Invalid Move orders are NEVER added.
protected void validate(ValidationOptions valOpts, Unit unit) throws OrderException
OrderException
protected final Unit.Type getValidatedUnitType(Province province, Unit.Type unitType, Unit unit) throws OrderException
If a type is undefined, the type is derived from the existing unit. If the existing unit is not found (or mismatched), an exception is thrown.
OrderException
protected final void checkPower(Power power, TurnState turnState, boolean checkIfActive) throws OrderException
OrderException
protected final void checkSeasonRetreat(TurnState state, java.lang.String orderName) throws OrderException
OrderException
protected final void checkSeasonAdjustment(TurnState state, java.lang.String orderName) throws OrderException
OrderException
protected final void checkSeasonMovement(TurnState state, java.lang.String orderName) throws OrderException
OrderException
protected final void appendFull(java.lang.StringBuffer sb)
protected final void appendBrief(java.lang.StringBuffer sb)
public java.lang.String toString()
public boolean equals(java.lang.Object obj)
Note that full equality MUST be implemented for each subclassed Order object! Subclasses are advised to call the super method for assistance.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |