From: David ‘Bombe’ Roden Date: Sat, 16 Mar 2013 18:51:08 +0000 (+0100) Subject: Add basic metadata. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=2471d13d0b9d03a7bc63bda522e6c3bb0e5b931f;p=sonitus.git Add basic metadata. --- diff --git a/src/main/java/net/pterodactylus/sonitus/data/Metadata.java b/src/main/java/net/pterodactylus/sonitus/data/Metadata.java new file mode 100644 index 0000000..22fbb27 --- /dev/null +++ b/src/main/java/net/pterodactylus/sonitus/data/Metadata.java @@ -0,0 +1,100 @@ +/* + * Sonitus - Metainfo.java - Copyright © 2013 David Roden + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.sonitus.data; + +import com.google.common.base.Optional; + +/** + * Metadata contains information about a source, e.g. the name of the content, + * the artist performing it, dates, comments, URLs, etc. The {@link Format}, + * however, is not part of the metadata because a {@link Source} already exposes + * it. + *

+ * Metadata, once created, is immutable. + * + * @author David ‘Bombe’ Roden + */ +public class Metadata { + + /** The artist performing the content. */ + private final Optional artist; + + /** The name of the content. */ + private final Optional name; + + /** Creates empty metadata. */ + public Metadata() { + this(null, null); + } + + /** + * Creates metadata with the given attributes. + * + * @param artist + * The artist performing the content (may be {@code null}) + * @param name + * The name of the content (may be {@code null}) + */ + private Metadata(String artist, String name) { + this.artist = Optional.fromNullable(artist); + this.name = Optional.fromNullable(name); + } + + /** + * Returns the artist, if any. + * + * @return The artist, or {@link Optional#absent()} + */ + public Optional artist() { + return artist; + } + + /** + * Returns new metadata with the same attributes as this metadata, except for + * the artist. + * + * @param artist + * The new artist + * @return New metadata with a changed artist + */ + public Metadata artist(String artist) { + return new Metadata(artist, this.artist.orNull()); + } + + /** + * Returns the name of the content, if any. + * + * @return The name, or {@link Optional#absent()} + */ + public Optional name() { + return name; + } + + /** + * Returns new metadata with the same attributes as this metadata, except for + * the name. + * + * @param name + * The new name + * @return New metadata with a changed name + */ + public Metadata name(String name) { + return new Metadata(name, this.name.orNull()); + } + +}