com.taursys.model
Class AbstractListValueHolder

java.lang.Object
  extended bycom.taursys.model.AbstractCollectionValueHolder
      extended bycom.taursys.model.AbstractListValueHolder
All Implemented Interfaces:
javax.swing.event.ChangeListener, java.util.Collection, CollectionValueHolder, java.util.EventListener, java.util.List, ListValueHolder, ValueHolder
Direct Known Subclasses:
ObjectListValueHolder, VOListValueHolder

public class AbstractListValueHolder
extends AbstractCollectionValueHolder
implements ListValueHolder

AbstractListValueHolder is a partial implementation of a ListValueHolder Interface.

Version:
1.0
Author:
Marty Phelan

Constructor Summary
AbstractListValueHolder(ObjectValueHolder holder)
          Constructs a new AbstractListValueHolder
AbstractListValueHolder(ObjectValueHolder holder, java.util.List list)
          Constructs a new AbstractListValueHolder
 
Method Summary
 void add(int index, java.lang.Object element)
           
 boolean add(java.lang.Object o)
          Ensures that the underlying collection of this holder contains the specified element (optional operation).
 boolean addAll(java.util.Collection c)
          Adds all of the elements in the specified collection to the underlying collection of this holder (optional operation).
 boolean addAll(int index, java.util.Collection c)
           
 void addListSelectionListener(javax.swing.event.ListSelectionListener l)
          Add a listener to the list that's notified each time a change to the selection occurs.
 void clear()
          Removes all of the elements from the underlying collection of this holder (optional operation).
protected  void fireValueChanged()
          Notifies all ListSelectionListeners that the position has changed.
protected  void fireValueChanged(javax.swing.event.ListSelectionEvent e)
          Notifies all ListSelectionListeners of the given ListSelectionEvent.
 void first()
          Makes the last object in the List available.
 java.lang.Object get(int index)
           
 java.util.Comparator getComparator()
          Get the Comparator that will be used to sort this List.
 java.util.List getList()
          Gets the List that this ValueHolder will use.
 int getPosition()
          Gets the current position in the list.
 java.lang.Object getPropertyValue(java.lang.String propertyName, int index)
          Returns the value of the given property in the valueObject of the given index.
 java.lang.Object[] getPropertyValues(java.lang.String[] propertyNames, int index)
          Get the values for the given properties in the valueObject at the given index.
 int getRowCount()
          Gets the current number of rows in the list.
 boolean hasAny()
          Indicates if the List has any Objects.
 boolean hasNext()
          Indicates whether there is another (any) Objects in the List.
 boolean hasPrior()
          Indicates whether there is a prior Object in the List.
 int indexOf(java.lang.Object o)
           
 int indexOf(java.lang.String[] propertyNames, java.lang.Object[] values)
          Search through the items in the list for a match based on comparing the given properties/values.
 void last()
          Makes the last object in the List available.
 int lastIndexOf(java.lang.Object o)
           
 java.util.ListIterator listIterator()
           
 java.util.ListIterator listIterator(int index)
           
 void moveTo(int row)
          Makes the given row number the current available object.
 void next()
          Makes the next object in the List available.
 void prior()
          Makes the prior object in the List available.
 java.lang.Object remove()
           
 java.lang.Object remove(int index)
           
 boolean remove(java.lang.Object o)
          Removes a single instance of the specified element from this collection, if it is present (optional operation).
 boolean removeAll(java.util.Collection c)
          Removes all the underlying collection of this holder's elements that are also contained in the specified collection (optional operation).
 void removeListSelectionListener(javax.swing.event.ListSelectionListener l)
          Remove a listener from the list that's notified each time a change to the selection occurs.
 void reset()
          Resets this holder so that you can iterate the List from the beginning.
 boolean retainAll(java.util.Collection c)
          Retains only the elements in the underlying collection of this holder that are contained in the specified collection (optional operation).
 java.lang.Object set(int index, java.lang.Object element)
           
 void setCollection(java.util.Collection newCollection)
          Sets the List that this ValueHolder will use and moves to first position (if any).
 void setComparator(java.util.Comparator comparator)
          Set the Comparator that will be used to sort this List.
 void setList(java.util.List newList)
          Sets the List(collection) that this ValueHolder will use.
 void setObject(java.lang.Object obj)
          Sets (replace/copy) the object in the current position.
 void setPropertyValues(java.lang.String[] propertyNames, java.lang.Object[] values, int index)
          Set the values for the given properties in the valueObject.
 void sort()
          Sort the list using the current comparator.
 java.util.List subList(int fromIndex, int toIndex)
           
 java.lang.String toString()
          Returns a string representation of this object.
 
