|
| Components |
|
| |||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||||||
com.sas.collection.StaticStringList
public class StaticStringList
A StaticStringList is a class which hides the update
methods of a StringList object. This is useful if
you have an object which has an internal StringList
and you would like to make available read-only access to that
StringList. To do so, you could provide a public method
which return the type StaticStringListInterface:
private StringListInterface members;
// or perhaps private StringList members
public StaticStringListInterface getMembers()
{ return new StaticStringList(members); }
but someone can always bypass this by checking if
a StaticStringListInterface is really a StringListInterface:
StaticStringListInterface sc = yourObject.getMembers();
if (sc instanceof StringListInterface)
{
StringListInterface c = (StringListInterface) sc;
// wreak havoc with your StringList
}
The StaticStringList class provides an elegant way
around this by creating an object which cannot be
cast to a StringCollection or StringListInterface.
A recommended way for your to use the StaticStringList
class is to only create it once and always return
that reference.
private StaticStringList sc;
public StaticStringListInterface getMembers()
{
if (sc == null)
sc = new StaticStringList(members);
return sc;
}
Note, however, that if you create a new members
collection, you will need to create a new StaticStringList
object as well, since there is no way to change the StringListInterface
that the StaticStringList refers to. Also, be aware that in such cases,
other object which hold references to your old StaticStringList object
will have stale object references.
| Field Summary |
|---|
| Fields inherited from class com.sas.collection.BaseCollection |
|---|
allContentsChangedListeners, mappingObject |
| Constructor Summary | |
|---|---|
StaticStringList(StaticStringListInterface strings)
Create a StaticStringList which provides read-only
access to another string list. |
|
| Method Summary | |
|---|---|
boolean |
contains(java.lang.Object object)
Test if a collection contains an object. |
int |
count()
Return the number of items in this string collection. |
boolean |
equals(StaticStringListInterface list)
Compare the current items with those in another StaticStringList and tell whether
the lists are identical. |
int |
getIndex(java.lang.String item,
int startIndex)
Returns the index associated with the item (searches forward) |
java.util.Enumeration |
getItems()
Get an enumeration of this collection's contents. |
int |
getLastIndex(java.lang.String item,
int startIndex)
Returns the index associated with the item (searches backward) |
java.lang.String |
getString(int index)
Fetch a string at a index. |
java.lang.String[] |
getStringItems()
Return the Strings in this string list as an array of String. |
StaticStringListInterface |
getStringItems(int start,
int last)
Extract a sublist of items from this string list |
| Methods inherited from class com.sas.collection.CollectionMirror |
|---|
addContentsChangedListener, clone, contentsChanged, equals, getSource, hashCode, removeContentsChangedListener, toString |
| Methods inherited from class com.sas.collection.BaseCollection |
|---|
anyContentsChangedListeners, apply, disableEvents, enableEvents, enableEvents, fireContentsChanged, map, unmap |
| Methods inherited from interface com.sas.collection.StaticStringListInterface |
|---|
clone |
| Methods inherited from interface com.sas.collection.ContentsChangedSource |
|---|
addContentsChangedListener, removeContentsChangedListener |
| Methods inherited from interface com.sas.beans.PropertyChangeSource |
|---|
addPropertyChangeListener, removePropertyChangeListener |
| Constructor Detail |
|---|
public StaticStringList(StaticStringListInterface strings)
StaticStringList which provides read-only
access to another string list.
strings - a string list. Note that the parameter type is
StaticStringListInterface but normally the actual
collection passed will implement StringListInterface| Method Detail |
|---|
public boolean equals(StaticStringListInterface list)
StaticStringList and tell whether
the lists are identical. The equals method is used to compare
the Strings.
equals in interface StaticStringListInterfacelist - Another string list to be compared to.
true if identical, false otherwise.
public int getIndex(java.lang.String item,
int startIndex)
getIndex in interface StaticStringListInterfaceitem - item to search forstartIndex - index where search should start
java.lang.IndexOutOfBoundsException - if the start index
is not in the range [0..count()-1]public java.lang.String[] getStringItems()
String.
getStringItems in interface StaticStringListInterfaceString values in this string list.
public StaticStringListInterface getStringItems(int start,
int last)
getStringItems in interface StaticStringListInterfacestart - the index of the first item, zero based.last - the index of the last item, zero based.
java.lang.IndexOutOfBoundsException - if start or last
are not in the range [0, count()-1].StaticOrderedCollectionInterface.getItems(int, int),
String.substring(int, int)
public int getLastIndex(java.lang.String item,
int startIndex)
getLastIndex in interface StaticStringListInterfaceitem - item to search forstartIndex - index where search should start
java.lang.IndexOutOfBoundsException - if the start index
is not in the range [0..count()-1]public java.lang.String getString(int index)
getString in interface StaticStringListInterfacethe - position of the item, zero based indexing.
java.lang.IndexOutOfBoundsException - if index
is not in the range [0, count-1].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 boolean contains(java.lang.Object object)
contains in interface StaticCollectionInterfacecontains in class BaseCollectionobject - an object to find in this string collection.
StaticCollectionInterface.contains(java.lang.Object)
|
| Components |
|
| |||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||||||