Class LocalizedEnumNames<T>

java.lang.Object
net.glowstone.command.LocalizedEnumNames<T>
Type Parameters:
T - the type being mapped to and from strings.

public class LocalizedEnumNames<T> extends Object
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 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 T
      unknownKey - a key in strings.properties that provides a name for unknown future values
      commaSeparatedNamesKey - 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 bundle
      baseName - the base name of the resource bundle
      reversedMap - 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 T
      unknownKey - a key in strings.properties that provides a name for unknown future values
      commaSeparatedNamesKey - 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 bundle
      baseName - the base name of the resource bundle
      reversedMap - true if the keys and values are reversed
  • Method Details

    • getAutoCompleteSuggestions

      @NotNull public @NotNull List<String> getAutoCompleteSuggestions(Locale locale, String arg)
      Retrieves autocomplete suggestions that are values of type T.
      Parameters:
      locale - the input locale
      arg - the incomplete argument to finish
      Returns:
      a list of autocomplete suggestions
    • nameToValue

      @Nullable public T nameToValue(Locale locale, String name)
      Gets a value by its localized name. Both the specified locale and ALSO_ACCEPT_LOCALE are accepted, and matching is case- and accent-insensitive (per Collator.PRIMARY).
      Parameters:
      locale - the locale the user is assumed to be using
      name - the name to look up
      Returns:
      the matching value, or null if none matches
    • valueToName

      public String valueToName(Locale locale, T value)
      Gets the localized name for an instance of T.
      Parameters:
      locale - the output locale
      value - the value to look up the name for
      Returns:
      the localized name