Methods inherited from class com.taursys.model.AbstractCollectionValueHolder
addChangeListener, contains, containsAll, getAlias, getCollection, getJavaDataType, getObject, getObjectValueHolder, getParentPropertyName, getParentValueHolder, getPropertyValue, getPropertyValues, isEmpty, iterator, removeChangeListener, setAlias, setParentPropertyName, setParentValueHolder, setPropertyValue, setPropertyValues, size, stateChanged, toArray, toArray
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.taursys.model.CollectionValueHolder
contains, containsAll, equals, getObject, hashCode, isEmpty, iterator, size, toArray, toArray
 
Methods inherited from interface com.taursys.model.ValueHolder
addChangeListener, getAlias, getJavaDataType, getPropertyValue, getPropertyValues, removeChangeListener, setPropertyValue, setPropertyValues
 
Methods inherited from interface java.util.List
contains, containsAll, equals, hashCode, isEmpty, iterator, size, toArray, toArray
 

Constructor Detail

AbstractListValueHolder

public AbstractListValueHolder(ObjectValueHolder holder)
Constructs a new AbstractListValueHolder


AbstractListValueHolder

public AbstractListValueHolder(ObjectValueHolder holder,
                               java.util.List list)
Constructs a new AbstractListValueHolder

Method Detail

hasNext

public boolean hasNext()
Indicates whether there is another (any) Objects in the List.

Specified by:
hasNext in interface CollectionValueHolder
Overrides:
hasNext in class AbstractCollectionValueHolder

hasPrior

public boolean hasPrior()
Indicates whether there is a prior Object in the List.

Specified by:
hasPrior in interface ListValueHolder

hasAny

public boolean hasAny()
Indicates if the List has any Objects.

Specified by:
hasAny in interface ListValueHolder

getPosition

public int getPosition()
Gets the current position in the list. Returns -1 if position invalid.

Specified by:
getPosition in interface ListValueHolder

getRowCount

public int getRowCount()
Gets the current number of rows in the list.

Specified by:
getRowCount in interface ListValueHolder

moveTo

public void moveTo(int row)
Makes the given row number the current available object. You should first invoke getRowCount to ensure that you are not requesting a row out of range.

Specified by:
moveTo in interface ListValueHolder

first

public void first()
Makes the last object in the List available. You should first invoke the hasAny to ensure that there is an object in the List. If the list is empty, the current object will be null.

Specified by:
first in interface ListValueHolder

next

public void next()
Makes the next object in the List available. You should invoke the hasNext method BEFORE invoking this method to ensure that there IS a next object.

Specified by:
next in interface CollectionValueHolder
Overrides:
next in class AbstractCollectionValueHolder

prior

public void prior()
Makes the prior object in the List available. You should first invoke the hasPrior to ensure that there is a prior object in the List.

Specified by:
prior in interface ListValueHolder

last

public void last()
Makes the last object in the List available. You should first invoke the hasAny to ensure that there is an object in the List. If the list is empty, the current object will be null.

Specified by:
last in interface ListValueHolder

reset

public void reset()
Resets this holder so that you can iterate the List from the beginning.

Specified by:
reset in interface CollectionValueHolder
Overrides:
reset in class AbstractCollectionValueHolder

indexOf

public int indexOf(java.lang.String[] propertyNames,
                   java.lang.Object[] values)
            throws ModelException
Search through the items in the list for a match based on comparing the given properties/values.

Specified by:
indexOf in interface ListValueHolder
Parameters:
propertyNames - which properties to compare for a match
values - the values to match
Returns:
the first item in the list which matches the criteria else -1
Throws:
ModelException

getPropertyValues

public java.lang.Object[] getPropertyValues(java.lang.String[] propertyNames,
                                            int index)
                                     throws ModelException
Get the values for the given properties in the valueObject at the given index.

Specified by:
getPropertyValues in interface ListValueHolder
Throws:
ModelException

getPropertyValue

