From 2471d13d0b9d03a7bc63bda522e6c3bb0e5b931f Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 16 Mar 2013 19:51:08 +0100 Subject: [PATCH] Add basic metadata. --- .../net/pterodactylus/sonitus/data/Metadata.java | 100 +++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 src/main/java/net/pterodactylus/sonitus/data/Metadata.java 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()); + } + +} -- 2.7.4