|
| Components |
|
| |||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||||||
com.sas.collection.StaticCollection
public class StaticCollection
A StaticCollection is a class which hides the update
methods of a collection object. This is useful if
you have an object which has an internal collection
and you would like to make available a public read-only interface to that
collection. To do so, you could provide a public method
which returns the type StaticCollectionInterface:
private CollectionInterface members; or perhaps private Collection members
public StaticCollectionInterface getMembers()
{ return members; }
but someone could by the static typing this by checking if
the StaticCollectionInterface
is really a CollectionInterface, and gain
update access to your internal collection:
StaticCollectionInterface sc = yourObject.getMembers();
if (sc instanceof CollectionInterface)
{
CollectionInterface c = (CollectionInterface) sc;
// wreak havoc with your collection
}
The StaticCollection class provides an elegant way
around this by creating an object which cannot be
cast to a Collection or CollectionInterface.
public StaticCollectionInterface getMembers()
{ return new StaticCollection(members); }
A recommended way for your to use the StaticCollection
class is to only create it once and always return
that reference.
private StaticCollection sc;
public StaticCollectionInterface getMembers()
{
if (sc == null)
sc = new StaticCollection(members);
return sc;
}
Note, however, that if you create a new members
internal collection, you will need to create a new StaticCollection
object as well, since there is no way to change the CollectionInterface
that the StaticCollection refers to. Also, be aware that in such cases,
other object which hold references to your old StaticCollection object
will have stale object references.
| Field Summary |
|---|
| Fields inherited from class com.sas.collection.BaseCollection |
|---|
allContentsChangedListeners, mappingObject |
| Constructor Summary | |
|---|---|
StaticCollection(StaticCollectionInterface collection)
Create a StaticCollection which provides read-only access to a Collection. |
|
| Method Summary | |
|---|---|
void |
apply(com.sas.util.ApplyInterface action)
Apply an action to all elements in the collection |
boolean |
contains(java.lang.Object object)
Test if a collection contains an object. |
void |
contentsChanged(com.sas.collection.ContentsChangedEvent event)
Handle a change event from the original collection. |
int |
count()
Return the number of items in the collection. |
boolean |
equals(java.lang.Object object)
Test if this collection is equal to another static collection |
java.util.Enumeration |
getItems()
Get an enumeration of the collection contents. |
int |
hashCode()
Return the object's hashcode |
java.lang.String |
toString()
Convert this StaticOrderedCollectionInterface to a String |
| Methods inherited from class com.sas.collection.CollectionMirror |
|---|
addContentsChangedListener, clone, getSource, removeContentsChangedListener |
| Methods inherited from class com.sas.collection.BaseCollection |
|---|
anyContentsChangedListeners, disableEvents, enableEvents, enableEvents, fireContentsChanged, map, unmap |
| Methods inherited from interface com.sas.collection.StaticCollectionInterface |
|---|
clone |
| Methods inherited from interface com.sas.collection.ContentsChangedSource |
|---|
addContentsChangedListener, removeContentsChangedListener |
| Methods inherited from interface com.sas.beans.PropertyChangeSource |
|---|
addPropertyChangeListener, removePropertyChangeListener |
| Constructor Detail |
|---|
public StaticCollection(StaticCollectionInterface collection)
collection - a collection. Note that the parameter type is
StaticCollectionInterface but normally the actual
collection passed will implement CollectionInterface or some other
modifiable collection interface.| Method Detail |
|---|
public void apply(com.sas.util.ApplyInterface action)
apply in interface StaticCollectionInterfaceapply in class BaseCollectionaction - an action to apply to all the collection elements.
This does not change the collection, but it may change the
objects held within the collection.public boolean contains(java.lang.Object object)
contains in interface StaticCollectionInterfacecontains in class BaseCollectionobject - an object to find in the collection.
StaticCollectionInterface.contains(java.lang.Object)public int count()
count in interface com.sas.util.Countablecount in class BaseCollectionpublic java.util.Enumeration getItems()
getItems in interface com.sas.util.EnumerablegetItems in class BaseCollectionEnumerable.getItems()public java.lang.String toString()
toString in class CollectionMirrorpublic int hashCode()
hashCode in class CollectionMirrorpublic boolean equals(java.lang.Object object)
equals in class CollectionMirrortrue if this object equals another
object, else return falsepublic void contentsChanged(com.sas.collection.ContentsChangedEvent event)
contentsChanged in interface com.sas.collection.ContentsChangedListenercontentsChanged in class CollectionMirrorevent - an event from the original source.
|
| Components |
|
| |||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||||||