Package net.glowstone.command
Class LocalizedEnumNames<T>
java.lang.Object
net.glowstone.command.LocalizedEnumNames<T>
- Type Parameters:
T
- the type being mapped to and from strings.
This is used to map an enum or multiton type to and from the localized names of its instances,
which have their own properties file. These properties files are unusual in that the localized
names are keys, not values; the values are integers that are mapped to instances of T using
keyResolver
.-
Constructor Summary
ConstructorDescriptionLocalizedEnumNames
(Function<String, ? extends T> keyResolver, @NonNls String unknownKey, @Nullable @NonNls String commaSeparatedNamesKey, @NonNls String baseName, boolean reversedMap) Creates an instance.LocalizedEnumNames
(IntFunction<? extends T> integerResolver, @NonNls String unknownKey, @Nullable @NonNls String commaSeparatedNamesKey, @NonNls String baseName, boolean reversedMap) Creates an instance. -
Method Summary
Modifier and TypeMethodDescriptiongetAutoCompleteSuggestions
(Locale locale, String arg) Retrieves autocomplete suggestions that are values of type T.nameToValue
(Locale locale, String name) Gets a value by its localized name.valueToName
(Locale locale, T value) Gets the localized name for an instance of T.
-
Constructor Details
-
LocalizedEnumNames
public LocalizedEnumNames(IntFunction<? extends T> integerResolver, @NonNls @NonNls String unknownKey, @Nullable @NonNls @Nullable @NonNls String commaSeparatedNamesKey, @NonNls @NonNls String baseName, boolean reversedMap) Creates an instance.- Parameters:
integerResolver
- used to map integers in the resource bundle to instances of TunknownKey
- a key in strings.properties that provides a name for unknown future valuescommaSeparatedNamesKey
- a key in strings.properties that provides canonical names for auto-complete, separated by commas; or null to build one using all values of the resource bundlebaseName
- the base name of the resource bundlereversedMap
- true if the keys and values are reversed
-
LocalizedEnumNames
public LocalizedEnumNames(Function<String, ? extends T> keyResolver, @NonNls @NonNls String unknownKey, @Nullable @NonNls @Nullable @NonNls String commaSeparatedNamesKey, @NonNls @NonNls String baseName, boolean reversedMap) Creates an instance.- Parameters:
keyResolver
- used to map keys in the resource bundle to instances of TunknownKey
- a key in strings.properties that provides a name for unknown future valuescommaSeparatedNamesKey
- a key in strings.properties that provides canonical names for auto-complete, separated by commas; or null to build one using all values of the resource bundlebaseName
- the base name of the resource bundlereversedMap
- true if the keys and values are reversed
-
-
Method Details
-
getAutoCompleteSuggestions
Retrieves autocomplete suggestions that are values of type T.- Parameters:
locale
- the input localearg
- the incomplete argument to finish- Returns:
- a list of autocomplete suggestions
-
nameToValue
Gets a value by its localized name. Both the specified locale andALSO_ACCEPT_LOCALE
are accepted, and matching is case- and accent-insensitive (perCollator.PRIMARY
).- Parameters:
locale
- the locale the user is assumed to be usingname
- the name to look up- Returns:
- the matching value, or null if none matches
-
valueToName
Gets the localized name for an instance of T.- Parameters:
locale
- the output localevalue
- the value to look up the name for- Returns:
- the localized name
-