org.beanfabrics.model
Class MapPM<K,V extends PresentationModel>

java.lang.Object
  extended by org.beanfabrics.AbstractBean
      extended by org.beanfabrics.ValidatableBean
          extended by org.beanfabrics.model.AbstractPM
              extended by org.beanfabrics.model.MapPM<K,V>
All Implemented Interfaces:
java.lang.Iterable<V>, Bean, ContextOwner, IListPM<V>, IMapPM<K,V>, PresentationModel, Supportable, Validatable

public class MapPM<K,V extends PresentationModel>
extends AbstractPM
implements IMapPM<K,V>

The MapPM is a map of presentation models. Basically it provides methods for adding, removing, accessing and iterating elements and informs listeners about changes. It also maintains a Selection.

Author:
Michael Karneim

Nested Class Summary
 class MapPM.DefaultValidationRule
           
 
Nested classes/interfaces inherited from class org.beanfabrics.model.AbstractPM
AbstractPM.PropertiesValidationRule
 
Constructor Summary
MapPM()
           
 
Method Summary
 void addListListener(ListListener l)
          Adds a ListListener to this model.
 void clear()
           
 boolean contains(V element)
          Returns true if this collection contains the specified element.
 boolean containsKey(K key)
           
protected  ValidationRule createDefaultValidationRule()
           
 V get(K key)
           
 java.util.Collection<V> getAll(int[] indices)
           
 java.util.Collection<V> getAll(int startIndex, int endIndex)
           
 V getAt(int index)
          Returns the element at the specified position in this list.
 K getKey(int index)
           
 K getKey(V element)
           
 java.util.Set<K> getKeys(java.util.Collection<?> col)
          Returns a set of all keys of the elements in the given collection.
 java.util.Set<K> getKeys(int[] indices)
           
 java.util.List<K> getKeys(int beginIndex, int endIndex)
           
protected  ListSupport getListPropertySupport()
           
 SelectedKeys<K> getSelectedKeys()
           
 Selection<V> getSelection()
          Returns the selection of this list.
 java.util.Collection<SortKey> getSortKeys()
          Returns the (immutable) collection of SortKey objects that reflect the current sorting state of this list.
 int indexOf(V element)
          Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.
 int indexOfKey(K key)
           
 int[] indicesOf(java.util.Collection elements)
          Returns an sorted array of all indices of the given elements starting with the smallest index.
 int[] indicesOfKeys(java.util.Collection<K> keys)
          Returns an sorted array of all indices of the elements with the given keys starting with the smallest index.
 boolean isEmpty()
          Returns true if this collection contains no elements.
 boolean isRevalidateElementsOnChangeEnabled()
           
 java.util.Iterator<V> iterator()
           
 java.util.Iterator<K> keyiterator()
           
 java.util.Set<K> keySet()
           
 java.util.ListIterator<V> listIterator(int index)
          Returns a list iterator of the elements in this list (in proper sequence), starting at the specified position in this list.
protected  void onEntriesChanged(java.util.EventObject evt)
           
 V put(K key, V newElement)
           
 V put(K key, V newElement, int toIndex)
           
 void putAll(java.util.Map<K,V> aMap)
           
 boolean remove(V elem)
           
 boolean removeAll(java.util.Collection<? extends V> col)
           
 java.util.Collection<V> removeAllIndices(int[] indices)
           
 java.util.Collection<V> removeAllKeys(java.util.Set<K> keySet)
           
 V removeAt(int index)
           
 V removeKey(K key)
           
 void removeListListener(ListListener l)
          Removes a ListListener from this model.
 java.util.Collection<V> retainAllKeys(java.util.Set<K> keySet)
           
