From f9283a20abd9eaed0b0436bc54c60576233121f4 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Mon, 11 Apr 2016 09:32:59 -0400 Subject: Added new method to pairs and holders --- .../main/java/bjc/utils/funcutils/StringUtils.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'BJC-Utils2/src/main/java/bjc/utils/funcutils/StringUtils.java') diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcutils/StringUtils.java b/BJC-Utils2/src/main/java/bjc/utils/funcutils/StringUtils.java index a73292c..ac36d15 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/StringUtils.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/StringUtils.java @@ -37,4 +37,24 @@ public class StringUtils { return input.matches("\\A(?:" + regex + ")+\\Z"); } + /** + * Checks if the given expression contains the specified operator in a + * situation that indicates its use as an infix operator. + * + * @param expression + * The expression to check + * @param operator + * The operator to see if it is contained + * @return Whether or not the given expression contains the specified + * operator as a infix operator + */ + public static boolean containsInfixOperator(String expression, + String operator) { + // Bit annoying to have to use a full class name, but what are you + // going to do? + return org.apache.commons.lang3.StringUtils + .countMatches(expression, operator) == 1 + && !expression.equalsIgnoreCase(operator) + && !expression.startsWith(operator); + } } -- cgit v1.2.3