2 * Sonitus - Metainfo.java - Copyright © 2013 David Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.sonitus.data;
20 import com.google.common.base.Optional;
23 * Metadata contains information about a source, e.g. the name of the content,
24 * the artist performing it, dates, comments, URLs, etc. The {@link Format},
25 * however, is not part of the metadata because a {@link Source} already exposes
28 * Metadata, once created, is immutable.
30 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
32 public class Metadata {
34 /** The artist performing the content. */
35 private final Optional<String> artist;
37 /** The name of the content. */
38 private final Optional<String> name;
40 /** Creates empty metadata. */
46 * Creates metadata with the given attributes.
49 * The artist performing the content (may be {@code null})
51 * The name of the content (may be {@code null})
53 private Metadata(String artist, String name) {
54 this.artist = Optional.fromNullable(artist);
55 this.name = Optional.fromNullable(name);
59 * Returns the artist, if any.
61 * @return The artist, or {@link Optional#absent()}
63 public Optional<String> artist() {
68 * Returns new metadata with the same attributes as this metadata, except for
73 * @return New metadata with a changed artist
75 public Metadata artist(String artist) {
76 return new Metadata(artist, this.artist.orNull());
80 * Returns the name of the content, if any.
82 * @return The name, or {@link Optional#absent()}
84 public Optional<String> name() {
89 * Returns new metadata with the same attributes as this metadata, except for
94 * @return New metadata with a changed name
96 public Metadata name(String name) {
97 return new Metadata(name, this.name.orNull());