Class StringOption

  • All Implemented Interfaces:
    java.lang.Cloneable, java.lang.Comparable<FreeColObject>, ObjectWithId, Option<java.lang.String>

    public class StringOption
    extends AbstractOption<java.lang.String>
    Represents an option that can be a string selected from a list of possible values (choices).
    • Field Detail

      • logger

        private static final java.util.logging.Logger logger
      • value

        private java.lang.String value
        The value of this option.
      • choices

        private final java.util.List<java.lang.String> choices
        A list of choices to provide to the UI.
    • Constructor Detail

      • StringOption

        public StringOption​(Specification specification)
        Creates a new StringOption.
        Parameters:
        specification - The Specification to refer to.
      • StringOption

        public StringOption​(java.lang.String id,
                            Specification specification)
        Creates a new StringOption.
        Parameters:
        id - The object identifier.
        specification - The Specification to refer to.
    • Method Detail

      • getChoices

        public final java.util.List<java.lang.String> getChoices()
        Get the list of string choices.
        Returns:
        The list of choices.
      • setChoices

        public final void setChoices​(java.util.List<java.lang.String> newChoices)
        Set the choices.
        Parameters:
        newChoices - The new list of choices.
      • getValue

        public java.lang.String getValue()
        Gets the value of this option.
        Specified by:
        getValue in interface Option<java.lang.String>
        Specified by:
        getValue in class AbstractOption<java.lang.String>
        Returns:
        The value of this Option.
      • setValue

        public void setValue​(java.lang.String value)
        Sets the value of this option.
        Specified by:
        setValue in interface Option<java.lang.String>
        Specified by:
        setValue in class AbstractOption<java.lang.String>
        Parameters:
        value - The new value of this Option.
      • setValue

        protected void setValue​(java.lang.String valueString,
                                java.lang.String defaultValueString)
        Sets the value of this option from the given string representation. Both parameters must not be null at the same time. This method does nothing. Override it if the option has a suitable string representation.
        Overrides:
        setValue in class AbstractOption<java.lang.String>
        Parameters:
        valueString - The string representation of the value of this Option.
        defaultValueString - The string representation of the default value of this Option.
      • writeAttributes

        protected void writeAttributes​(FreeColXMLWriter xw)
                                throws javax.xml.stream.XMLStreamException
        Write the attributes of this object to a stream. To be overridden if required by any object that has attributes and uses the toXML(FreeColXMLWriter, String) call.
        Overrides:
        writeAttributes in class AbstractOption<java.lang.String>
        Parameters:
        xw - The FreeColXMLWriter to write to.
        Throws:
        javax.xml.stream.XMLStreamException - if there are any problems writing to the stream.
      • writeChildren

        protected void writeChildren​(FreeColXMLWriter xw)
                              throws javax.xml.stream.XMLStreamException
        Write the children of this object to a stream. To be overridden if required by any object that has children and uses the toXML(FreeColXMLWriter, String) call.
        Overrides:
        writeChildren in class FreeColObject
        Parameters:
        xw - The FreeColXMLWriter to write to.
        Throws:
        javax.xml.stream.XMLStreamException - if there are any problems writing to the stream.
      • readChildren

        protected void readChildren​(FreeColXMLReader xr)
                             throws javax.xml.stream.XMLStreamException
        Reads the children of this object from an XML stream.
        Overrides:
        readChildren in class FreeColObject
        Parameters:
        xr - The FreeColXMLReader to read from.
        Throws:
        javax.xml.stream.XMLStreamException - if there is a problem reading the stream.
      • readChild

        protected void readChild​(FreeColXMLReader xr)
                          throws javax.xml.stream.XMLStreamException
        Reads a single child object. Subclasses must override to read their enclosed elements. This particular instance of the routine always throws XMLStreamException because we should never arrive here. However it is very useful to always call super.readChild() when an unexpected tag is encountered, as the exception thrown here provides some useful debugging context.
        Overrides:
        readChild in class FreeColObject
        Parameters:
        xr - The FreeColXMLReader to read from.
        Throws:
        javax.xml.stream.XMLStreamException - if there is a problem reading the stream.
      • getXMLTagName

        public java.lang.String getXMLTagName()
        Get the serialization tag for this object.
        Specified by:
        getXMLTagName in class FreeColObject
        Returns:
        The tag.