dip.order
Class Order

java.lang.Object
  extended bydip.order.Order
All Implemented Interfaces:
Orderable, java.io.Serializable
Direct Known Subclasses:
Build, Convoy, DefineState, Disband, Hold, Move, Remove, Support, Waive

public abstract class Order
extends java.lang.Object
implements Orderable, java.io.Serializable

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.

See Also:
Serialized Form

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

ORD_VAL_BORDER

protected static final java.lang.String ORD_VAL_BORDER
See Also:
Constant Field Values

power

protected Power power
Power who gave the order to the unit


src

protected Location src
Location of the ordered unit


srcUnitType

protected Unit.Type srcUnitType
Type of the ordered unit

Constructor Detail

Order

protected Order()
No-arg constructor


Order

protected Order(Power power,
                Location src,
                Unit.Type srcUnit)
Constructor for the Order object

Parameters:
power - Power giving the Order
src - Location of the ordered unit
srcUnit - Unit type
Since:
Method Detail

getSource

public final Location getSource()
Description copied from interface: Orderable
Gets the Location of the ordered unit

Specified by:
getSource in interface Orderable

getSourceUnitType

public final Unit.Type getSourceUnitType()
Description copied from interface: Orderable
Gets the Type of the ordered unit

Specified by:
getSourceUnitType in interface Orderable

getPower

public final Power getPower()
Description copied from interface: Orderable
Gets the Power ordering the ordered Source unit

Specified by:
getPower in interface Orderable

toFormattedString

public java.lang.String toFormattedString(OrderFormatOptions ofo)
Description copied from interface: Orderable
Formats the order using the OrderFormat format string.

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.

Specified by:
toFormattedString in interface Orderable

validate

public void validate(TurnState state,
                     ValidationOptions valOpts,
                     RuleOptions ruleOpts)
              throws OrderException
Validate the order.

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.

Specified by:
validate in interface Orderable
Parameters:
state - Current turn state
valOpts - Current validation options
Throws:
OrderException

addSupportsOfAndMovesToSource

protected final 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.

Only "hold" supports are added. Invalid Move orders are NEVER added.


validate

protected void validate(ValidationOptions valOpts,
                        Unit unit)
                 throws OrderException
Validates a dislodged or non-dislodged unit, depending upon what type of unit is specified

Throws:
OrderException

getValidatedUnitType

protected final Unit.Type getValidatedUnitType(Province province,
                                               Unit.Type unitType,
                                               Unit unit)
                                        throws OrderException
Convenience method for matching unit types.

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.

Throws:
OrderException

checkPower

protected final void checkPower(Power power,
                                TurnState turnState,
                                boolean checkIfActive)
                         throws OrderException
Validates the given Power

Throws:
OrderException

checkSeasonRetreat

protected final void checkSeasonRetreat(TurnState state,
                                        java.lang.String orderName)
                                 throws OrderException
Convenience method to check that we are in the Retreat phase

Throws:
OrderException

checkSeasonAdjustment

protected final void checkSeasonAdjustment(TurnState state,
                                           java.lang.String orderName)
                                    throws OrderException
Convenience method to check that we are in the Adjustment phase

Throws:
OrderException

checkSeasonMovement

protected final void checkSeasonMovement(TurnState state,
                                         java.lang.String orderName)
                                  throws OrderException
Convenience method to check that we are in the Movement phase

Throws:
OrderException

appendFull

protected final void appendFull(java.lang.StringBuffer sb)
Convenience Method: prints the beginning of an order in a verbose format.
Example: France: Army Spain/sc


appendBrief

protected final void appendBrief(java.lang.StringBuffer sb)
Convenience Method: prints the beginning of an order in a brief format.
Example: France: Army spa/sc


toString

public java.lang.String toString()
For debugging: calls toBriefString(). Note this will fail if order is null.


equals

public boolean equals(java.lang.Object obj)
Determines if the orders are equal.

Note that full equality MUST be implemented for each subclassed Order object! Subclasses are advised to call the super method for assistance.



Copyright 2002-2004 Zachary DelProposto / jDip Development Team. All Rights Reserved.