com.sas.collection
Class Collection

com.sas.collection.Collection
All Implemented Interfaces:
com.sas.beans.PropertyChangeSource, com.sas.beans.VetoableChangeSource, CollectionInterface, com.sas.collection.ContentsChangedSource, StaticCollectionInterface, ComponentInterface, com.sas.DeepClonable, LinkPropertiesInterface, ModelInterface, com.sas.PublicClonable, com.sas.util.Countable, com.sas.util.Enumerable, com.sas.util.EventGateInterface, ViewInterface, MultipleValueEventSourceInterface, java.beans.PropertyChangeListener, java.io.ObjectInputValidation, java.io.Serializable, java.lang.Cloneable, java.util.EventListener
Direct Known Subclasses:
Set

public class Collection
implements CollectionInterface, com.sas.DeepClonable

A implementation of CollectionInterface, for objects which store and retrieve values. This collection can act as a set (an item cannot exist more than once in the collection at any time), or it can allow duplicates. If the collection has set semantics, tests for containment etc. rely on identity comparisons, not equality comparisons.

See Also:
Set, Serialized Form

Field Summary
static java.lang.String RB_KEY
           
 
Fields inherited from class com.sas.collection.BaseCollection
allContentsChangedListeners, mappingObject
 
Constructor Summary
Collection()
          Default Constructor.
Collection(boolean isSet)
          Construct a collection with set semantics.
Collection(java.lang.String data)
          Construct an Collection from a string of comma delimited values
Collection(java.lang.String data, boolean isSet)
          Construct an Collection from a string of comma delimited values.
 
Method Summary
 void add(java.lang.Object item)
          Add an item to a collection.
 void addItems(java.util.Enumeration items)
          Add all elements of an enumeration to this collection.
 void apply(com.sas.util.ApplyInterface action)
          Applies the action to every item in the collection.
 java.lang.Object clone()
          Clone a Collection.
 java.lang.Object clone(com.sas.DeepCloneSupport support, boolean deeply)
          Clone this object using a deep copy.
 boolean contains(java.lang.Object item)
          Test if this collection contains an object.
 int count()
          Returns the number of items in this collection
 void dumpComponent()
          Prints the collection to System.out.
static com.sas.beans.ExtendedBeanInfo getExtendedBeanInfo()
           
 java.util.Enumeration getItems()
          Return an enumeration of all the elements.
 boolean isSet()
          Return true if this collection is a set, false otherwise.
 boolean remove(java.lang.Object item)
          Remove an item from this collection.
 void removeAll()
          Remove all items from this collection.
 int removeAll(java.lang.Object item)
          Remove all occurrences of an item from this collection.
static java.lang.Object toArray(StaticCollectionInterface collection)
          Return a new array of objects containing the contents of this collection.
 java.lang.String toString()
          Convert this collection 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 interface com.sas.collection.ContentsChangedSource
addContentsChangedListener, removeContentsChangedListener
 
Methods inherited from interface com.sas.beans.PropertyChangeSource
addPropertyChangeListener, removePropertyChangeListener
 

Field Detail

RB_KEY

public static final java.lang.String RB_KEY
See Also:
Constant Field Values
Constructor Detail

Collection

public Collection()
Default Constructor. This creates a collection which allows duplicate items.


Collection

public Collection(boolean isSet)
Construct a collection with set semantics. If the collection has set semantics, tests for containment etc. rely on identity comparisons, not equality comparisons.

Parameters:
isSet - if true, this collection acts like a set; that is, it does not allow duplicate values.
See Also:
Set

Collection

public Collection(java.lang.String data,
                  boolean isSet)
Construct an Collection from a string of comma delimited values. If the collection has set semantics, tests for containment etc. rely on identity comparisons, not equality comparisons.

Parameters:
data - a string values, separated by commas. Boolean and number objects are recognized and parsed into appropriate Boolean, Integer, Long, or Double objects; everything else is parsed into a String or Character.
isSet - if true, this collection acts like a set; that is, it does not allow duplicate values.
Throws:
java.lang.IllegalArgumentException - if the data string is invalid
See Also:
Set, StringToCollectionInterfaceTransform

Collection

public Collection(java.lang.String data)
Construct an Collection from a string of comma delimited values

Parameters:
data - a string values, separated by commas.
Throws:
java.lang.IllegalArgumentException - if the data string is invalid
See Also:
Collection(String, boolean)
Method Detail

getExtendedBeanInfo

