13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 package org.jemmy.resources; 26 27 /** 28 * 29 * @author shura 30 */ 31 public interface StringComparePolicy { 32 33 /** 34 * 35 */ 36 public static final StringComparePolicy EXACT = new ComparePolicy(true, true); 37 /** 38 * 39 */ 40 public static final StringComparePolicy SUBSTRING = new ComparePolicy(false, true); 41 42 /** 43 * 44 * @param golden 45 * @param value 46 * @return 47 */ 48 public boolean compare(String golden, String value); 49 50 /** 51 * 52 */ 53 static class ComparePolicy implements StringComparePolicy { 54 55 boolean ce; 56 boolean cc; 57 58 /** 59 * 60 * @param ce if true then entire strings are compared, if false golden 61 * could be a substring of a value 62 * @param cc case sensitive comparison policy 63 */ 64 public ComparePolicy(boolean ce, boolean cc) { 65 this.cc = cc; 66 this.ce = ce; 67 } 68 69 /** 70 * 71 * @param golden 72 * @param value 73 * @return 74 */ 75 public boolean compare(String golden, String value) { 76 if (value == null) { 77 return golden == null; 78 } else if (golden == null) { 79 return !ce; 80 } 81 String g, v; 82 if (cc) { 83 g = golden; 84 v = value; 85 } else { 86 g = golden.toUpperCase(); 87 v = value.toUpperCase(); 88 } 89 if (ce) { 90 return v.equals(g); 91 } else { 92 return v.contains(g); 93 } 94 } | 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 package org.jemmy.resources; 26 27 /** 28 * 29 * @author shura 30 */ 31 public interface StringComparePolicy { 32 33 public static final StringComparePolicy EXACT = new ComparePolicy(true, true); 34 public static final StringComparePolicy SUBSTRING = new ComparePolicy(false, true); 35 36 public boolean compare(String golden, String value); 37 38 static class ComparePolicy implements StringComparePolicy { 39 40 boolean ce; 41 boolean cc; 42 43 /** 44 * @param ce if true then entire strings are compared, if false golden 45 * could be a substring of a value 46 * @param cc case sensitive comparison policy 47 */ 48 public ComparePolicy(boolean ce, boolean cc) { 49 this.cc = cc; 50 this.ce = ce; 51 } 52 53 public boolean compare(String golden, String value) { 54 if (value == null) { 55 return golden == null; 56 } else if (golden == null) { 57 return !ce; 58 } 59 String g, v; 60 if (cc) { 61 g = golden; 62 v = value; 63 } else { 64 g = golden.toUpperCase(); 65 v = value.toUpperCase(); 66 } 67 if (ce) { 68 return v.equals(g); 69 } else { 70 return v.contains(g); 71 } 72 } |