dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #29301
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14768: Sql support methods in TextUtils
------------------------------------------------------------
revno: 14768
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2014-04-10 14:43:23 +0200
message:
Sql support methods in TextUtils
modified:
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/TextUtils.java
dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/TextUtilsTest.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/TextUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/TextUtils.java 2014-04-03 16:03:26 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/TextUtils.java 2014-04-10 12:43:23 +0000
@@ -35,6 +35,8 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.apache.commons.lang.StringUtils;
+
/**
* @author Lars Helge Overland
*/
@@ -182,6 +184,34 @@
}
/**
+ * Removes the last occurence of the word "or" from the given string,
+ * including potential trailing spaces, case-insentitive.
+ *
+ * @param string the string.
+ * @return the chopped string.
+ */
+ public static String removeLastOr( String string )
+ {
+ string = StringUtils.stripEnd( string, " " );
+
+ return StringUtils.removeEndIgnoreCase( string, "or" );
+ }
+
+ /**
+ * Removes the last occurence of the word "and" from the given string,
+ * including potential trailing spaces, case-insentitive.
+ *
+ * @param string the string.
+ * @return the chopped string.
+ */
+ public static String removeLastAnd( String string )
+ {
+ string = StringUtils.stripEnd( string, " " );
+
+ return StringUtils.removeEndIgnoreCase( string, "and" );
+ }
+
+ /**
* Trims the given string from the end.
*
* @param value the value to trim.
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/TextUtilsTest.java'
--- dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/TextUtilsTest.java 2014-03-22 15:30:31 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/TextUtilsTest.java 2014-04-10 12:43:23 +0000
@@ -86,4 +86,24 @@
assertEquals( new ArrayList<String>( Arrays.asList( "John", "Doe", "Main", "Road", "25" ) ), TextUtils.getTokens( "John Doe Main Road 25" ) );
assertEquals( new ArrayList<String>( Arrays.asList( "Ted,Johnson", "Upper-Road", "45" ) ), TextUtils.getTokens( "Ted,Johnson Upper-Road 45" ) );
}
+
+ @Test
+ public void testRemoveLastOr()
+ {
+ assertEquals( null, TextUtils.removeLastOr( null ) );
+ assertEquals( "", TextUtils.removeLastOr( "" ) );
+ assertEquals( "or name='tom' or name='john' ", TextUtils.removeLastOr( "or name='tom' or name='john' or" ) );
+ assertEquals( "or name='tom' or name='john' ", TextUtils.removeLastOr( "or name='tom' or name='john' or " ) );
+ assertEquals( "or name='tom' or name='john' ", TextUtils.removeLastOr( "or name='tom' or name='john' or " ) );
+ }
+
+ @Test
+ public void testRemoveLastAnd()
+ {
+ assertEquals( null, TextUtils.removeLastAnd( null ) );
+ assertEquals( "", TextUtils.removeLastAnd( "" ) );
+ assertEquals( "and name='tom' and name='john' ", TextUtils.removeLastAnd( "and name='tom' and name='john' and" ) );
+ assertEquals( "and name='tom' and name='john' ", TextUtils.removeLastAnd( "and name='tom' and name='john' and " ) );
+ assertEquals( "and name='tom' and name='john' ", TextUtils.removeLastAnd( "and name='tom' and name='john' and " ) );
+ }
}