public class SingleTagTaggedStrings extends java.lang.Object implements TaggedStrings
Since all the strings have the same tag value, we use a sorted string array to hold the strings. We use binary search to locate the strings of interest. While using an array is slower than using a hash map (binary search = o(n*log(n)), hash = o(1)), the array saves lots of memory.
Modifier and Type | Field and Description |
---|---|
protected java.lang.String[] |
strings
Array of string values.
|
protected java.lang.String |
tag
The common tag for all the string values.
|
Constructor and Description |
---|
SingleTagTaggedStrings(java.lang.String[] strings,
java.lang.String tag)
Create SingleTagTaggedStrings object.
|
Modifier and Type | Method and Description |
---|---|
boolean |
containsString(java.lang.String string)
See if specified string exists.
|
java.util.Set<java.lang.String> |
getAllStrings()
Get set of all unique string values.
|
java.util.Set<java.lang.String> |
getAllTags()
Get set of all unique tag values.
|
int |
getStringCount()
Get number of strings.
|
java.lang.String |
getTag(java.lang.String string)
Get the tag value associated with a string.
|
void |
putTag(java.lang.String string,
java.lang.String tag)
Set the tag value associated with a string.
|
protected java.lang.String[] strings
protected java.lang.String tag
public SingleTagTaggedStrings(java.lang.String[] strings, java.lang.String tag)
strings
- String array of strings.tag
- The common tag for all the strings.public boolean containsString(java.lang.String string)
containsString
in interface TaggedStrings
string
- The string.public java.lang.String getTag(java.lang.String string)
getTag
in interface TaggedStrings
string
- The string.public int getStringCount()
getStringCount
in interface TaggedStrings
public java.util.Set<java.lang.String> getAllStrings()
getAllStrings
in interface TaggedStrings
public java.util.Set<java.lang.String> getAllTags()
getAllTags
in interface TaggedStrings
The result always contains just one value, the common tag value associated with all the strings.
public void putTag(java.lang.String string, java.lang.String tag)
putTag
in interface TaggedStrings
string
- The string.tag
- The tag.
This is a no-op in this implementation.