/*
* 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.pattern;
import net.sourceforge.chaperon.common.Decoder;
import net.sourceforge.chaperon.model.Violations;
/**
* This represents a set of characters within a character class.
*
* @author <a href="mailto:stephan@apache.org">Stephan Michels</a>
* @version CVS $Id: CharacterSet.java,v 1.6 2003/12/09 19:55:52 benedikta Exp $
*/
public class CharacterSet implements CharacterClassElement
{
private String set = "";
private String location = null;
/**
* Creates set of characters.
*/
public CharacterSet() {}
/**
* Set the set of characters.
*
* @param set Set of characters.
*/
public void setCharacters(String set)
{
this.set = set;
}
/**
* Returns the to comparing characters
*
* @return To comparing characters
*/
public String getCharacters()
{
return set;
}
/**
* 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;
}
/**
* Return a string representation of this pattern
*
* @return String representation of the pattern.
*/
public String toString()
{
return Decoder.decode(set, Decoder.CLASS);
}
/**
* Create a clone of this pattern.
*
* @return Clone of this pattern.
*
* @throws CloneNotSupportedException If an exception occurs during the cloning.
*/
public Object clone()
{
CharacterSet clone = new CharacterSet();
clone.setCharacters(getCharacters());
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 ((set==null) || (set.length()==0))
violations.addViolation("Character set contains no characters", getLocation());
return violations;
}
}