uk.co.agena.minerva.util.model
Class VariableList

java.lang.Object
  extended by uk.co.agena.minerva.util.model.VariableList
All Implemented Interfaces:
java.lang.Cloneable, Writable

public class VariableList
extends java.lang.Object
implements java.lang.Cloneable, Writable

This class encapsulates a List of Variables and provides various convenience methods for using the underlying List.


Field Summary
 
Fields inherited from interface uk.co.agena.minerva.util.model.Writable
FIELD_SEPARATOR
 
Constructor Summary
VariableList()
          Default Constructor.
 
Method Summary
 void addVariable(java.lang.String variableName)
          Creates a new Variable with the supplied name and adds it to the List of Variables.
 Variable addVariable(java.lang.String variableName, double defaultValue)
          Creates a new Variable with the supplied name and default value and adds it to the List of Variables.
 void addVariable(java.lang.String variableName, double value, double defaultValue)
          Creates a new Variable with the supplied name, actual value and default value and adds it to the List of Variables.
 void addVariable(Variable v)
          Adds the supplied Variable to the list of variables.
 void checkVariableName(java.lang.String variableName)
          Throws a MinervaVariableException if the variableName is not valid e.g.
 java.lang.Object clone()
          Clones the VariableList.
 java.util.List getAllVariableNames()
          Gets the String Names of all the Variables in this VariableList and adds them to a List which can be returned.
 Variable getVariable(java.lang.String variableName)
          Finds the Variable with the supplied name.
 java.util.List getVariables()
           
 double getVersion()
          Returns the version of the class.
 int read(java.util.List strings, int currentLineNumber)
           
 void removeAllVariables()
          Removes all Variables from the List.
 void removeVariable(Variable v)
          Removes the specified Variable from the list of Variables if it is a member of the List.
 void setVariables(java.util.List variables)
           
 void setVersion(double version)
          Sets the version number of the class.
 int size()
          Returns the number of Variables in the List.
 void updateVariable(Variable v, java.lang.String newName, double newDefaultValue)
          Updates the specified Variable to have the new Name and Default Value that have been specified.
 java.util.List write()
          Writes the object in question to a List of Strings.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VariableList

public VariableList()
Default Constructor.

Method Detail

getVersion

public double getVersion()
Description copied from interface: Writable
Returns the version of the class. Used to ensure backward compatibility.

Specified by:
getVersion in interface Writable
Returns:
the version number

setVersion

public void setVersion(double version)
Description copied from interface: Writable
Sets the version number of the class. Used to ensure backward compatibility.

Specified by:
setVersion in interface Writable
Parameters:
version - the version number

getVariables

public java.util.List getVariables()

setVariables

public void setVariables(java.util.List variables)

getVariable

public Variable getVariable(java.lang.String variableName)
                     throws MinervaVariableException
Finds the Variable with the supplied name.

Parameters:
variableName - the name of the Variable being sought
Returns:
the found Variable
Throws:
MinervaVariableException - if no Variable with the supplied name can be found

checkVariableName

public void checkVariableName(java.lang.String variableName)
                       throws MinervaVariableException
Throws a MinervaVariableException if the variableName is not valid e.g. contains spaces, operators etc or if a Variable with the specified Name already exists in the VariableList. This should always be called before adding a new Variable as invalid names and two Variables in a VariableList with the same name is not permitted.

Parameters:
variableName - The Name we are checking
Throws:
MinervaVariableException - If the variableName is invalid or there is a Variable with the specified name in this VariableList already.

addVariable

public void addVariable(java.lang.String variableName)
                 throws MinervaVariableException
Creates a new Variable with the supplied name and adds it to the List of Variables.

Parameters:
variableName - the name of the Variable to be created and added
Throws:
MinervaVariableException - if a Variable with the same name already exists in the List

addVariable

public Variable addVariable(java.lang.String variableName,
                            double defaultValue)
                     throws MinervaVariableException
Creates a new Variable with the supplied name and default value and adds it to the List of Variables.

Parameters:
variableName - the name of the Variable to be created and added
defaultValue - the defaultValue of the Variable to be created and added
Returns:
The newly created Variable.
Throws:
MinervaVariableException - if a Variable with the same name already exists in the List

addVariable

public void addVariable(java.lang.String variableName,
                        double value,
                        double defaultValue)
                 throws MinervaVariableException
Creates a new Variable with the supplied name, actual value and default value and adds it to the List of Variables.

Parameters:
variableName - the name of the Variable to be created and added
value - the value of the Variable to be created and added
defaultValue - the defaultValue of the Variable to be created and added
Throws:
MinervaVariableException - if a Variable with the same name already exists in the List

addVariable

public void addVariable(Variable v)
                 throws MinervaVariableException
Adds the supplied Variable to the list of variables.

Parameters:
v - the Variable to be added
Throws:
MinervaVariableException - if a Variable with the same name already exists in the List

removeAllVariables

public void removeAllVariables()
Removes all Variables from the List.


size

public int size()
Returns the number of Variables in the List.

Returns:
the number of Variables in the List

removeVariable

public void removeVariable(Variable v)
                    throws MinervaVariableException
Removes the specified Variable from the list of Variables if it is a member of the List.

Parameters:
v - The Variable to be removed
Throws:
MinervaVariableException - If the specified Variable is not a member of the List

updateVariable

public void updateVariable(Variable v,
                           java.lang.String newName,
                           double newDefaultValue)
                    throws MinervaVariableException
Updates the specified Variable to have the new Name and Default Value that have been specified. The Variable must exist in this VariableList for any action to be taken.

Parameters:
v - The Variable that is to be updated
newName - The New Name for the Variable
newDefaultValue - The New Default Value for the Variable
Throws:
MinervaVariableException - If the specified Variable is not a member of this List or if a Variable with the specified newName already exists (two Variables can't have the same name).

getAllVariableNames

public java.util.List getAllVariableNames()
Gets the String Names of all the Variables in this VariableList and adds them to a List which can be returned.

Returns:

write

public java.util.List write()
                     throws MinervaReadWriteException
Description copied from interface: Writable
Writes the object in question to a List of Strings.

Specified by:
write in interface Writable
Returns:
the List to which the Strings have been written
Throws:
MinervaReadWriteException - if there

read

public int read(java.util.List strings,
                int currentLineNumber)
         throws MinervaReadWriteException
Specified by:
read in interface Writable
Throws:
MinervaReadWriteException

clone

public java.lang.Object clone()
Clones the VariableList.

Overrides:
clone in class java.lang.Object
Returns:
a copy of this VariableList


Copyright © 2006 Agena Ltd. All Rights Reserved.