com.miginfocom.property
Class CollectionProperty<T>

java.lang.Object
  extended by com.miginfocom.property.Property<java.util.Collection<T>>
      extended by com.miginfocom.property.CollectionProperty<T>
All Implemented Interfaces:
FieldProperty<java.util.Collection<T>>, java.io.Serializable, java.lang.Iterable<T>, CollectionPropertyI<T>, PropertyI<java.util.Collection<T>>
Direct Known Subclasses:
ListProperty

public class CollectionProperty<T>
extends Property<java.util.Collection<T>>
implements java.lang.Iterable<T>, CollectionPropertyI<T>

See Also:
Serialized Form

Field Summary
 
Fields inherited from class com.miginfocom.property.Property
UNINITIALIZED
 
Constructor Summary
CollectionProperty()
          Constructor for creating a lazy-initialized collection.
CollectionProperty(java.util.Collection<T> col)
          Constructor.
CollectionProperty(T... values)
          Constructor.
 
Method Summary
 Result<T> add(T value)
          Adds a value to the collection.
 ResultList<T> addAll(java.util.Collection<? extends T> elements)
          Adds a whole collection to this one.
protected  void checkModifyAccess()
           
 boolean contains(T value)
          Returns if value is in this property collecion.
 boolean containsAll(java.util.Collection<?> c)
          Returns if all c elements is in this property collecion.
protected  java.util.Collection<T> create()
          Creates the collection.
 PropertyIterator<T> iterator()
          Returns an iterator that iterates over this property's entries.
protected  java.util.Collection<T> makeUnmodifiable(java.util.Collection<T> value)
          Makes the value unmodifiable, usually by wrapping it.
 Result<T> remove(T value)
          Removes a value from the collection.
 ResultList<T> removeAll()
          Removes all elements in this property by iterating and removing.
 int size()
          Returns the number of elements in this property.
 
Methods inherited from class com.miginfocom.property.Property
addPropertyListener, addPropertyListener, checkInit, cloneObject, createInfo, get, getBean, getInfo, getInternal, getName, init, initNotify, isNull, removePropertyListener, set, setInternal, toString, writeReplace
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.java.properties.PropertyI
get, set
 

Constructor Detail

CollectionProperty

public CollectionProperty()
Constructor for creating a lazy-initialized collection. create() will be called when the first real need for a collection object comes unless 'nullable' is true and 'lazy' is false in which case a NullPointerException will be thrown.


CollectionProperty

public CollectionProperty(java.util.Collection<T> col)
Constructor.

Parameters:
col - The initial collection. NOTE! The reference will be used as the backing collection and will not be cloned! May be null which is the same as calling the empty argument constructor.

CollectionProperty

public CollectionProperty(T... values)
Constructor. Will not lazy initialize with a call to create().

Parameters:
values - The initial collection. Will be cloned and changes to the array will not be reflected in this property. May be null which is the same as calling the empty argument constructor.
Method Detail

create

protected java.util.Collection<T> create()
Creates the collection. This happens the first time the collection is needed if there was no value sent into the constructor.

Overrides:
create in class Property<java.util.Collection<T>>
Returns:
A collection. Default is a ArrayList of default size.

makeUnmodifiable

protected java.util.Collection<T> makeUnmodifiable(java.util.Collection<T> value)
Description copied from class: Property
Makes the value unmodifiable, usually by wrapping it. This is what should be done when the get/set policy is Transfer.UNMODIFIABLE. Should be overridden by collection and map properties to wrap. Other property type can also overrider this to make the value unmidifiable.

Overrides:
makeUnmodifiable in class Property<java.util.Collection<T>>
Parameters:
value - The value. May be null in which canse null should be returned.
Returns:
The unmodifiable value.

add

public Result<T> add(T value)
Description copied from interface: CollectionPropertyI
Adds a value to the collection. Will throw a NullPointerException if the collection is null.

Specified by:
add in interface CollectionPropertyI<T>
Parameters:
value - The value to add.
Returns:
The result for the add. Never null.

addAll

public ResultList<T> addAll(java.util.Collection<? extends T> elements)
Description copied from interface: CollectionPropertyI
Adds a whole collection to this one.

This method iterates over the collection and adds with CollectionPropertyI.add(T)

Specified by:
addAll in interface CollectionPropertyI<T>
Parameters:
elements - The collection which elements to add. Not null.
Returns:
All the results for the add. Never null.

remove

public Result<T> remove(T value)
Description copied from interface: CollectionPropertyI
Removes a value from the collection. Will throw a NullPointerException if the collection is null.

Specified by:
remove in interface CollectionPropertyI<T>
Parameters:
value - The value to remove.
Returns:
The result for the remove. Never null.

removeAll

public ResultList<T> removeAll()
Description copied from interface: CollectionPropertyI
Removes all elements in this property by iterating and removing. Will throw a NullPointerException if the collection is null.

Specified by:
removeAll in interface CollectionPropertyI<T>
Returns:
The results for all the removes. Never null.

contains

public boolean contains(T value)
Description copied from interface: CollectionPropertyI
Returns if value is in this property collecion. Will throw a NullPointerException if the collection is null.

Specified by:
contains in interface CollectionPropertyI<T>
Parameters:
value - The value to check for. May be null.
Returns:
If value is in this property collecion. Never null.

containsAll

public boolean containsAll(java.util.Collection<?> c)
Description copied from interface: CollectionPropertyI
Returns if all c elements is in this property collecion. Will throw a NullPointerException if the collection is null.

Specified by:
containsAll in interface CollectionPropertyI<T>
Parameters:
c - The collection containing the elements to check. Not null.
Returns:
If all c elements is in this property collecion. Never null.

iterator

public PropertyIterator<T> iterator()
Description copied from interface: CollectionPropertyI
Returns an iterator that iterates over this property's entries. Will throw a NullPointerException if the collection is null.

Specified by:
iterator in interface java.lang.Iterable<T>
Specified by:
iterator in interface CollectionPropertyI<T>
Returns:
An iterator that iterates over this property's entries. Never null.

size

public int size()
Description copied from interface: CollectionPropertyI
Returns the number of elements in this property. Will throw a NullPointerException if the collection is null.

Specified by:
size in interface CollectionPropertyI<T>
Returns:
The number of elements in this property.

checkModifyAccess

protected final void checkModifyAccess()


Copyright © 2007 MiG InfoCom AB. All Rights Reserved.