com.ibm.datapower.wamt
Class StringCollection

java.lang.Object
  extended by com.ibm.datapower.wamt.StringCollection

public class StringCollection
extends java.lang.Object

A simple collection of Strings. This is used in multiple classes in the clientAPI package (task-level API) and the deviceCommunication package (AMP). This class is important because it has many helper methods, such as doing comparisons with subsets, non-sorted equality, etc.

WARNING: THIS CLASS IS NOT NLS ENABLED. It should only be used to store "data" type strings that are dynamically obtained from elsewhere. Examples would be features from firmware or domain names from a device.


Field Summary
static java.lang.String COPYRIGHT_2009_2013
           
static StringCollection EMPTY
          A representation of any empty collection.
 
Constructor Summary
StringCollection()
          Create a new collection of Strings.
StringCollection(java.lang.String[] array)
          Create a new collection of Strings and initialize the collection with the contents of the array.
StringCollection(StringCollection clonable)
          Create a new collection of Strings that is a clone.
StringCollection(StringCollection collection1, StringCollection collection2)
          Create a new StringCollection that is a merged instance of two other collections.
 
Method Summary
 void add(java.lang.String string)
          Add a new String into the collection.
 boolean contains(java.lang.String target)
          Check if the collection contains the specified String.
static StringCollection createCollectionFromDisplayName(java.lang.String s)
          Create a StringCollection instance based on a string created by getDisplayName.
static StringCollection createCollectionFromString(java.lang.String s, char delimiter)
          Create a StringCollection instance based on a string created by marshalToString.
 boolean equals(java.lang.Object that)
          Check if the two collections have the same content.
 java.lang.String get(int index)
          Get the String at the specified index in the collection.
 java.lang.String getDisplayName()
          Create a human-readable representation of this collection that is intended for consumption by end users.
 int hashCode()
           
 boolean isSupersetOf(StringCollection that)
          Check if one collection (this) is a superset of another collection (that).
 java.lang.String marshalToString(char delimiter)
          Get a String representation of the collection.
 void remove(java.lang.String string)
          Remove the specified String object from the collection.
 int size()
          Get the number of Strings currently in this collection.
 java.lang.String toString()
          Create a human-readable representation of this collection.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

EMPTY

public static final StringCollection EMPTY
A representation of any empty collection. This member is available so that many instances of empty collections can all reference this single collection, thus saving memory. The modification methods below such as add(String) and remove(String) have been written to disallow changes to this singleton.


COPYRIGHT_2009_2013

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

StringCollection

public StringCollection()
Create a new collection of Strings. The collection is empty.


StringCollection

public StringCollection(java.lang.String[] array)
Create a new collection of Strings and initialize the collection with the contents of the array.

Parameters:
array - the initial contents for the collection.

StringCollection

public StringCollection(StringCollection clonable)
Create a new collection of Strings that is a clone. The new collection is a separate collection, but it references all the same String objects of the original (clonable) collection.

Parameters:
clonable - the original collection to make a copy (clone) of.

StringCollection

public StringCollection(StringCollection collection1,
                        StringCollection collection2)
Create a new StringCollection that is a merged instance of two other collections. It will eliminate duplicate values. It does not modify the two original collections (collection1 and collection2).

Parameters:
collection1 - a collection of Strings to be included in the merged instance
collection2 - a collection of Strings to be included in the merged instance
Method Detail

size

public int size()
Get the number of Strings currently in this collection.

Returns:
the number of Strings currently in this collection.

get

public java.lang.String get(int index)
Get the String at the specified index in the collection.

Parameters:
index - the index into the collection that locates the desired String
Returns:
the String at the specified index in the collection

marshalToString

public java.lang.String marshalToString(char delimiter)
                                 throws DMgrException
Get a String representation of the collection. Each string is separated by the specified delimiter.

Parameters:
delimiter - The delimiter for each String in the collection that is returned in the aggregate string
Returns:
all the Strings in the collection seperated by delimiter

createCollectionFromString

public static final StringCollection createCollectionFromString(java.lang.String s,
                                                                char delimiter)
Create a StringCollection instance based on a string created by marshalToString.

Parameters:
s - The string created by marshalToString
delimiter - The delimiter passed to marshalToString
Returns:
an all the Strings in the collection seperated by delimiter

add

public void add(java.lang.String string)
Add a new String into the collection. It is added to the end of the collection.

Parameters:
string - the String to add to the collection.

remove

public void remove(java.lang.String string)
Remove the specified String object from the collection.

Parameters:
string - the String object to remove from the collection.
See Also:
contains(String)

contains

public boolean contains(java.lang.String target)
Check if the collection contains the specified String. When looking in the collection for the desired String, the String.equals method is invoked instead of ==, which means it will find Strings of the same content even if they are different object instances.

Parameters:
target - look for a String in the collection that has this contents
Returns:
true if the same contents were found, false otherwise

equals

public boolean equals(java.lang.Object that)
Check if the two collections have the same content. It will walk through each each String in this collection and verify that the exact String is in the other collection. The two collections may not be a superset or subset of each other, they must contain the same Strings of the same values. When we say "same Strings" it means .equals() equivalence, not == equivalence. Also, sort order of the collections is irrevelant, meaning that equivalency is not dependent on the order of the Strings in the collection.

Overrides:
equals in class java.lang.Object
Parameters:
that - the other StringCollection to compare equivalency to this.
Returns:
true if the two collections are equivalent, false otherwise.

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

isSupersetOf

public boolean isSupersetOf(StringCollection that)
Check if one collection (this) is a superset of another collection (that). In other words, verify that the first collection (this) contains all the elements that are in the second collection (that). This is order independent for both collections. The isSupersetOf test is true if the two collections are equal, meaning that the first collection does not need to have a greater number of elements than the second collection.

Parameters:
that - the collection which is a subset of this
Returns:
true if the first collection is a superset of the second collection, false otherwise.

toString

public java.lang.String toString()
Create a human-readable representation of this collection. This is intended more for debugging than consumption by end users.

Overrides:
toString in class java.lang.Object
Returns:
a human-readable representation of this collection.
See Also:
getDisplayName()

getDisplayName

public java.lang.String getDisplayName()
Create a human-readable representation of this collection that is intended for consumption by end users.

Returns:
a human-readable representation of this collection that is intended for consumption by end users.
See Also:
createCollectionFromDisplayName(String)

createCollectionFromDisplayName

public static final StringCollection createCollectionFromDisplayName(java.lang.String s)
Create a StringCollection instance based on a string created by getDisplayName.

Parameters:
s - The string created by getDisplayName. Since getDisplayName separates members by ", ", embedded sequences of ", " in a member will result in the member being split into 2 members.
Returns:
The StringCollection created from s
See Also:
getDisplayName()


© Copyright IBM Corp. 2006, 2010 All Rights Reserved.