/*
* 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: Optional.java,v 1.1 2003/12/12 14:11:34 benedikta Exp $
*/
public class Optional extends PatternList
{
public Optional() {}
public boolean isNullable()
{
return true;
}
/**
* 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
{
Optional clone = new Optional();
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;
}
}