Class Faction

java.lang.Object
  extended by Faction
All Implemented Interfaces:
java.lang.Cloneable

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

Contains MMS Faction data for a single faction

Author:
Michael Latham

Field Summary
(package private)  int M_CANCEL
           
private  java.lang.String m_factionName
           
(package private)  int M_NO
           
private  java.util.Vector<java.lang.String> m_properties
           
(package private)  int M_YES
           
 
Constructor Summary
Faction()
          Default constructor - creates an empty Faction; not preferred
Faction(java.lang.String factionName)
          Preferred constructor - creates faction with the given name
 
Method Summary
 void addAllProperties(java.util.Vector<java.lang.String> vList)
          Adds all the Faction properties to the given vector
 void addFactionProperty(java.lang.String mmsLine)
          Given the string for the property, add it to the list of properties
 void addUnit(java.lang.String newUnit)
          Add a new Unit to the list
 void addUnitProperties(java.util.Vector<java.lang.String> vList, int unitIdx)
          Add all non-unit declarations to the given vector
 void addUnitProperty(int unitIdx, java.lang.String propVal)
          Adds a new property for the given Unit
 void addUnits(java.util.Vector<java.lang.String> vList)
          Add all units to the given vector
 void changeName(java.lang.String newName)
          Replaces all properties with the new name
 Faction clone()
          Clone class for a deep copy
 java.lang.String getFactionForScenarioFile()
          Return this faction for the output file buffer of a scenario
 java.lang.String getFactionProperty(int idx)
          Return the element at the given index (zero based) as a String
 java.lang.String getLocation()
           
 java.lang.String getName()
           
 java.lang.String getPropertyValue(java.lang.String lParam)
          Return the propery value for the given property string
 int getUnitCount()
           
 java.lang.String getUnitValue(java.lang.String lParam)
          Return the Unit value for the given property string
 boolean propertyIsUnit(java.lang.String lParam)
          Determine if given property is a Unit declaration
 boolean removeProperty(java.lang.String prop)
          Remove the given property from the list
 void removeUnit(int oldUnitNum)
          Remove the Unit and all its properties
 void replaceUnit(java.lang.String oldUnit, java.lang.String newUnit)
          Replace a Unit with new Unit info
 void replaceUnitProperty(int unitIdx, java.lang.String oldVal, java.lang.String newVal)
          Replace property for the given Unit and property
 void setLocation(java.lang.String newLoc)
          Sets the location property to the given location
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

M_NO

final int M_NO
See Also:
Constant Field Values

M_YES

final int M_YES
See Also:
Constant Field Values

M_CANCEL

final int M_CANCEL
See Also:
Constant Field Values

m_factionName

private java.lang.String m_factionName

m_properties

private java.util.Vector<java.lang.String> m_properties
Constructor Detail

Faction

public Faction()
Default constructor - creates an empty Faction; not preferred


Faction

public Faction(java.lang.String factionName)
Preferred constructor - creates faction with the given name

Method Detail

clone

public Faction clone()
Clone class for a deep copy

Overrides:
clone in class java.lang.Object
Returns:
Copy of this Faction object

getName

public java.lang.String getName()
Returns:
name of Faction

addFactionProperty

public void addFactionProperty(java.lang.String mmsLine)
Given the string for the property, add it to the list of properties

Parameters:
mmsLine - The line for the property (e.g. Unit_Rangers_1=Stone Rhino SERO,Capt Black,3,3)

getFactionProperty

public java.lang.String getFactionProperty(int idx)
Return the element at the given index (zero based) as a String

Parameters:
idx - Zero based index
Returns:
Element as a String at index, or null

addAllProperties

public void addAllProperties(java.util.Vector<java.lang.String> vList)
Adds all the Faction properties to the given vector

Parameters:
vList - String vector that will receive all Faction properties

addUnits

public void addUnits(java.util.Vector<java.lang.String> vList)
Add all units to the given vector

Parameters:
vList - String vector that will receive list of Units

addUnitProperties

public void addUnitProperties(java.util.Vector<java.lang.String> vList,
                              int unitIdx)
Add all non-unit declarations to the given vector

Parameters:
vList - String vector that will receive list of Units
unitIdx - Unit number; a number less than 1 implies get all unit properties

propertyIsUnit

public boolean propertyIsUnit(java.lang.String lParam)
Determine if given property is a Unit declaration

Parameters:
lParam - Property to check
Returns:
true if Unit declaration; false otherwise

getUnitValue

public java.lang.String getUnitValue(java.lang.String lParam)
Return the Unit value for the given property string

Parameters:
lParam - Full property string
Returns:
Value of the property, or blanks if invalid format

getPropertyValue

public java.lang.String getPropertyValue(java.lang.String lParam)
Return the propery value for the given property string

Parameters:
lParam - Full property string
Returns:
String Value of the property, or blanks if invalid format

getLocation

public java.lang.String getLocation()
Returns:
Value of the location, or blanks if not set

removeProperty

public boolean removeProperty(java.lang.String prop)
Remove the given property from the list

Parameters:
prop - Entire property string
Returns:
true if removed; false if error or not found

addUnit

public void addUnit(java.lang.String newUnit)
Add a new Unit to the list

Parameters:
newUnit - Unit value of format: mech,pilot,x,y,...

replaceUnit

public void replaceUnit(java.lang.String oldUnit,
                        java.lang.String newUnit)
Replace a Unit with new Unit info

Parameters:
oldUnit - - current Unit to replace
newUnit - - new Unit description

getUnitCount

public int getUnitCount()
Returns:
Total number of units declared

removeUnit

public void removeUnit(int oldUnitNum)
Remove the Unit and all its properties

Parameters:
oldUnitNum - Unit number

addUnitProperty

public void addUnitProperty(int unitIdx,
                            java.lang.String propVal)
Adds a new property for the given Unit

Parameters:
unitIdx - Unit number
propVal - Property and value

replaceUnitProperty

public void replaceUnitProperty(int unitIdx,
                                java.lang.String oldVal,
                                java.lang.String newVal)
Replace property for the given Unit and property

Parameters:
unitIdx - Unit number
oldVal - Old property and value
newVal - New property and value

setLocation

public void setLocation(java.lang.String newLoc)
Sets the location property to the given location

Parameters:
newLoc - Location (N, NE, S, etc.)

changeName

public void changeName(java.lang.String newName)
Replaces all properties with the new name

Parameters:
newName - New name of Faction

getFactionForScenarioFile

public java.lang.String getFactionForScenarioFile()
Return this faction for the output file buffer of a scenario

Returns:
Scenario file buffer for this Faction