de.fhdarmstadt.fbi.dtree.model
Class SimplePattern

java.lang.Object
  extended byde.fhdarmstadt.fbi.dtree.model.SimplePattern
All Implemented Interfaces:
java.lang.Cloneable, RegularPattern

public class SimplePattern
extends java.lang.Object
implements RegularPattern, java.lang.Cloneable

The SimplePattern class allows the construction of patterns in the form:

Pattern := (Const)Var[Pattern]*
Var := "(.*)"
Const := Possibly empty sequence of characters

Every pattern starts with a constant expression followed by one or more sequences of alternating variables and constants. Every pattern ends with an constant expression.

Constants can be empty strings.

Patterns are specified by defining the constant elements. Therefore, to define a pattern in the form "AxBxC" where A, B, C are constants and every x denotes a variable, one would write:

SimplePattern p = new SimplePattern(Classification.POSITIVE); p.add ("A"); p.add ("B"); p.add ("C"); and the resulting regular pattern in Perl syntax would be: (A).*(B).*(C).


Constructor Summary
SimplePattern(Classification classification)
          Creates an initially empty pattern with the given classification.
 
Method Summary
 void add(java.lang.String constant)
          Adds another constant element to the pattern.
 java.lang.Object clone()
          Clones this pattern.
 Classification getClassification()
          Returns this pattern's classification.
 java.lang.String getConstant(int i)
          Returns the n-th constant element in the pattern.
 java.lang.String getPattern()
          Returns a regular pattern in Perl syntax.
 int size()
          Returns the size of constant elements.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface de.fhdarmstadt.fbi.dtree.model.RegularPattern
equals
 

Constructor Detail

SimplePattern

public SimplePattern(Classification classification)
Creates an initially empty pattern with the given classification.

Parameters:
classification - the classification, never null.
Throws:
java.lang.NullPointerException - if the given classification is null.
Method Detail

add

public void add(java.lang.String constant)
Adds another constant element to the pattern. If the pattern was empty, then this constant will define the new pattern. If there were already other patterns defined, an implicit variable element is added before this constant.

Parameters:
constant - the new constant, never null

size

public int size()
Returns the size of constant elements.

Returns:
the number of constants in this pattern.

getConstant

public java.lang.String getConstant(int i)
Returns the n-th constant element in the pattern.

Parameters:
i - the index of the constant.
Returns:
the constant, never null.
Throws:
java.lang.IndexOutOfBoundsException - if the given index is negative or greater or equal to size().

getPattern

public java.lang.String getPattern()
Returns a regular pattern in Perl syntax. If the pattern is empty, then an empty perl pattern is returned.

Specified by:
getPattern in interface RegularPattern
Returns:
the pattern as string.
See Also:
Pattern

clone

public java.lang.Object clone()
Clones this pattern.

Returns:
a clone of this pattern.

getClassification

public Classification getClassification()
Returns this pattern's classification.

Specified by:
getClassification in interface RegularPattern
Returns:
the classification, never null.