TrueZIP Kernel 7.0-rc2

de.schlichtherle.truezip.util
Class CanonicalStringSet

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractSet<String>
          extended by de.schlichtherle.truezip.util.CanonicalStringSet
All Implemented Interfaces:
Iterable<String>, Collection<String>, Set<String>
Direct Known Subclasses:
SuffixSet

@DefaultAnnotation(value=edu.umd.cs.findbugs.annotations.NonNull.class)
public class CanonicalStringSet
extends AbstractSet<String>

An abstract set of the canonical string representation of objects in natural sort order. An object is canonicalized by the idempotent function CanonicalStringSet.Canonicalizer.map(java.lang.Object).

Canonical 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 sort 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.

Author:
Christian Schlichtherle

Nested Class Summary
static interface CanonicalStringSet.Canonicalizer
          An idempotent function which maps an arbitrary object to its canonical string representation.
private  class CanonicalStringSet.CanonicalStringIterator
           
 
Field Summary
private  CanonicalStringSet.Canonicalizer canonicalizer
          The canonicalizer for strings.
private  char separator
          The separator for string lists.
private  Set<String> set
          The sorted map which implements the behaviour of this class.
 
Constructor Summary
CanonicalStringSet(CanonicalStringSet.Canonicalizer canonicalizer, char separator)
          Constructs a new, empty set of canonical strings.
 
Method Summary
 boolean add(String s)
           The implementation in the class CanonicalStringSet first canonicalizes the given parameter before the operation is continued.
 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.
 void clear()
           
 boolean contains(Object o)
           The implementation in the class CanonicalStringSet first canonicalizes the given parameter before the operation is continued.
 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<String> iterator()
           
 boolean remove(Object o)
           The implementation in the class CanonicalStringSet first canonicalizes the given parameter before the operation is continued.
 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()
           
<T> T[]
toArray(T[] array)
           
 String toString()
          Returns the string list in canonical form for this canonical string 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
 

Field Detail

canonicalizer

private final CanonicalStringSet.Canonicalizer canonicalizer
The canonicalizer for strings.


separator

private final char separator
The separator for string lists.


set

private final Set<String> set
The sorted map which implements the behaviour of this class.

Constructor Detail

CanonicalStringSet

public CanonicalStringSet(CanonicalStringSet.Canonicalizer canonicalizer,
                          char separator)
Constructs a new, empty set of canonical strings.

Parameters:
canonicalizer - the idempotent function to use for canonicalizing strings.
separator - The separator character to use for string lists.
Method Detail

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Collection<String>
Specified by:
isEmpty in interface Set<String>
Overrides:
isEmpty in class AbstractCollection<String>

size

public int size()
Specified by:
size in interface Collection<String>
Specified by:
size in interface Set<String>
Specified by:
size in class AbstractCollection<String>

iterator

public Iterator<String> iterator()
Specified by:
iterator in interface Iterable<String>
Specified by:
iterator in interface Collection<String>
Specified by:
iterator in interface Set<String>
Specified by:
iterator in class AbstractCollection<String>

toArray

public Object[] toArray()
Specified by:
toArray in interface Collection<String>
Specified by:
toArray in interface Set<String>
Overrides:
toArray in class AbstractCollection<String>

toArray

public <T> T[] toArray(T[] array)
Specified by:
toArray in interface Collection<String>
Specified by:
toArray in interface Set<String>
Overrides:
toArray in class AbstractCollection<String>

toString

public String toString()
Returns the string list in canonical form for this canonical string set. If this canonical string set is empty, an empty string is returned.

Overrides:
toString in class AbstractCollection<String>

contains

public boolean contains(@Nullable
                        Object o)

The implementation in the class CanonicalStringSet first canonicalizes the given parameter before the operation is continued.

Specified by:
contains in interface Collection<String>
Specified by:
contains in interface Set<String>
Overrides:
contains in class AbstractCollection<String>

add

public boolean add(@Nullable
                   String s)

The implementation in the class CanonicalStringSet first canonicalizes the given parameter before the operation is continued.

Specified by:
add in interface Collection<String>
Specified by:
add in interface Set<String>
Overrides:
add in class AbstractCollection<String>

remove

public boolean remove(@Nullable
                      Object o)

The implementation in the class CanonicalStringSet first canonicalizes the given parameter before the operation is continued.

Specified by:
remove in interface Collection<String>
Specified by:
remove in interface Set<String>
Overrides:
remove in class AbstractCollection<String>

clear

public void clear()
Specified by:
clear in interface Collection<String>
Specified by:
clear in interface Set<String>
Overrides:
clear in class AbstractCollection<String>

containsAll

public boolean containsAll(CanonicalStringSet set)
Tests if all canonical strings in the given set are contained in this set. An empty set is considered to be a true subset of this set.

Parameters:
set - A non-null set of canonical strings.
Returns:
true Iff all strings in the given set are contained in this set.

containsAll

public boolean containsAll(String list)
Tests if the canonical form of all strings in the given string list is contained in this set. If a string in the list does not have a canonical form, it's skipped. This implies that if the list is empty or entirely consists of strings which do not have a canonical form, true is returned. In other words, an empty set is considered to be a true subset of this set.

Parameters:
list - a non-null string list.
Returns:
true Iff the canonical form of all strings in the given string list is contained in this set.

addAll

public boolean addAll(CanonicalStringSet set)
Adds all canonical strings in the given set to this set after they have been canonicalized by this set again.

Parameters:
set - a non-null set of canonical strings.
Returns:
true Iff this set of canonicalized strings has changed as a result of the call.

addAll

public boolean addAll(String list)
Adds the canonical form of all strings in the given list to this set. If a string in the list does not have a canonical form, it's skipped.

Parameters:
list - a non-null string list.
Returns:
true Iff this set of canonicalized strings has changed as a result of the call.

retainAll

public boolean retainAll(CanonicalStringSet set)
Retains all canonical strings in the given set in this set.

Parameters:
set - a non-null set of canonical strings.
Returns:
true Iff this set changed as a result of the call.

retainAll

public boolean retainAll(String list)
Retains the canonical form of all strings in the given list in this set. If a string in the list does not have a canonical form, it's skipped.

Parameters:
list - a non-null string list.
Returns:
true Iff this set changed as a result of the call.

removeAll

public boolean removeAll(CanonicalStringSet set)
Removes all canonical strings in the given set from this set.

Parameters:
set - a non-null set of strings.
Returns:
true Iff this set changed as a result of the call.

removeAll

public boolean removeAll(String list)
Removes the canonical form of all strings in the given list from this set. If a string in the list does not have a canonical form, it's skipped.

Parameters:
list - a non-null string list.
Returns:
true Iff this set changed as a result of the call.

TrueZIP Kernel 7.0-rc2

Copyright © 2005-2011 Schlichtherle IT Services. All Rights Reserved.