org.opensha.commons.param.constraint.impl
Class LocationConstraint

java.lang.Object
  extended by org.opensha.commons.param.constraint.AbstractParameterConstraint<Location>
      extended by org.opensha.commons.param.constraint.impl.LocationConstraint
All Implemented Interfaces:
Serializable, Named, DiscreteParameterConstraint<Location>, ParameterConstraint<Location>

public class LocationConstraint
extends AbstractParameterConstraint<Location>
implements DiscreteParameterConstraint<Location>

Title: LocationConstraint

Description: This constraint contains a list of possible allowed location values. These can typically be presented in a GUI picklist. This is the same fucntionality for all StringConstraint.

Version:
1.0
Author:
Nitin Gupta
See Also:
Serialized Form

Field Summary
protected static String C
          Class name for debugging.
protected static boolean D
          If true print out debug statements.
 
Fields inherited from class org.opensha.commons.param.constraint.AbstractParameterConstraint
editable, name, nullAllowed
 
Constructor Summary
LocationConstraint()
          No-Arg constructor for the LocationConstraint object.
LocationConstraint(List<Location> locations)
          Constructor for the LocationConstraint object.
 
Method Summary
 void addLocation(Location loc)
          Adds a Location to the list of allowed values, if this constraint is editable.
 Object clone()
          Returns a copy so you can't edit or damage the origial.
 boolean containsLocation(Location loc)
          Returns true if the location is in the allowed list, false otherwise
 List<Location> getAllowedLocations()
          Returns a cloned ArrayList of the allowed Locations.
 List<Location> getAllowedValues()
          Returns a cloned ArrayList of the allowed Locations.
 boolean isAllowed(Location loc)
          Determine if the new value being set is allowed.
 ListIterator listIterator()
          Returns an Iterator over allowed values.
 void removeLocation(Location loc)
          Removes a Location from the list of allowed values, if this constraint is editable.
 void setLocations(List<Location> locations)
          Sets all allowed locations via a ArrayList, which is copied into this object's internal storage structure.
 int size()
          Returns number of allowed values.
 String toString()
          Prints out the current state of this parameter, i.e.
 
Methods inherited from class org.opensha.commons.param.constraint.AbstractParameterConstraint
checkEditable, getName, isEditable, isNullAllowed, setName, setNonEditable, setNullAllowed
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.opensha.commons.param.constraint.ParameterConstraint
getName, isEditable, isNullAllowed, setName, setNonEditable, setNullAllowed
 

Field Detail

C

protected static final String C
Class name for debugging.

See Also:
Constant Field Values

D

protected static final boolean D
If true print out debug statements.

See Also:
Constant Field Values
Constructor Detail

LocationConstraint

public LocationConstraint()
No-Arg constructor for the LocationConstraint object. Calls the super() constructor.


LocationConstraint

public LocationConstraint(List<Location> locations)
                   throws ConstraintException
Constructor for the LocationConstraint object. Sets all allowed locations via a ArrayList, which is copied into this object's internal storage structure.

Parameters:
locations - ArrayList of allowed locations
Throws:
ConstraintException - Thrown if the passed in vector size is 0
Method Detail

setLocations

public void setLocations(List<Location> locations)
                  throws ConstraintException,
                         EditableException
Sets all allowed locations via a ArrayList, which is copied into this object's internal storage structure.

Parameters:
locations - ArrayList of allowed locations
Throws:
ConstraintException - Thrown if the passed in vector size is 0
EditableException

getAllowedLocations

public List<Location> getAllowedLocations()
Returns a cloned ArrayList of the allowed Locations.


getAllowedValues

public List<Location> getAllowedValues()
Returns a cloned ArrayList of the allowed Locations.

Specified by:
getAllowedValues in interface DiscreteParameterConstraint<Location>

isAllowed

public boolean isAllowed(Location loc)
Determine if the new value being set is allowed. First checks if null and if nulls are allowed. Then verifies the Object is a Location. Finally the code verifies that the Location is in the allowed locations vector. If any of these checks fails, false is returned.

Specified by:
isAllowed in interface ParameterConstraint<Location>
Parameters:
obj - Object to check if allowed Location
Returns:
True if the value is allowed

listIterator

public ListIterator listIterator()
Returns an Iterator over allowed values.

Specified by:
listIterator in interface DiscreteParameterConstraint<Location>

addLocation

public void addLocation(Location loc)
                 throws EditableException
Adds a Location to the list of allowed values, if this constraint is editable.

Throws:
EditableException

removeLocation

public void removeLocation(Location loc)
                    throws EditableException
Removes a Location from the list of allowed values, if this constraint is editable.

Throws:
EditableException

containsLocation

public boolean containsLocation(Location loc)
Returns true if the location is in the allowed list, false otherwise


size

public int size()
Returns number of allowed values.

Specified by:
size in interface DiscreteParameterConstraint<Location>

toString

public String toString()
Prints out the current state of this parameter, i.e. classname and allowed values. Useful for debugging.

Overrides:
toString in class Object

clone

public Object clone()
Returns a copy so you can't edit or damage the origial.

Specified by:
clone in interface ParameterConstraint<Location>
Specified by:
clone in class AbstractParameterConstraint<Location>
Returns:
Exact copy of this object's state.