# Class ListProperty<T,K>

java.lang.Object
com.codename1.properties.PropertyBase<T,K>
com.codename1.properties.CollectionProperty<T,K>
com.codename1.properties.ListProperty<T,K>

All Implemented Interfaces:
  `Iterable<T>`

public class ListProperty<T,K> extends CollectionProperty<T,K>
Base class for a property as a list which can contain multiple elements within

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ListProperty(String name)`
  Constructs a property with null value
  `ListProperty(String name, Class<T> elementType, T... values)`
  Constructs a property with the given name and values by specifying the type of the elements explicitly.
  `ListProperty(String name, T... values)`
  Constructs a property with the given name and value

- ## Method Summary

  Modifier and Type
  Method
  Description
  `K`
  `add(int offset, T v)`
  Adds a property value and fires a change event
  `K`
  `add(T v)`
  Adds a property value to the end of the list and fires a change event
  `K`
  `addAll(Collection<? extends T> v)`
  Adds a all properties value to the list and fires a change event
  `List<Object>`
  `asExplodedList()`
  Returns a copy of the content as a new list but if the value is a PropertyBusinessObject it will be converted to a Map
  `List<T>`
  `asList()`
  Returns a copy of the content as a new list
  `void`
  `clear()`
  Remove all the elements from the list
  `boolean`
  `contains(T element)`
  Returns true if the given element is contained in the list property
  `boolean`
  `equals(Object obj)`
  Compares this property to another property
  `T`
  `get(int offset)`
  Gets the property value
  `int`
  `hashCode()`
  Returns the internal hashcode or 0 for null property
  `int`
  `indexOf(T element)`
  Returns the index of the given element in the list property
  `Iterator<T>`
  `iterator()`
  Iterate over the elements of the property
  `K`
  `remove(int offset)`
  Removes the item at the given offset
  `K`
  `remove(T v)`
  Removes the item with this value
  `K`
  `removeAll(Collection<? extends T> v)`
  Removes from the list all values from the given collection and fires a change event if the list has changed
  `K`
  `set(int offset, T v)`
  Sets the property value and potentially fires a change event
  `K`
  `set(Collection<T> t)`
  Sets the entire content of the property
  `K`
  `setList(Collection<T> t)`
  Historical alias of set(Collection t) Sets the entire content of the property
  `int`
  `size()`
  The size of the property list

  ### Methods inherited from class PropertyBase

  `addChangeListener, bindGlobalGetListener, bindGlobalSetListener, firePropertyChanged, getClientProperty, getGenericType, getLabel, getName, putClientProperty, removeChangeListener, setLabel, stopListening, toString, validateCollectionType`
  Modifier and Type
  Method
  Description
  `void`
  `addChangeListener(PropertyChangeListener<T,K> pl)`
  Fires a notification that a property value changed to the given listener
  `static void`
  `bindGlobalGetListener(PropertyChangeListener listener)`
  Binds an event callback for get calls and property reads
  `static void`
  `bindGlobalSetListener(PropertyChangeListener listener)`
  Binds an event callback for set calls and property mutation
  `protected void`
  `firePropertyChanged()`
  Delivers the property change event to listeners if applicable
  `Object`
  `getClientProperty(String key)`
  Returns the client property set to this property name
  `Class`
  `getGenericType()`
  Returns the generic type of this property if it is known or null
  `String`
  `getLabel()`
  The label of the property defaults to its name but can be changed to anything
  `String`
  `getName()`
  The property name is immutable and can't be changed after creation it should match the parent field name by convention
  `void`
  `putClientProperty(String key, Object o)`
  Places a property that will apply statically to all instances of this property
  `void`
  `removeChangeListener(PropertyChangeListener<T,K> pl)`
  Removes the property change listener from the list of listeners
  `void`
  `setLabel(String label)`
  The label of the property defaults to its name but can be changed to anything, it can be used when binding a property to UI elements
  `void`
  `stopListening()`
  This method will work when invoked from a propertyChanged callback and should be similar to `removePropertyChangeListener(this)`.
  `String`
  `toString()`
  Default toString that provides easier debug information
  `protected final void`
  `validateCollectionType(Class elementType)`
  Validates that the collection type is valid and throws an exception otherwise

  ### Methods inherited from class Object

  `clone, getClass, notify, notifyAll, wait, wait, wait`
  Modifier and Type
  Method
  Description
  `protected Object`
  `clone()`
  `final Class`
  `getClass()`
  Returns the runtime class of an object.
  `final void`
  `notify()`
  Wakes up a single thread that is waiting on this object's monitor.
  `final void`
  `notifyAll()`
  Wakes up all threads that are waiting on this object's monitor.
  `final void`
  `wait()`
  Causes current thread to wait until another thread invokes the method or the method for this object.
  `final void`
  `wait(long timeout)`
  Causes current thread to wait until either another thread invokes the method or the method for this object, or a specified amount of time has elapsed.
  `final void`
  `wait(long timeout, int nanos)`
  Causes current thread to wait until another thread invokes the method or the method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.

- ## Constructor Details

  - ### ListProperty

    public ListProperty(String name, T... values)

    Constructs a property with the given name and value

    ###### Parameters

    - `name`: the name of the property

    - `values`: default values for the property

  - ### ListProperty

    public ListProperty(String name, Class<T> elementType, T... values)

    Constructs a property with the given name and values by specifying the type of the elements explicitly. The element type needs to be specified if the list should contain `PropertyBusinessObject`s and needs to get deserialized properly!

    ###### Parameters

    - `name`: the name of the property

    - `elementType`: subclass of `PropertyBusinessObject`

    - `values`: default values for the property

  - ### ListProperty

    public ListProperty(String name)

    Constructs a property with null value

    ###### Parameters

    - `name`: the name of the property

- ## Method Details

  - ### get

    public T get(int offset)

    Gets the property value

    ###### Parameters

    - `offset`: the offset within the list

    ###### Returns

    the property value

  - ### size

    public int size()

    The size of the property list

    ###### Returns

    the number of elements

    Specified by:
      `size` in class `CollectionProperty<T,K>`

  - ### set

    public K set(int offset, T v)

    Sets the property value and potentially fires a change event

    ###### Parameters

    - `offset`: the position for the new value

    - `v`: the new value

    ###### Returns

    the parent object for chaining

  - ### set

    public K set(Collection<T> t)

    Sets the entire content of the property

    ###### Parameters

    - `t`: the collection of elements to set

    ###### Returns

    the parent object for chaining

    Specified by:
      `set` in class `CollectionProperty<T,K>`

  - ### setList

    public K setList(Collection<T> t)

    Historical alias of set(Collection t) Sets the entire content of the property

    ###### Parameters

    - `t`: the collection of elements to set

    ###### Returns

    the parent object for chaining

  - ### add

    public K add(int offset, T v)

    Adds a property value and fires a change event

    ###### Parameters

    - `offset`: the position for the new value

    - `v`: the new value

  - ### add

    public K add(T v)

    Adds a property value to the end of the list and fires a change event

    ###### Parameters

    - `v`: the new value
    Specified by:
      `add` in class `CollectionProperty<T,K>`

  - ### addAll

    public K addAll(Collection<? extends T> v)

    Adds a all properties value to the list and fires a change event

    ###### Parameters

    - `v`: the collection of values to add
    Specified by:
      `addAll` in class `CollectionProperty<T,K>`

  - ### remove

    public K remove(int offset)

    Removes the item at the given offset

    ###### Parameters

    - `offset`: the offset
    Specified by:
      `remove` in class `CollectionProperty<T,K>`

  - ### remove

    public K remove(T v)

    Removes the item with this value

    ###### Parameters

    - `v`: the value object
    Specified by:
      `remove` in class `CollectionProperty<T,K>`

  - ### removeAll

    public K removeAll(Collection<? extends T> v)

    Removes from the list all values from the given collection and fires a change event if the list has changed

    ###### Parameters

    - `the`: item to remove
    Specified by:
      `removeAll` in class `CollectionProperty<T,K>`

  - ### equals

    public boolean equals(Object obj)

    Compares this property to another property

    ###### Parameters

    - `obj`: the other property

    ###### Returns

    true if they are equal in name and value

    Overrides:
      `equals` in class `PropertyBase<T,K>`

  - ### hashCode

    public int hashCode()

    Returns the internal hashcode or 0 for null property

    ###### Returns

    the hashcode value

    Overrides:
      `hashCode` in class `PropertyBase<T,K>`

  - ### iterator

    public Iterator<T> iterator()

    Iterate over the elements of the property

    ###### Returns

    an iterator

    Specified by:
      `iterator` in interface `Iterable<T>`
    Specified by:
      `iterator` in class `CollectionProperty<T,K>`
    Returns:
      An `Iterator` instance.

  - ### asList

    public List<T> asList()

    Returns a copy of the content as a new list

    ###### Returns

    a list

    Specified by:
      `asList` in class `CollectionProperty<T,K>`

  - ### asExplodedList

    public List<Object> asExplodedList()

    Returns a copy of the content as a new list but if the value is a PropertyBusinessObject it will be converted to a Map

    ###### Returns

    a list

    Specified by:
      `asExplodedList` in class `CollectionProperty<T,K>`

  - ### clear

    public void clear()
    Remove all the elements from the list
    Specified by:
      `clear` in class `CollectionProperty<T,K>`

  - ### contains

    public boolean contains(T element)

    Returns true if the given element is contained in the list property

    ###### Parameters

    - `element`: the element

    ###### Returns

    true if the given element is contained in the list property

    Specified by:
      `contains` in class `CollectionProperty<T,K>`

  - ### indexOf

    public int indexOf(T element)

    Returns the index of the given element in the list property

    ###### Parameters

    - `element`: the element

    ###### Returns

    the index of the given element in the list property