Class ListAttribute

All Implemented Interfaces:
com.esotericsoftware.kryo.KryoSerializable, Serializable, Cloneable, Iterable<String>, Collection<String>, List<String>, RandomAccess, SequencedCollection<String>

public class ListAttribute extends ArrayList<String> implements com.esotericsoftware.kryo.KryoSerializable
This class implements an utility object typically used for setting attributes.
It is possible to pass to the constructor a string containing values, separated by a customizable delimiter character (the default one is the character |), in order to automatically obtain a list containing the values.
The class exposes the getter methods to find the values in a smart way; it is possible to query the list even on positions greater than the size of the list itself; in that case a default value will be returned, that can be global or local, both customizable.
See Also:
  • Field Details

    • defaultValue

      protected String defaultValue
      The defaultValue is the last attribute value of the collection if present
  • Constructor Details

    • ListAttribute

      public ListAttribute()
      Constructs an empty ListAttribute
    • ListAttribute

      public ListAttribute(String values)
      Constructs a ListAttribute starting from the string passed as parameter. Every element must be separated from the others with the default separator character, that is | (pipe)
      Parameters:
      values - The string that defines the values, separated with the | character
    • ListAttribute

      public ListAttribute(String values, char delim)
      Constructs a ListAttribute starting from the string passed as parameter. Every element must be separated from the others with the separator character, passed as second parameter
      Parameters:
      values - The string that defines the values
      delim - The character used as separator between the values
  • Method Details

    • setDefault

      public void setDefault(String def)
      Sets the global default value, that is null by default
      Parameters:
      def - The value to set
    • getDefault

      public String getDefault()
      Gets the default global value for the attribute list
      Returns:
      the default value
    • translate

      public ListAttribute translate(Teacher t)
      Translates the values of the list
      Parameters:
      t - The Teacher that will manage the translations
      Returns:
      this instance of ListAttribute with the translated values
    • translateLabel

      public ListAttribute translateLabel(Teacher t)
      Translates the values of the list, considering them as labels
      Parameters:
      t - The Teacher that will manage the translations
      Returns:
      this instance of ListAttribute with the translated values
    • getString

      public String getString(int i, String def)
      Extracts a String from the list.
      Parameters:
      i - The position of the String to extract
      def - The default value returned if the String in the desired position is null, or when the position is greater than the size of the list and the global default value is null
      Returns:
      The String in the desired position. If the String is null it returns the default value passed as parameter. If the position is greater than the size of the list and the global default value (the one set with the method setDefault(java.lang.String)) is null, it returns the default value passed as parameter; if the position is greater than the size of the list and the global default value is not null, it returns the global default value
    • getDouble

      public Double getDouble(int i, Double def)
      Extracts a Double value from the list.
      Parameters:
      i - The position of the Double to extract
      def - The default value returned if the Double in the desired position is null, or when the position is greater than the size of the list and the global default value is null
      Returns:
      The Double in the desired position. If the Double is null it returns the default value passed as parameter. If the position is greater than the size of the list and the global default value (the one set with the method setDefault(java.lang.String)) is null, it returns the default value passed as parameter; if the position is greater than the size of the list and the global default value is not null, it returns the global default value
    • getdouble

      public Double getdouble(int i, double def)
      Extracts a double value from the list.
      Parameters:
      i - The position of the double to extract
      def - The default value returned if the double in the desired position is null, or when the position is greater than the size of the list and the global default value is null
      Returns:
      The double in the desired position. If the double is null it returns the default value passed as parameter. If the position is greater than the size of the list and the global default value (the one set with the method setDefault(java.lang.String)) is null, it returns the default value passed as parameter; if the position is greater than the size of the list and the global default value is not null, it returns the global default value
    • getLong

      public Long getLong(int i, Long def)
      Extracts a Long value from the list.
      Parameters:
      i - The position of the Long to extract
      def - The default value returned if the Long in the desired position is null, or when the position is greater than the size of the list and the global default value is null
      Returns:
      The Long in the desired position. If the Long is null it returns the default value passed as parameter. If the position is greater than the size of the list and the global default value (the one set with the method setDefault(java.lang.String)) is null, it returns the default value passed as parameter; if the position is greater than the size of the list and the global default value is not null, it returns the global default value
    • getlong

      public long getlong(int i, long def)
      Extracts a long value from the list.
      Parameters:
      i - The position of the long to extract
      def - The default value returned if the long in the desired position is null, or when the position is greater than the size of the list and the global default value is null
      Returns:
      The long in the desired position. If the long is null it returns the default value passed as parameter. If the position is greater than the size of the list and the global default value (the one set with the method setDefault(java.lang.String)) is null, it returns the default value passed as parameter; if the position is greater than the size of the list and the global default value is not null, it returns the global default value
    • set

      public String set(int pos, String s)
      Specified by:
      set in interface List<String>
      Overrides:
      set in class ArrayList<String>
    • write

      public void write(com.esotericsoftware.kryo.Kryo kryo, com.esotericsoftware.kryo.io.Output output)
      Specified by:
      write in interface com.esotericsoftware.kryo.KryoSerializable
    • read

      public void read(com.esotericsoftware.kryo.Kryo kryo, com.esotericsoftware.kryo.io.Input input)
      Specified by:
      read in interface com.esotericsoftware.kryo.KryoSerializable