net.sf.freecol.common.option
Class OptionGroup

java.lang.Object
  extended by net.sf.freecol.common.model.FreeColObject
      extended by net.sf.freecol.common.option.AbstractOption<OptionGroup>
          extended by net.sf.freecol.common.option.OptionGroup
All Implemented Interfaces:
java.lang.Cloneable, Option<OptionGroup>
Direct Known Subclasses:
ActionManager, ClientOptions

public class OptionGroup
extends AbstractOption<OptionGroup>

Used for grouping objects of Options.


Field Summary
private static java.util.logging.Logger logger
           
private  java.util.Map<java.lang.String,Option> optionMap
           
private  java.util.List<Option> options
           
 
Fields inherited from class net.sf.freecol.common.option.AbstractOption
isDefined
 
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE, ID_ATTRIBUTE, ID_ATTRIBUTE_TAG, INFINITY, NO_ID, PARTIAL_ATTRIBUTE, UNDEFINED, VALUE_TAG
 
Constructor Summary
OptionGroup(Specification specification)
           
OptionGroup(java.lang.String id)
          Creates a new OptionGroup.
OptionGroup(java.lang.String id, Specification specification)
           
 
Method Summary
 void add(Option option)
          Adds the given Option.
private  void addOptionGroup(OptionGroup group)
           
 OptionGroup clone()
           
 boolean getBoolean(java.lang.String id)
          Gets the boolean value of an option.
 int getInteger(java.lang.String id)
          Gets the integer value of an option.
 java.lang.String getName()
          Returns the name of this Option.
 Option getOption(java.lang.String id)
           
 java.util.List<Option> getOptions()
           
 java.lang.String getShortDescription()
          Gives a short description of this Option.
 java.lang.String getString(java.lang.String id)
          Gets the string value of an option.
 OptionGroup getValue()
          Returns the OptionGroup itself.
static java.lang.String getXMLElementTagName()
          Gets the tag name of the root element representing this object.
 java.util.Iterator<Option> iterator()
          Returns an Iterator for the Options.
protected  void readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
          Initialize this object from an XML-representation of this object.
 void removeAll()
          Removes all of the Options from this OptionGroup.
 void setBoolean(java.lang.String id, boolean value)
          Sets the boolean value of an option.
 void setInteger(java.lang.String id, int value)
          Sets the integer value of an option.
 void setString(java.lang.String id, java.lang.String value)
          Sets the string value of an option.
 void setValue(OptionGroup value)
          Copy the options of another OptionGroup.
 java.lang.String toString()
          Debug print helper.
protected  void toXMLImpl(javax.xml.stream.XMLStreamWriter out)
          This method writes an XML-representation of this object to the given stream.
 
Methods inherited from class net.sf.freecol.common.option.AbstractOption
generateChoices, getGroup, isNullValueOK, readAttributes, readOption, setGroup, setValue, setValues
 
Methods inherited from class net.sf.freecol.common.model.FreeColObject
addPropertyChangeListener, addPropertyChangeListener, dumpObject, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getId, getPropertyChangeListeners, getPropertyChangeListeners, getSpecification, hasAbility, hasAttribute, hasListeners, readAttributes, readChild, readChild, readChildren, readChildren, readFromArrayElement, readFromArrayElement, readFromListElement, readFromXML, readFromXMLElement, readFromXMLImpl, readFromXMLPartialImpl, removePropertyChangeListener, removePropertyChangeListener, save, save, setId, setSpecification, toXML, toXML, toXML, toXMLElement, toXMLElement, toXMLElement, toXMLElement, toXMLElementPartial, toXMLPartialImpl, writeAttribute, writeAttributes, writeChildren
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.sf.freecol.common.option.Option
getId, readFromXML, toXML
 

Field Detail

logger

private static java.util.logging.Logger logger

options

private java.util.List<Option> options

optionMap

private java.util.Map<java.lang.String,Option> optionMap
Constructor Detail

OptionGroup

public OptionGroup(java.lang.String id)
Creates a new OptionGroup.

Parameters:
id - The identifier for this option.

OptionGroup

public OptionGroup(Specification specification)

OptionGroup

public OptionGroup(java.lang.String id,
                   Specification specification)
Method Detail

clone

public OptionGroup clone()
                  throws java.lang.CloneNotSupportedException
