Class StringBuilderUtil

java.lang.Object
com.reve.utils.string.StringBuilderUtil

public class StringBuilderUtil extends Object
  • Constructor Details

    • StringBuilderUtil

      public StringBuilderUtil()
  • Method Details

    • appendNumber

      public static StringBuilder appendNumber(StringBuilder stringBuilder, long value, int digitCounts)
      Append the given number into the StringBuilder. It will be made sure that the number takes exactly the given number of digit count. If the value exceeds the number of digits than the given number of digitCounts, it will discard the most significant numbers. And if the value have less digits than given digitCounts, 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 the StringBuilder. It will be made sure that the number takes minimum the given number of digit count. If the value have less digits than given digitCounts, 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 the StringBuilder. It will be made sure that the number takes maximum the given number of digit count. If the value exceeds the number of digits than the given number of digitCounts, 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