Class ListOption<T>

    • Field Detail

      • logger

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

        private AbstractOption<T> template
        The AbstractOption used to generate new values.
      • maximumNumber

        private int maximumNumber
        The maximum number of list entries. Defaults to Integer.MAX_VALUE.
      • value

        private final java.util.List<AbstractOption<T>> value
        The list of options.
      • allowDuplicates

        protected boolean allowDuplicates
        Whether the list can include duplicates. This was always true before adding this variable so the default should remain == true.
      • MAXIMUM_NUMBER_TAG

        private static final java.lang.String MAXIMUM_NUMBER_TAG
        See Also:
        Constant Field Values
    • Constructor Detail

      • ListOption

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

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

      • getTemplate

        public AbstractOption<T> getTemplate()
        Gets the generating template.
        Returns:
        The template.
      • setTemplate

        public void setTemplate​(AbstractOption<T> template)
        Sets the generating template.
        Parameters:
        template - The template to set.
      • getMaximumNumber

        public int getMaximumNumber()
        Gets the maximum number of allowed values.
        Returns:
        The maximum number of allowed values for this option.
      • setMaximumNumber

        public void setMaximumNumber​(int maximumNumber)
        Sets the maximum number of allowed values.
        Parameters:
        maximumNumber - The new maximum number of allowed values.
      • getOptionValues

        public java.util.List<T> getOptionValues()
        Get the values of the current non-null options in the list.
        Returns:
        A list of option values.
      • addMember

        private void addMember​(AbstractOption<T> ao)
        Add a member to the values list.
        Parameters:
        ao - The new AbstractOption member to add.
      • getAllowDuplicates

        public boolean getAllowDuplicates()
        Does this list allow duplicates?
        Returns:
        True if duplicates are allowed.
      • setAllowDuplicates

        public void setAllowDuplicates​(boolean allowDuplicates)
        Set the deduplicatation flag.
        Parameters:
        allowDuplicates - The new deduplication flag;
      • canAdd

        public boolean canAdd​(AbstractOption<T> ao)
        Can an option be added to this list?
        Parameters:
        ao - The option to check.
        Returns:
        True if the option can be added.
      • setListValues

        protected void setListValues​(ListOption<T> lo)
        Set the list option values from another list option.
        Parameters:
        lo - The other ListOption.
      • isNullValueOK

        public boolean isNullValueOK()
        Is null an acceptable value for this option? Override this in subclasses where necessary.
        Overrides:
        isNullValueOK in class AbstractOption<java.util.List<AbstractOption<T>>>
        Returns:
        False.
      • 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.util.List<AbstractOption<T>>>
        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.
      • readAttributes

        public void readAttributes​(FreeColXMLReader xr)
                            throws javax.xml.stream.XMLStreamException
        Reads the attributes of this object from an XML stream.
        Overrides:
        readAttributes in class AbstractOption<java.util.List<AbstractOption<T>>>
        Parameters:
        xr - The FreeColXMLReader to read from.
        Throws:
        javax.xml.stream.XMLStreamException - if there is a problem reading the stream.
      • readChildren

        public 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

        public 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.
      • readChildOption

        private AbstractOption<T> readChildOption​(FreeColXMLReader xr)
                                           throws javax.xml.stream.XMLStreamException
        Hack to suppress warning when reading a typed option. FIXME: Work out how to make this go away.
        Parameters:
        xr - The FreeColXMLReader to read from.
        Returns:
        A child typed AbstractOption.
        Throws:
        javax.xml.stream.XMLStreamException - if the stream is corrupt.