package com.horstmann.labrat;


import java.util.regex.Pattern;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.taskdefs.condition.Condition;

public class MatchRegexCondition implements Condition {
    private String value;
    private String regex;

    // The setter for the "value" attribute
    public void setValue(String value) {
        this.value = value;
    }
    
    public void setRegex(String regex)
    {
       this.regex = regex;
    }
    

    // This method evaluates the condition
    public boolean eval() {
        if (value == null) {
            throw new BuildException("value attribute is not set");
        }
        if (regex == null) {
           throw new BuildException("regex attribute is not set");
        }        
        return Pattern.matches(regex, value);
   }
}