public static com.sas.beans.ExtendedBeanInfo getExtendedBeanInfo()

isSet

public boolean isSet()
Return true if this collection is a set, false otherwise.

Returns:
true if this collection is a set (i.e. does not allow a single item to be added more than one time), false otherwise. If the collection is not a set, you can add an item multiple times. Note that you cannot change the set behavior of a collection.

add

public void add(java.lang.Object item)
Add an item to a collection. This may have no effect if this collection is a set and the item already exists.

Specified by:
add in interface CollectionInterface
Parameters:
item - an object to add to this collection

addItems

public void addItems(java.util.Enumeration items)
Add all elements of an enumeration to this collection. Note: to add the contents of another collection, use * targetCollection.addItems(otherCollection.getItems()).

Specified by:
addItems in interface CollectionInterface
Parameters:
items - an Enumeration of items to add to this collection
Throws:
java.lang.ClassCastException - In some implementations, the objects that are stored may be restricted to a particular type (such as String).

apply

public void apply(com.sas.util.ApplyInterface action)
Applies the action to every item in the collection. This is a general way to modify all the items in a collection. No ContentsChangedEvent is fired since we do not know if the applied operation modifies the objects. (The contents of this collection does not actually change.)

Specified by:
apply in interface StaticCollectionInterface
Overrides:
apply in class BaseCollection
Parameters:
action - An object that provides a function which takes an object as an argument and then does something to it.

removeAll

public void removeAll()
Remove all items from this collection.

Specified by:
removeAll in interface CollectionInterface

contains

public boolean contains(java.lang.Object item)
Test if this collection contains an object. If this collection is a set, this is an identity test, not based on the equals() method, as is done for other collections.

Specified by:
contains in interface StaticCollectionInterface
Overrides:
contains in class BaseCollection
Parameters:
item - the item to search for
Returns:
true if and only the item exists
See Also:
StaticCollectionInterface.contains(java.lang.Object)

count

public int count()
Returns the number of items in this collection

Specified by:
count in interface com.sas.util.Countable
Specified by:
count in class BaseCollection
Returns:
the number of items in this collection

dumpComponent

public void dumpComponent()
Prints the collection to System.out.

Specified by:
dumpComponent in interface ComponentInterface
Overrides:
dumpComponent in class Component
See Also:
ComponentInterface.dumpComponent()

getItems

public java.util.Enumeration getItems()
Return an enumeration of all the elements. The order of the items in the enumeration is unspecified.

Specified by:
getItems in interface com.sas.util.Enumerable
Specified by:
getItems in class BaseCollection
Returns:
an enumeration of all the items in the collection.
See Also:
Enumerable.getItems()

remove

public boolean remove(java.lang.Object item)
Remove an item from this collection. If the element appears multiple times, only the first occurrence is removed.

Specified by:
remove in interface CollectionInterface
Parameters:
item - The item to remove
Returns:
true if item removed, false if not.

removeAll

public int removeAll(java.lang.Object item)
Remove all occurrences of an item from this collection.

Specified by:
removeAll in interface CollectionInterface
Parameters:
item - the item to remove
Returns:
the number of items deleted

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Clone a Collection.

Specified by:
clone in interface CollectionInterface
Specified by:
clone in interface StaticCollectionInterface
Specified by:
clone in interface com.sas.PublicClonable
Overrides:
clone in class BaseCollection
Returns:
a new Collection with the same contents, but no listeners.
Throws:
java.lang.CloneNotSupportedException - if the clone fails.

clone

public java.lang.Object clone(com.sas.DeepCloneSupport support,
                              boolean deeply)
                       throws java.lang.CloneNotSupportedException
Clone this object using a deep copy. With this method, this class implements DeepClonable This object and all the objects it contains are cloned, preserving the same structure.

Specified by:
clone in interface com.sas.DeepClonable
Parameters:
support - 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.
Throws:
java.lang.CloneNotSupportedException

toString

public java.lang.String toString()
Convert this collection to a single string.

Overrides:
toString in class java.lang.Object
Returns:
a string consisting of the comma separated values in this collection
See Also:
StaticCollectionInterfaceToStringTransform

toArray

public static java.lang.Object toArray(StaticCollectionInterface collection)
Return a new array of objects containing the contents of this collection.

Parameters:
collection - a non-null object implementing the StaticCollectionInterface
Returns:
an object array; the array length == count() The array may contain null items.



Copyright © 2009 SAS Institute Inc. All Rights Reserved.