Class PArray

java.lang.Object
org.praxislive.core.Value
org.praxislive.core.types.PArray
All Implemented Interfaces:
Iterable<Value>

public final class PArray extends Value implements Iterable<Value>
An ordered list of Values.
  • Field Details

  • Method Details

    • get

      public Value get(int index)
      Query the value at the given index in the list. If the index is negative or greater than size, the index is modulated into range rather than throwing an exception - useful for cycling. If this PArray is empty, this is returned.
      Parameters:
      index - position of value
      Returns:
      value at index
    • size

      public int size()
      Query the number of values in the list.
      Returns:
      size of list
    • toString

      public String toString()
      Description copied from class: Value
      Values must override the default method to return a string representation that is immutable.
      Specified by:
      toString in class Value
      Returns:
      String representation
    • isEmpty

      public boolean isEmpty()
      Description copied from class: Value
      Check whether this Value is an empty value and has a zero length string representation. Subclasses may wish to override this for efficiency if the String representation is lazily created.
      Overrides:
      isEmpty in class Value
      Returns:
      boolean true if empty
    • equivalent

      public boolean equivalent(Value arg)
      Description copied from class: Value
      Indicates whether some other Value is equivalent to this one. Unlike Value.equals(java.lang.Object) this method is not symmetric - a value of a different type might be equivalent to this without the other type considering the reverse to be true.

      The default implementation uses identity or String equality.

      Overrides:
      equivalent in class Value
      Parameters:
      arg - value to test for equivalence
      Returns:
      true if value is equivalent to this
    • hashCode

      public int hashCode()
      Description copied from class: Value
      Values must override the default hashcode method.
      Specified by:
      hashCode in class Value
      Returns:
      int hashcode
    • equals

      public boolean equals(Object obj)
      Description copied from class: Value
      Values must override the default equals method. This method should only return true if the supplied Object is of the same type as the implementing Value. Values of an unknown type should be coerced before calling this method. This method does not have to guarantee that this.equals(that) == this.toString().equals(that.toString())
      Specified by:
      equals in class Value
      Parameters:
      obj -
      Returns:
      boolean
    • iterator

      public Iterator<Value> iterator()
      Specified by:
      iterator in interface Iterable<Value>
    • stream

      public Stream<Value> stream()
      An ordered stream over the list of values.
      Returns:
      stream of values
    • asList

      public List<Value> asList()
      An unmodifiable List view of this list of values.
      Returns:
      view as unmodifiable list
    • asListOf

      public <T> List<T> asListOf(Class<T> type)
      Access an unmodifiable List view of this PArray as a list of the provided value type.

      If the provided type is Value then this method acts the same as calling asList().

      If the provided type is a Value subclass and all values in the list returned by asList() are of this type, then the list is cast and returned.

      If the provided type is a Value subclass or any other type supported by ValueMapper then a new list will be returned with the values converted to the required type.

      This method throws an IllegalArgumentException if no value mapper exists for the provided type, of if not all list values can be converted to the provided type.

      Type Parameters:
      T - value type
      Parameters:
      type - class of the value type
      Returns:
      list view of the provided value type
      Throws:
      IllegalArgumentException - if there is no mapper for the provided type, or if all values cannot be converted to the provided type
    • of

      public static PArray of(Collection<? extends Value> collection)
      Create a PArray from the given collection of values.
      Parameters:
      collection - collection of values
      Returns:
      new PArray
    • of

      public static PArray of(Value... values)
      Create a PArray from the given collection of values.
      Parameters:
      values - array of values
      Returns:
      new PArray
    • parse

      public static PArray parse(String text) throws ValueFormatException
      Parse the given text into a PArray.
      Parameters:
      text - text to parse
      Returns:
      parsed PArray
      Throws:
      ValueFormatException
    • from

      public static Optional<PArray> from(Value value)
      Cast or convert the provided value into a PArray, wrapped in an Optional. If the value is already a PArray, the Optional will wrap the existing value. If the value is not a PArray and cannot be converted into one, an empty Optional is returned.
      Parameters:
      value - value
      Returns:
      optional PArray
    • info

      public static ArgumentInfo info()
      Utility method to create an ArgumentInfo for arguments of type PArray.
      Returns:
      argument info
    • collector

      public static <T extends Value> Collector<T,?,PArray> collector()
      Create a Collector that can create a PArray from a Stream of Values.
      Type Parameters:
      T - Value type
      Returns:
      new PArray collector