Package com.reve.utils.string
Class StringBuilderUtil
java.lang.Object
com.reve.utils.string.StringBuilderUtil
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringBuilderappendNumber(StringBuilder stringBuilder, long value, int digitCounts) Append the given number into theStringBuilder.static StringBuilderappendNumberForMaxDigit(StringBuilder stringBuilder, long value, int digitCounts) Append the given number into theStringBuilder.static StringBuilderappendNumberForMinDigit(StringBuilder stringBuilder, long value, int digitCounts) Append the given number into theStringBuilder.
-
Constructor Details
-
StringBuilderUtil
public StringBuilderUtil()
-
-
Method Details
-
appendNumber
Append the given number into theStringBuilder. It will be made sure that the number takes exactly the given number of digit count. If thevalueexceeds the number of digits than the given number ofdigitCounts, it will discard the most significant numbers. And if thevaluehave less digits than givendigitCounts, it will add extra 0 as prefix to the number.for example value = 10, digitCounts = 3 will append 010 value = 1234, digitCounts = 3 will append 234
- Parameters:
stringBuilder- given number will be appended into this instance.value- this value will be appended.digitCounts- number of digits to be appended.- Returns:
- the same instance of
StringBuilder
-
appendNumberForMinDigit
public static StringBuilder appendNumberForMinDigit(StringBuilder stringBuilder, long value, int digitCounts) Append the given number into theStringBuilder. It will be made sure that the number takes minimum the given number of digit count. If thevaluehave less digits than givendigitCounts, it will add extra 0 as prefix to the number, otherwise it will append all the digits even if it exceeds the given digit counts.for example value = 10, digitCounts = 3 will append 010 value = 1234, digitCounts = 3 will append 1234
- Parameters:
stringBuilder- given number will be appended into this instance.value- this value will be appended.digitCounts- minimum number of digits to be appended.- Returns:
- the same instance of
StringBuilder
-
appendNumberForMaxDigit
public static StringBuilder appendNumberForMaxDigit(StringBuilder stringBuilder, long value, int digitCounts) Append the given number into theStringBuilder. It will be made sure that the number takes maximum the given number of digit count. If thevalueexceeds the number of digits than the given number ofdigitCounts, it will discard the most significant numbers, otherwise it will append all the digits even if it has fewer digits than given digit counts.for example value = 10, digitCounts = 3 will append 10 value = 1234, digitCounts = 3 will append 234
- Parameters:
stringBuilder- given number will be appended into this instance.value- this value will be appended. If this value is 0, it will add nothing in the given string builder.digitCounts- maximum number of digits to be appended.- Returns:
- the same instance of
StringBuilder
-