Package net.sourceforge.chaperon.model.extended

Source Code of net.sourceforge.chaperon.model.extended.OneOrMore

/*
*  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.extended;

import net.sourceforge.chaperon.model.Violations;

/**
* @author <a href="mailto:stephan@apache.org">Stephan Michels</a>
* @version CVS $Id: OneOrMore.java,v 1.5 2004/01/07 08:28:49 benedikta Exp $
*/
public class OneOrMore extends PatternList
{
  public OneOrMore() {}

  public void update()
  {
    super.update();

    PatternSet firstSet = getFirstSet();
    for (PatternIterator i = getLastSet().getPattern(); i.hasNext();)
    {
      Pattern lastPattern = i.next();
      for (PatternIterator j = firstSet.getPattern(); j.hasNext();)
      {
        Pattern firstPattern = j.next();
        lastPattern.addSuccessor(firstPattern);
      }
    }
  }

  /**
   * Return a string representation of this pattern
   *
   * @return String representation of the pattern.
   */
  public String toString()
  {
    StringBuffer buffer = new StringBuffer();

    if (getPatternCount()>0)
    {
      buffer.append(super.toString());
      buffer.append("+");
    }

    return buffer.toString();
  }

  public String toString(PatternSet previous, PatternSet next)
  {
    StringBuffer buffer = new StringBuffer();

    if (getPatternCount()>0)
    {
      buffer.append(super.toString(previous, next));
      buffer.append("+");
    }

    return buffer.toString();
  }

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

    for (int i = 0; i<getPatternCount(); i++)
      clone.addPattern((Pattern)getPattern(i).clone());

    return clone;
  }

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

    /*if (pattern==null)
      violations.addViolation("Multiplier contains no pattern",
                              getLocation());*/
    for (int i = 0; i<getPatternCount(); i++)
      violations.addViolations(getPattern(i).validate());

    return violations;
  }
}
TOP

Related Classes of net.sourceforge.chaperon.model.extended.OneOrMore

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.