laser.regularlanguage.regularexpression
Class RE<L extends LabelInterface>

java.lang.Object
  extended by laser.regularlanguage.regularexpression.RE<L>
Type Parameters:
L - The type of Label associated with this RE.
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, ArtifactInterface, Persistent, Visualizable

public class RE<L extends LabelInterface>
extends java.lang.Object
implements ArtifactInterface, java.lang.Cloneable

An RE represents a regular expresssion (RE).

Author:
Jamieson M. Cobleigh (laser-software@cs.umass.edu)
See Also:
Serialized Form

Field Summary
static java.lang.String LS
          The platform specific line separator
 
Fields inherited from interface laser.util.Persistent
PER_EXTENSION, READ_PERSISTENT_METHOD_NAME
 
Constructor Summary
protected RE(REFactory<L> reFactory, AlphabetInterface<L> alphabet, TreeNode<L> re)
          Creates a new RE PRECONDITION: The regular expression must use only labels in the given alphabet.
 
Method Summary
 java.util.List<java.lang.String> checkWellFormed()
          Checks if this RE is well-formed.
 RE<L> clone()
          Returns a clone of this RE.
 AlphabetInterface<L> getAlphabet()
          Gets the alphabet.
 java.lang.StringBuffer getDescription()
          Gets the natural language (NL) description.
 REFactory<L> getFactory()
          Gets the REFactory that creates RE of this type.
 java.lang.String getName()
          Gets the String name of this RE.
 TreeNode<L> getRegularExpression()
          Gets the regular expression.
 java.util.Set<TreeNode<L>> getUniqueTerms()
          Returns the Set of unique terms in this RE.
 java.lang.String getVisExtension()
          Gets the file extension that will be used for the visual form of this object.
 boolean isExtendedRE()
          Returns true if this RE is extended and false if it is basic.
static RE readPersistent(java.io.InputStream in)
          Reads the object that was saved by writePersistent from the given InputStream.
static RE readPersistent(java.lang.String filename)
          Reads the object that was saved by writePersistent from the given file.
 void setDescription(java.lang.StringBuffer description)
          Sets the natural language (NL) description.
 void setName(java.lang.String name)
          Sets the String name of this RE.
 java.lang.String toString()
          Returns a String representation of this RE.
 void visualize(java.lang.String filename)
          Outputs the visual form of this object to the given file.
 void visualize(java.io.Writer out)
          Outputs the visual form of this object to the given Writer.
 void writePersistent(java.io.OutputStream out)
          Takes this object and outputs the persistent form of it to the given OutputStream.
 void writePersistent(java.lang.String filename)
          Takes this object and outputs the persistent form of it to the given file.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LS

public static final java.lang.String LS
The platform specific line separator

Constructor Detail

RE

protected RE(REFactory<L> reFactory,
             AlphabetInterface<L> alphabet,
             TreeNode<L> re)
Creates a new RE PRECONDITION: The regular expression must use only labels in the given alphabet.

Parameters:
reFactory - The REFactory that created this RE (non-null)
alphabet - the alphabet (non-null)
re - the regular expression (non-null)
Method Detail

getFactory

public REFactory<L> getFactory()
Gets the REFactory that creates RE of this type.

Returns:
The appropriate REFactory

checkWellFormed

public java.util.List<java.lang.String> checkWellFormed()
Checks if this RE is well-formed. Returns any well-formedness violations if they exist and null otherwise.

Returns:
Any well-formedness violations if they exist and null otherwise

getName

public java.lang.String getName()
Gets the String name of this RE.

NOTE: The name is optional.

Returns:
The String name

setName

public void setName(java.lang.String name)
Sets the String name of this RE.

NOTE: The name is optional.

Parameters:
name - The new String name

getDescription

public java.lang.StringBuffer getDescription()
Gets the natural language (NL) description.

NOTE: The description is optional.

Returns:
The NL description

setDescription

public void setDescription(java.lang.StringBuffer description)
Sets the natural language (NL) description.

NOTE: The description is optional.

Parameters:
description - The new NL description

getAlphabet

public AlphabetInterface<L> getAlphabet()
Gets the alphabet.

NOTE: The alphabet is required.

Returns:
the alphabet

getRegularExpression

public TreeNode<L> getRegularExpression()
Gets the regular expression.

NOTE: The regular expression is required.

Returns:
the regular expression

getUniqueTerms

public java.util.Set<TreeNode<L>> getUniqueTerms()
Returns the Set of unique terms in this RE.

Returns:
The Set of unique terms

isExtendedRE

public boolean isExtendedRE()
Returns true if this RE is extended and false if it is basic.

Returns:
True if extended and false if basic

getVisExtension

public java.lang.String getVisExtension()
Gets the file extension that will be used for the visual form of this object.

Specified by:
getVisExtension in interface Visualizable
Returns:
The visual file extension

visualize

public void visualize(java.lang.String filename)
               throws java.io.IOException,
                      VisualizableException
Outputs the visual form of this object to the given file.

Specified by:
visualize in interface Visualizable
Parameters:
filename - The file to output the visual form to
Throws:
java.io.IOException - an IO error during the write
VisualizableException - an error occured while creating the visual form of the artifact

visualize

public void visualize(java.io.Writer out)
               throws java.io.IOException,
                      VisualizableException
Outputs the visual form of this object to the given Writer.

Specified by:
visualize in interface Visualizable
Parameters:
out - a Writer to output the visual form to
Throws:
java.io.IOException - an IO error during the write
VisualizableException - an error occured while creating the visual form of the artifact

readPersistent

public static RE readPersistent(java.lang.String filename)
                         throws java.io.IOException,
                                PersistentException
Reads the object that was saved by writePersistent from the given file.

Parameters:
filename - The name of the file to use (non-null)
Throws:
java.io.IOException - if an I/O error occurs
PersistentException - if there is a problem with the persistent process

readPersistent

public static RE readPersistent(java.io.InputStream in)
                         throws java.io.IOException,
                                PersistentException
Reads the object that was saved by writePersistent from the given InputStream.

Parameters:
in - The InputStream to use (non-null)
Throws:
java.io.IOException - if an I/O error occurs
PersistentException - if there is a problem with the persistent process

writePersistent

public void writePersistent(java.lang.String filename)
                     throws java.io.IOException,
                            PersistentException
Takes this object and outputs the persistent form of it to the given file.

Specified by:
writePersistent in interface Persistent
Parameters:
filename - The name of the file to use (non-null)
Throws:
java.io.IOException - if an I/O error occurs
PersistentException - if there is a problem with the persistent process

writePersistent

public void writePersistent(java.io.OutputStream out)
                     throws java.io.IOException,
                            PersistentException
Takes this object and outputs the persistent form of it to the given OutputStream.

Specified by:
writePersistent in interface Persistent
Parameters:
out - The OutputStream to use (non-null)
Throws:
java.io.IOException - if an I/O error occurs
PersistentException - if there is a problem with the persistence process

clone

public RE<L> clone()
Returns a clone of this RE.

Overrides:
clone in class java.lang.Object
Returns:
A clone of this Object

toString

public java.lang.String toString()
Returns a String representation of this RE.

Overrides:
toString in class java.lang.Object
Returns:
A String representation of this Object