protected  void revalidateAllExcept(V element)
           
 void revalidateElements()
          Revalidates all elements of this map.
 void setAll(java.util.Map<K,V> newMap)
           
 void setRevalidateElementsOnChangeEnabled(boolean enabled)
           
 int size()
          Returns the number of elements in this collection.
 void sortBy(boolean ascending, Path... paths)
          Sorts the entries of this map by comparing the PresentationModels at the end of the given paths.
 void sortBy(java.util.Collection<SortKey> newSortKeys)
           
 void sortBy(SortKey... newSortKeys)
           
 void swap(int indexA, int indexB)
          Swaps the position of the two elements specified by the given indexes.
 void swap(V elemA, V elemB)
          Swaps the position of these elements.
 java.lang.Object[] toArray()
          Returns an array containing all of the elements in this list in proper sequence (from first to last element).
 java.util.Collection<V> toCollection()
          Returns a new Collection of all elements.
 
Methods inherited from class org.beanfabrics.model.AbstractPM
createPropertiesValidationRule, getContext, getSupportMap, revalidateProperties
 
Methods inherited from class org.beanfabrics.ValidatableBean
getValidationState, getValidator, isValid, revalidate, setValidationState
 
Methods inherited from class org.beanfabrics.AbstractBean
addPropertyChangeListener, addPropertyChangeListener, equals, getPropertyChangeSupport, removePropertyChangeListener, removePropertyChangeListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.beanfabrics.Bean
addPropertyChangeListener, addPropertyChangeListener, getPropertyChangeSupport, removePropertyChangeListener, removePropertyChangeListener
 
Methods inherited from interface org.beanfabrics.validation.Validatable
getValidationState, getValidator, isValid, revalidate
 
Methods inherited from interface org.beanfabrics.support.Supportable
getSupportMap
 
Methods inherited from interface org.beanfabrics.context.ContextOwner
getContext
 

Constructor Detail

MapPM

public MapPM()
Method Detail

isRevalidateElementsOnChangeEnabled

public boolean isRevalidateElementsOnChangeEnabled()

setRevalidateElementsOnChangeEnabled

public void setRevalidateElementsOnChangeEnabled(boolean enabled)

onEntriesChanged

protected void onEntriesChanged(java.util.EventObject evt)

revalidateElements

public void revalidateElements()
Revalidates all elements of this map.


revalidateAllExcept

protected void revalidateAllExcept(V element)

getListPropertySupport

protected ListSupport getListPropertySupport()

isEmpty

public boolean isEmpty()
Description copied from interface: IListPM
Returns true if this collection contains no elements.

Specified by:
isEmpty in interface IListPM<V extends PresentationModel>
Returns:
true if this collection contains no elements

clear

public void clear()

put

public V put(K key,
             V newElement)

put

public V put(K key,
             V newElement,
             int toIndex)

swap

public void swap(int indexA,
                 int indexB)
Description copied from interface: IListPM
Swaps the position of the two elements specified by the given indexes.

Specified by:
swap in interface IListPM<V extends PresentationModel>

swap

public void swap(V elemA,
                 V elemB)
Swaps the position of these elements.

Specified by:
swap in interface IListPM<V extends PresentationModel>

sortBy

public void sortBy(boolean ascending,
                   Path... paths)
Sorts the entries of this map by comparing the PresentationModels at the end of the given paths.

Specified by:
sortBy in interface IListPM<V extends PresentationModel>
Parameters:
ascending - if true, the resulting order will be ascending, otherwise descending.
paths - one or more Path objects must be specified to define which PresentationModel properties will be used for comparison.

sortBy

public void sortBy(java.util.Collection<SortKey> newSortKeys)
Specified by:
sortBy in interface IListPM<V extends PresentationModel>

sortBy

public void sortBy(SortKey... newSortKeys)
Specified by:
sortBy in interface IListPM<V extends PresentationModel>

getSortKeys

public java.util.Collection<SortKey> getSortKeys()
Returns the (immutable) collection of SortKey objects that reflect the current sorting state of this list.

Specified by:
getSortKeys in interface IListPM<V extends PresentationModel>
Returns:
the (immutable) collection of SortKey objects that reflect the current sorting state of this list

size

public int size()
Description copied from interface: IListPM
Returns the number of elements in this collection.

Specified by:
size in interface IListPM<V extends PresentationModel>
Returns:
the number of elements in this collection

getAll

public java.util.Collection<V> getAll(int startIndex,
                                      int endIndex)

getAll

public java.util.Collection<V> getAll(int[] indices)

