/*
* 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: ZeroOrMore.java,v 1.7 2004/01/07 08:28:49 benedikta Exp $
*/
public class ZeroOrMore extends PatternList
{
public ZeroOrMore() {}
public boolean isNullable()
{
return true;
}
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
{
ZeroOrMore clone = new ZeroOrMore();
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;
}
}