Browse Source

equals BC to support subclasses :/

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@574302 13f79535-47bb-0310-9956-ffa450edef68
master
Matthew Jason Benson 18 years ago
parent
commit
ffeb30bcce
1 changed files with 28 additions and 10 deletions
  1. +28
    -10
      src/main/org/apache/tools/ant/taskdefs/condition/Equals.java

+ 28
- 10
src/main/org/apache/tools/ant/taskdefs/condition/Equals.java View File

@@ -39,8 +39,11 @@ public class Equals implements Condition {
* @since Ant 1.8
*/
public void setArg1(Object arg1) {
this.arg1 = arg1;
args |= 1;
if (arg1 instanceof String) {
setArg1((String) arg1);
} else {
setArg1Internal(arg1);
}
}

/**
@@ -49,17 +52,25 @@ public class Equals implements Condition {
* @param a1 the first string
*/
public void setArg1(String a1) {
setArg1((Object) a1);
setArg1Internal(a1);
}

private void setArg1Internal(Object arg1) {
this.arg1 = arg1;
args |= 1;
}
/**
* Set the second argument
* @param arg2 the second argument.
* @since Ant 1.8
*/
public void setArg2(Object arg2) {
this.arg2 = arg2;
args |= 2;
if (arg2 instanceof String) {
setArg2((String) arg2);
} else {
setArg2Internal(arg2);
}
}

/**
@@ -68,9 +79,14 @@ public class Equals implements Condition {
* @param a2 the second string
*/
public void setArg2(String a2) {
setArg2((Object) a2);
setArg2Internal(a2);
}

private void setArg2Internal(Object arg2) {
this.arg2 = arg2;
args |= 2;
}
/**
* Should we want to trim the arguments before comparing them?
* @param b if true trim the arguments
@@ -99,13 +115,15 @@ public class Equals implements Condition {
throw new BuildException("both arg1 and arg2 are required in equals");
}

if (arg1 instanceof String && trim) {
arg1 = ((String) arg1).trim();
}
if (arg2 instanceof String && trim) {
arg2 = ((String) arg2).trim();
}
if (arg1 instanceof String && arg2 instanceof String) {
String s1 = (String) arg1;
String s2 = (String) arg2;
if (trim) {
s1 = s1.trim();
s2 = s2.trim();
}
return caseSensitive ? s1.equals(s2) : s1.equalsIgnoreCase(s2);
}
return arg1 == arg2 || arg1 != null && arg1.equals(arg2);


Loading…
Cancel
Save