|
| Components |
|
| |||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||||||
java.lang.Object
|
+--com.sas.Component
|
+--com.sas.collection.BaseCollection
|
+--com.sas.collection.AssociationList
AssociationList is an implementation of AssociationListinterface, a collection which stores and retrieves values by either key or integer index. An AssociationList combines OrderedCollectionInterface and DictionaryInterface. It provides key/value pairs, but maintains an order to the data.
| Field Summary | |
protected OrderedCollectionInterface |
items
items is the ordered collection of data items. |
protected OrderedCollectionInterface |
keys
keys is the ordered collection of keys. |
static String |
RB_KEY
|
| Fields inherited from class com.sas.collection.BaseCollection |
allContentsChangedListeners, mappingObject |
| Constructor Summary | |
AssociationList()
Default Constructor |
|
AssociationList(Class orderedCollectionClass)
Constructor which allows you to choose of the type of collection to use for the internal implementation. |
|
AssociationList(String data)
Constructs a new association list populated with elements parsed from a string. |
|
| Method Summary | |
void |
add(int index,
Object key,
Object item)
Add an item into this association list at the specified index. |
void |
add(Object item)
Add an item to this association list. |
void |
add(Object item,
int index)
Insert an item into a specific location in this association list. |
void |
addItems(Enumeration newItems)
Add all elements of an enumeration to this association list. |
void |
addItems(Enumeration enum,
int index)
Add all elements of an enumeration to this collection at the specified location. |
void |
apply(ApplyInterface action)
Applies the action to every item in the current association list. |
void |
applyToPairs(ApplyInterface action)
Applies the 'apply' function in the action to all key/value pairs in the collection. |
Object |
clone()
Clone the object. |
Object |
clone(DeepCloneSupport support,
boolean deeply)
Clone this object using a deep copy. |
boolean |
contains(Object item)
Test the existence of an object in this association list. |
boolean |
containsKey(Object key)
Test the existence of an key in a association list. |
int |
count()
Returns the number of items in this association list |
int |
count(Object value)
Count the number of times the value exists in this association list. |
int |
countKey(Object key)
Count the number of times the given key is used in this association list |
void |
dumpComponent()
Prints attribute information about the class. |
boolean |
equals(AssociationListInterface otherAssociationList)
Compare the current items with those in another AssociationList and tell whether the collections are identical. |
boolean |
equals(Object object)
Compare to another object |
boolean |
equals(StaticOrderedCollectionInterface orderedCollection)
Compare the current items with those in another collection and tell whether the collections are identical. |
protected void |
fireContentsChanged(ContentsChangedEvent event,
boolean notifyItemsChanged,
boolean notifyKeysChanged)
Send a ContentsChangedEvent event to all the ContentsChangedListener objects in the listener list. |
Object |
get(int index)
Fetch an item at a index. |
Object |
get(Object key)
Fetch the item corresponding to a key. |
Object |
get(Object key,
int index)
Fetch the item corresponding to a key. |
static ExtendedBeanInfo |
getExtendedBeanInfo()
|
int |
getIndex(Object element,
int startIndex)
Starting at startIndex, search forward for the first occurrence of item in this association list. |
Enumeration |
getItems()
Return an enumeration of all the items |
Enumeration |
getItems(int start,
int end)
Return an enumeration of a range of items. |
Object |
getKey(int index)
Get the key corresponding to a position |
Object |
getKey(Object item)
Get the key corresponding to an item. |
Object |
getKey(Object item,
int start)
Get the item corresponding to an key Note that an association list may contain the same item via multiple keys. |
Enumeration |
getKeys()
return an Enumeration of all the keys. |
Enumeration |
getKeys(Object item)
Return an Enumeration of all the keys for a given item. |
int |
getLastIndex(Object element,
int startIndex)
Starting at startIndex, searche backwards towards item 0 and returns the index associated with the last occurence of the item in this association list. |
Enumeration |
getPairs()
Returns an enumeration of all the key/value pairs from an association list. |
Enumeration |
getPairs(int start,
int end)
Returns an enumeration of the key/value item pairs from an association list |
boolean |
remove(Object item)
Remove an item from this association list. |
void |
removeAll()
remove all items from this association list |
int |
removeAll(Object item)
Remove an item from this association list. |
void |
removeAllAt(Object key)
Remove all items with the specified key. |
Object |
removeAt(int index)
Remove from this association list the item at the specified index. |
void |
removeAt(Object key)
Remove the item corresponding to the specified key. |
void |
removeAt(Object key,
int start)
Remove the item corresponding to the specified key. |
void |
set(int index,
Object item)
Replace the item at the specified index with a new item. |
void |
set(int index,
Object key,
Object item)
Put an item into this association list, replacing a previous item that was there by the same key/index. |
void |
set(Object key,
Object item)
Put an item into this association list, possibly replacing a previous item that was there by the same key |
void |
setKey(int index,
Object key)
Set the key corresponding to a position |
void |
setSize(int newSize)
Set the number of items that are being held in this association list. |
void |
sort(Comparator comparator)
Sorts the items from the current collection using the provided comparison function. |
void |
sort(Comparator comparator,
int start,
int end)
Sorts the current collection in place using the provided comparison function. |
String |
toString()
Convert this association list to a single string. |
String |
toString(char delimiter,
char separator,
boolean alwaysQuote)
Convert this association list to a single string. |
| Methods inherited from class com.sas.collection.BaseCollection |
addContentsChangedListener, anyContentsChangedListeners, disableEvents, enableEvents, enableEvents, fireContentsChanged, map, removeContentsChangedListener, unmap |
| Methods inherited from class com.sas.Component |
addLink, addPropertyChangeListener, addVetoableChangeListener, anyPropertyChangeListeners, attachModel, attachView, beansIsDesignTime, beansSetDesignTime, clone, detachModel, detachView, firePropertyChange, firePropertyChange, fireVetoableChange, getComponentDescription, getComponentSupportInfo, getEventMethod, getEventValues, getLinkInfo, getModelInterface, getRequiredInterfaces, getResources, getStringResource, getViewInterfaceSupportInfo, initialize, initializeComponent, isDesignTime, isLinked, propertyChange, queryLinks, queryLinks, refresh, removeAllLinks, removeInterfaceTraps, removeLink, removePropertyChangeListener, removeVetoableChangeListener, setComponentDescription, setComponentSupportInfo, setDefaultValues, setLinkInfo, setModelInterface, setRequiredInterfaces, setViewInterfaceSupportInfo, supportsListenerInterface, supportsRequiredInterfaces, trapInterfaceEvents, validateObject |
| Methods inherited from class java.lang.Object |
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface com.sas.collection.ContentsChangedSource |
addContentsChangedListener, removeContentsChangedListener |
| Methods inherited from interface com.sas.beans.PropertyChangeSource |
addPropertyChangeListener, removePropertyChangeListener |
| Field Detail |
public static final String RB_KEY
protected OrderedCollectionInterface items
protected OrderedCollectionInterface keys
| Constructor Detail |
public AssociationList()
public AssociationList(Class orderedCollectionClass)
orderedCollectionClass - a class to instantiate to
store the keys and items. This class must have a public no-arg
constructor and must implement the com.sas.collection.OrderedCollectionInterfaceIllegalArgumentException - if an exception
is caught trying to instantiate the orderedCollectionClasspublic AssociationList(String data)
data - a string of key=value pairs, separated by the delimiter
returned from con.sas.util.Util.getListDelimiterChar().
Booleans and Numbers are recognized and parsed into
appropriate java.lang.Boolean, java.lang.Integer, java.lang.Long,
or java.lang.Double objects (for either the key or the value);
everything else is parsed into a String or Character.
For example, new AssociationList("A=1,two=2,3=true")
results in an association list with three values. The keys
are "A", "two", and the Integer 3,
and the values are the Integer 1, the Integer 2, and Boolean.TRUE
when the default delimiter returned from com.sas.util.Util.getListDelimiterChar()
is a comma. Be sure to use the character returned from the
com.sas.util.Util.getListDelimiterChar() method as the delimiter
when forming the string to get parsed.IllegalArgumentException - if the data string
is invalidStringToDictionaryInterfaceTransform| Method Detail |
public static ExtendedBeanInfo getExtendedBeanInfo()
protected void fireContentsChanged(ContentsChangedEvent event,
boolean notifyItemsChanged,
boolean notifyKeysChanged)
event - the event to send
public void set(int index,
Object key,
Object item)
set in interface AssociationListInterfaceindex - where in the implicit order to set the item.key - the key by which the item may be retrieved later.item - the value to put into this association list
public void add(int index,
Object key,
Object item)
get(index)
and getKey(index)add in interface AssociationListInterfaceindex - where in the implicit order to insert the item.key - the key by which the item may be retrieved later.item - the value to put into this association listpublic void removeAllAt(Object key)
removeAllAt in interface AssociationListInterfacekey - remove all items with this key.public int removeAll(Object item)
removeAll in interface CollectionInterfaceitem - the item to removepublic void add(Object item)
add in interface CollectionInterfaceitem - an object to add to this association listpublic void addItems(Enumeration newItems)
addItems in interface CollectionInterfacenewItems - an Enumeration of items to add to this association listCollectionInterfacepublic void apply(ApplyInterface action)
apply in interface StaticCollectionInterfaceapply in class BaseCollectionaction - An object that performs some action to another object.
action.apply(pair) is excecuted on successive key/value pairs until all pairs in the
this association list have been operated on, or until the method
returns ApplyInterface.ABORTpublic void removeAll()
removeAll in interface CollectionInterfacepublic boolean contains(Object item)
contains in interface StaticCollectionInterfacecontains in class BaseCollectionitem - the item to search forpublic boolean containsKey(Object key)
containsKey in interface StaticDictionaryInterfacekey - the key to search forpublic int count()
count in interface Countablecount in class BaseCollectionpublic int count(Object value)
value - a value to countpublic int countKey(Object key)
key - the association list key to countpublic void dumpComponent()
dumpComponent in class com.sas.Componentpublic Object get(int index)
get in interface IndexedGetInterfaceindex - the position of the item, zero-based indexing.IndexOutOfBoundsException - if index
is not in the range [0, count()-1].get(java.lang.Object,int),
get(java.lang.Object)public Object get(Object key)
get in interface StaticDictionaryInterfacekey - the Object key with which the item was added to this association listNoSuchElementException - when there is no entry for
the specified key. (Note that null
is a valid value for a key.)get(java.lang.Object,int),
get(int)
public Object get(Object key,
int index)
get in interface AssociationListInterfacekey - the Object key with which the item was added to this association listindex - start searching for the key at this indexNoSuchElementException - when there is no entry for
the specified key. (Note that null
is a valid value for a key.)get(java.lang.Object),
get(int)public Enumeration getItems()
getItems in interface EnumerablegetItems in class BaseCollection
public Enumeration getItems(int start,
int end)
getItems in interface StaticOrderedCollectionInterfacestart - the index of the first item in the range of items to getend - get the items between start and (end-1)public Object getKey(Object item)
getKey in interface StaticDictionaryInterfaceitem - the item whose key you wish to find.NoSuchElementException - if the item is not found
public Object getKey(Object item,
int start)
getKey in interface AssociationListInterfaceitem - the item whose key you wish to find.start - the index of where to start searchingNoSuchElementException - if the item is not foundIndexOutOfBoundsException - if
if the index is invalidpublic Object getKey(int index)
getKey in interface AssociationListInterfaceindex - return the key corresponding to this indexIndexOutOfBoundsException - if index
is not in the range [0, count()-1]
public void setKey(int index,
Object key)
setKey in interface AssociationListInterfaceindex - replace the key at this indexkey - the new keyIndexOutOfBoundsException - if index
is not in the range [0, count()-1]public Enumeration getKeys(Object item)
getKeys in interface StaticDictionaryInterfaceitem - the item to search forpublic Enumeration getKeys()
getKeys in interface StaticDictionaryInterfacepublic boolean remove(Object item)
remove in interface CollectionInterfacethe - item to remove
public void removeAt(Object key,
int start)
key - remove the item which corresponds to this keystart - start index for finding the key.public void removeAt(Object key)
removeAt in interface DictionaryInterfacekey - remove the item which corresponds to this key
public int getIndex(Object element,
int startIndex)
getIndex in interface StaticOrderedCollectionInterfaceelement - item to search forstartIndex - the position where the search should startIndexOutOfBoundsException - if the index is
not in the range [0..count()-1].ClassCastException - In some implementations,
the objects that are stored may be restricted to a particular
type (such as String). (a RuntimeException)
public int getLastIndex(Object element,
int startIndex)
getLastIndex in interface StaticOrderedCollectionInterfaceelement - item to search forstartIndex - the position where the search should startIndexOutOfBoundsException - if the index is
not in the range [0..count()-1].ClassCastException - In some implementations,
the objects that are stored may be restricted to a particular
type (such as String). (a RuntimeException)
public void set(Object key,
Object item)
set in interface DictionaryInterfacekey - the key by which the item may be retrieved later.item - the value to put into this association list
public Object clone()
throws CloneNotSupportedException
clone in interface AssociationListInterfaceclone in class BaseCollectionCloneNotSupportedException - if the clone fails.
public Object clone(DeepCloneSupport support,
boolean deeply)
throws CloneNotSupportedException
DeepClonable
This object and all the objects it contains
are cloned, preserving the same structure.clone in interface DeepClonablesupport - a required object which keeps track
of cloned objects during the deep cloning.deeply - If true, clone recursively using the deep clone support.
if false, this is equivalent to a normal clone.public boolean equals(StaticOrderedCollectionInterface orderedCollection)
equals in interface StaticOrderedCollectionInterfaceorderedCollection - Another ordered collection to be compared to. May be null (returns false)public boolean equals(AssociationListInterface otherAssociationList)
otherAssociationList - Another AssociationList to be compared to. May be null (returns false)public boolean equals(Object object)
equals in class Objectobject - another object
public void add(Object item,
int index)
add in interface OrderedCollectionInterfaceitem - the item to add to this association list.
The item may exist multiple times in this association list.index - Insert the object before the indexed item. The
newly inserted item can be accessed by get(index) afterwards.IndexOutOfBoundsException - if index
is not in the range [0, count()].ClassCastException - In some implementations,
the objects that are stored may be restricted to a particular
type (such as String). (a RuntimeException)
public void addItems(Enumeration enum,
int index)
addItems in interface OrderedCollectionInterfaceenum - an Enumeration of items to add to this association listindex - Insert the objects starting before the indexed item. The
first of the newly inserted item can be accessed by get(index)
afterwards.ClassCastException - In some implementations,
the objects that are stored may be restricted to a particular
type (such as String). (a RuntimeException)public Object removeAt(int index)
removeAt in interface OrderedCollectionInterfaceindex - the position of the item, zero-based indexing.IndexOutOfBoundsException - if index
is not in the range [0, count()-1].
public void set(int index,
Object item)
set in interface OrderedCollectionInterfaceindex - The position where the Object will be placed.item - The Object to be added to this association list.IndexOutOfBoundsException - if index
is not in the range [0, count()-1].ClassCastException - In some implementations,
the objects that are stored may be restricted to a particular
type (such as String). (a RuntimeException)public void setSize(int newSize)
setSize in interface OrderedCollectionInterfacesize - The new size of this association listIndexOutOfBoundsException - if index is less than zero.public void sort(Comparator comparator)
sort in interface Sortablecomparator - An instance of a subclass of Comparator which provides a
compare(Object,Object) function.Comparator
public void sort(Comparator comparator,
int start,
int end)
sort in interface Sortablecomparator - A Comparator which provides a
compare(Object,Object)
method. The values passed to the comparator
are Pair objects
which contain the key and the value
for a slot in this association list.
The pair.getFirst() is the key;
pair.getSecond() is the value,
so your comparator must cast the Object parameter to a Pair and
extract the key and value in order to make a comparison. Or, you
can use a PairFirst or PairSecond object wrapped around a
simpler comparator.
Use a new PairFirst(comparator) object around your comparator if you want
to sort by key only; just keys will be extracted from the two items
and passed to your comparator. Use a PairSecond(comparator) object if you want to
sort by value only; the values will be extracted from the two items
and passed to your comparison.start - the index of the first item in the range to sortend - sort the items between start and (end-1)Pair,
PairFirst,
PairSecondpublic void applyToPairs(ApplyInterface action)
applyToPairs in interface AssociationListInterfaceaction - An object that provides a function which takes an
object as an argument and then does something to it.
The values passed to the Comparator
function are Pair objects which contain the key and the value.
In each returned Pair, the pair.getFirst() is the key;
pair.getSecond() is the value.
The application of the action continues until all items in the
this association list have been operated on, or until a call to the
action.apply(Object item) method returns ApplyInterface.ABORTPairpublic Enumeration getPairs()
getPairs in interface AssociationListInterface
public Enumeration getPairs(int start,
int end)
getPairs in interface AssociationListInterfacestart - the index of the first item, zero based.end - one past the index of the last item to include in the enumeration, zero based.
-1 indicates that the enumeration should return all remaining items, even
if items are added/removed before the enumeration gets to them. (If you
pass count() for the end parameter, the enumeration will save the end
value and stop there, even if more items are added to this association
list after the enumeration was created.)IndexOutOfBoundsException - if start
is not in the range [0, count()-1], or start>last
or end is not in the range [0, count()]public String toString()
toString in class Object
public String toString(char delimiter,
char separator,
boolean alwaysQuote)
delimiter - a delimiter for separating the items.separator - a separator which appears between the keys and the valuesalwaysQuote - if true, all items are quoted. If false, only
quote items which require quotes (such as strings containing
the delimiter character, or the '\' character, etc.)
|
| Components |
|
| |||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||||||