# Class CollectionProperty<T,K>

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

All Implemented Interfaces:
  `Iterable<T>`

Direct Known Subclasses:
  `ListProperty, SetProperty`

public abstract class CollectionProperty<T,K> extends PropertyBase<T,K> implements Iterable<T>
Base class for a property as a collection which can contain multiple elements within

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `CollectionProperty(String name)`
  `CollectionProperty(String name, Class genericType)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `abstract K`
  `add(T v)`
  Adds a property value to the collection and fires a change event if collection has changed
  `abstract K`
  `addAll(Collection<? extends T> v)`
  Adds a collection of values to the collection and fires a change event if the collection has changed
  `abstract 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
  `abstract List<T>`
  `asList()`
  Returns a copy of the content as a new list
  `abstract void`
  `clear()`
  Remove all the elements from the collection and fires a change event
  `abstract boolean`
  `contains(T element)`
  Returns true if the given element is contained in the collection property
  `abstract Iterator<T>`
  `iterator()`
  Iterate over the elements of the property
  `abstract K`
  `remove(int offset)`
  Removes the given item
  `abstract K`
  `remove(T v)`
  Removes the given item
  `abstract K`
  `removeAll(Collection<? extends T> v)`
  Removes from this collection all of its elements that are contained in the specified collection and fires a change event if the collection has changed
  `abstract K`
  `set(Collection<T> t)`
  Sets the entire content of the property
  `abstract int`
  `size()`
  The size of the property collection

  ### Methods inherited from class PropertyBase

  `addChangeListener, bindGlobalGetListener, bindGlobalSetListener, equals, firePropertyChanged, getClientProperty, getGenericType, getLabel, getName, hashCode, putClientProperty, removeChangeListener, setLabel, stopListening, toString, validateCollectionType`

  ### Methods inherited from class Object

  `clone, getClass, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### CollectionProperty

    public CollectionProperty(String name)

  - ### CollectionProperty

    public CollectionProperty(String name, Class genericType)

- ## Method Details

  - ### size

    public abstract int size()

    The size of the property collection

    ###### Returns

    the number of elements

  - ### set

    public abstract 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

  - ### add

    public abstract K add(T v)

    Adds a property value to the collection and fires a change event if collection has changed

    ###### Parameters

    - `v`: the new value

  - ### addAll

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

    Adds a collection of values to the collection and fires a change event if the collection has changed

    ###### Parameters

    - `v`: the collection of values to add

  - ### remove

    public abstract K remove(T v)

    Removes the given item

    ###### Parameters

    - `v`: the item to remove

  - ### remove

    public abstract K remove(int offset)

    Removes the given item

    ###### Parameters

    - `offset`: the index

  - ### removeAll

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

    Removes from this collection all of its elements that are contained in the specified collection and fires a change event if the collection has changed

    ###### Parameters

    - `v`: the collection of values to remove

  - ### iterator

    public abstract Iterator<T> iterator()

    Iterate over the elements of the property

    ###### Returns

    an iterator

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

  - ### asList

    public abstract List<T> asList()

    Returns a copy of the content as a new list

    ###### Returns

    a list

  - ### asExplodedList

    public abstract 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

  - ### clear

    public abstract void clear()
    Remove all the elements from the collection and fires a change event

  - ### contains

    public abstract boolean contains(T element)

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

    ###### Parameters

    - `element`: the element

    ###### Returns

    true if the given element is contained in the collection property