Specified by:
clone in interface Option<OptionGroup>
Specified by:
clone in class AbstractOption<OptionGroup>
Throws:
java.lang.CloneNotSupportedException

add

public void add(Option option)
Adds the given Option.

Parameters:
option - The Option that should be added to this OptionGroup.

addOptionGroup

private void addOptionGroup(OptionGroup group)

getOptions

public java.util.List<Option> getOptions()

getOption

public Option getOption(java.lang.String id)

getInteger

public int getInteger(java.lang.String id)
Gets the integer value of an option.

Parameters:
id - The id of the option.
Returns:
The value.
Throws:
java.lang.IllegalArgumentException - If there is no integer value associated with the specified option.
java.lang.NullPointerException - if the given Option does not exist.

setInteger

public void setInteger(java.lang.String id,
                       int value)
Sets the integer value of an option.

Parameters:
id - The id of the option.
value - the new value of the option.
Throws:
java.lang.IllegalArgumentException - If there is no integer value associated with the specified option.
java.lang.NullPointerException - if the given Option does not exist.

getBoolean

public boolean getBoolean(java.lang.String id)
Gets the boolean value of an option.

Parameters:
id - The id of the option.
Returns:
The value.
Throws:
java.lang.IllegalArgumentException - If there is no boolean value associated with the specified option.
java.lang.NullPointerException - if the given Option does not exist.

setBoolean

public void setBoolean(java.lang.String id,
                       boolean value)
Sets the boolean value of an option.

Parameters:
id - The id of the option.
value - the new value of the option.
Throws:
java.lang.IllegalArgumentException - If there is no boolean value associated with the specified option.
java.lang.NullPointerException - if the given Option does not exist.

getString

public java.lang.String getString(java.lang.String id)
Gets the string value of an option.

Parameters:
id - String, option ID
Returns:
String option value.
Throws:
java.lang.IllegalArgumentException - If the specified option is not of String type
java.lang.NullPointerException - if the given Option does not exist.

setString

public void setString(java.lang.String id,
                      java.lang.String value)
Sets the string value of an option.

Parameters:
id - String, option ID
value - String, the new value of the option
Throws:
java.lang.IllegalArgumentException - If the specified option is not of String type
java.lang.NullPointerException - if the given Option does not exist.

removeAll

public void removeAll()
Removes all of the Options from this OptionGroup.


iterator

public java.util.Iterator<Option> iterator()
Returns an Iterator for the Options.

Returns:
The Iterator.

toXMLImpl

protected void toXMLImpl(javax.xml.stream.XMLStreamWriter out)
                  throws javax.xml.stream.XMLStreamException
This method writes an XML-representation of this object to the given stream.

Specified by:
toXMLImpl in class FreeColObject
Parameters:
out - The target stream.
Throws:
javax.xml.stream.XMLStreamException - if there are any problems writing to the stream.

readFromXMLImpl

protected void readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
                        throws javax.xml.stream.XMLStreamException
Initialize this object from an XML-representation of this object.

Overrides:
readFromXMLImpl in class AbstractOption<OptionGroup>
Parameters:
in - The input stream with the XML.
Throws:
javax.xml.stream.XMLStreamException - if a problem was encountered during parsing.

getName

public java.lang.String getName()
Returns the name of this Option.

Returns:
The name as provided in the constructor.

getShortDescription

public java.lang.String getShortDescription()
Gives a short description of this Option. Can for instance be used as a tooltip text.

Returns:
A short description of this Option.

getValue

public OptionGroup getValue()
Returns the OptionGroup itself.

Specified by:
getValue in interface Option<OptionGroup>
Specified by:
getValue in class AbstractOption<OptionGroup>
Returns:
an Object value

setValue

public void setValue(OptionGroup value)
Copy the options of another OptionGroup.

Specified by:
setValue in interface Option<OptionGroup>
Specified by:
setValue in class AbstractOption<OptionGroup>
Parameters:
value - an Object value

toString

public java.lang.String toString()
Debug print helper.

Specified by:
toString in interface Option<OptionGroup>
Overrides:
toString in class java.lang.Object
Returns:
Human-readable description of this OptionGroup.

getXMLElementTagName

public static java.lang.String getXMLElementTagName()
Gets the tag name of the root element representing this object.

Returns:
"optionGroup".