de.fhdarmstadt.fbi.dtree.model
Class SimpleAlphabet

java.lang.Object
  extended byde.fhdarmstadt.fbi.dtree.model.SimpleAlphabet
All Implemented Interfaces:
Alphabet

public class SimpleAlphabet
extends java.lang.Object
implements Alphabet

An simple, unmodifiable alphabet implementation. This implementation guarantees that its contents do not change after the object has been constructed and that this alphabet is always valid.


Constructor Summary
SimpleAlphabet(java.lang.Character[] symbols)
          Creates a alphabet for the given symbols.
 
Method Summary
 boolean contains(java.lang.Character c)
          Checks, whether the given character is contained in this alphabet.
 Alphabet getImmutableInstance()
          Returns an immutable instance of this alphabet.
 java.util.Iterator getSymbols()
          Returns the symbols contained in this alphabet as iterator.
 boolean isEmpty()
          Checks, whether the alphabet is empty.
 boolean isValid(java.lang.String s)
          Tests, whether all characters of the given string are contained in this alphabet.
 java.lang.Character[] toArray()
          Returns the symbol set of this alphabet as Character-array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleAlphabet

public SimpleAlphabet(java.lang.Character[] symbols)
Creates a alphabet for the given symbols. The given array must not contain null values and must contain two or more unique characters.

Parameters:
symbols - the symbols as character array
Throws:
java.lang.NullPointerException - if the given array or any object within the array is null.
java.lang.IllegalArgumentException - if the given alphabet is invalid.
Method Detail

getSymbols

public java.util.Iterator getSymbols()
Returns the symbols contained in this alphabet as iterator. The iterator will return java.lang.Character objects. The returned result set is not guaranteed to be sorted.

Specified by:
getSymbols in interface Alphabet
Returns:
the symbols as iterator.

isEmpty

public boolean isEmpty()
Checks, whether the alphabet is empty. An alphabet is considered empty, if the number of symbols within the alphabet is less or equal to one.

Specified by:
isEmpty in interface Alphabet
Returns:
always false, as it is not possible to construct an empty SimpleAlphabet.

toArray

public java.lang.Character[] toArray()
Returns the symbol set of this alphabet as Character-array.

Specified by:
toArray in interface Alphabet
Returns:
the symbol set as character array.

contains

public boolean contains(java.lang.Character c)
Checks, whether the given character is contained in this alphabet.

Specified by:
contains in interface Alphabet
Parameters:
c - the character, which should be tested.
Returns:
true, if the characters is a member of this alphabet, false otherwise.
Throws:
java.lang.NullPointerException - if the given character is null.

isValid

public boolean isValid(java.lang.String s)
Tests, whether all characters of the given string are contained in this alphabet.

Specified by:
isValid in interface Alphabet
Parameters:
s - the string, which should be tested
Returns:
true, if the string is valid within this alphabet, false otherwise

getImmutableInstance

public Alphabet getImmutableInstance()
Returns an immutable instance of this alphabet. The returned instance will no longer be affected by any operation on this alphabet.

Specified by:
getImmutableInstance in interface Alphabet
Returns:
the immutable alphabet