Interface Metadata

  • All Known Implementing Classes:
    SimpleMetadata

    public interface Metadata
    An immutable collection of name-value pairs for simple types.

    Implementations must ensure that the only allowed data types for metadata property values are String, Boolean, Integer, Long, and Double. This should satisfy virtually any legitimate metadata need, while ensuring that metadata can be easily represented using two-dimensional structures.

    Author:
    Carl Harris
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Interface Description
      static interface  Metadata.Builder
      A builder that creates instances of Metadata.
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      <T> T get​(java.lang.String name, java.lang.Class<? extends T> type)
      Gets a metadata property value.
      boolean isEmpty()
      Tests whether this metadata object has any properties.
      java.util.Set<java.lang.String> names()
      Gets the names of the properties in this metadata collection.
      java.util.Map<java.lang.String,​java.lang.Object> toMap()
      Gets the contents of this metadata collection as a map.
    • Method Detail

      • isEmpty

        boolean isEmpty()
        Tests whether this metadata object has any properties.
        Returns:
        true if this metadata object has no properties
      • names

        java.util.Set<java.lang.String> names()
        Gets the names of the properties in this metadata collection.
        Returns:
        set of names
      • toMap

        java.util.Map<java.lang.String,​java.lang.Object> toMap()
        Gets the contents of this metadata collection as a map.
        Returns:
        map representation of this metadata; subsequent changes to the returned map will have no effect on this metadata collection
      • get

        <T> T get​(java.lang.String name,
                  java.lang.Class<? extends T> type)
        Gets a metadata property value.

        As a special case, when retrieving a numeric property value (any of the supported subtypes of Number, if the stored value is not directly assignable to the specified type, it will be coerced to the specified type using one of methods provided on the Number class for doing so.

        Type Parameters:
        T - return type
        Parameters:
        name - name of the property to retrieve.
        type - property type; the underlying implementation will restrict property values to String, Boolean, Integer, Long, Double
        Returns:
        property value or null if there is no property with the given name
        Throws:
        java.lang.ClassCastException - if the value associated with the given name cannot be cast or coerced to type.