public java.lang.Object getPropertyValue(java.lang.String propertyName,
                                         int index)
                                  throws ModelException
Returns the value of the given property in the valueObject of the given index.

Specified by:
getPropertyValue in interface ListValueHolder
Throws:
ModelException

setPropertyValues

public void setPropertyValues(java.lang.String[] propertyNames,
                              java.lang.Object[] values,
                              int index)
                       throws ModelException
Set the values for the given properties in the valueObject. Fires a StateChanged event to any listeners.

Throws:
ModelException

setObject

public void setObject(java.lang.Object obj)
Sets (replace/copy) the object in the current position. You should ensure that the current position is valid before invoking this method. Depending on the specific implementation, the given object may either replace the current object in the list, or the property values of the given object may be copied to the current object in the list.

Specified by:
setObject in interface CollectionValueHolder
Overrides:
setObject in class AbstractCollectionValueHolder

setCollection

public void setCollection(java.util.Collection newCollection)
Sets the List that this ValueHolder will use and moves to first position (if any). The list contains the set of Value Objects.

Overrides:
setCollection in class AbstractCollectionValueHolder
Parameters:
newCollection - the List that this ValueHolder will use
Throws:
java.lang.ClassCastException - if given collection is not a List

setList

public void setList(java.util.List newList)
Sets the List(collection) that this ValueHolder will use. Sorts the list by the current comparator (if any), moves to first position (if any) and broadcasts a ListContentChangeEvent and a ListSelectionEvent. The list contains the set of ValueObjects.

Parameters:
newList - the List that this ValueHolder will use

getList

public java.util.List getList()
Gets the List that this ValueHolder will use. The list contains the set of Value Objects.


setComparator

public void setComparator(java.util.Comparator comparator)
Set the Comparator that will be used to sort this List. The list is sorted whenever you change the list (using setList) or invoke the sort method.

Parameters:
comparator - the Comparator used to sort this List.

getComparator

public java.util.Comparator getComparator()
Get the Comparator that will be used to sort this List. The list is sorted whenever you change the list (using setList) or invoke the sort method.

Returns:
the Comparator used to sort this List.

sort

public void sort()
Sort the list using the current comparator. After sorting, move the position to the beginning of the list and broadcast a ListContentChangeEvent and a ListSelectionEvent. No actions occur if the comparator is null.


removeListSelectionListener

public void removeListSelectionListener(javax.swing.event.ListSelectionListener l)
Remove a listener from the list that's notified each time a change to the selection occurs.

Specified by:
removeListSelectionListener in interface ListValueHolder
Parameters:
l - the ListSelectionListener
See Also:
addListSelectionListener(javax.swing.event.ListSelectionListener)

addListSelectionListener

public void addListSelectionListener(javax.swing.event.ListSelectionListener l)
Add a listener to the list that's notified each time a change to the selection occurs.

Specified by:
addListSelectionListener in interface ListValueHolder
Parameters:
l - the ListSelectionListener
See Also:
removeListSelectionListener(javax.swing.event.ListSelectionListener)

fireValueChanged

protected void fireValueChanged()
Notifies all ListSelectionListeners that the position has changed. It generates a ListselectionEvent with this value holder as the source, the current position as the first and last index, and false as ValueIsAdjusting.


fireValueChanged

protected void fireValueChanged(javax.swing.event.ListSelectionEvent e)
Notifies all ListSelectionListeners of the given ListSelectionEvent.


remove

public java.lang.Object remove()

remove

public java.lang.Object remove(int index)
Specified by:
remove in interface java.util.List

remove

public boolean remove(java.lang.Object o)
Description copied from interface: CollectionValueHolder
Removes a single instance of the specified element from this collection, if it is present (optional operation). More formally, removes an element e such that (o==null ? e==null : o.equals(e)), if the underlying collection of this holder contains one or more such elements. Returns true if the underlying collection of this holder contained the specified element (or equivalently, if the underlying collection of this holder changed as a result of the call).

Specified by:
remove in interface CollectionValueHolder
Overrides:
remove in class AbstractCollectionValueHolder
Parameters:
o - element to be removed from the underlying collection of this holder, if present.
Returns:
true if the underlying collection of this holder changed as a result of the call

removeAll

