|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractCollection
java.util.AbstractSet
de.schlichtherle.util.CanonicalStringSet
public class CanonicalStringSet
A set of canonicalized strings in natural order.
A string is canonicalized by the template method canonicalize(java.lang.String)
,
which should get overridden by subclasses.
String sets can be converted from and to string lists by using
addAll(String)
and toString()
.
A string list is a string which consists of zero or more elements
which are separated by the separator character provided to the
constructor.
Note that in general, a string list is just a sequence of strings elements.
In particular, a string list may be empty (but not null
) and
its elements don't have to be in canonical form, may be duplicated in the
list and may be listed in arbitrary order.
However, string lists have a canonical form, too:
A string list in canonical form (or canonical string list for short)
is a string list which contains only canonical strings in natural order
and does not contain any duplicates (so it's actually a set).
Unless otherwise documented, all Set
methods work on the
canonical form of the string elements in this set.
Null elements are not permitted in this set.
Constructor Summary | |
---|---|
CanonicalStringSet(char separator)
Constructs a new, empty set of canonical strings. |
|
CanonicalStringSet(char separator,
CanonicalStringSet set)
Constructs a new set of canonical strings from the given set of canonical strings. |
|
CanonicalStringSet(char separator,
String list)
Deprecated. This constructor is dangerous: It may call canonicalize(java.lang.String) , which may result in a call from a
superclass if this constructor is called from a subclass. |
Method Summary | |
---|---|
boolean |
add(Object list)
Adds the canonical form of all strings in the given list to this set. |
boolean |
addAll(CanonicalStringSet set)
Adds all canonical strings in the given set to this set after they have been canonicalized by this set again. |
boolean |
addAll(String list)
Adds the canonical form of all strings in the given list to this set. |
protected String |
canonical(String s)
Deprecated. Override and use canonicalize(java.lang.String) instead. |
protected String |
canonicalize(String s)
A template method which returns the canonical form of s or
null if the given string does not have a canonical form. |
void |
clear()
|
boolean |
contains(Object list)
Tests if the canonical form of all strings in the given string list is contained in this set. |
boolean |
containsAll(CanonicalStringSet set)
Tests if all canonical strings in the given set are contained in this set. |
boolean |
containsAll(String list)
Tests if the canonical form of all strings in the given string list is contained in this set. |
boolean |
isEmpty()
|
Iterator |
iterator()
Returns a new iterator for all canonical string elements in this set. |
Iterator |
originalIterator()
Returns a new iterator for all original string elements in this set. |
boolean |
remove(Object list)
Removes the canonical form of all strings in the given list from this set. |
boolean |
removeAll(CanonicalStringSet set)
Removes all canonical strings in the given set from this set. |
boolean |
removeAll(String list)
Removes the canonical form of all strings in the given list from this set. |
boolean |
retainAll(CanonicalStringSet set)
Retains all canonical strings in the given set in this set. |
boolean |
retainAll(String list)
Retains the canonical form of all strings in the given list in this set. |
int |
size()
|
Object[] |
toArray()
|
Object[] |
toArray(Object[] array)
|
String |
toString()
Returns the canonical string list representation of this set. |
Methods inherited from class java.util.AbstractSet |
---|
equals, hashCode, removeAll |
Methods inherited from class java.util.AbstractCollection |
---|
addAll, containsAll, retainAll |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.Set |
---|
addAll, containsAll, retainAll |
Constructor Detail |
---|
public CanonicalStringSet(char separator)
separator
- The separator character to use in string lists.public CanonicalStringSet(char separator, CanonicalStringSet set)
separator
- The separator character to use in string lists.set
- A set of canonical strings - may be null
to
construct an empty set.public CanonicalStringSet(char separator, String list)
canonicalize(java.lang.String)
, which may result in a call from a
superclass if this constructor is called from a subclass.
separator
- The separator character to use in string lists.list
- A string list - may be null
to
construct an empty set.Method Detail |
---|
protected String canonical(String s)
canonicalize(java.lang.String)
instead.
protected String canonicalize(String s)
s
or
null
if the given string does not have a canonical form.
The implementation in CanonicalStringSet
simply returns the
parameter.
s
- The string to get canonicalized.
Never null
and never contains the separator.
s
or null
if
s
does not have a canonical form.public final boolean isEmpty()
isEmpty
in interface Collection
isEmpty
in interface Set
isEmpty
in class AbstractCollection
public final int size()
size
in interface Collection
size
in interface Set
size
in class AbstractCollection
public final boolean contains(Object list)
true
is returned.
In other words, an empty set is considered to be a true subset of this
set.
contains
in interface Collection
contains
in interface Set
contains
in class AbstractCollection
list
- A non-null string list.
true
Iff the canonical form of all strings in the
given string list is contained in this set.
NullPointerException
- If list
is null
.
ClassCastException
- If list
is not a String
.public final Iterator iterator()
iterator
in interface Iterable
iterator
in interface Collection
iterator
in interface Set
iterator
in class AbstractCollection
public final Iterator originalIterator()
public final Object[] toArray()
toArray
in interface Collection
toArray
in interface Set
toArray
in class AbstractCollection
public final Object[] toArray(Object[] array)
toArray
in interface Collection
toArray
in interface Set
toArray
in class AbstractCollection
public final boolean add(Object list)
add
in interface Collection
add
in interface Set
add
in class AbstractCollection
list
- A non-null string list.
true
Iff this set changed as a result of the call.
NullPointerException
- If list
is null
.
ClassCastException
- If list
is not a String
.public final boolean remove(Object list)
remove
in interface Collection
remove
in interface Set
remove
in class AbstractCollection
list
- A non-null string list.
true
Iff this set changed as a result of the call.
NullPointerException
- If list
is null
.
ClassCastException
- If list
is not a String
.public final boolean containsAll(CanonicalStringSet set)
set
- A non-null set of canonical strings.
true
Iff all strings in the given set are contained
in this set.
NullPointerException
- If set
is null
.public final boolean containsAll(String list)
true
is returned.
In other words, an empty set is considered to be a true subset of this
set.
list
- A non-null string list.
true
Iff the canonical form of all strings in the
given string list is contained in this set.
NullPointerException
- If list
is null
.public final boolean addAll(CanonicalStringSet set)
set
- A non-null set of canonical strings.
true
Iff this set of canonicalized strings has
changed as a result of the call.
NullPointerException
- If set
is null
.public final boolean addAll(String list)
list
- A non-null string list.
true
Iff this set of canonicalized strings has
changed as a result of the call.
NullPointerException
- If list
is null
.public final boolean retainAll(CanonicalStringSet set)
set
- A non-null set of canonical strings.
true
Iff this set of canonicalized strings has
changed as a result of the call.
NullPointerException
- If set
is null
.public final boolean retainAll(String list)
list
- A non-null string list.
true
Iff this set of canonicalized strings has
changed as a result of the call.
NullPointerException
- If list
is null
.public final boolean removeAll(CanonicalStringSet set)
set
- A non-null set of strings.
true
Iff this set of canonicalized strings has
changed as a result of the call.
NullPointerException
- If set
is null
.public final boolean removeAll(String list)
list
- A non-null string list.
true
Iff this set of canonicalized strings has
changed as a result of the call.
NullPointerException
- If list
is null
.public final void clear()
clear
in interface Collection
clear
in interface Set
clear
in class AbstractCollection
public final String toString()
toString
in class AbstractCollection
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |