Class ExtendedEnum.ExternalEnumNames<T extends Named>

  • Type Parameters:
    T - the type of the enum
    Enclosing class:
    ExtendedEnum<T extends Named>

    public static final class ExtendedEnum.ExternalEnumNames<T extends Named>
    extends java.lang.Object
    Maps names used by external systems to the standard name used here.

    A frequent problem in parsing external file formats is converting enum values. This class provides a suitable mapping, allowing multiple external names to map to one standard name.

    A single instance represents the mapping for a single external group. This allows the mapping for different groups to differ. For example, the mapping used by FpML may differ from that used by Bloomberg.

    Instances of this class are configured via INI files and provided via ExtendedEnum.

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      ImmutableMap<java.lang.String,​java.lang.String> externalNames()
      Returns the complete map of external name to standard name.
      T lookup​(java.lang.String name)
      Looks up an instance by name.
      <S extends T>
      S
      lookup​(java.lang.String name, java.lang.Class<S> subtype)
      Looks up an instance by name and type.
      java.lang.String reverseLookup​(T namedEnum)
      Looks up the external name given a standard enum instance.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Method Detail

      • lookup

        public T lookup​(java.lang.String name)
        Looks up an instance by name.

        This finds the instance matching the specified name. Instances may have alternate names (aliases), thus the returned instance may have a name other than that requested.

        Parameters:
        name - the enum name to return
        Returns:
        the named enum
        Throws:
        java.lang.IllegalArgumentException - if the name is not found
      • lookup

        public <S extends T> S lookup​(java.lang.String name,
                                      java.lang.Class<S> subtype)
        Looks up an instance by name and type.

        This finds the instance matching the specified name, ensuring it is of the specified type. Instances may have alternate names (aliases), thus the returned instance may have a name other than that requested.

        Type Parameters:
        S - the enum subtype
        Parameters:
        subtype - the enum subtype to match
        name - the enum name to return
        Returns:
        the named enum
        Throws:
        java.lang.IllegalArgumentException - if the name is not found or has the wrong type
      • externalNames

        public ImmutableMap<java.lang.String,​java.lang.String> externalNames()
        Returns the complete map of external name to standard name.

        The map is keyed by the external name.

        Returns:
        the map of external names
      • reverseLookup

        public java.lang.String reverseLookup​(T namedEnum)
        Looks up the external name given a standard enum instance.

        This searches the map of external names and returns the first matching entry that maps to the given standard name.

        Parameters:
        namedEnum - the named enum to find an external name for
        Returns:
        the external name
        Throws:
        java.lang.IllegalArgumentException - if there is no external name
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object