Table of Contents
Text
Text contains tools for generating text from various objects.
TextFactory
TextFactory
is a singleton class that builds strings from Text
objects and contains references to various tools to use in generation. Use the build(Text)
and build(Text…)
methods for generation. The implementation is annotated as a @Component
for the Injector module and will be automatically instantiated by it.
TextConfiguration
TextConfiguration
is a configuration object that is used by all configurable classes of the module. ConfigurationKey
is used to determine the type and default value of a configuration entry, and values to configuration entries may be static objects or a Supplier<T>
. Configuration keys specific to a single class are contained in the class, and generic keys are in the ConfigurationKeys
utility class. These generic keys are:
ConfigurationKey<String> DELIMITER
determines the delimiter used in normal concatenation. The default value is “ConfigurationKey<String> LIST_DELIMITER
determines the delimiter used in list concatenation, which is when the last delimiter should be different from the other ones. The default value is “,
”ConfigurationKey<String> LIST_LAST_DELIMITER
determines the last delimiter used in list concatenation. The default value is “and
”ConfigurationKey<Handle> NUMBER_FORMATTER
determines theNumberFormatter
to be used when formatting numbersConfigurationKey<Handle> NUMBER_SUFFIX_FORMATTER
determines theNumberSuffixFormatter
to be used by number formatters to separate a number to a mantissa and exponent
Text
Text
is an interface that contains a text generation method and possibly references to other objects to aid in generation. There are multiple default implementations of text:
StaticText
is the simplest text implementation. It takes in a string and returns it on generationConfigurationText<T>
takes in aConfigurationKey<T>
and aFunction<T,String>
, and returns the configuration value ran through the function on generationNameText<T>
takes in aSupplier<T>
and returns the name for the supplied object on generation. Name is resolved withTextFactory.getName(T)
. It has oneConfigurationKey<Boolean>
calledUSE_PLURAL
which uses the plural form of the name iftrue
. The default value isfalse
NumberText
takes in aSupplier<Number>
and returns the formatted version of the supplied number on generation. The number is formatted using theConfigurationKeys.NUMBER_FORMATTER
andConfigurationKeys.NUMBER_SUFFIX_FORMATTER
configuration keysNumeralText
is the same asNumberText
, but works on numerals from the Math module instead of regular numbersValueText
is the same asNumberText
, but works on values from the Values module instead of regular numbers. It also has aConfigurationKey<Boolean>
calledUSE_MODIFIED
, which uses theValue.getValue()
method iftrue
and theValue.getBase()
method iffalse
. The default value istrue
ChainedText
takes in any amount of other text objects and chains them together using delimiters. It has oneConfigurationKey<Boolean>
calledUSE_LIST_MODIFIER
which usesConfigurationKeys.LIST_DELIMITER
andConfigurationKeys.LIST_LAST_DELIMITER
iftrue
andConfigurationKeys.DELIMITER
iffalse
. The default value isfalse
NumberFormatter
NumberFormatter
is an interface that formats a BigDecimal
number to a string representation. It uses a NumberSuffixFormatter
to separate the number into mantissa and exponent parts when necessary. There are three default implementations of number formatter:
SimpleNumberFormatter
is the simplest number formatter. It has three configuration keys:ConfigurationKey<Integer> PRECISION
determines the precision of the formatted number. This is directly equivalent toMathContext.getPrecision()
. The default value is 6ConfigurationKey<Integer> MIN_EXPONENT
determines the minimum power of ten that the number must be before aNumberSuffixFormatter
is used to generate an exponential suffix for the number. This value must be smaller than or equal toPRECISION
. The default value is 3ConfigurationKey<Boolean> STRIP_ZEROS
determines if trailing zeros after a decimal point should be stripped. The default value istrue
EvenLengthNumberFormatter
works mostly in the same way as theSimpleNumberFormatter
, but tries to format all numbers to take the same amount of characters. It has three configuration keys:ConfigurationKey<Integer> LENGTH
determines how many characters the resulting string should be in length. Values smaller than 7 are not recommended. The default value is 8ConfigurationKey<Integer> MIN_EXPONENT
determines the minimum power of ten that the number must be before aNumberSuffixFormatter
is used to generate an exponential suffix for the number. This value must be smaller than or equal toLENGTH
. The default value is 3ConfigurationKey<Boolean> PAD_ZEROS
determines if numbers resulting in fewer characters thanLENGHT
should be padded with a decimal separator (if one is not present already) and trailing zeros. The default value istrue
SplittingNumberFormatter
splits a number into multiple parts. This is most useful when formatting durations of time. It has four configuration keys:ConfigurationKey<Split[]> SPLITS
determines how numbers are split. Every split object contains a number multiplier and a suffix in singular and plural form. The splits must be in ascending order based on the multiplier, and the first split’s multiplier is recommended to be 1. The default value isTIME_SHORT
. Two preset split arrays are defined:TIME_SHORT
splits a number of seconds into different units of time ranging from seconds to years. Months are assumed to be 30 days in length, and years 365 days in length. The units are abbreviated as their name’s first character, except for months which are abbreviated withmo
to avoid confusion with minutesTIME_LONG
is the same asTIME_SHORT
but uses full names for the suffixes
ConfigurationKey<Handle> FORMATTER
determines whichNumberFormatter
is to be used for each individual split. The default value is the handle forSimpleNumberFormatter
ConfigurationKey<Boolean> ROUND_SMALLEST
determines if the least significant split should be rounded down to an integer value. The default value istrue
ConfigurationKey<Boolean> USE_LIST_MODIFIER
determines ifConfigurationKeys.LIST_DELIMITER
andConfigurationKeys.LIST_LAST_DELIMITER
should be used instead ofConfigurationKeys.DELIMITER
. The default value istrue
All NumberFormatter
implementations are annotated with @Component
for the Injector module and will be automatically instantiated by it.
NumberSuffixFormatter
NumberSuffixFormatter
is an interface that separates a BigDecimal
number into a mantissa and an exponent. It is used by number formatters. There are three default implementations of number suffix formatter:
ExponentSuffixFormatter
splits a number into a mantissa and an exponent based on two configuration keys:ConfigurationKey<Integer> INTERVAL
determines the interval of exponents. For values larger than 1, the exponent is rounded down to the nearest multiple of the interval, and the mantissa is scaled accordingly. A value of 3 is equivalent to engineering representation. Values smaller than 1 are not allowed. The default value is 1ConfigurationKey<Boolean> EXPONENT_PLUS
determines if the exponent should be prefixed by a plus when it is positive. The default value isfalse
CharDigitSuffixFormatter
is otherwise the same as theExponentSuffixFormatter
, but instead of regular digits, it represents the exponent in an arbitrary base with any characters as digits. It has three configuration keys:ConfigurationKey<char[]> CHARACTERS
determines the characters to be used as digits. It defaults toALPHABET
, which contains the 26 English alphabet in lowercaseConfigurationKey<Integer> INTERVAL
determines the interval of exponents. It works otherwise in the same way asExponentSuffixFormatter
’sINTERVAL
, but for values larger than 1 the exponent doesn’t represent powers of 10, but powers of 10INTERVAL
. For example, formatting the number 52500 with default characters and interval 1 would result in5.25d
, and with interval 3 the result would be52.5a
. The default value is 1ConfigurationKey<Boolean> EXPONENT_PLUS
determines if the exponent should be prefixed by a plus when it is positive. The default value isfalse
NamedSuffixFormatter
is otherwise the same as theCharDigitSuffixFormatter
, but it uses string suffixes instead of exponents. It has three configuration keys:ConfigurationKey<String[]> SUFFIXES
determines the suffixes to be used. The default value isSHORT
. Three preset split arrays are defined:SI
contains abbreviated SI unit prefixes up toQ
(Quetta, 1030)SHORT
contains abbreviated names of powers of 1000 in the short scale, up toNOg
(Novenoctogintillion, 10270)LONG
contains abbreviated names of powers of 1000 in the long scale, up toQaQD
(Quattuorquadragintilliard, 10267)
ConfigurationKey<Integer> INTERVAL
determines the interval of exponents, in the same way asCharDigitSuffixFormatter
does. The default suffixes should all use a value of 3. The default value is 3
All NumberSuffixFactory
implementations are annotated with @Component
for the Injector module and will be automatically instantiated by it.
NameConverter<T>
NameConverter<T>
is an interface that converts an object to a singular and optionally also a plural name. The name converter is used by NameText<T>
. There are two default implementations of name converter:
HandleNameConverter
converts a handle to a name by using its id. It is not plural capableHandledNameConverter
converts a handled object to a name by using its handle’s id. It is not plural capable
All NameConverter<T>
implementations are annotated with @Component
for the Injector module and will be automatically instantiated by it.
PluralConverter
PluralConverter
is an interface that converts a singular string into plural form. The default implementation DefaultPluralConverter
has three rules:
- If the string ends in
s
,x
orch
,es
is added to the end of the string - If the string ends in a consonant followed by
y
, they
is stripped andies
is added to the end of the string - In all other cases,
s
is added to the end of the string
The implementation is annotated as a @Component
for the Injector module and will be automatically instantiated by it.