1 18 package org.apache.tools.ant.types; 19 20 import java.util.Arrays ; 21 22 import org.apache.tools.ant.BuildException; 23 24 31 public class Comparison extends EnumeratedAttribute { 32 private static final String [] VALUES 33 = new String [] {"equal", "greater", "less", 34 "ne", "ge", "le", "eq", "gt", "lt", "more"}; 35 36 37 public static final Comparison EQUAL = new Comparison("equal"); 38 39 40 public static final Comparison NOT_EQUAL = new Comparison("ne"); 41 42 43 public static final Comparison GREATER = new Comparison("greater"); 44 45 46 public static final Comparison LESS = new Comparison("less"); 47 48 49 public static final Comparison GREATER_EQUAL = new Comparison("ge"); 50 51 52 public static final Comparison LESS_EQUAL = new Comparison("le"); 53 54 private static final int[] EQUAL_INDEX = {0, 4, 5, 6}; 55 private static final int[] LESS_INDEX = {2, 3, 5, 8}; 56 private static final int[] GREATER_INDEX = {1, 3, 4, 7, 9}; 57 58 61 public Comparison() { 62 } 63 64 68 public Comparison(String value) { 69 setValue(value); 70 } 71 72 76 public String [] getValues() { 77 return VALUES; 78 } 79 80 85 public boolean evaluate(int comparisonResult) { 86 if (getIndex() == -1) { 87 throw new BuildException("Comparison value not set."); 88 } 89 int[] i = comparisonResult < 0 ? LESS_INDEX 90 : comparisonResult > 0 ? GREATER_INDEX : EQUAL_INDEX; 91 return Arrays.binarySearch(i, getIndex()) >= 0; 92 } 93 94 } 95 96 | Popular Tags |