Package net.sourceforge.chaperon.model.lexicon

Source Code of net.sourceforge.chaperon.model.lexicon.Lexicon

/*
*  Copyright (C) Chaperon. All rights reserved.
*  -------------------------------------------------------------------------
*  This software is published under the terms of the Apache Software License
*  version 1.1, a copy of which has been included  with this distribution in
*  the LICENSE file.
*/

package net.sourceforge.chaperon.model.lexicon;

import net.sourceforge.chaperon.model.Violations;

import java.util.Enumeration;
import java.util.Vector;

/**
* The lexicon represents a collection of lexemes.
*
* @author <a href="mailto:stephan@apache.org">Stephan Michels </a>
* @version CVS $Id: Lexicon.java,v 1.3 2003/12/09 19:55:52 benedikta Exp $
*/
public class Lexicon
{
  private Vector lexemes = new Vector();
  private String location = null;

  /**
   * Add a lexeme to this lexicon.
   *
   * @param lexeme Lexeme, which should be added.
   */
  public void addLexeme(Lexeme lexeme)
  {
    lexemes.addElement(lexeme);
  }

  /**
   * Remove a lexeme from this lexicon.
   *
   * @param lexeme Lexeme, which should be removed.
   */
  public void removeLexeme(Lexeme lexeme)
  {
    lexemes.removeElement(lexeme);
  }

  /**
   * Return a lexeme given by an index.
   *
   * @param index Index of the lexeme.
   *
   * @return Lexeme.
   */
  public Lexeme getLexeme(int index)
  {
    return (Lexeme)lexemes.elementAt(index);
  }

  /**
   * Return the count of lexemes in this lexicon.
   *
   * @return Count of lexemes.
   */
  public int getLexemeCount()
  {
    return lexemes.size();
  }

  /**
   * Set the location from the input source.
   *
   * @param location Location in the input source.
   */
  public void setLocation(String location)
  {
    this.location = location;
  }

  /**
   * Returns the location from the input source.
   *
   * @return Location in the input source.
   */
  public String getLocation()
  {
    return location;
  }

  /**
   * Validates the lexicon.
   *
   * @return Return a list of violations, if this object isn't valid.
   */
  public Violations validate()
  {
    Violations violations = new Violations();

    if (lexemes.size()==0)
      violations.addViolation("Lexicon contains not lexemes", location);

    for (Enumeration en = lexemes.elements(); en.hasMoreElements();)
      violations.addViolations(((Lexeme)en.nextElement()).validate());

    return violations;
  }

  /**
   * Create a clone of this lexicon.
   *
   * @return Clone of this lexicon.
   *
   * @throws CloneNotSupportedException If an exception occurs during the cloning.
   */
  public Object clone() throws CloneNotSupportedException
  {
    Lexicon clone = new Lexicon();

    for (int i = 0; i<lexemes.size(); i++)
      clone.lexemes.addElement(((Lexeme)lexemes.elementAt(i)).clone());

    clone.location = location;

    return clone;
  }
}
TOP

Related Classes of net.sourceforge.chaperon.model.lexicon.Lexicon

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.