edu.neu.ccs.quick
Class StringSet

java.lang.Object
  extended byedu.neu.ccs.quick.StringSet

public final class StringSet
extends Object

StringSet encapsulates a structure that maintains a set of Strings both in the original order of entry and in sorted order.

Since:
2.3
Version:
2.3

Field Summary
private  QuickVector stringList
          The vector of strings in order.
private  QuickTreeSet stringSet
          The string sorted set.
 
Constructor Summary
StringSet()
          The default constructor.
StringSet(String[] strings)
          The constructor with an array of strings.
 
Method Summary
 void addString(String string)
          Adds the given String to the StringSet.
 void addStrings(String[] strings)
          Adds an array of strings to the set.
 void clear()
          Clear the set of all strings.
 boolean contains(String string)
          Returns true if this set contains the String.
 String[] getSortedStrings()
          Returns as an array the Strings in this set in sorted order.
 String getString(int index)
          Returns the String string at the given index in order of entry into the set; or null if the index is out of bounds.
 String[] getStrings()
          Returns as an array the Strings in this set in order of entry into the set.
 String remove(int index)
          Removes and returns the string corresponding to the given index in order of entry in the set provided that the index is in bounds; otherwise returns null.
 String remove(String string)
          Removes and returns the given String string provided that the string is in the set; otherwise returns null.
 void setStrings(String[] strings)
          Clears the set and adds an array of strings to the set.
 int size()
          Returns the number of strings in this set.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

stringSet

private QuickTreeSet stringSet
The string sorted set.


stringList

private QuickVector stringList
The vector of strings in order.

Constructor Detail

StringSet

public StringSet()
The default constructor.


StringSet

public StringSet(String[] strings)

The constructor with an array of strings.

Parameters:
strings - the array of strings
Method Detail

addString

public void addString(String string)

Adds the given String to the StringSet.

The string must be non-null and must not already be in the set; otherwise does nothing.

Parameters:
string - the string to enter into the set

addStrings

public void addStrings(String[] strings)

Adds an array of strings to the set.

Parameters:
strings - the array of strings

setStrings

public void setStrings(String[] strings)

Clears the set and adds an array of strings to the set.

If strings is null, then only clears.

Parameters:
strings - the array of strings

remove

public String remove(int index)

Removes and returns the string corresponding to the given index in order of entry in the set provided that the index is in bounds; otherwise returns null.

Parameters:
index - the index of the string
Returns:
the string at the given index or null

remove

public String remove(String string)

Removes and returns the given String string provided that the string is in the set; otherwise returns null.

Parameters:
string - to remove
Returns:
the string or null

clear

public void clear()

Clear the set of all strings.


size

public int size()
Returns the number of strings in this set.

Returns:
the number of strings

getString

public String getString(int index)

Returns the String string at the given index in order of entry into the set; or null if the index is out of bounds.

Parameters:
index - the index of the string
Returns:
the associated string or null

getStrings

public String[] getStrings()

Returns as an array the Strings in this set in order of entry into the set.

Returns:
the array of strings in this set

getSortedStrings

public String[] getSortedStrings()

Returns as an array the Strings in this set in sorted order.

Returns:
the sorted array of strings in this set

contains

public boolean contains(String string)
Returns true if this set contains the String.

Parameters:
string - the string to test
Returns:
whether or not the string is in the set