de.schlichtherle.io.util
Class SuffixSet

java.lang.Object
  extended by java.util.AbstractCollection
      extended by java.util.AbstractSet
          extended by de.schlichtherle.util.CanonicalStringSet
              extended by de.schlichtherle.io.util.SuffixSet
All Implemented Interfaces:
Iterable, Collection, Set

public final class SuffixSet
extends CanonicalStringSet

An ordered set of canonicalized suffixes. A suffix is the part of a file name string after the last dot. It must not contain the character '|'. A suffix in canonical form (or canonical suffix for short) is a lowercase string which is not empty and does not start with a dot ('.').

For example, the suffix "zip" is in canonical form, while the suffixes "", "Zip", "ZIP", ".zip", ".Zip", ".ZIP", and "zip|Zip|ZIP|.zip|.Zip|.ZIP" aren't.

Suffix sets can be converted from and to suffix lists by using CanonicalStringSet.addAll(String) and CanonicalStringSet.toString(). A suffix list is a string which consists of zero or more suffixes which are separated by the character '|'. Note that in general, a suffix list is just a sequence of suffixes. In particular, a suffix list may be empty (but not null) and its suffixes don't have to be in canonical form, may be duplicated in the list and may be listed in arbitrary order. However, suffix lists have a canonical form, too: A suffix list in canonical form (or canonical suffix list for short) is a suffix list which contains only canonical suffixes 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 suffixes in this set.

Null suffixes are not permitted in this set.

Since:
TrueZIP 6.5
Version:
TrueZIP 6.7
Author:
Christian Schlichtherle

Constructor Summary
SuffixSet()
          Constructs a new, empty suffix set.
SuffixSet(Collection c)
          Constructs a new suffix set by adding the canonical form of all suffixes for all suffix lists in the given collection.
SuffixSet(String list)
          Constructs a new suffix set from the given suffix list.
 
Method Summary
protected  String canonicalize(String suffix)
          Returns the canonical form of suffix or null if the given suffix does not have a canonical form.
 String toRegex()
          Returns a case insensitive regular expression to match (file) paths against the suffixes in this set.
 
Methods inherited from class de.schlichtherle.util.CanonicalStringSet
add, addAll, addAll, canonical, clear, contains, containsAll, containsAll, isEmpty, iterator, originalIterator, remove, removeAll, removeAll, retainAll, retainAll, size, toArray, toArray, toString
 
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

SuffixSet

public SuffixSet()
Constructs a new, empty suffix set.


SuffixSet

public SuffixSet(String list)
Constructs a new suffix set from the given suffix list.

Parameters:
list - A suffix list - may be null to construct an empty set.

SuffixSet

public SuffixSet(Collection c)
Constructs a new suffix set by adding the canonical form of all suffixes for all suffix lists in the given collection.

Parameters:
c - A collection of suffix lists - may be null to construct an empty set.
Throws:
ClassCastException - If the collection does not only contain Strings.
Method Detail

canonicalize

protected String canonicalize(String suffix)
Returns the canonical form of suffix or null if the given suffix does not have a canonical form. An example of the latter case is the empty string.

Overrides:
canonicalize in class CanonicalStringSet
Parameters:
suffix - The string to get canonicalized. Never null and never contains the separator.
Returns:
The canonical form of s or null if s does not have a canonical form.

toRegex

public String toRegex()
Returns a case insensitive regular expression to match (file) paths against the suffixes in this set. If the regular expression matches, the matching suffix is captured as the first matching group. If this suffix set is empty, an unmatchable expression is returned.