standup.lexicon
Class CustomLexicon

java.lang.Object
  extended by standup.lexicon.LexemeSet
      extended by standup.lexicon.CustomLexicon
All Implemented Interfaces:
XMLizable, XMLsaveable
Direct Known Subclasses:
Topic

public class CustomLexicon
extends LexemeSet
implements XMLsaveable

A CustomLexicon is a LexemeSet that has a label and is XMLsaveable. The accessor functions of adding and removing Lexemes also update modified, a boolean field which can be used to determine whether this CustomLexicon is consistent with its XML copy on disk. Also has a boolean field active which indicates whether or not it is active within its containing LexicalComponents.

Author:
Ruli Manurung

Field Summary
(package private)  boolean active
          Signifies whether this custom lexicon is currently activated in the working lexicon.
protected  String label
          An identifier for this CustomLexicon.
private  boolean modified
          Signifies whether this custom lexicon has been changed with respect to the local copy on disk.
 
Fields inherited from class standup.lexicon.LexemeSet
set
 
Constructor Summary
CustomLexicon(Element doc)
          Constructor method for loading an existing CustomLexicon from the given XML Element.
CustomLexicon(File file)
          Constructor method for loading an existing CustomLexicon from the given File.
CustomLexicon(String l)
          Constructor method for the creation of a new, empty, CustomLexicon.
CustomLexicon(String l, Collection<Lexeme> lexemes)
          Constructor method for the creation of an existing collection of Lexemes, e.g.
CustomLexicon(URL url)
          Constructor method for loading an existing CustomLexicon from the file pointed to by the given URL.
 
