Package me.datafox.dfxengine.text
Class TextFactoryImpl
java.lang.Object
me.datafox.dfxengine.text.TextFactoryImpl
- All Implemented Interfaces:
TextFactory
Implementation of
TextFactory, a singleton class that generates Strings from Text
objects. It manages Names, NameConverters,
NumberFormatters, NumberSuffixFacctories,
TextConfiguration and the PluralConverter. This class is designed to be used with the
Injector.-
Constructor Summary
ConstructorsConstructorDescriptionTextFactoryImpl(org.slf4j.Logger logger, HandleManager handleManager, TextHandles handles, List<Name<?>> names, List<NameConverter<?>> nameConverters, List<NumberFormatter> numberFormatters, List<NumberSuffixFormatter> numberSuffixFormatters, PluralConverter pluralConverter) -
Method Summary
Modifier and TypeMethodDescription<T> Name<T> <T> voidaddNameConverter(NameConverter<T> converter) voidaddNumberFormatter(NumberFormatter formatter) voidaddNumberSuffixFormatter(NumberSuffixFormatter formatter) If no defaultNumberSuffixFormatteris set and thisNumberSuffixFormattercan format any number (NumberSuffixFormatter.isInfinite()returnstrue), it will be set as default.<T> Name<T> createName(T object, String name) ThePluralConverteris used to generate the plural form.<T> Name<T> createName(T object, String singular, String plural) This method should always return the sameTextConfigurationinstance.<T> Name<T> getName(T object) If aNameassociated with the object is present, it is returned.<T> StringgetName(T object, boolean plural) If aNameassociated with the object is present, it is used.<T> NameConverter<T> getNameConverter(Class<T> type) getNumberFormatter(Handle handle) getNumberFormatter(TextConfiguration configuration) getNumberSuffixFormatter(Handle handle) getNumberSuffixFormatter(TextConfiguration configuration) voidinitialize(List<TextConfiguration> configurations) voidsetConfiguration(TextConfiguration configuration) Clears currentTextConfigurationand applies the provided one to it.voidThe defaultNumberSuffixFormattermust be capable of formatting any number (NumberSuffixFormatter.isInfinite()returnstrue).voidsetPluralConverter(PluralConverter converter) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface me.datafox.dfxengine.text.api.TextFactory
getHandleManager
-
Constructor Details
-
TextFactoryImpl
public TextFactoryImpl(org.slf4j.Logger logger, HandleManager handleManager, TextHandles handles, List<Name<?>> names, List<NameConverter<?>> nameConverters, List<NumberFormatter> numberFormatters, List<NumberSuffixFormatter> numberSuffixFormatters, PluralConverter pluralConverter) - Parameters:
logger-Loggerfor this factoryhandleManager-HandleManagerfor this factoryhandles-TextHandlesfor this factorynames-Namesfor this factorynameConverters-NameConvertersfor this factorynumberFormatters-NumberFormattersfor this factorynumberSuffixFormatters-NumberSuffixFormattersfor this factorypluralConverter-PluralConverterfor this factory
-
-
Method Details
-
build
- Specified by:
buildin interfaceTextFactory- Parameters:
text-Textobject to build- Returns:
Stringrepresentation of the text
-
build
- Specified by:
buildin interfaceTextFactory- Parameters:
texts-Textobjects to build- Returns:
Stringrepresentation of the texts
-
createName
ThePluralConverteris used to generate the plural form.- Specified by:
createNamein interfaceTextFactory- Type Parameters:
T- type of the object- Parameters:
object- object to be namedname- name for the object in singular form- Returns:
Nameassociated with the object
-
createName
- Specified by:
createNamein interfaceTextFactory- Type Parameters:
T- type of the object to be named- Parameters:
object- object to be namedsingular- name for the object in singular formplural- name for the object in plural form- Returns:
Nameassociated with the object
-
addName
- Specified by:
addNamein interfaceTextFactory- Type Parameters:
T- type of the object to be named- Parameters:
name-Nameobject- Returns:
- previous
Nameassociated with the owner, ornullif no previous mapping is present
-
getName
Description copied from interface:TextFactoryIf aNameassociated with the object is present, it is returned. Otherwise, a new Name is created usingNameConverterif a valid one is present orObject.toString()if not. ThePluralConverterwill be used for the plural form if theNameConverteris not plural capable or not present.- Specified by:
getNamein interfaceTextFactory- Type Parameters:
T- type of the object to be named- Parameters:
object- object to be named- Returns:
Nameassociated with the object
-
getName
Description copied from interface:TextFactoryIf aNameassociated with the object is present, it is used. Otherwise, a new Name is created usingNameConverterif a valid one is present orObject.toString()if not. ThePluralConverterwill be used for the plural form if theNameConverteris not plural capable or not present.- Specified by:
getNamein interfaceTextFactory- Type Parameters:
T- type of the object to be named- Parameters:
object- object to be namedplural- iftrue, the plural form is returned- Returns:
- name of the object
-
addNameConverter
- Specified by:
addNameConverterin interfaceTextFactory- Type Parameters:
T- type of the object that thisNameConverteris capable of converting- Parameters:
converter-NameConverterto be registered
-
getNameConverter
- Specified by:
getNameConverterin interfaceTextFactory- Type Parameters:
T- type of the object to be named- Parameters:
type-Classof the object to be named- Returns:
NameConverterassociated with the type or any of its interfaces or superclasses
-
addNumberFormatter
- Specified by:
addNumberFormatterin interfaceTextFactory- Parameters:
formatter-NumberFormatterto be registered
-
getNumberFormatter
- Specified by:
getNumberFormatterin interfaceTextFactory- Parameters:
handle-Handleof aNumberFormatter- Returns:
NumberFormatterassociated with theHandleornullif none is present
-
getNumberFormatter
- Specified by:
getNumberFormatterin interfaceTextFactory- Parameters:
configuration-TextConfigurationto be used- Returns:
NumberFormatterconfigured in theTextConfigurationornullif none is present
-
addNumberSuffixFormatter
If no defaultNumberSuffixFormatteris set and thisNumberSuffixFormattercan format any number (NumberSuffixFormatter.isInfinite()returnstrue), it will be set as default.- Specified by:
addNumberSuffixFormatterin interfaceTextFactory- Parameters:
formatter-NumberSuffixFormatterto be registered
-
getNumberSuffixFormatter
- Specified by:
getNumberSuffixFormatterin interfaceTextFactory- Parameters:
handle-Handleof aNumberSuffixFormatter- Returns:
NumberSuffixFormatterassociated with theHandleornullif none is present
-
getNumberSuffixFormatter
- Specified by:
getNumberSuffixFormatterin interfaceTextFactory- Parameters:
configuration-TextConfigurationto be used- Returns:
NumberSuffixFormatterconfigured in theTextConfigurationornullif none is present
-
setDefaultNumberSuffixFormatter
The defaultNumberSuffixFormattermust be capable of formatting any number (NumberSuffixFormatter.isInfinite()returnstrue).- Specified by:
setDefaultNumberSuffixFormatterin interfaceTextFactory- Parameters:
formatter-NumberSuffixFormatterto be set as default
-
getDefaultNumberSuffixFormatter
- Specified by:
getDefaultNumberSuffixFormatterin interfaceTextFactory- Returns:
- default
NumberSuffixFormatterornullif none is present
-
setConfiguration
Clears currentTextConfigurationand applies the provided one to it. This method should not overwrite the currentTextConfigurationinstance and only alter its state.- Specified by:
setConfigurationin interfaceTextFactory- Parameters:
configuration-TextConfigurationto be applied
-
getConfiguration
Description copied from interface:TextFactoryThis method should always return the sameTextConfigurationinstance.- Specified by:
getConfigurationin interfaceTextFactory- Returns:
- current
TextConfiguration
-
setPluralConverter
- Specified by:
setPluralConverterin interfaceTextFactory- Parameters:
converter-PluralConverterto be registered
-
getPluralConverter
- Specified by:
getPluralConverterin interfaceTextFactory- Returns:
- registered
PluralConverterornullif none is present
-
initialize
-