public boolean removeAll(java.util.Collection c)
Description copied from interface: CollectionValueHolder
Removes all the underlying collection of this holder's elements that are also contained in the specified collection (optional operation). After this call returns, the underlying collection of this holder will contain no elements in common with the specified collection.

Specified by:
removeAll in interface CollectionValueHolder
Overrides:
removeAll in class AbstractCollectionValueHolder
Parameters:
c - elements to be removed from the underlying collection of this holder.
Returns:
true if the underlying collection of this holder changed as a result of the call
See Also:
AbstractCollectionValueHolder.remove(Object), AbstractCollectionValueHolder.contains(Object)

retainAll

public boolean retainAll(java.util.Collection c)
Description copied from interface: CollectionValueHolder
Retains only the elements in the underlying collection of this holder that are contained in the specified collection (optional operation). In other words, removes from the underlying collection of this holder all of its elements that are not contained in the specified collection.

Specified by:
retainAll in interface CollectionValueHolder
Overrides:
retainAll in class AbstractCollectionValueHolder
Parameters:
c - elements to be retained in the underlying collection of this holder.
Returns:
true if the underlying collection of this holder changed as a result of the call
See Also:
AbstractCollectionValueHolder.remove(Object), AbstractCollectionValueHolder.contains(Object)

clear

public void clear()
Description copied from interface: CollectionValueHolder
Removes all of the elements from the underlying collection of this holder (optional operation). This collection will be empty after this method returns unless it throws an exception.

Specified by:
clear in interface CollectionValueHolder
Overrides:
clear in class AbstractCollectionValueHolder

add

public boolean add(java.lang.Object o)
Description copied from interface: CollectionValueHolder
Ensures that the underlying collection of this holder contains the specified element (optional operation). Returns true if the underlying collection of this holder changed as a result of the call. (Returns false if the underlying collection of this holder does not permit duplicates and already contains the specified element.)

Collections that support this operation may place limitations on what elements may be added to the underlying collection of this holder. In particular, some collections will refuse to add null elements, and others will impose restrictions on the type of elements that may be added. Collection classes should clearly specify in their documentation any restrictions on what elements may be added.

If a collection refuses to add a particular element for any reason other than that it already contains the element, it must throw an exception (rather than returning false). This preserves the invariant that a collection always contains the specified element after this call returns.

Specified by:
add in interface CollectionValueHolder
Overrides:
add in class AbstractCollectionValueHolder
Parameters:
o - element whose presence in the underlying collection of this holder is to be ensured.
Returns:
true if the underlying collection of this holder changed as a result of the call

add

public void add(int index,
                java.lang.Object element)
Specified by:
add in interface java.util.List

addAll

public boolean addAll(java.util.Collection c)
Description copied from interface: CollectionValueHolder
Adds all of the elements in the specified collection to the underlying collection of this holder (optional operation). The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (This implies that the behavior of this call is undefined if the specified collection is the underlying collection of this holder, and the underlying collection of this holder is nonempty.)

Specified by:
addAll in interface CollectionValueHolder
Overrides:
addAll in class AbstractCollectionValueHolder
Parameters:
c - elements to be inserted into the underlying collection of this holder.
Returns:
true if the underlying collection of this holder changed as a result of the call
See Also:
AbstractCollectionValueHolder.add(Object)

addAll

public boolean addAll(int index,
                      java.util.Collection c)
Specified by:
addAll in interface java.util.List

set

public java.lang.Object set(int index,
                            java.lang.Object element)
Specified by:
set in interface java.util.List

get

public java.lang.Object get(int index)
Specified by:
get in interface java.util.List

indexOf

public int indexOf(java.lang.Object o)
Specified by:
indexOf in interface java.util.List

lastIndexOf

public int lastIndexOf(java.lang.Object o)
Specified by:
lastIndexOf in interface java.util.List

listIterator

public java.util.ListIterator listIterator()
Specified by:
listIterator in interface java.util.List

listIterator

public java.util.ListIterator listIterator(int index)
Specified by:
listIterator in interface java.util.List

subList

public java.util.List subList(int fromIndex,
                              int toIndex)
Specified by:
subList in interface java.util.List

toString

public java.lang.String toString()
Returns a string representation of this object. This contains the object identity and state information.

Overrides:
toString in class AbstractCollectionValueHolder
Returns:
a string representation of this object


Copyright © 2007 Martin T Phelan. All Rights Reserved.