Class Formats
java.lang.Object
com.amalgamasimulation.utils.format.Formats
- Direct Known Subclasses:
AmericanFormats,BritishFormats,RussianFormats
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final AmericanFormatsUnites States of America formatsstatic final BritishFormatsBritish formatsList of most frequently used currenciesstatic final CurrencyUnited Arab Emirates Dirham currency, AEDstatic final CurrencyBrazilian Real currency, BRLstatic final CurrencyEuro currency, EURstatic final CurrencyBritish Pound currency, GBPstatic final CurrencyIndian Rupee currency, INRstatic final CurrencyRussian Rouble currency, RUBstatic final CurrencyTurkish Lira currency, TRYstatic final CurrencyUnited States Dollar currency, USDstatic final Stringstatic final Stringstatic final Stringstatic final RussianFormatsRussian / Eastern European formats -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringcamelCaseToWords(String input) Converts a camelCase or PascalCase string into a space-separated, lowercase phrase.static StringcapitalizeSentence(String input) Normalizes a sentence by converting the entire string to lower case and then capitalizing the first character.abstract StringReturns the specified value without fractional part and with thecurrencysymbol ($, €, etc.) in the beginning.abstract StringcurrencyLong(double value, Currency currency) Returns the specified value without fractional part and with the ISO 4217currencycode (USD, EUR, etc.) in the beginning.
Uses the locale-specific thousands separator.abstract StringcurrencyLongSign(double value, Currency currency) Returns the specified value without fractional part and with the leading sign (+ or -) followed by the ISO 4217currencycode (USD, EUR, etc.).abstract StringcurrencyLongTwoDecimals(double value, Currency currency) Returns the specified value with two digits of fractional part and with the ISO 4217currencycode (USD, EUR, etc.) in the beginning.abstract StringcurrencyLongTwoDecimalsSign(double value, Currency currency) Returns the specified value with two digits of fractional part and with the leading sign (+ or -) followed by the ISO 4217currencycode (USD, EUR, etc.).abstract StringcurrencySign(double value, Currency currency) Returns the specified value without fractional part and with the leading sign (+ or -) followed by thecurrencysymbol ($, €, etc.).abstract StringcurrencyTwoDecimals(double value, Currency currency) Returns the specified value with two digits of fractional part and with thecurrencysymbol ($, €, etc.) in the beginning.abstract StringcurrencyTwoDecimalsSign(double value, Currency currency) Returns the specified value with two digits of fractional part and with the leading sign (+ or -) followed by thecurrencysymbol ($, €, etc.).
Uses the locale-specific decimal and thousands separators.abstract StringcustomDecimals(double value, int countSign) abstract Stringabstract StringdayMonthLongYear(LocalDate date) abstract Stringabstract Stringabstract Stringabstract StringdayMonthYear(LocalDate date) abstract StringdayMonthYear(LocalDateTime date) abstract Stringdollar(double value) Returns the specified value without fractional part and with the dollar character ($) in the beginning.abstract StringdollarSign(double value) Returns the specified value without fractional part and with the leading sign (+ or -) followed by the dollar character ($).abstract StringdollarTwoDecimals(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.abstract StringdollarTwoDecimalsSign(double value) Returns the specified value with two digits of fractional part and with the leading sign (+ or -) followed by the dollar character ($).duration(double amount, ChronoUnit chronoUnit) abstract Stringduration(long millis) duration(LocalDateTime beginDate, LocalDateTime endDate) protected StringgetCurrencySymbol(Currency currency) static Formatsstatic Stringstatic Stringstatic Stringabstract StringhoursMinutes(LocalDateTime date) abstract StringhoursMinutes(LocalTime date) static booleanabstract Stringkmb(double value) Convenient formatting for large values.abstract StringkmbCurrency(double value, Currency currency) Returns the kmb-formattedvaluewith thecurrencysymbol ($, €, etc.) in the beginning.abstract StringkmbCurrencyLong(double value, Currency currency) Returns the kmb-formattedvaluewith the ISO 4217currencycode (USD, EUR, etc.) in the beginning.abstract StringkmbDollars(double value) Returns the kmb-formattedvaluewith the dollar character ($) in the beginning.abstract StringkmbShort(double value) Convenient formatting for large values.abstract StringmonthLongYear(LocalDate date) abstract StringmonthLongYear(LocalDateTime date) abstract Stringabstract StringmonthYear(LocalDateTime date) abstract StringnoDecimals(double value) Returns the specified value formatted without decimal separator and fractional part.abstract StringnoDecimalsSign(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 signabstract LocalDateTimeparseDayMonthLongYear(String dateString) abstract LocalDateTimeparseDayMonthLongYearHoursMinutes(String dateString) abstract LocalDateTimeparseHoursMinutes(String dateString) abstract Stringpercent(double value) Returns the specified value formatted as whole percentage without fractional part and with the percent character (%) in the end.abstract StringpercentSign(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.abstract StringpercentTwoDecimals(double value) Returns the specified value formatted as percentage with two decimal digits and with the percent character (%) in the end.abstract StringpercentTwoDecimalsSign(double value) Returns a string representation of a numeric value formatted as a percentage with two decimal places, including a leading sign (+ or -).static StringpluralizedEnglishNoun(String singularNoun) Returns the plural form of an English noun or noun expression.abstract StringpreciseNumberFormat(double value) static voidsetDefaultFormats(Formats formats) static Stringstatic StringtoBlockBySpaces(String string, int lineLength, int maxLinesCount) static Stringstatic StringtrimWithEllipsis(String string, int length) static StringtrimWithMiddleEllipsis(String string, int length) abstract StringtwoDecimals(double value) Returns the specified value formatted with decimal separator and two digits of fractional part.
Uses the locale-specific decimal and thousands separators.abstract StringtwoDecimalsSign(double value) Returns a string representation of a numeric value formatted with two decimal places, including a leading sign (+ or -).
-
Field Details
-
NEW_LINE
-
ELLIPSIS
- See Also:
-
EMPTY_STRING
- See Also:
-
CURRENCY_USD
United States Dollar currency, USD -
CURRENCY_EUR
Euro currency, EUR -
CURRENCY_GBP
British Pound currency, GBP -
CURRENCY_INR
Indian Rupee currency, INR -
CURRENCY_BRL
Brazilian Real currency, BRL -
CURRENCY_RUB
Russian Rouble currency, RUB -
CURRENCY_TRY
Turkish Lira currency, TRY -
CURRENCY_AED
United Arab Emirates Dirham currency, AED -
CURRENCIES
List of most frequently used currencies -
AMERICAN
Unites States of America formats -
BRITISH
British formats -
RUSSIAN
Russian / Eastern European formats
-
-
Constructor Details
-
Formats
public Formats()
-
-
Method Details
-
noDecimals
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
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
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
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
-
dollar
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
Returns the specified value without fractional part and with thecurrencysymbol ($, €, etc.) in the beginning.
Uses the locale-specific thousands separator.- Parameters:
value- specified valuecurrency- currency of the value- Returns:
- string representation of the specified value
-
currencyLong
Returns the specified value without fractional part and with the ISO 4217currencycode (USD, EUR, etc.) in the beginning.
Uses the locale-specific thousands separator.- Parameters:
value- specified valuecurrency- currency of the value- Returns:
- string representation of the specified value
-
dollarTwoDecimals
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
Returns the specified value with two digits of fractional part and with thecurrencysymbol ($, €, etc.) in the beginning.
Uses the locale-specific decimal and thousands separators.- Parameters:
value- specified valuecurrency- currency of the value- Returns:
- string representation of the specified value
-
currencyLongTwoDecimals
Returns the specified value with two digits of fractional part and with the ISO 4217currencycode (USD, EUR, etc.) in the beginning.
Uses the locale-specific decimal and thousands separators.- Parameters:
value- specified valuecurrency- currency of the value- Returns:
- string representation of the specified value
-
noDecimalsSign
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
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
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
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
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
Returns the specified value without fractional part and with the leading sign (+ or -) followed by thecurrencysymbol ($, €, etc.).
Uses the locale-specific thousands separator.- Parameters:
value- specified valuecurrency- currency of the value- Returns:
- string representation of the specified value
-
currencyLongSign
Returns the specified value without fractional part and with the leading sign (+ or -) followed by the ISO 4217currencycode (USD, EUR, etc.).
Uses the locale-specific thousands separator.- Parameters:
value- specified valuecurrency- currency of the value- Returns:
- string representation of the specified value
-
dollarTwoDecimalsSign
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
Returns the specified value with two digits of fractional part and with the leading sign (+ or -) followed by thecurrencysymbol ($, €, etc.).
Uses the locale-specific decimal and thousands separators.- Parameters:
value- specified valuecurrency- currency of the value- Returns:
- string representation of the specified value
-
currencyLongTwoDecimalsSign
Returns the specified value with two digits of fractional part and with the leading sign (+ or -) followed by the ISO 4217currencycode (USD, EUR, etc.).
Uses the locale-specific decimal and thousands separators.- Parameters:
value- specified valuecurrency- currency of the value- Returns:
- string representation of the specified value
-
monthYear
-
dayMonthYear
-
monthLongYear
-
dayMonthLongYear
-
monthYear
-
dayMonthYear
-
monthLongYear
-
dayMonthLongYear
-
hoursMinutes
-
hoursMinutes
-
dayMonthLongYearHoursMinutes
-
dayMonthLongYearHoursMinutesSeconds
-
dayMonthHoursMinutes
-
preciseNumberFormat
-
kmbShort
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"
kmbShort(0)is "0"kmbShort(2)is "2"kmbShort(12_000)is "12K"kmbShort(4_000_000)is "4M"
- Parameters:
value- specified value- Returns:
- string representation of the specified value
- See Also:
-
kmb
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
Returns the kmb-formattedvaluewith 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
Returns the kmb-formattedvaluewith thecurrencysymbol ($, €, etc.) in the beginning.
Uses the locale-specific thousands separator.- Parameters:
value- specified valuecurrency- currency of the value- Returns:
- string representation of the specified value
- See Also:
-
kmbCurrencyLong
Returns the kmb-formattedvaluewith the ISO 4217currencycode (USD, EUR, etc.) in the beginning.
Uses the locale-specific thousands separator.- Parameters:
value- specified valuecurrency- currency of the value- Returns:
- string representation of the specified value
- See Also:
-
duration
-
customDecimals
-
parseDayMonthLongYearHoursMinutes
-
parseDayMonthLongYear
-
parseHoursMinutes
-
duration
-
duration
-
duration
-
setDefaultFormats
-
getDefaultFormats
-
isRussianFormats
public static boolean isRussianFormats() -
trim
-
trimWithEllipsis
-
trimWithMiddleEllipsis
-
toBlock
-
toBlockBySpaces
-
getNewLine
-
getEllipsis
-
getEmptyString
-
pluralizedEnglishNoun
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
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 benullor empty- Returns:
- a lowercase string with spaces inserted before capital letters, or
the original input if it is
nullor empty
-
capitalizeSentence
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
inputisnullor blank
-