Class StringMapping<T>


  • public final class StringMapping<T>
    extends Object
    An efficient mapping of enumerated strings to some other object.
    Author:
    David M. Lloyd
    • Field Detail

      • items

        private final T[] items
    • Constructor Detail

      • StringMapping

        public StringMapping​(StringEnumeration stringEnumeration,
                             Function<String,​T> mapping)
        Construct a new instance.
        Parameters:
        stringEnumeration - the string enumeration (must not be null)
        mapping - the mapping function (must not be null)
    • Method Detail

      • getItemById

        public T getItemById​(int index)
                      throws IllegalArgumentException
        Get an item from this mapping by ID.
        Parameters:
        index - the index to look up
        Returns:
        the mapped item for the given ID
        Throws:
        IllegalArgumentException - if the given index is out of range
      • getStringEnumeration

        public StringEnumeration getStringEnumeration()
        Get the string enumeration for this mapping.
        Returns:
        the string enumeration for this mapping (not null)