Method Summary
 boolean add(Lexeme l)
          Tries to add the given Lexeme to this CustomLexicon.
 boolean add(LexemeSet ls)
          Tries to add the Lexemes contained within the given LexemeSet to this CustomLexicon, effectively making this CustomLexicon the union of the two.
 CustomLexicon duplicate()
          Returns a duplicate of this CustomLexicon.
 boolean equals(Object obj)
           
 String getLabel()
          Returns the label of this CustomLexicon.
 int hashCode()
           
 boolean isActive()
          Returns true if this CustomLexicon is to be considered active within a {@link LexicalComponents}, {@code false} otherwise.
 boolean isModified()
          Returns true if this CustomLexicon has been modified since the last time it was loaded from/saved to disk, false otherwise.
 boolean remove(Lexeme l)
          Tries to remove the given Lexeme from this CustomLexicon.
 boolean remove(LexemeSet ls)
          Tries to remove the Lexemes contained within the given LexemeSet from this CustomLexicon.
 Lexeme removeRandom()
          Tries to remove a random Lexeme from this CustomLexicon and return it.
 void rename(String newLabel)
          Renames the label of this CustomLexicon.
 void save(File file)
          Implementation of {@link XMLsaveable#save(File).
 boolean setActive(boolean newValue)
          Sets the value to be returned by isActive().
 void setModified(boolean mod)
          Sets the value to be returned by isModified().
 String toString()
           
 void writeXML(Writer out, String indent)
          Implementation of XMLizable.writeXML(Writer, String).
 
Methods inherited from class standup.lexicon.LexemeSet
addLexemesFromXML, contains, getLexemeCount, getLexemes, getLexemesIterator, getRandom, getSpelledClusters, getSpelledLexemes, getSpelledLexemes, isEmpty
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

modified

private boolean modified
Signifies whether this custom lexicon has been changed with respect to the local copy on disk.


label

protected String label
An identifier for this CustomLexicon. It must be unique within its containing LexicalComponents. Note that this label is saved to disk, so there are potential naming conflicts when CustomLexicons are loaded and saved to/from different LexicalComponents.


active

boolean active
Signifies whether this custom lexicon is currently activated in the working lexicon.

Constructor Detail

CustomLexicon

public CustomLexicon(String l)
Constructor method for the creation of a new, empty, CustomLexicon. Sets both modified and active to true.

Parameters:
l - the label for the newly created CustomLexicon

CustomLexicon

public CustomLexicon(String l,
                     Collection<Lexeme> lexemes)
Constructor method for the creation of an existing collection of Lexemes, e.g. by reading it from disk. Sets both modified and active to true.

Parameters:
l - the label for the newly created CustomLexicon
lexemes - a Collection of Lexemes to be added to the newly created CustomLexicon

CustomLexicon

public CustomLexicon(URL url)
Constructor method for loading an existing CustomLexicon from the file pointed to by the given URL. Sets modified of the resulting instance to false and active to true.

Parameters:
url -

CustomLexicon

public CustomLexicon(File file)
Constructor method for loading an existing CustomLexicon from the given File. Sets modified of the resulting instance to false and active to true.

Parameters:
file -

CustomLexicon

public CustomLexicon(Element doc)
Constructor method for loading an existing CustomLexicon from the given XML Element. Sets modified of the resulting instance to false and active to true.

Parameters:
doc - the XML Element containing the CustomLexicon details. It should have been the output of writeXML(Writer, String).
Method Detail

hashCode

public int hashCode()
Overrides:
hashCode in class LexemeSet

equals

public boolean equals(Object obj)
Overrides:
equals in class LexemeSet

toString

public String toString()
Overrides:
toString in class LexemeSet

duplicate

public CustomLexicon duplicate()
Returns a duplicate of this CustomLexicon. Sets modified of the returned CustomLexicon to true.

Overrides:
duplicate in class LexemeSet
Returns:

add

public boolean add(Lexeme l)
Tries to add the given Lexeme to this CustomLexicon. Additionally, if this CustomLexicon changed as a result of the addition, sets modified to true.

Overrides:
add in class LexemeSet
Parameters:
l - the Lexeme to be added to this object
Returns:
true if this object changed as a result, or false if the Lexeme already exists in this object

add

public boolean add(LexemeSet ls)
Tries to add the Lexemes contained within the given LexemeSet to this CustomLexicon, effectively making this CustomLexicon the union of the two. Additionally, if this CustomLexicon changed as a result of the addition, sets modified to true.

Overrides:
add in class LexemeSet
Parameters:
ls - the LexemeSet to be added to this object
Returns:
true if this object changed as a result, or false if all the Lexemes in the given LexemeSet already exist in this object

remove

public boolean remove(Lexeme l)
Tries to remove the given Lexeme from this CustomLexicon. Additionally, if this CustomLexicon changed as a result of the removal, sets modified to true.

Overrides:
remove in class LexemeSet
Parameters:
l - the Lexeme to be removed from this object
Returns:
true if this object changed as a result, or false if the Lexeme did not previously exist in this object

remove

public boolean remove(LexemeSet ls)
Tries to remove the Lexemes contained within the given LexemeSet from this CustomLexicon. Additionally, if this CustomLexicon changed as a result of the removal, sets modified to true.

Overrides:
remove in class LexemeSet
Parameters:
ls - the LexemeSet to be removed from this object
Returns:
true if this object changed as a result, or false if all the Lexemes in the given LexemeSet did not previously exist in this object

removeRandom

public Lexeme removeRandom()
Tries to remove a random Lexeme from this CustomLexicon and return it. Additionally, if this CustomLexicon changed as a result, sets modified to true.

Overrides:
removeRandom in class LexemeSet
Returns:
the randomly removed Lexeme

isModified

public boolean isModified()
Returns true if this CustomLexicon has been modified since the last time it was loaded from/saved to disk, false otherwise.

Returns:

setModified

public void setModified(boolean mod)
Sets the value to be returned by isModified().

Parameters:
mod - the new value of modified

getLabel

public String getLabel()
Returns the label of this CustomLexicon.

Returns:

rename

public void rename(String newLabel)
Renames the label of this CustomLexicon.

Parameters:
newLabel - the new label for this CustomLexicon

isActive

public boolean isActive()
Returns true if this CustomLexicon is to be considered active within a {@link LexicalComponents}, {@code false} otherwise.

Returns:

setActive

public boolean setActive(boolean newValue)
Sets the value to be returned by isActive().

Parameters:
newValue - the new value of active
Returns:
the previous value of active

writeXML

public void writeXML(Writer out,
                     String indent)
              throws IOException,
                     XMLException
Implementation of XMLizable.writeXML(Writer, String).

Specified by:
writeXML in interface XMLizable
Overrides:
writeXML in class LexemeSet
Parameters:
out - The output stream for the XML file, which is assumed to be already opened and writable.
indent - A string to be prepended before every line written by this method. If passed appropriate white space, e.g. XMLUtils.xmlIndent, it can be used to control indentation.
Throws:
IOException
XMLException

save

public void save(File file)
Implementation of {@link XMLsaveable#save(File).

Specified by:
save in interface XMLsaveable
Parameters:
file - the file where this CustomLexicon is to be saved