de.fhdarmstadt.fbi.dtree.model
Class MutableAlphabet

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

public class MutableAlphabet
extends java.lang.Object
implements Alphabet

An editable alphabet implementation. The contents of this alphabet can be modified.


Constructor Summary
MutableAlphabet()
          Creates a new, initially empty alphabet.
 
Method Summary
 boolean addCharacter(java.lang.Character c)
          Adds the specified character to this alphabet if it is not already present.
 void clear()
          Removes all elements from this alphabet.
 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.
 boolean removeCharacter(java.lang.Character c)
          Removes the specified character from this alphabet if it is contained in this alphabet.
 java.lang.Character[] toArray()
          Converts the given character to an array of java.lang.Character objects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MutableAlphabet

public MutableAlphabet()
Creates a new, initially empty alphabet.

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 resultset is sorted.

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

addCharacter

public boolean addCharacter(java.lang.Character c)
Adds the specified character to this alphabet if it is not already present.

Parameters:
c - element to be added to this alphabet.
Returns:
true if the alphabet did not already contain the specified character.
Throws:
java.lang.NullPointerException - if the given character is null.

removeCharacter

public boolean removeCharacter(java.lang.Character c)
Removes the specified character from this alphabet if it is contained in this alphabet.

Parameters:
c - element to be removed from this alphabet.
Returns:
true if the alphabet contained the specified character, false otherwise
Throws:
java.lang.NullPointerException - if the given character is null.

toArray

public java.lang.Character[] toArray()
Converts the given character to an array of java.lang.Character objects.

Specified by:
toArray in interface Alphabet
Returns:
the array containing all symbols of this alphabet.

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:
true, if the alphabet is empty, false otherwise.

clear

public void clear()
Removes all elements from this alphabet.


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