com.miginfocom.property
Class MapProperty<K,V>

java.lang.Object
  extended by com.miginfocom.property.Property<java.util.Map<K,V>>
      extended by com.miginfocom.property.MapProperty<K,V>
All Implemented Interfaces:
FieldProperty<java.util.Map<K,V>>, java.io.Serializable, java.lang.Iterable<java.util.Map.Entry<K,V>>, MapPropertyI<K,V>, PropertyI<java.util.Map<K,V>>

public class MapProperty<K,V>
extends Property<java.util.Map<K,V>>
implements java.lang.Iterable<java.util.Map.Entry<K,V>>, MapPropertyI<K,V>

See Also:
Serialized Form

Field Summary
 
Fields inherited from class com.miginfocom.property.Property
UNINITIALIZED
 
Constructor Summary
MapProperty()
          Constructor for creating a lazy-initialized collection.
MapProperty(K[] keys, V[] values)
          Constructor.
MapProperty(java.util.Map<K,V> map)
          Constructor.
 
Method Summary
protected  void checkModifyAccess()
           
 boolean containsKey(K key)
          Returns if key is in this map.
 boolean containsValue(V value)
          Returns if value is in this map.
protected  java.util.Map<K,V> create()
          Creates the map.
 V get(K key)
          Returns the value the the key points to.
 PropertyIterator<java.util.Map.Entry<K,V>> iterator()
          Returns an iterator that iterates over this property's entries.
 java.util.Set<K> keySet()
          Returns an, always unmodifiable, key set direct from the backing Map.
protected  java.util.Map<K,V> makeUnmodifiable(java.util.Map<K,V> value)
          Makes the value unmodifiable, usually by wrapping it.
 Result<java.util.Map.Entry<K,V>> put(K key, V value)
          Associates the value with the key.
 ResultList<java.util.Map.Entry<K,V>> putAll(java.util.Map<? extends K,? extends V> elements)
          Adds a whole map to this one.
 Result<java.util.Map.Entry<K,V>> remove(K key)
          Removes the value that the key points to.
 ResultList<java.util.Map.Entry<K,V>> removeAll()
          Removes all elements in this property by iterating and removing.
 int size()
          Returns the number of elements in this property.
 java.util.Collection<V> values()
          Returns the values from the backing Map as an unmidifiable collection.
 
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
 

Constructor Detail

MapProperty

public MapProperty()
Constructor for creating a lazy-initialized collection. create() will be called when the first real need for a collection object comes.


MapProperty

public MapProperty(java.util.Map<K,V> map)
Constructor.

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

MapProperty

public MapProperty(K[] keys,
                   V[] values)
Constructor.

Parameters:
keys - The keys and values that the property will be initialized with. Not null arrays. Both keys and values can be null. Length must match.
values - The keys and values that the property will be initialized with. Not null arrays. Both keys and values can be null. Length must match.
Method Detail

create

protected java.util.Map<K,V> create()
Creates the map. This happens the first time the map is needed if there was no value sent into the constructor.

Overrides:
create in class Property<java.util.Map<K,V>>
Returns:
A map. Default is a HashMap of default size.

makeUnmodifiable

protected java.util.Map<K,V> makeUnmodifiable(java.util.Map<K,V> 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.Map<K,V>>
Parameters:
value - The value. May be null in which canse null should be returned.
Returns:
The unmodifiable value.

get

public V get(K key)
Description copied from interface: MapPropertyI
Returns the value the the key points to.

Specified by:
get in interface MapPropertyI<K,V>
Parameters:
key - The key.
Returns:
The value that the key points to.

put

public Result<java.util.Map.Entry<K,V>> put(K key,
                                            V value)
Description copied from interface: MapPropertyI
Associates the value with the key.

Specified by:
put in interface MapPropertyI<K,V>
Parameters:
key - The key.
value - The value.
Returns:
The result of the put operation. Never null.

putAll

public ResultList<java.util.Map.Entry<K,V>> putAll(java.util.Map<? extends K,? extends V> elements)
Description copied from interface: MapPropertyI
Adds a whole map to this one.

This method iterates over the collection and adds with MapPropertyI.put(Object, Object)

Specified by:
putAll in interface MapPropertyI<K,V>
Parameters:
elements - The collection which elements to add. Not null.
Returns:
All the results for the add. Never null.

remove

public Result<java.util.Map.Entry<K,V>> remove(K key)
Description copied from interface: MapPropertyI
Removes the value that the key points to. Will throw a NullPointerException if the collection is null.

Specified by:
remove in interface MapPropertyI<K,V>
Parameters:
key - The key.
Returns:
The result for the remove. Never null.

removeAll

public ResultList<java.util.Map.Entry<K,V>> removeAll()
Description copied from interface: MapPropertyI
Removes all elements in this property by iterating and removing.

Specified by:
removeAll in interface MapPropertyI<K,V>
Returns:
The results for all the removes. Never null.

keySet

public java.util.Set<K> keySet()
Description copied from interface: MapPropertyI
Returns an, always unmodifiable, key set direct from the backing Map.

Specified by:
keySet in interface MapPropertyI<K,V>
Returns:
The key set direct from the backing Map. Never null.

values

public java.util.Collection<V> values()
Description copied from interface: MapPropertyI
Returns the values from the backing Map as an unmidifiable collection.

Specified by:
values in interface MapPropertyI<K,V>
Returns:
The values from the backing Map as an unmidifiable collection. Never null.

containsKey

public boolean containsKey(K key)
Description copied from interface: MapPropertyI
Returns if key is in this map. Will throw a NullPointerException if the collection is null.

Specified by:
containsKey in interface MapPropertyI<K,V>
Parameters:
key - The value to check for. May be null.
Returns:
If key is in this map.

containsValue

public boolean containsValue(V value)
Description copied from interface: MapPropertyI
Returns if value is in this map. Will throw a NullPointerException if the collection is null.

Specified by:
containsValue in interface MapPropertyI<K,V>
Parameters:
value - The value to check for. May be null.
Returns:
If value is in this map.

iterator

public PropertyIterator<java.util.Map.Entry<K,V>> iterator()
Description copied from interface: MapPropertyI
Returns an iterator that iterates over this property's entries. Will throw a NullPointerException if the map is null.

Specified by:
iterator in interface java.lang.Iterable<java.util.Map.Entry<K,V>>
Specified by:
iterator in interface MapPropertyI<K,V>
Returns:
An iterator that iterates over this property's entries. Never null.

size

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

Specified by:
size in interface MapPropertyI<K,V>
Returns:
The number of elements in this property.

checkModifyAccess

protected final void checkModifyAccess()


Copyright © 2007 MiG InfoCom AB. All Rights Reserved.