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> DELIMITERdetermines the delimiter used in normal concatenation. The default value is “” (a whitespace)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 theNumberFormatterto be used when formatting numbersConfigurationKey<Handle> NUMBER_SUFFIX_FORMATTERdetermines theNumberSuffixFormatterto 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 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_PLURALwhich uses the plural form of the name iftrue. The default value isfalseNumberTexttakes in aSupplier<Number>and returns the formatted version of the supplied number on generation. The number is formatted using theConfigurationKeys.NUMBER_FORMATTERandConfigurationKeys.NUMBER_SUFFIX_FORMATTERconfiguration keysNumeralTextis the same asNumberText, but works on numerals from the Math module instead of regular numbersValueTextis 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 iftrueand theValue.getBase()method iffalse. The default value istrueChainedTexttakes in any amount of other text objects and chains them together using delimiters. It has oneConfigurationKey<Boolean>calledUSE_LIST_MODIFIERwhich usesConfigurationKeys.LIST_DELIMITERandConfigurationKeys.LIST_LAST_DELIMITERiftrueandConfigurationKeys.DELIMITERiffalse. 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:
SimpleNumberFormatteris the simplest number formatter. It has three configuration keys:ConfigurationKey<Integer> PRECISIONdetermines the precision of the formatted number. This is directly equivalent toMathContext.getPrecision(). The default value is 6ConfigurationKey<Integer> MIN_EXPONENTdetermines the minimum power of ten that the number must be before aNumberSuffixFormatteris 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_ZEROSdetermines if trailing zeros after a decimal point should be stripped. The default value istrue
EvenLengthNumberFormatterworks 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> LENGTHdetermines how many characters the resulting string should be in length. Values smaller than 7 are not recommended. The default value is 8ConfigurationKey<Integer> MIN_EXPONENTdetermines the minimum power of ten that the number must be before aNumberSuffixFormatteris 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_ZEROSdetermines if numbers resulting in fewer characters thanLENGHTshould be padded with a decimal separator (if one is not present already) and trailing zeros. The default value istrue
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 isTIME_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 withmoto avoid confusion with minutesTIME_LONGis the same asTIME_SHORTbut uses full names for the suffixes
ConfigurationKey<Handle> FORMATTERdetermines whichNumberFormatteris to be used for each individual split. The default value is the handle forSimpleNumberFormatterConfigurationKey<Boolean> ROUND_SMALLESTdetermines if the least significant split should be rounded down to an integer value. The default value istrueConfigurationKey<Boolean> USE_LIST_MODIFIERdetermines ifConfigurationKeys.LIST_DELIMITERandConfigurationKeys.LIST_LAST_DELIMITERshould 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:
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 1ConfigurationKey<Boolean> EXPONENT_PLUSdetermines if the exponent should be prefixed by a plus when it is positive. The default value isfalse
CharDigitSuffixFormatteris 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[]> CHARACTERSdetermines the characters to be used as digits. It defaults toALPHABET, which contains the 26 English alphabet in lowercaseConfigurationKey<Integer> INTERVALdetermines 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_PLUSdetermines if the exponent should be prefixed by a plus when it is positive. The default value isfalse
NamedSuffixFormatteris otherwise the same as theCharDigitSuffixFormatter, but it uses string suffixes instead of exponents. It has three configuration keys:ConfigurationKey<String[]> SUFFIXESdetermines the suffixes to be used. The default value isSHORT. Three preset split arrays are defined:SIcontains abbreviated SI unit prefixes up toQ(Quetta, 1030)SHORTcontains abbreviated names of powers of 1000 in the short scale, up toNOg(Novenoctogintillion, 10270)LONGcontains abbreviated names of powers of 1000 in the long scale, up toQaQD(Quattuorquadragintilliard, 10267)
ConfigurationKey<Integer> INTERVALdetermines the interval of exponents, in the same way asCharDigitSuffixFormatterdoes. 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 capableHandledNameConverterconverts 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,xorch,esis added to the end of the string - If the string ends in a consonant followed by
y, 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.
