com.prozima.pengine
Class CostTable

java.lang.Object
  extended by com.prozima.pengine.CostTable
All Implemented Interfaces:
java.lang.Cloneable

public class CostTable
extends java.lang.Object
implements java.lang.Cloneable

A CostTable controls the allocation of CostRules, allowing their organisation by time and priority. Eras are used to define the periods of time during which specific cost rules apply. Within the same era, cost rules are applied in the order of their priority.


Field Summary
static int DEFAULT_ERA_ID
          ID of the default era.
static int DEFAULT_RULE_PRIORITY
          Priority assigned to default cost rule - cannot be changed.
static int MAX_PRIORITY
          Maximum priority a cost rule may be assigned.
static int MIN_PRIORITY
          Minimum priority a cost rule may be assigned.
 
Constructor Summary
CostTable()
          Create a CostTable and initialise it with default values.
 
Method Summary
 boolean addCostRule(int inEraID, boolean inAddAtTop, CostRule inRule)
          Add a cost rule to the cost table.
 java.lang.Integer createEra(DayAndYear inStart)
          Create a new Era which is used to control cost rules.
 java.util.Set<java.lang.Integer> getAllEraIDs()
          Get set of all defined era IDs.
 java.util.List<CostRule> getCostRules(int inEraID)
          Get an ordered list of all the cost rules for a specific era.
 boolean priorityDecrease(int inEraID, CostRule inRule)
          Decrease the priority of a cost rule.
 boolean priorityIncrease(int inEraID, CostRule inRule)
          Increase the priority of a cost rule.
 boolean removeCostRule(int inEraID, CostRule inRule)
          Remove a cost rule from the cost table.
 boolean removeEra(int inEraID)
          Remove a previously created era.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_ERA_ID

public static final int DEFAULT_ERA_ID
ID of the default era. era begins with the earliest possible start date. This era cannot be deleted and its start date cannot be modified. All subsequently created Eras have an ID which is larger than this value.

See Also:
Constant Field Values

DEFAULT_RULE_PRIORITY

public static final int DEFAULT_RULE_PRIORITY
Priority assigned to default cost rule - cannot be changed.

See Also:
Constant Field Values

MAX_PRIORITY

public static final int MAX_PRIORITY
Maximum priority a cost rule may be assigned.

See Also:
Constant Field Values

MIN_PRIORITY

public static final int MIN_PRIORITY
Minimum priority a cost rule may be assigned.

See Also:
Constant Field Values
Constructor Detail

CostTable

public CostTable()
Create a CostTable and initialise it with default values.

Method Detail

addCostRule

public boolean addCostRule(int inEraID,
                           boolean inAddAtTop,
                           CostRule inRule)
Add a cost rule to the cost table. If another cost rule exists with the same priority then its priority and the priority of all lower priority cost rules will be dropped.

Parameters:
inEraID - ID of the era.
inAddAtTop - true if cost rule should be added with a priority greater than other cost rules. false if cost rule should be added with the lowest priority.
inRule - Cost rule which is being added.
Returns:
true if the cost rule could be set ok, otherwise false.

createEra

public java.lang.Integer createEra(DayAndYear inStart)
Create a new Era which is used to control cost rules.

Parameters:
inStart - Start of the era.
Returns:
ID allocated to the era or null if no era could be created. If an era already exists with the same start then its ID is returned.

getAllEraIDs

public java.util.Set<java.lang.Integer> getAllEraIDs()
Get set of all defined era IDs.

Returns:
Set of IDs identifying each era.

getCostRules

public java.util.List<CostRule> getCostRules(int inEraID)
Get an ordered list of all the cost rules for a specific era. Highest priority cost rules are at the beginning of the list.

Parameters:
inEraID - ID of an era.
Returns:
List of cost rules. List is empty if there if no era corresponds to the era ID passed as a parameter or if no cost rules exist for this era.

priorityDecrease

public boolean priorityDecrease(int inEraID,
                                CostRule inRule)
Decrease the priority of a cost rule.

Parameters:
inEraID - ID identifying the era which the cost rule belongs to.
inRule - Cost rule which should have its priority decreased.
Returns:
true if a cost rule exists for the specified era and it's priority was decreased. false if cost rule does not exist for specified era or if cost rule already has minimum priority.

priorityIncrease

public boolean priorityIncrease(int inEraID,
                                CostRule inRule)
Increase the priority of a cost rule.

Parameters:
inEraID - ID identifying the era which the cost rule belongs to.
inRule - Cost rule which should have its priority increased.
Returns:
true if a cost rule exists for the specified era and it's priority was increased. false if cost rule does not exist for specified era or if cost rule already has maximum priority.

removeCostRule

public boolean removeCostRule(int inEraID,
                              CostRule inRule)
Remove a cost rule from the cost table.

Parameters:
inEraID - ID of the era. era must exist.
inRule - Cost rule which is to be removed. Should not be null.
Returns:
true if the cost rule could be found and removed, otherwise false.

removeEra

public boolean removeEra(int inEraID)
Remove a previously created era. All time periods stored for this era are also deleted. The default era can never be deleted.

Parameters:
inEraID - ID of the era.
Returns:
true if an era exists with this ID and it was successfully removed. false if an era does not exist with this ID.