getAt

public V getAt(int index)
Description copied from interface: IListPM
Returns the element at the specified position in this list.

Specified by:
getAt in interface IListPM<V extends PresentationModel>
Returns:
the element at the specified position in this list

get

public V get(K key)

removeAt

public V removeAt(int index)

removeKey

public V removeKey(K key)

remove

public boolean remove(V elem)

removeAll

public boolean removeAll(java.util.Collection<? extends V> col)

toCollection

public java.util.Collection<V> toCollection()
Description copied from interface: IListPM
Returns a new Collection of all elements.

Specified by:
toCollection in interface IListPM<V extends PresentationModel>
Returns:
a new Collection of all elements

toArray

public java.lang.Object[] toArray()
Description copied from interface: IListPM
Returns an array containing all of the elements in this list in proper sequence (from first to last element).

Specified by:
toArray in interface IListPM<V extends PresentationModel>
Returns:
an array containing all of the elements in this list in proper sequence (from first to last element)

keySet

public java.util.Set<K> keySet()

containsKey

public boolean containsKey(K key)

contains

public boolean contains(V element)
Description copied from interface: IListPM
Returns true if this collection contains the specified element.

Specified by:
contains in interface IListPM<V extends PresentationModel>
Returns:
true if this collection contains the specified element

indexOfKey

public int indexOfKey(K key)

indexOf

public int indexOf(V element)
Description copied from interface: IListPM
Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.

Specified by:
indexOf in interface IListPM<V extends PresentationModel>
Returns:
the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element

indicesOfKeys

public int[] indicesOfKeys(java.util.Collection<K> keys)
Returns an sorted array of all indices of the elements with the given keys starting with the smallest index.


indicesOf

public int[] indicesOf(java.util.Collection elements)
Returns an sorted array of all indices of the given elements starting with the smallest index.


getKey

public K getKey(V element)

getKey

public K getKey(int index)

getKeys

public java.util.List<K> getKeys(int beginIndex,
                                 int endIndex)

getKeys

public java.util.Set<K> getKeys(int[] indices)

getKeys

public java.util.Set<K> getKeys(java.util.Collection<?> col)
Returns a set of all keys of the elements in the given collection. For elements that are not in this map no key is inserted into the result.

Parameters:
col -
Returns:
a set of all keys of the elements in the given collection

getSelectedKeys

public SelectedKeys<K> getSelectedKeys()

getSelection

public Selection<V> getSelection()
Description copied from interface: IListPM
Returns the selection of this list.

Specified by:
getSelection in interface IListPM<V extends PresentationModel>
Returns:
the selection of this list

addListListener

public void addListListener(ListListener l)
Description copied from interface: IListPM
Adds a ListListener to this model.

Specified by:
addListListener in interface IListPM<V extends PresentationModel>

removeListListener

public void removeListListener(ListListener l)
Description copied from interface: IListPM
Removes a ListListener from this model.

Specified by:
removeListListener in interface IListPM<V extends PresentationModel>

iterator

public java.util.Iterator<V> iterator()
Specified by:
iterator in interface java.lang.Iterable<V extends PresentationModel>

listIterator

public java.util.ListIterator<V> listIterator(int index)
Description copied from interface: IListPM
Returns a list iterator of the elements in this list (in proper sequence), starting at the specified position in this list.

Specified by:
listIterator in interface IListPM<V extends PresentationModel>
Returns:
a list iterator of the elements in this list (in proper sequence), starting at the specified position in this list

keyiterator

public java.util.Iterator<K> keyiterator()

removeAllKeys

public java.util.Collection<V> removeAllKeys(java.util.Set<K> keySet)

retainAllKeys

public java.util.Collection<V> retainAllKeys(java.util.Set<K> keySet)

removeAllIndices

public java.util.Collection<V> removeAllIndices(int[] indices)

putAll

public void putAll(java.util.Map<K,V> aMap)

setAll

public void setAll(java.util.Map<K,V> newMap)

createDefaultValidationRule

protected ValidationRule createDefaultValidationRule()


© 2010 by Michael Karneim, http://www.beanfabrics.org