Add basic metadata.
[sonitus.git] / src / main / java / net / pterodactylus / sonitus / data / Metadata.java
1 /*
2  * Sonitus - Metainfo.java - Copyright © 2013 David Roden
3  *
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.
8  *
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.
13  *
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/>.
16  */
17
18 package net.pterodactylus.sonitus.data;
19
20 import com.google.common.base.Optional;
21
22 /**
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
26  * it.
27  * <p/>
28  * Metadata, once created, is immutable.
29  *
30  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
31  */
32 public class Metadata {
33
34         /** The artist performing the content. */
35         private final Optional<String> artist;
36
37         /** The name of the content. */
38         private final Optional<String> name;
39
40         /** Creates empty metadata. */
41         public Metadata() {
42                 this(null, null);
43         }
44
45         /**
46          * Creates metadata with the given attributes.
47          *
48          * @param artist
49          *              The artist performing the content (may be {@code null})
50          * @param name
51          *              The name of the content (may be {@code null})
52          */
53         private Metadata(String artist, String name) {
54                 this.artist = Optional.fromNullable(artist);
55                 this.name = Optional.fromNullable(name);
56         }
57
58         /**
59          * Returns the artist, if any.
60          *
61          * @return The artist, or {@link Optional#absent()}
62          */
63         public Optional<String> artist() {
64                 return artist;
65         }
66
67         /**
68          * Returns new metadata with the same attributes as this metadata, except for
69          * the artist.
70          *
71          * @param artist
72          *              The new artist
73          * @return New metadata with a changed artist
74          */
75         public Metadata artist(String artist) {
76                 return new Metadata(artist, this.artist.orNull());
77         }
78
79         /**
80          * Returns the name of the content, if any.
81          *
82          * @return The name, or {@link Optional#absent()}
83          */
84         public Optional<String> name() {
85                 return name;
86         }
87
88         /**
89          * Returns new metadata with the same attributes as this metadata, except for
90          * the name.
91          *
92          * @param name
93          *              The new name
94          * @return New metadata with a changed name
95          */
96         public Metadata name(String name) {
97                 return new Metadata(name, this.name.orNull());
98         }
99
100 }