Class Formats

java.lang.Object
com.amalgamasimulation.utils.format.Formats
Direct Known Subclasses:
AmericanFormats, BritishFormats, RussianFormats

public abstract class Formats extends Object
  • Field Details

    • NEW_LINE

      public static final String NEW_LINE
    • ELLIPSIS

      public static final String ELLIPSIS
      See Also:
    • EMPTY_STRING

      public static final String EMPTY_STRING
      See Also:
    • CURRENCY_USD

      public static final Currency CURRENCY_USD
      United States Dollar currency, USD
    • CURRENCY_EUR

      public static final Currency CURRENCY_EUR
      Euro currency, EUR
    • CURRENCY_GBP

      public static final Currency CURRENCY_GBP
      British Pound currency, GBP
    • CURRENCY_INR

      public static final Currency CURRENCY_INR
      Indian Rupee currency, INR
    • CURRENCY_BRL

      public static final Currency CURRENCY_BRL
      Brazilian Real currency, BRL
    • CURRENCY_RUB

      public static final Currency CURRENCY_RUB
      Russian Rouble currency, RUB
    • CURRENCY_TRY

      public static final Currency CURRENCY_TRY
      Turkish Lira currency, TRY
    • CURRENCY_AED

      public static final Currency CURRENCY_AED
      United Arab Emirates Dirham currency, AED
    • CURRENCIES

      public static final List<Currency> CURRENCIES
      List of most frequently used currencies
    • AMERICAN

      public static final AmericanFormats AMERICAN
      Unites States of America formats
    • BRITISH

      public static final BritishFormats BRITISH
      British formats
    • RUSSIAN

      public static final RussianFormats RUSSIAN
      Russian / Eastern European formats
  • Constructor Details

    • Formats

      public Formats()
  • Method Details

    • noDecimals

      public abstract String noDecimals(double value)
      Returns the specified value formatted without decimal separator and fractional part.
      Uses the locale-specific thousands separator.
      Parameters:
      value - specified value
      Returns:
      string representation of the specified value
    • twoDecimals

      public abstract String twoDecimals(double value)
      Returns the specified value formatted with decimal separator and two digits of fractional part.
      Uses the locale-specific decimal and thousands separators.
      Parameters:
      value - specified value
      Returns:
      string representation of the specified value
    • percent

      public abstract String percent(double value)
      Returns the specified value formatted as whole percentage without fractional part and with the percent character (%) in the end.
      Note that the value is multiplied by 100 when converted to percentage.
      Parameters:
      value - specified value
      Returns:
      string representation of the specified value
    • percentTwoDecimals

      public abstract String percentTwoDecimals(double value)
      Returns the specified value formatted as percentage with two decimal digits and with the percent character (%) in the end.
      Note that the value is multiplied by 100 when converted to percentage.
      Parameters:
      value - specified value
      Returns:
      string representation of the specified value
    • getCurrencySymbol

      protected String getCurrencySymbol(Currency currency)
    • dollar

      public abstract String dollar(double value)
      Returns the specified value without fractional part and with the dollar character ($) in the beginning.
      Uses the locale-specific thousands separator.
      Parameters:
      value - specified value
      Returns:
      string representation of the specified value
    • currency

      public abstract String currency(double value, Currency currency)
      Returns the specified value without fractional part and with the currency symbol ($, €, etc.) in the beginning.
      Uses the locale-specific thousands separator.
      Parameters:
      value - specified value
      currency - currency of the value
      Returns:
      string representation of the specified value
    • currencyLong

      public abstract String currencyLong(double value, Currency currency)
      Returns the specified value without fractional part and with the ISO 4217 currency code (USD, EUR, etc.) in the beginning.
      Uses the locale-specific thousands separator.
      Parameters:
      value - specified value
      currency - currency of the value
      Returns:
      string representation of the specified value
    • dollarTwoDecimals

      public abstract String dollarTwoDecimals(double value)
      Returns the specified value with two digits of fractional part and with dollar character ($) in the beginning.
      Uses the locale-specific decimal and thousands separators.
      Parameters:
      value - specified value
      Returns:
      string representation of the specified value
    • currencyTwoDecimals

      public abstract String currencyTwoDecimals(double value, Currency currency)
      Returns the specified value with two digits of fractional part and with the currency symbol ($, €, etc.) in the beginning.
      Uses the locale-specific decimal and thousands separators.
      Parameters:
      value - specified value
      currency - currency of the value
      Returns:
      string representation of the specified value
    • currencyLongTwoDecimals

      public abstract String currencyLongTwoDecimals(double value, Currency currency)
      Returns the specified value with two digits of fractional part and with the ISO 4217 currency code (USD, EUR, etc.) in the beginning.
      Uses the locale-specific decimal and thousands separators.
      Parameters:
      value - specified value
      currency - currency of the value
      Returns:
      string representation of the specified value
    • noDecimalsSign

      public abstract String noDecimalsSign(double value)
      Returns the string representation of the numeric value without any decimal points or fractional parts, including a leading sign (+ or -) based on the value's sign
      Parameters:
      value - The numeric value to format.
      Returns:
      A string representation of the numeric value with no decimals, including a leading sign to indicate positive or negative value
    • twoDecimalsSign

      public abstract String twoDecimalsSign(double value)
      Returns a string representation of a numeric value formatted with two decimal places, including a leading sign (+ or -).
      Parameters:
      value - The numeric value to format.
      Returns:
      A formatted string showing the numeric value with two decimal places and a leading sign
    • percentSign

      public abstract String percentSign(double value)
      Returns a string representation of a numeric value formatted as a whole percentage, including a leading sign (+ or -) to indicate whether the percentage is positive or negative.
      Parameters:
      value - The numeric value to format as a percentage, typically a value between 0 and 1
      Returns:
      A string representing the numeric value as a whole percentage, with a leading sign
    • percentTwoDecimalsSign

      public abstract String percentTwoDecimalsSign(double value)
      Returns a string representation of a numeric value formatted as a percentage with two decimal places, including a leading sign (+ or -).
      Parameters:
      value - The numeric value to format as a percentage, typically a value between 0 and 1
      Returns:
      A formatted string showing the percentage with two decimal places and a leading sign
    • dollarSign

      public abstract String dollarSign(double value)
      Returns the specified value without fractional part and with the leading sign (+ or -) followed by the dollar character ($).
      Uses the locale-specific thousands separator.
      Parameters:
      value - specified value
      Returns:
      string representation of the specified value
    • currencySign

      public abstract String currencySign(double value, Currency currency)
      Returns the specified value without fractional part and with the leading sign (+ or -) followed by the currency symbol ($, €, etc.).
      Uses the locale-specific thousands separator.
      Parameters:
      value - specified value
      currency - currency of the value
      Returns:
      string representation of the specified value
    • currencyLongSign

      public abstract String currencyLongSign(double value, Currency currency)
      Returns the specified value without fractional part and with the leading sign (+ or -) followed by the ISO 4217 currency code (USD, EUR, etc.).
      Uses the locale-specific thousands separator.
      Parameters:
      value - specified value
      currency - currency of the value
      Returns:
      string representation of the specified value
    • dollarTwoDecimalsSign

      public abstract String dollarTwoDecimalsSign(double value)
      Returns the specified value with two digits of fractional part and with the leading sign (+ or -) followed by the dollar character ($).
      Uses the locale-specific decimal and thousands separators.
      Parameters:
      value - specified value
      Returns:
      string representation of the specified value
    • currencyTwoDecimalsSign

      public abstract String currencyTwoDecimalsSign(double value, Currency currency)
      Returns the specified value with two digits of fractional part and with the leading sign (+ or -) followed by the currency symbol ($, €, etc.).
      Uses the locale-specific decimal and thousands separators.
      Parameters:
      value - specified value
      currency - currency of the value
      Returns:
      string representation of the specified value
    • currencyLongTwoDecimalsSign

      public abstract String currencyLongTwoDecimalsSign(double value, Currency currency)
      Returns the specified value with two digits of fractional part and with the leading sign (+ or -) followed by the ISO 4217 currency code (USD, EUR, etc.).
      Uses the locale-specific decimal and thousands separators.
      Parameters:
      value - specified value
      currency - currency of the value
      Returns:
      string representation of the specified value
    • monthYear

      public abstract String monthYear(LocalDate date)
    • dayMonthYear

      public abstract String dayMonthYear(LocalDate date)
    • monthLongYear

      public abstract String monthLongYear(LocalDate date)
    • dayMonthLongYear

      public abstract String dayMonthLongYear(LocalDate date)
    • monthYear

      public abstract String monthYear(LocalDateTime date)
    • dayMonthYear

      public abstract String dayMonthYear(LocalDateTime date)
    • monthLongYear

      public abstract String monthLongYear(LocalDateTime date)
    • dayMonthLongYear

      public abstract String dayMonthLongYear(LocalDateTime date)
    • hoursMinutes

      public abstract String hoursMinutes(LocalDateTime date)
    • hoursMinutes

      public abstract String hoursMinutes(LocalTime date)
    • dayMonthLongYearHoursMinutes

      public abstract String dayMonthLongYearHoursMinutes(LocalDateTime date)
    • dayMonthLongYearHoursMinutesSeconds

      public abstract String dayMonthLongYearHoursMinutesSeconds(LocalDateTime date)
    • dayMonthHoursMinutes

      public abstract String dayMonthHoursMinutes(LocalDateTime date)
    • preciseNumberFormat

      public abstract String preciseNumberFormat(double value)
    • kmbShort

      public abstract String kmbShort(double value)
      Convenient formatting for large values.

      Works almost like the kmb(double) method, but keeps at most one digit in the fractional part (if any).
      A single digit in the fractional part is shown only if that digit is the 2nd significant digit and is not zero:

      • kmbShort(1.6) is "1.6"
      • kmbShort(0.8) is "0.8"
      • kmbShort(9_400) is "9.4K"
      • kmbShort(-8_600_000) is "-8.6M"
      Otherwise, the fractional part is not shown:
      • kmbShort(0) is "0"
      • kmbShort(2) is "2"
      • kmbShort(12_000) is "12K"
      • kmbShort(4_000_000) is "4M"
      Uses the locale-specific decimals separator.
      Parameters:
      value - specified value
      Returns:
      string representation of the specified value
      See Also:
    • kmb

      public abstract String kmb(double value)
      Convenient formatting for large values.
      Examples:
      • kmb(0) is "0.00"
      • kmb(12) is "12.0"
      • kmb(120) is "120"
      • kmb(1_200) is "1.20K"
      • kmb(1_200_098) is "1.20M"

      Uses the locale-specific decimals separator.
      Parameters:
      value - specified value
      Returns:
      string representation of the specified value
    • kmbDollars

      public abstract String kmbDollars(double value)
      Returns the kmb-formatted value with the dollar character ($) in the beginning.
      Uses the locale-specific thousands separator.
      Parameters:
      value - specified value
      Returns:
      string representation of the specified value
      See Also:
    • kmbCurrency

      public abstract String kmbCurrency(double value, Currency currency)
      Returns the kmb-formatted value with the currency symbol ($, €, etc.) in the beginning.
      Uses the locale-specific thousands separator.
      Parameters:
      value - specified value
      currency - currency of the value
      Returns:
      string representation of the specified value
      See Also:
    • kmbCurrencyLong

      public abstract String kmbCurrencyLong(double value, Currency currency)
      Returns the kmb-formatted value with the ISO 4217 currency code (USD, EUR, etc.) in the beginning.
      Uses the locale-specific thousands separator.
      Parameters:
      value - specified value
      currency - currency of the value
      Returns:
      string representation of the specified value
      See Also:
    • duration

      public abstract String duration(long millis)
    • customDecimals

      public abstract String customDecimals(double value, int countSign)
    • parseDayMonthLongYearHoursMinutes

      public abstract LocalDateTime parseDayMonthLongYearHoursMinutes(String dateString)
    • parseDayMonthLongYear

      public abstract LocalDateTime parseDayMonthLongYear(String dateString)
    • parseHoursMinutes

      public abstract LocalDateTime parseHoursMinutes(String dateString)
    • duration

      public String duration(double amount, ChronoUnit chronoUnit)
    • duration

      public String duration(Duration duration)
    • duration

      public String duration(LocalDateTime beginDate, LocalDateTime endDate)
    • setDefaultFormats

      public static void setDefaultFormats(Formats formats)
    • getDefaultFormats

      public static Formats getDefaultFormats()
    • isRussianFormats

      public static boolean isRussianFormats()
    • trim

      public static String trim(String string, int length)
    • trimWithEllipsis

      public static String trimWithEllipsis(String string, int length)
    • trimWithMiddleEllipsis

      public static String trimWithMiddleEllipsis(String string, int length)
    • toBlock

      public static String toBlock(String string, int lineLength, int maxLinesCount)
    • toBlockBySpaces

      public static String toBlockBySpaces(String string, int lineLength, int maxLinesCount)
    • getNewLine

      public static String getNewLine()
    • getEllipsis

      public static String getEllipsis()
    • getEmptyString

      public static String getEmptyString()
    • pluralizedEnglishNoun

      public static String pluralizedEnglishNoun(String singularNoun)
      Returns the plural form of an English noun or noun expression. For example:
      • for "truck" returns "trucks"
      • for "drilling machine" returns "drilling machines"
      • for "person" returns "people"
      Parameters:
      singularNoun - English singular noun to be pluralized
      Returns:
      pluralized form of the noun
    • camelCaseToWords

      public static String camelCaseToWords(String input)
      Converts a camelCase or PascalCase string into a space-separated, lowercase phrase.

      For example:

       camelCaseToWords("DrillingMachineType") → "drilling machine type"
       camelCaseToWords("userID") → "user id"
       
      Parameters:
      input - the input string in camelCase or PascalCase format; may be null or empty
      Returns:
      a lowercase string with spaces inserted before capital letters, or the original input if it is null or empty
    • capitalizeSentence

      public static String capitalizeSentence(String input)
      Normalizes a sentence by converting the entire string to lower case and then capitalizing the first character.
      Parameters:
      input - the input string to normalize
      Returns:
      a string with the first character in upper case and all remaining characters in lower case, or the original value if input is null or blank