Package me.datafox.dfxengine.text.api
Interface TextFactory
- All Known Implementing Classes:
TextFactoryImpl
public interface TextFactory
A singleton class that generates
Strings from Text objects. It manages Names,
NameConverters, NumberFormatters,
NumberSuffixFacctories, TextConfiguration and the 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) 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)
-
Method Details
-
build
-
build
-
getHandleManager
HandleManager getHandleManager()- Returns:
HandleManagerused by this factory
-
createName
ThePluralConverteris used to generate the plural form.- 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
- 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
-
getName
If 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.- Type Parameters:
T- type of the object to be named- Parameters:
object- object to be named- Returns:
Nameassociated with the object
-
getName
If 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.- 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
- Type Parameters:
T- type of the object that thisNameConverteris capable of converting- Parameters:
converter-NameConverterto be registered
-
getNameConverter
- 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
- Parameters:
formatter-NumberFormatterto be registered
-
getNumberFormatter
- Parameters:
handle-Handleof aNumberFormatter- Returns:
NumberFormatterassociated with theHandleornullif none is present
-
getNumberFormatter
- 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.- Parameters:
formatter-NumberSuffixFormatterto be registered
-
getNumberSuffixFormatter
- Parameters:
handle-Handleof aNumberSuffixFormatter- Returns:
NumberSuffixFormatterassociated with theHandleornullif none is present
-
getNumberSuffixFormatter
- Parameters:
configuration-TextConfigurationto be used- Returns:
NumberSuffixFormatterconfigured in theTextConfigurationornullif none is present
-
setDefaultNumberSuffixFormatter
The defaultNumberSuffixFormattermust be capable of formatting any number (NumberSuffixFormatter.isInfinite()returnstrue).- Parameters:
formatter-NumberSuffixFormatterto be set as default
-
getDefaultNumberSuffixFormatter
NumberSuffixFormatter getDefaultNumberSuffixFormatter()- 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.- Parameters:
configuration-TextConfigurationto be applied
-
getConfiguration
TextConfiguration getConfiguration()This method should always return the sameTextConfigurationinstance.- Returns:
- current
TextConfiguration
-
setPluralConverter
- Parameters:
converter-PluralConverterto be registered
-
getPluralConverter
PluralConverter getPluralConverter()- Returns:
- registered
PluralConverterornullif none is present
-