1 18 19 package org.apache.tools.ant.taskdefs.condition; 20 21 import org.apache.tools.ant.BuildException; 22 23 29 public class Contains implements Condition { 30 31 private String string, subString; 32 private boolean caseSensitive = true; 33 34 39 public void setString(String string) { 40 this.string = string; 41 } 42 43 48 public void setSubstring(String subString) { 49 this.subString = subString; 50 } 51 52 57 public void setCasesensitive(boolean b) { 58 caseSensitive = b; 59 } 60 61 66 public boolean eval() throws BuildException { 67 if (string == null || subString == null) { 68 throw new BuildException("both string and substring are required " 69 + "in contains"); 70 } 71 72 return caseSensitive 73 ? string.indexOf(subString) > -1 74 : string.toLowerCase().indexOf(subString.toLowerCase()) > -1; 75 } 76 } 77 | Popular Tags |