This is an old revision of the document!
Table of Contents
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> DELIMITERdetermines the delimiter used in normal concatenation. The default value is “- ConfigurationKey<String> LIST_DELIMITERdetermines 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_DELIMITERdetermines the last delimiter used in list concatenation. The default value is “- and”
- ConfigurationKey<Handle> NUMBER_FORMATTERdetermines the- NumberFormatterto be used when formatting numbers
- ConfigurationKey<Handle> NUMBER_SUFFIX_FORMATTERdetermines the- NumberSuffixFormatterto 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:
- StaticTextis the simplest text implementation. It takes in a string and returns it on generation
- ConfigurationText<T>takes in a- ConfigurationKey<T>and a- Function<T,String>, and returns the configuration value ran through the function on generation
- NameText<T>takes in a- Supplier<T>and returns the name for the supplied object on generation. Name is resolved with- TextFactory.getName(T). It has one- ConfigurationKey<Boolean>called- USE_PLURALwhich uses the plural form of the name if- true. The default value is- false
- NumberTexttakes in a- Supplier<Number>and returns the formatted version of the supplied number on generation. The number is formatted using the- ConfigurationKeys.NUMBER_FORMATTERand- ConfigurationKeys.NUMBER_SUFFIX_FORMATTERconfiguration keys
- NumeralTextis the same as- NumberText, but works on numerals from the Math module instead of regular numbers
- ValueTextis the same as- NumberText, but works on values from the Values module instead of regular numbers. It also has a- ConfigurationKey<Boolean>called- USE_MODIFIED, which uses the- Value.getValue()method if- trueand the- Value.getBase()method if- false. The default value is- true
- ChainedTexttakes in any amount of other text objects and chains them together using delimiters. It has one- ConfigurationKey<Boolean>called- USE_LIST_MODIFIERwhich uses- ConfigurationKeys.LIST_DELIMITERand- ConfigurationKeys.LIST_LAST_DELIMITERif- trueand- ConfigurationKeys.DELIMITERif- false. The default value is- false
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:
- SimpleNumberFormatteris the simplest number formatter. It has three configuration keys:- ConfigurationKey<Integer> PRECISIONdetermines the precision of the formatted number. This is directly equivalent to- MathContext.getPrecision(). The default value is 6
- ConfigurationKey<Integer> MIN_EXPONENTdetermines the minimum power of ten that the number must be before a- NumberSuffixFormatteris used to generate an exponential suffix for the number. This value must be smaller than or equal to- PRECISION. The default value is 3
- ConfigurationKey<Boolean> STRIP_ZEROSdetermines if trailing zeros after a decimal point should be stripped. The default value is- true
 
- EvenLengthNumberFormatterworks mostly in the same way as the- SimpleNumberFormatter, but tries to format all numbers to take the same amount of characters. It has three configuration keys:- ConfigurationKey<Integer> LENGTHdetermines how many characters the resulting string should be in length. Values smaller than 7 are not recommended. The default value is 8
- ConfigurationKey<Integer> MIN_EXPONENTdetermines the minimum power of ten that the number must be before a- NumberSuffixFormatteris used to generate an exponential suffix for the number. This value must be smaller than or equal to- LENGTH. The default value is 3
- ConfigurationKey<Boolean> PAD_ZEROSdetermines if numbers resulting in fewer characters than- LENGHTshould be padded with a decimal separator (if one is not present already) and trailing zeros. The default value is- true
 
- SplittingNumberFormattersplits a number into multiple parts. This is most useful when formatting durations of time. It has four configuration keys:- ConfigurationKey<Split[]> SPLITSdetermines 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 is- TIME_SHORT. Two preset split arrays are defined:- TIME_SHORTsplits 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 with- moto avoid confusion with minutes
- TIME_LONGis the same as- TIME_SHORTbut uses full names for the suffixes
 
- ConfigurationKey<Handle> FORMATTERdetermines which- NumberFormatteris to be used for each individual split. The default value is the handle for- SimpleNumberFormatter
- ConfigurationKey<Boolean> ROUND_SMALLESTdetermines if the least significant split should be rounded down to an integer value. The default value is- true
- ConfigurationKey<Boolean> USE_LIST_MODIFIERdetermines if- ConfigurationKeys.LIST_DELIMITERand- ConfigurationKeys.LIST_LAST_DELIMITERshould be used instead of- ConfigurationKeys.DELIMITER. The default value is- true
 
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:
- ExponentSuffixFormattersplits a number into a mantissa and an exponent based on two configuration keys:- ConfigurationKey<Integer> INTERVALdetermines 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 1
- ConfigurationKey<Boolean> EXPONENT_PLUSdetermines if the exponent should be prefixed by a plus when it is positive. The default value is- false
 
- CharDigitSuffixFormatteris otherwise the same as the- ExponentSuffixFormatter, 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[]> CHARACTERSdetermines the characters to be used as digits. It defaults to- ALPHABET, which contains the 26 English alphabet in lowercase
- ConfigurationKey<Integer> INTERVALdetermines the interval of exponents. It works otherwise in the same way as- ExponentSuffixFormatter’s- INTERVAL, but for values larger than 1 the exponent doesn’t represent powers of 10, but powers of 10- INTERVAL. For example, formatting the number 52500 with default characters and interval 1 would result in- 5.25d, and with interval 3 the result would be- 52.5a. The default value is 1
- ConfigurationKey<Boolean> EXPONENT_PLUSdetermines if the exponent should be prefixed by a plus when it is positive. The default value is- false
 
- NamedSuffixFormatteris otherwise the same as the- CharDigitSuffixFormatter, but it uses string suffixes instead of exponents. It has three configuration keys:- ConfigurationKey<String[]> SUFFIXESdetermines the suffixes to be used. The default value is- SHORT. Three preset split arrays are defined:- SIcontains abbreviated SI unit prefixes up to- Q(Quetta, 1030)
- SHORTcontains abbreviated names of powers of 1000 in the short scale, up to- NOg(Novenoctogintillion, 10270)
- LONGcontains abbreviated names of powers of 1000 in the long scale, up to- QaQD(Quattuorquadragintilliard, 10267)
 
- ConfigurationKey<Integer> INTERVALdetermines the interval of exponents, in the same way as- CharDigitSuffixFormatterdoes. 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:
- HandleNameConverterconverts a handle to a name by using its id. It is not plural capable
- HandledNameConverterconverts 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 ins,xorch,esis added to the end of the string
- If the string ends in a consonant followed byy, theyis stripped andiesis added to the end of the string
- In all other cases,sis 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.
