Class Options

All Implemented Interfaces:
Serializable, Cloneable, Iterable<OptionEntry>, Collection<OptionEntry>, Set<OptionEntry>

public class Options extends AbstractSet<OptionEntry> implements Cloneable, Serializable
This class represents a list of possible values that are valid for a particular field.
Additionally the class provides a text string describing the value for display purposes.
The class is implemented as a set of OptionEntry objects where the entry value is used as the key for the set and thus must be unique.
See Also:
  • Field Details

  • Constructor Details

    • Options

      public Options()
    • Options

      public Options(int initialCapacity)
    • Options

      public Options(Options other)
    • Options

      public Options(OptionEntry[] entries)
    • Options

      public Options(Class<? extends Enum<?>> enumType)
  • Method Details

    • addAll

      public boolean addAll(Collection<? extends OptionEntry> source)
      Specified by:
      addAll in interface Collection<OptionEntry>
      Specified by:
      addAll in interface Set<OptionEntry>
      Overrides:
      addAll in class AbstractCollection<OptionEntry>
    • clone

      public Options clone()
      Overrides:
      clone in class Object
    • getOptionGroupResolver

      public Options.OptionGroupResolver getOptionGroupResolver()
      Returns the function that determines the group to which an option entry belongs.
      Returns:
      the group resolver function or null
    • setOptionGroupResolver

      public void setOptionGroupResolver(Options.OptionGroupResolver optionGroupResolver)
      Sets a function that determines the group to which an option entry belongs. e.g.: options.setOptionGroupResolver((oe) -> ((MyEnum)oe.getValue()).getCategory());
      Parameters:
      optionGroupResolver - the group resolver function
    • getIndex

      protected int getIndex(Object value)
    • createOptionEntry

      protected OptionEntry createOptionEntry(Object value, String text, boolean active)
    • getEntry

      public OptionEntry getEntry(Object value)
    • get

      public String get(Object value)
    • isActive

      public boolean isActive(Object value)
    • getEntryAt

      public OptionEntry getEntryAt(int i)
      Gets the entry at index i
      Parameters:
      i - the index
      Returns:
      the OptionEntry or null
    • getValueAt

      public Object getValueAt(int i)
      Gets the value of the entry at index i
      Parameters:
      i - the index
      Returns:
      the value or null if not found
    • getTextAt

      public String getTextAt(int i)
      Gets the text of the entry at index i
      Parameters:
      i - the index
      Returns:
      the text or an empty String if not found
    • getValues

      public Set<Object> getValues(boolean activeOnly)
      Returns all values as a set
      Parameters:
      activeOnly - flag whether to return the active items only
      Returns:
      the value set
    • getValues

      public final Set<Object> getValues()
      Returns all values as a set
      Returns:
      the value set
    • getActiveCount

      public int getActiveCount()
      Returns the number of active elements
      Returns:
      the number of active elements
    • getActive

      public Options getActive()
      Returns the subset of active options
      Returns:
      the active options
    • set

      public void set(Object value, String text, Boolean active, Options.InsertPos pos)
      Sets or Adds an option at a certain position
      Parameters:
      value - the value object
      text - the text
      active - flag if element is active (selectable)
      pos - the position, see Options.InsertPos
    • set

      public final void set(Object value, String text, Options.InsertPos pos)
      Sets or Adds an option at a certain position
      Parameters:
      value - the value object
      text - the text
      pos - the position, see Options.InsertPos
    • set

      public void set(Object value, String text, Boolean active)
      Sets or adds Adds an option at the bottom
      Parameters:
      value - the value object
      text - the text
      active - flag whether or not the option is active
    • set

      public final void set(Object value, String text)
      Sets or adds Adds an option at the bottom
      Parameters:
      value - the value object
      text - the text
    • add

      public final Options add(Object value, String text, boolean active)
      Adds or updates an option Same as set() but allows Option building
      Parameters:
      value - the value
      text - the text for this value
      active - flag if element is active (selectable)
      Returns:
      returns self (this)
    • add

      public final Options add(Object value, String text)
      Adds or updates an option Same as set() but allows Option building
      Parameters:
      value - the value
      text - the text for this value
      Returns:
      returns self (this)
    • add

      public boolean add(OptionEntry option)
      Specified by:
      add in interface Collection<OptionEntry>
      Specified by:
      add in interface Set<OptionEntry>
      Overrides:
      add in class AbstractCollection<OptionEntry>
    • append

      public void append(OptionEntry option)
      Appends an option Useful for fast loading when it is certain that there are no duplicates WARNING: Does not check if the entry already exists
      Parameters:
      option - the option to append
    • append

      public void append(Object value, String text, boolean active)
      Appends an option Useful for fast loading when it is certain that there are no duplicates WARNING: Does not check if the entry already exists
      Parameters:
      value - the value object
      text - the text
      active - the flag whether or not this item is active
    • clear

      public void clear()
      Specified by:
      clear in interface Collection<OptionEntry>
      Specified by:
      clear in interface Set<OptionEntry>
      Overrides:
      clear in class AbstractCollection<OptionEntry>
    • contains

      public boolean contains(Object value)
      Specified by:
      contains in interface Collection<OptionEntry>
      Specified by:
      contains in interface Set<OptionEntry>
      Overrides:
      contains in class AbstractCollection<OptionEntry>
    • containsNull

      public boolean containsNull()
      Checks if the Option list contains an empty value
      Returns:
      true if it contains an empty value or false otherwise
    • has

      public boolean has(Object value)
      same as contains(), but IDE may not issue warning
      Parameters:
      value - the value to check
      Returns:
      true if it exists in the options list
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Collection<OptionEntry>
      Specified by:
      isEmpty in interface Set<OptionEntry>
      Overrides:
      isEmpty in class AbstractCollection<OptionEntry>
    • iterator

      public Iterator<OptionEntry> iterator()
      Specified by:
      iterator in interface Collection<OptionEntry>
      Specified by:
      iterator in interface Iterable<OptionEntry>
      Specified by:
      iterator in interface Set<OptionEntry>
      Specified by:
      iterator in class AbstractCollection<OptionEntry>
    • remove

      public boolean remove(Object value)
      Specified by:
      remove in interface Collection<OptionEntry>
      Specified by:
      remove in interface Set<OptionEntry>
      Overrides:
      remove in class AbstractCollection<OptionEntry>
    • size

      public int size()
      Specified by:
      size in interface Collection<OptionEntry>
      Specified by:
      size in interface Set<OptionEntry>
      Specified by:
      size in class AbstractCollection<OptionEntry>
    • toArray

      public Object[] toArray()
      Specified by:
      toArray in interface Collection<OptionEntry>
      Specified by:
      toArray in interface Set<OptionEntry>
      Overrides:
      toArray in class AbstractCollection<OptionEntry>
    • map

      public Map<Object,String> map()
      Returns an immutable Map for the options
      Returns:
      the map of options
    • map

      public <T> Map<T,String> map(Class<T> type)
      Returns an immutable Map for the options
      Type Parameters:
      T - the type of the map
      Parameters:
      type - the map type
      Returns:
      the map of options
    • toString

      public String toString()
      Overrides:
      toString in class AbstractCollection<OptionEntry>
    • addXml

      public void addXml(Element element, DataType dataType)
      Adds all these options to the xml element
      Parameters:
      element - the element to add the option tags to
      dataType - the dataType of the element
    • findInsertPos

      protected int findInsertPos(String text)