Skip to content

Commit

Permalink
1. Added new method for removing last char from string and replacing …
Browse files Browse the repository at this point in the history
…null or empty value with 0.

2. Renamed replaceNull method to replaceNullWithEmpty
  • Loading branch information
amitjangid80 committed Sep 14, 2018
1 parent 2a5bc48 commit e3de7f0
Showing 1 changed file with 55 additions and 11 deletions.
66 changes: 55 additions & 11 deletions app/src/main/java/com/amit/utilities/TextUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Created By AMIT JANGID
* 2018 April 17 - Tuesday - 12:52 PM
**/

@SuppressWarnings("unused")
public class TextUtilities
{
/**
Expand All @@ -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 "";
}
Expand All @@ -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;
}
}

0 comments on commit e3de7f0

Please sign in to comment.