Class MetadataSupport

    • Field Detail

      • path

        @Nonnull
        protected final java.nio.file.Path path
      • fallback

        @Nonnull
        protected java.util.Optional<java.util.function.Function<Key<?>,​MediaItem.Metadata>> fallback
      • properties

        protected final java.util.Map<Key<?>,​java.lang.Object> properties
    • Constructor Detail

      • MetadataSupport

        public MetadataSupport​(@Nonnull
                               java.nio.file.Path path)
    • Method Detail

      • get

        @Nonnull
        public <T> java.util.Optional<T> get​(@Nonnull
                                             Key<T> key)
        Extracts a single metadata item associated to the given key.
        Specified by:
        get in interface MediaItem.Metadata
        Type Parameters:
        T - the type of the item
        Parameters:
        key - the key
        Returns:
        the item
      • getAll

        @Nonnull
        public <T> T getAll​(@Nonnull
                            Key<T> key)
        Extracts a metadata item (typically a collection) associated to the given key.
        Specified by:
        getAll in interface MediaItem.Metadata
        Type Parameters:
        T - the type of the item
        Parameters:
        key - the key
        Returns:
        the item
      • containsKey

        public boolean containsKey​(@Nonnull
                                   Key<?> key)
        Returns true if an item with the given key is present.
        Specified by:
        containsKey in interface MediaItem.Metadata
        Parameters:
        key - the key
        Returns:
        true if found
      • getKeys

        @Nonnull
        public java.util.Set<Key<?>> getKeys()
        Returns all the keys contained in this instance.
        Specified by:
        getKeys in interface MediaItem.Metadata
        Returns:
        all the keys
      • getEntries

        @Nonnull
        public java.util.Set<java.util.Map.Entry<Key<?>,​?>> getEntries()
        Returns all the entries (key -> value) contained in this instance.
        Specified by:
        getEntries in interface MediaItem.Metadata
        Returns:
        all the entries
      • with

        @Nonnull
        public <T> MediaItem.Metadata with​(@Nonnull
                                           Key<T> key,
                                           @Nonnull
                                           T value)
        Returns a clone of this object with an additional item.
        Specified by:
        with in interface MediaItem.Metadata
        Type Parameters:
        T - the type of the item
        Parameters:
        key - the key
        value - the value
        Returns:
        the clone
      • withFallback

        @Nonnull
        public MediaItem.Metadata withFallback​(@Nonnull
                                               java.util.function.Function<Key<?>,​MediaItem.Metadata> fallback)
        Returns a clone of this object with a fallback data source; when an item is searched and not found, before giving up it will be searched in the given fallback.
        Specified by:
        withFallback in interface MediaItem.Metadata
        Parameters:
        fallback - the fallback
        Returns:
        the clone
      • with

        @Nonnull
        public <T> MediaItem.Metadata with​(@Nonnull
                                           Key<T> key,
                                           @Nonnull
                                           java.util.Optional<T> value)
        Returns a clone of this object with an additional optional value.
        Specified by:
        with in interface MediaItem.Metadata
        Type Parameters:
        T - the type of the item
        Parameters:
        key - the key
        value - the value
        Returns:
        the clone
      • put

        protected <V> void put​(@Nonnull
                               Key<V> key,
                               @Nullable
                               V value)
        FIXME: remove this, make it truly immutable.