Class EnumVocab<P extends java.lang.Enum<P>>

  • All Implemented Interfaces:
    Vocab

    public final class EnumVocab<P extends java.lang.Enum<P>>
    extends java.lang.Object
    implements Vocab
    A Vocab implementation that is backed by an Enum.

    Property names will be computed from Enum constant names by applying the following transformation:

    • The name is converted to lower case
    • The underscore character ('_') is replaced by the hyphen character ('-').
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private com.google.common.base.Converter<P,​java.lang.String> converter  
      private java.util.Map<java.lang.String,​Property> index  
      private java.lang.String uri  
    • Constructor Summary

      Constructors 
      Constructor Description
      EnumVocab​(java.lang.Class<P> clazz, com.google.common.base.CaseFormat format, java.lang.String base)
      Creates a new vocabulary backed by the given Enum class and with properties having the common URI stem base.
      EnumVocab​(java.lang.Class<P> clazz, com.google.common.base.CaseFormat format, java.lang.String base, java.lang.String prefix)
      Creates a new vocabulary backed by the given Enum class and with properties having the common URI stem base and prefix prefix
      EnumVocab​(java.lang.Class<P> clazz, java.lang.String base)
      Creates a new vocabulary backed by the given Enum class and with properties having the common URI stem base.
      EnumVocab​(java.lang.Class<P> clazz, java.lang.String base, java.lang.String prefix)
      Creates a new vocabulary backed by the given Enum class and with properties having the common URI stem base and prefix prefix
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Property get​(P property)
      Returns the Property for the given enum item contained in this vocabulary.
      java.lang.String getName​(P property)
      Returns the property name for the given enum item contained in this vocabulary.
      java.util.Collection<java.lang.String> getNames​(java.util.Collection<P> properties)
      Returns the property names of the given enum items contained in this vocabulary.
      java.lang.String getURI()
      Returns the base URI of this vocabulary.
      com.google.common.base.Optional<Property> lookup​(java.lang.String name)
      Returns whether a property in allowed in this vocabulary.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • index

        private final java.util.Map<java.lang.String,​Property> index
      • uri

        private final java.lang.String uri
      • converter

        private final com.google.common.base.Converter<P extends java.lang.Enum<P>,​java.lang.String> converter
    • Constructor Detail

      • EnumVocab

        public EnumVocab​(java.lang.Class<P> clazz,
                         java.lang.String base)
        Creates a new vocabulary backed by the given Enum class and with properties having the common URI stem base. Properties of the created vocabulary will have an empty prefix (in other words, this creates a default vocabulary).
        Parameters:
        clazz - the enumeration backing this vocabulary.
        base - the common stem URI of properties in this vocabulary.
      • EnumVocab

        public EnumVocab​(java.lang.Class<P> clazz,
                         com.google.common.base.CaseFormat format,
                         java.lang.String base)
        Creates a new vocabulary backed by the given Enum class and with properties having the common URI stem base. Properties of the created vocabulary will have an empty prefix (in other words, this creates a default vocabulary).
        Parameters:
        clazz - the enumeration backing this vocabulary.
        format - the case format used by properties in this vocabulary
        base - the common stem URI of properties in this vocabulary.
      • EnumVocab

        public EnumVocab​(java.lang.Class<P> clazz,
                         java.lang.String base,
                         java.lang.String prefix)
        Creates a new vocabulary backed by the given Enum class and with properties having the common URI stem base and prefix prefix
        Parameters:
        clazz - the enumeration backing this vocabulary.
        base - the common stem URI of properties in this vocabulary.
        prefix - the common prefix of properties in this vocabulary.
      • EnumVocab

        public EnumVocab​(java.lang.Class<P> clazz,
                         com.google.common.base.CaseFormat format,
                         java.lang.String base,
                         java.lang.String prefix)
        Creates a new vocabulary backed by the given Enum class and with properties having the common URI stem base and prefix prefix
        Parameters:
        clazz - the enumeration backing this vocabulary.
        format - the case format used by properties in this vocabulary
        base - the common stem URI of properties in this vocabulary.
        prefix - the common prefix of properties in this vocabulary.
    • Method Detail

      • lookup

        public com.google.common.base.Optional<Property> lookup​(java.lang.String name)
        Description copied from interface: Vocab
        Returns whether a property in allowed in this vocabulary.
        Specified by:
        lookup in interface Vocab
        Parameters:
        name - the property name (unprefixed).
        Returns:
        an Property reference which contains a Property if the lookup was successful or nothing if the property was not found in this vocabulary.
      • getURI

        public java.lang.String getURI()
        Description copied from interface: Vocab
        Returns the base URI of this vocabulary.
        Specified by:
        getURI in interface Vocab
        Returns:
        the base URI of this vocabulary.
      • get

        public Property get​(P property)
        Returns the Property for the given enum item contained in this vocabulary.
        Parameters:
        property - the property to look up, must not be null
        Returns:
        the result of looking up property in this vocabulary.
      • getName

        public java.lang.String getName​(P property)
        Returns the property name for the given enum item contained in this vocabulary.
        Parameters:
        property - the property to get the name of, must not be null
        Returns:
        the name of property.
      • getNames

        public java.util.Collection<java.lang.String> getNames​(java.util.Collection<P> properties)
        Returns the property names of the given enum items contained in this vocabulary.
        Parameters:
        properties - a collection of properties to get the name of, must not be null
        Returns:
        the collection of the names of properties in properties.