FileDocCategorySizeDatePackage
TimeComparison.javaAPI DocApache Ant 1.704064Wed Dec 13 06:16:24 GMT 2006org.apache.tools.ant.types

TimeComparison

public class TimeComparison extends EnumeratedAttribute
EnumeratedAttribute for time comparisons. Accepts values "before", "after", "equal".
since
Ant 1.7

Fields Summary
private static final String[]
VALUES
private static final org.apache.tools.ant.util.FileUtils
FILE_UTILS
public static final TimeComparison
BEFORE
Before Comparison.
public static final TimeComparison
AFTER
After Comparison.
public static final TimeComparison
EQUAL
Equal Comparison.
Constructors Summary
public TimeComparison()
Default constructor.


           
      
    
public TimeComparison(String value)
Construct a new TimeComparison with the specified value.

param
value the EnumeratedAttribute value.

        setValue(value);
    
Methods Summary
public static intcompare(long t1, long t2)
Compare two times.

param
t1 the first time to compare.
param
t2 the second time to compare.
return
a negative integer, a positive integer, or zero as t1 is before, after, or equal to t2 accounting for the default granularity.

        return compare(t1, t2, FILE_UTILS.getFileTimestampGranularity());
    
public static intcompare(long t1, long t2, long g)
Compare two times.

param
t1 the first time to compare.
param
t2 the second time to compare.
param
g the timestamp granularity.
return
a negative integer, a positive integer, or zero as t1 is before, after, or equal to t2 accounting for the specified granularity.

        long diff = t1 - t2;
        long abs = Math.abs(diff);
        return abs > Math.abs(g) ? (int) (diff / abs) : 0;
    
public booleanevaluate(long t1, long t2)
Evaluate two times against this TimeComparison.

param
t1 the first time to compare.
param
t2 the second time to compare.
return
true if the comparison result fell within the parameters of this TimeComparison.

        return evaluate(t1, t2, FILE_UTILS.getFileTimestampGranularity());
    
public booleanevaluate(long t1, long t2, long g)
Evaluate two times against this TimeComparison.

param
t1 the first time to compare.
param
t2 the second time to compare.
param
g the timestamp granularity.
return
true if the comparison result fell within the parameters of this TimeComparison.

        int cmp = getIndex();
        if (cmp == -1) {
            throw new BuildException("TimeComparison value not set.");
        }
        if (cmp == 0) {
            return t1 - g < t2;
        }
        if (cmp == 1) {
            return t1 + g > t2;
        }
        return Math.abs(t1 - t2) <= g;
    
public java.lang.String[]getValues()
Return the possible values.

return
String[] of EnumeratedAttribute values.

        return VALUES;