From e3de7f004aaf32c4f28abb4ee57dc7adc697646c Mon Sep 17 00:00:00 2001 From: amitjangid80 Date: Fri, 14 Sep 2018 12:44:56 +0530 Subject: [PATCH] 1. Added new method for removing last char from string and replacing null or empty value with 0. 2. Renamed replaceNull method to replaceNullWithEmpty --- .../com/amit/utilities/TextUtilities.java | 66 +++++++++++++++---- 1 file changed, 55 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/amit/utilities/TextUtilities.java b/app/src/main/java/com/amit/utilities/TextUtilities.java index b540374..b2de3cb 100644 --- a/app/src/main/java/com/amit/utilities/TextUtilities.java +++ b/app/src/main/java/com/amit/utilities/TextUtilities.java @@ -4,7 +4,7 @@ * Created By AMIT JANGID * 2018 April 17 - Tuesday - 12:52 PM **/ - +@SuppressWarnings("unused") public class TextUtilities { /** @@ -14,19 +14,21 @@ public class TextUtilities * @param string - string where you want to replace null * @return it will return empty string **/ - public static String replaceNull(String string) + public static String replaceNullWithEmpty(String string) { if (string == null) { return ""; } - - if (string.equalsIgnoreCase("null")) + else if (string.equalsIgnoreCase("null")) { return ""; } - - if (string.equalsIgnoreCase(" ")) + else if (string.equalsIgnoreCase(" ")) + { + return ""; + } + else if (string.equalsIgnoreCase("")) { return ""; } @@ -43,16 +45,58 @@ public static String replaceNull(String string) **/ public static int replaceTrueOrFalse(String string) { - if (string.equalsIgnoreCase("True")) + return string.equalsIgnoreCase("True") ? 1 : 0; + } + + /** + * 2018 September 14 - Friday - 12:34 PM + * replace null with zero method + * + * this method will replace null or empty values of string with zero + * + * @param stringToReplace - string to replace null with + * @return it will return 1 or 0 + **/ + public static int replaceNullWithZero(String stringToReplace) + { + if (stringToReplace == null) { - return 1; + return 0; } - - if (string.equalsIgnoreCase("False")) + else if (stringToReplace.equalsIgnoreCase("null")) { return 0; } + else if (stringToReplace.equalsIgnoreCase(" ")) + { + return 0; + } + else if (stringToReplace.equalsIgnoreCase("")) + { + return 0; + } + else + { + return Integer.parseInt(stringToReplace); + } + } + + /** + * 2018 September 14 - Friday - 12:34 PM + * remove last char method + * + * this method will remove the last character of the string + * + * @param stringToRemovedLastCharFrom - string to remove the last character from + * @return it will return string with last character removed + **/ + public static String removeLastChar(String stringToRemovedLastCharFrom) + { + if (stringToRemovedLastCharFrom != null && stringToRemovedLastCharFrom.length() > 0) + { + stringToRemovedLastCharFrom = stringToRemovedLastCharFrom.substring(0, stringToRemovedLastCharFrom.length() - 1); + } - return 0; + return stringToRemovedLastCharFrom; } }