source: release-kits/lirk3/ant-scripts/tasks/orans/old/IsAfter.java@ 14982

Last change on this file since 14982 was 14982, checked in by oranfry, 16 years ago

initial import of LiRK3

File size: 1.5 KB
Line 
1import java.util.*;
2import org.apache.tools.ant.*;
3import org.apache.tools.ant.taskdefs.*;
4import org.apache.tools.ant.taskdefs.condition.*;
5
6/**
7 * takes node addresses as arguments. E.g., 1.4.3.2
8 *
9 * node address x is after node address y iff, where y has n places,
10 * the values in the first n places of x are greater or equal to
11 * their corresponding values in y
12 */
13
14public class IsAfter implements Condition {
15
16 private String x = "";
17 private String y = "";
18
19 public boolean eval() {
20
21 System.out.println( "x: " + x );
22 System.out.println( "y: " + y );
23
24 if ( x.equals("") || y.equals("") ) {
25 throw new BuildException("Error - x or y not specified !!");
26 }
27
28 //check that both are in the form int.int.int
29
30 //break into chambers
31 String[] xs = x.split("\\.");
32 String[] ys = y.split("\\.");
33
34 //figure out n
35 int n = ys.length;
36
37 //step through, making sure x values are higher than or equal to y values
38 for ( int i=0; i<n; i++ ) {
39 int xValue = i<xs.length ? Integer.parseInt( xs[i] ) : 0;
40 int yValue = Integer.parseInt( ys[i] );
41
42 System.out.println( xValue + " " + yValue );
43 if( xValue < yValue ) {
44 System.out.println("x not after y");
45 return false;
46 }
47
48 if( xValue > yValue ) {
49 System.out.println("x is after y");
50 return true;
51 }
52 }
53
54 // if execution reaches here, first n places are equal
55 System.out.println("x is after y");
56 return true;
57 }
58
59
60 public void setX(String x) {
61 this.x=x;
62 }
63
64 public void setY(String y) {
65 this.y=y;
66 }
67
68}
Note: See TracBrowser for help on using the repository browser.