FileDocCategorySizeDatePackage
Compare.javaAPI DocApache Ant 1.704884Wed Dec 13 06:16:20 GMT 2006org.apache.tools.ant.types.resources.selectors

Compare

public class Compare extends org.apache.tools.ant.types.DataType implements ResourceSelector
ResourceSelector that compares against "control" Resource(s) using ResourceComparators.
since
Ant 1.7

Fields Summary
private static final String
ONE_CONTROL_MESSAGE
private org.apache.tools.ant.types.resources.comparators.DelegatedResourceComparator
comp
private org.apache.tools.ant.types.Quantifier
against
private org.apache.tools.ant.types.Comparison
when
private org.apache.tools.ant.types.resources.Union
control
Constructors Summary
Methods Summary
public synchronized voidadd(org.apache.tools.ant.types.resources.comparators.ResourceComparator c)
Add a ResourceComparator to this Compare selector. If multiple ResourceComparators are added, they will be processed in LIFO order.

param
c the ResourceComparator to add.


                                  
         
        if (isReference()) {
            throw noChildrenAllowed();
        }
        comp.add(c);
    
public synchronized org.apache.tools.ant.types.ResourceCollectioncreateControl()
Create the nested control element. These are the resources to compare against.

return
ResourceCollection.

        if (isReference()) {
            throw noChildrenAllowed();
        }
        if (control != null) {
            throw oneControl();
        }
        control = new Union();
        return control;
    
protected synchronized voiddieOnCircularReference(java.util.Stack stk, org.apache.tools.ant.Project p)
Overrides the version from DataType to recurse on nested ResourceComparators.

param
stk the stack of data types to use (recursively).
param
p the project to use to dereference the references.
throws
BuildException on error.

        if (isChecked()) {
            return;
        }
        if (isReference()) {
            super.dieOnCircularReference(stk, p);
        } else {
            if (control != null) {
                DataType.invokeCircularReferenceCheck(control, stk, p);
            }
            DataType.invokeCircularReferenceCheck(comp, stk, p);
            setChecked(true);
        }
    
public synchronized booleanisSelected(org.apache.tools.ant.types.Resource r)
{@inheritDoc}

        if (isReference()) {
            return ((ResourceSelector) getCheckedRef()).isSelected(r);
        }
        if (control == null) {
            throw oneControl();
        }
        int t = 0, f = 0;
        for (Iterator it = control.iterator(); it.hasNext();) {
            if (when.evaluate(comp.compare(r, (Resource) it.next()))) {
                t++;
            } else {
                f++;
            }
        }
        return against.evaluate(t, f);
    
private org.apache.tools.ant.BuildExceptiononeControl()

        return new BuildException(super.toString() + ONE_CONTROL_MESSAGE);
    
public synchronized voidsetAgainst(org.apache.tools.ant.types.Quantifier against)
Set the quantifier to be used. Default "all".

param
against the Quantifier EnumeratedAttribute to use.

        if (isReference()) {
            throw tooManyAttributes();
        }
        this.against = against;
    
public synchronized voidsetWhen(org.apache.tools.ant.types.Comparison when)
Set the comparison to be used. Default "equal".

param
when the Comparison EnumeratedAttribute to use.

        if (isReference()) {
            throw tooManyAttributes();
        }
        this.when = when;