FileDocCategorySizeDatePackage
ResourceCount.javaAPI DocApache Ant 1.703943Wed Dec 13 06:16:20 GMT 2006org.apache.tools.ant.taskdefs

ResourceCount

public class ResourceCount extends org.apache.tools.ant.Task implements org.apache.tools.ant.taskdefs.condition.Condition
Count resources from a ResourceCollection, storing to a property or writing to the log. Can also be used as a Condition.
since
Ant 1.7

Fields Summary
private static final String
ONE_NESTED_MESSAGE
private static final String
COUNT_REQUIRED
private org.apache.tools.ant.types.ResourceCollection
rc
private org.apache.tools.ant.types.Comparison
when
private Integer
count
private String
property
Constructors Summary
Methods Summary
public voidadd(org.apache.tools.ant.types.ResourceCollection r)
Add the ResourceCollection to count.

param
r the ResourceCollection to count.
throws
BuildException if already set.


                         
        
        if (rc != null) {
            throw new BuildException(ONE_NESTED_MESSAGE);
        }
        rc = r;
    
public booleaneval()
Fulfill the condition contract.

return
true if the specified ResourceCollection satisfies the set criteria.
throws
BuildException if an error occurs.

        if (rc == null) {
            throw new BuildException(ONE_NESTED_MESSAGE);
        }
        if (count == null) {
            throw new BuildException(COUNT_REQUIRED);
        }
        return when.evaluate(new Integer(rc.size()).compareTo(count));
    
public voidexecute()
Execute as a Task.

        if (rc == null) {
            throw new BuildException(ONE_NESTED_MESSAGE);
        }
        if (property == null) {
            log("resource count = " + rc.size());
        } else {
            getProject().setNewProperty(property, Integer.toString(rc.size()));
        }
    
public voidsetCount(int c)
Set the target count number for use as a Condition.

param
c number of Resources as int.

        count = new Integer(c);
    
public voidsetProperty(java.lang.String p)
Set the name of the property to set in task mode.

param
p the property name to set.

        property = p;
    
public voidsetRefid(org.apache.tools.ant.types.Reference r)
Set the ResourceCollection reference.

param
r the Reference.

        Object o = r.getReferencedObject();
        if (!(o instanceof ResourceCollection)) {
            throw new BuildException(r.getRefId()
                + " doesn\'t denote a ResourceCollection");
        }
        add((ResourceCollection) o);
    
public voidsetWhen(org.apache.tools.ant.types.Comparison c)
Set the comparison for use as a Condition.

param
c Comparison (an EnumeratedAttribute) When.
see
org.apache.tools.ant.types.Comparison

        when = c;