Class MetadataSupport
- java.lang.Object
-
- it.tidalwave.bluemarine2.model.spi.MetadataSupport
-
- All Implemented Interfaces:
MediaItem.Metadata
public class MetadataSupport extends java.lang.Object implements MediaItem.Metadata
- Author:
- Fabrizio Giudici
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface it.tidalwave.bluemarine2.model.MediaItem.Metadata
MediaItem.Metadata.Cddb, MediaItem.Metadata.ITunesComment
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Optional<java.util.function.Function<Key<?>,MediaItem.Metadata>>
fallback
protected java.nio.file.Path
path
protected java.util.Map<Key<?>,java.lang.Object>
properties
-
Fields inherited from interface it.tidalwave.bluemarine2.model.MediaItem.Metadata
ALBUM, ARTIST, ARTWORK, BIT_RATE, BITS_PER_SAMPLE, CDDB, CHANNELS, COMMENT, COMPOSER, DISK_COUNT, DISK_NUMBER, DURATION, ENCODER, ENCODING_TYPE, FILE_SIZE, FORMAT, ITUNES_COMMENT, MBZ_ARTIST_ID, MBZ_DISC_ID, MBZ_TRACK_ID, MBZ_WORK_ID, PUBLISHER, SAMPLE_RATE, TITLE, TRACK_NUMBER, YEAR
-
-
Constructor Summary
Constructors Constructor Description MetadataSupport(java.nio.file.Path path)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
containsKey(Key<?> key)
Returnstrue
if an item with the given key is present.<T> java.util.Optional<T>
get(Key<T> key)
Extracts a single metadata item associated to the given key.<T> T
getAll(Key<T> key)
Extracts a metadata item (typically a collection) associated to the given key.java.util.Set<java.util.Map.Entry<Key<?>,?>>
getEntries()
Returns all the entries (key -> value) contained in this instance.java.util.Set<Key<?>>
getKeys()
Returns all the keys contained in this instance.protected <V> void
put(Key<V> key, V value)
FIXME: remove this, make it truly immutable.<T> MediaItem.Metadata
with(Key<T> key, java.util.Optional<T> value)
Returns a clone of this object with an additional optional value.<T> MediaItem.Metadata
with(Key<T> key, T value)
Returns a clone of this object with an additional item.MediaItem.Metadata
withFallback(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.
-
-
-
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
-
-
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 interfaceMediaItem.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 interfaceMediaItem.Metadata
- Type Parameters:
T
- the type of the item- Parameters:
key
- the key- Returns:
- the item
-
containsKey
public boolean containsKey(@Nonnull Key<?> key)
Returnstrue
if an item with the given key is present.- Specified by:
containsKey
in interfaceMediaItem.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 interfaceMediaItem.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 interfaceMediaItem.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 interfaceMediaItem.Metadata
- Type Parameters:
T
- the type of the item- Parameters:
key
- the keyvalue
- 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 interfaceMediaItem.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 interfaceMediaItem.Metadata
- Type Parameters:
T
- the type of the item- Parameters:
key
- the keyvalue
- the value- Returns:
- the clone
-
put
protected <V> void put(@Nonnull Key<V> key, @Nullable V value)
FIXME: remove this, make it truly immutable.
-
-