Class ListValue

java.lang.Object
com.aquima.interactions.foundation.convert.Convertable
com.aquima.interactions.foundation.types.ListValue
All Implemented Interfaces:
IConvertable, IListValue, IValue, Serializable
Direct Known Subclasses:
AttributeListValue, Domain, DomainDefinition, DomainValues

public class ListValue extends Convertable implements IListValue
This class provides an implementation of the IListValue interface. This implementation also implements some other interfaces, as a list of values can be treated as another type under certain conditions. A list that only contains a single value, can be treated as a single value if, and only if, the value itself is a single value. The same goes for the range interface, as a list containing a single range value, can be treated as a range.
Since:
5.0
Author:
O. Kerpershoek
See Also:
  • Constructor Details

    • ListValue

      public ListValue(DataType datatype)
      Construct a ListValue object with a datatype, resulting in an instance where isUnknown() is false. This List is a unique set, you can override this by using the ListValue(DataType, boolean) constructor
      Parameters:
      datatype - The type of the values in the list.
    • ListValue

      public ListValue(DataType datatype, boolean isUniqueSet)
      Construct a ListValue object with a datatype and isUniqueSet, resulting in an instance where isUnknown() is false.
      Parameters:
      datatype - The type of the values in the list.
      isUniqueSet - Boolean indicating if the list only allows unique values.
    • ListValue

      public ListValue(IPrimitiveValue[] values)
      Construct a ListValue object with an array of values, resulting in an instance where isUnknown() is false Note that values.length > 0, otherwise a InitialisationException is thrown. This List is a unique set, you can override this by using the ListValue(IPrimitiveValue[], boolean) constructor
      Parameters:
      values - The values that should be put in the list.
    • ListValue

      public ListValue(IPrimitiveValue[] values, boolean isUniqueSet)
      Construct a ListValue object with an array of values, resulting in an instance where isUnknown() is false Note that values.length > 0, otherwise a InitialisationException is thrown.
      Parameters:
      values - The values that should be put in the list.
      isUniqueSet - Boolean indicating if the list only allows unique values.
    • ListValue

      public ListValue(DataType datatype, IPrimitiveValue[] values)
      Construct a ListValue object with a datatype and an array of values, resulting in an instance where isUnknown() is false. This List is a unique set, you can override this by using the ListValue(DataType, IPrimitiveValue[], boolean) constructor
      Parameters:
      datatype - The type of the values in the list.
      values - The values that should be put in the list.
    • ListValue

      public ListValue(DataType datatype, IPrimitiveValue[] values, boolean isUniqueSet)
      Construct a ListValue object with a datatype, an array of values and isUniqueSet, resulting in an instance where isUnknown() is false.
      Parameters:
      datatype - The type of the values in the list.
      values - The values that should be put in the list.
      isUniqueSet - Boolean indicating if the list only allows unique values.
    • ListValue

      public ListValue(IListValue other)
      Construct a ListValue object based on another ListValue.
      Parameters:
      other - The list value that should be copied by this list.
  • Method Details

    • unknownFor

      public static IListValue unknownFor(DataType type)
      This method creates an unknown list of the specified type.
      Parameters:
      type - The type of the list.
      Returns:
      an unknown list of the specified type.
    • isUniqueSet

      public boolean isUniqueSet()
      Description copied from interface: IListValue
      This method will return a boolean indicating if the list enforces all values to be unique. When a list is set to be unique, all duplicate values will be ignored, and each value will appear only once in the list.
      Specified by:
      isUniqueSet in interface IListValue
      Returns:
      boolean indicating if all values in the list must be unique.
    • insertValue

      protected void insertValue(int index, IPrimitiveValue primitiveValue)
    • addValue

      public boolean addValue(IPrimitiveValue primitiveValue)
      This method can be used to add a value to the list. When adding multiple values to a unique set try to collect them and use addAll(IPrimitiveValue[]) as checking if the value is already present every time can be expensive. AQ-9268 When a primitive value of type integer is added to a number list do not throw an exception because an integer is always a number.
      Parameters:
      primitiveValue - The value that should be added.
      Returns:
      Boolean indicating if the value was actually added.
    • addAll

      public void addAll(IPrimitiveValue[] values)
      This method can be used to add all the values from the array to the list.
      Parameters:
      values - Array containing all the values that need to be added.
    • removeValue

      public boolean removeValue(IPrimitiveValue primitiveValue)
      This method can be used to remove a value from the list.
      Parameters:
      primitiveValue - The value that should be removed.
      Returns:
      A boolean indicating if the values was actually removed.
    • clearValues

      public boolean clearValues(boolean setUnknown)
      This method can be used to remove all the values from the list.
      Parameters:
      setUnknown - Boolean indicating if the list should be unknown after the clear action.
      Returns:
      Boolean indicating if the clear action was successful.
    • getDataType

      public DataType getDataType()
      Description copied from interface: IValue
      This method returns the data type of the value.
      Specified by:
      getDataType in interface IValue
      Returns:
      The data type of the value.
    • isUnknown

      public boolean isUnknown()
      Description copied from interface: IValue
      This method returns a boolean indicating if the value is unknown.
      Specified by:
      isUnknown in interface IValue
      Returns:
      boolean indicating if the value is unknown.
    • isSingleValue

      public boolean isSingleValue()
      Description copied from interface: IValue
      This method returns a boolean indicating if this value may safely be converted to a single value by using the toSingleValue method. Objects that are already a single value will always return true, but ranges and list values may return true when they only contain a single value.
      Note: This method returns true when the value is convertible, it does not mean that the value can safely be casted to the ISingleValue interface.
      Specified by:
      isSingleValue in interface IValue
      Returns:
      boolean indicating if the value represent a single value.
    • isRangeValue

      public boolean isRangeValue()
      Description copied from interface: IValue
      This method returns a boolean indicating if this value may safely be converted to a range value by using the toRangeValue method. Objects that are already a range or single value will always return true, but list values may return true when they only contain a single value.
      Note: This method returns true when the value is convertable, it does not mean that the value can safely be casted to the IRangeValue interface.
      Specified by:
      isRangeValue in interface IValue
      Returns:
      boolean indicating if the value represent a range value.
    • toSingleValue

      public ISingleValue toSingleValue()
      Description copied from interface: IValue
      This method will attempt to convert the value to a single value. The conversion might fail and raise an exception when the value this method is called on is either a range or a list value. The method isSingleValue can be used to determine if this value can safely be converted to a single value. When the value this method is called on already implements the ISingleValue interface, the implementation may return the same value.
      Specified by:
      toSingleValue in interface IValue
      Returns:
      The same value as single value.
    • toRangeValue

      public IRangeValue toRangeValue()
      Description copied from interface: IValue
      This method will attempt to convert the value to a range value. The conversion might fail and raise an exception when the value this method is called on is either a list value. The method isRangeValue can be used to determine if this value can safely be converted to a range value. When the value this method is called on already implements the IRangeValue interface, the implementation may return the same value.
      Specified by:
      toRangeValue in interface IValue
      Returns:
      The same value as a range value.
    • toListValue

      public IListValue toListValue()
      Description copied from interface: IValue
      This method will convert the current value to a list value. This type of conversion is always possible for all IValue implementations. Values of type ISingleValue or IRangeValue will result in a list value containing the primitive value (list of size 1). When the value this method is called on already implements the IListValue interface, the implementation may return the same value.
      Specified by:
      toListValue in interface IValue
      Returns:
      The same value as list.
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: IListValue
      This method will return a boolean indicating if the list contains no values.
      Specified by:
      isEmpty in interface IListValue
      Returns:
      boolean indicating if the list contains no values.
    • contains

      public boolean contains(Object obj)
      Description copied from interface: IValue
      This method returns a boolean indicating if the object passed to this method is entirely part of this value. This method will thus also return true when the object passed is equal to this value, but the method will return false when only part (or none) of the object is represented by this value. Note that for value types that are singular in nature (for instance, implementations of ISingleValue) the operation of this method is limited to an equality check.
      Specified by:
      contains in interface IValue
      Parameters:
      obj - Object for which should be checked if it is entirely part of this value.
      Returns:
      boolean indicating if the object passed is entirely part of this value.
    • getValueCount

      public int getValueCount()
      Description copied from interface: IListValue
      This method will return the number of values that are present in the list. When the list value is UNKNOWN 0 will be returned.
      Specified by:
      getValueCount in interface IListValue
      Returns:
      The number of values in the list.
    • getValueAt

      public IPrimitiveValue getValueAt(int index)
      Description copied from interface: IListValue
      This method will return the value at the specified index. The index passed to this method is zero based, so the first element can be retrieved by invoking this method with 'index = 0', and the last element with 'index = getValueCount() - '.
      Specified by:
      getValueAt in interface IListValue
      Parameters:
      index - Integer containing the index of the value that is requested.
      Returns:
      The value at the specified index.
    • getValues

      public IPrimitiveValue[] getValues()
      Description copied from interface: IListValue
      This method will return an array containing all the values from the list. When the list does not contain any values, an empty array will be returned.
      Specified by:
      getValues in interface IListValue
      Returns:
      Array containing all the values from the list.
    • getSortedValues

      public IPrimitiveValue[] getSortedValues()
      Description copied from interface: IListValue
      This method will return the values from the list sorted using the compare method of the values. When the list does not contain any values, an empty list will be returned.
      Specified by:
      getSortedValues in interface IListValue
      Returns:
      Array containing the sorted values from the list.
    • getValue

      public Object getValue()
      Description copied from interface: IConvertable
      This method returns the internal object of this instance without any conversion.
      Specified by:
      getValue in interface IConvertable
      Specified by:
      getValue in class Convertable
      Returns:
      The internal Object of this attribute value.
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getInternalValues

      protected List<IPrimitiveValue> getInternalValues()
    • duplicate

      public IValue duplicate()
      Description copied from interface: IValue
      This method returns a deep copy of the value.
      Specified by:
      duplicate in interface IValue
      Returns:
      A deep clone.