1 /*
2  * aTunes
3  * Copyright (C) Alex Aranda, Sylvain Gaudard and contributors
4  *
5  * See http://www.atunes.org/wiki/index.php?title=Contributing for information about contributors
6  *
7  * http://www.atunes.org
8  * http://sourceforge.net/projects/atunes
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  */
20 
21 package net.sourceforge.atunes.kernel.modules.tags;
22 
23 import java.io.Serializable;
24 
25 import net.sourceforge.atunes.model.ITag;
26 
27 import org.joda.time.base.BaseDateTime;
28 
29 /**
30  * The abstract class for tags.
31  *
32  * @author fleax
33  */
34 public abstract class AbstractTag implements Serializable, ITag {
35 
36 	private static final long serialVersionUID = -4044670497563446883L;
37 
38 	/** The title. */
39 	String title;
40 
41 	/** The artist. */
42 	String artist;
43 
44 	/** The album. */
45 	String album;
46 
47 	/** The year. */
48 	int year;
49 
50 	/** The date. */
51 	BaseDateTime date;
52 
53 	/** The comment. */
54 	String comment;
55 
56 	/** The genre. */
57 	String genre;
58 
59 	/** The lyrics. */
60 	String lyrics;
61 
62 	/** The composer. */
63 	String composer;
64 
65 	/** The album artist. */
66 	String albumArtist;
67 
68 	/** The track number. */
69 	int trackNumber;
70 
71 	/** The disc number */
72 	int discNumber;
73 
74 	/**
75 	 * Rating
76 	 */
77 	int stars;
78 
79 	/** If this tag has an internal image */
80 	boolean internalImage;
81 
82 	@Override
getAlbum()83 	public String getAlbum() {
84 		return this.album;
85 	}
86 
87 	@Override
getAlbumArtist()88 	public String getAlbumArtist() {
89 		return this.albumArtist;
90 	}
91 
92 	@Override
getArtist()93 	public String getArtist() {
94 		return this.artist;
95 	}
96 
97 	@Override
getComment()98 	public String getComment() {
99 		return this.comment;
100 	}
101 
102 	@Override
getComposer()103 	public String getComposer() {
104 		return this.composer;
105 	}
106 
107 	@Override
getGenre()108 	public String getGenre() {
109 		return this.genre;
110 	}
111 
112 	@Override
getLyrics()113 	public String getLyrics() {
114 		return this.lyrics;
115 	}
116 
117 	@Override
getTitle()118 	public String getTitle() {
119 		return this.title;
120 	}
121 
122 	@Override
getTrackNumber()123 	public int getTrackNumber() {
124 		return this.trackNumber >= 0 ? this.trackNumber : 0;
125 	}
126 
127 	@Override
getYear()128 	public int getYear() {
129 		if (this.date != null) {
130 			return this.date.getYear();
131 		} else if (this.year >= 0) {
132 			return this.year;
133 		} else {
134 			return 0;
135 		}
136 	}
137 
138 	@Override
getDate()139 	public BaseDateTime getDate() {
140 		return this.date;
141 	}
142 
143 	@Override
setAlbum(final String album)144 	public void setAlbum(final String album) {
145 		this.album = album != null ? album.trim() : "";
146 	}
147 
148 	@Override
setAlbumArtist(final String albumArtist)149 	public void setAlbumArtist(final String albumArtist) {
150 		this.albumArtist = albumArtist != null ? albumArtist.trim() : "";
151 	}
152 
153 	@Override
setArtist(final String artist)154 	public void setArtist(final String artist) {
155 		this.artist = artist != null ? artist.trim() : "";
156 	}
157 
158 	@Override
setComment(final String comment)159 	public void setComment(final String comment) {
160 		this.comment = comment != null ? comment.trim() : "";
161 	}
162 
163 	@Override
setComposer(final String composer)164 	public void setComposer(final String composer) {
165 		this.composer = composer != null ? composer.trim() : "";
166 	}
167 
168 	@Override
setGenre(final String genre)169 	public void setGenre(final String genre) {
170 		this.genre = genre != null ? genre.trim() : "";
171 	}
172 
173 	@Override
setLyrics(final String lyrics)174 	public void setLyrics(final String lyrics) {
175 		this.lyrics = lyrics != null ? lyrics : "";
176 	}
177 
178 	@Override
setTitle(final String title)179 	public void setTitle(final String title) {
180 		this.title = title != null ? title.trim() : "";
181 	}
182 
183 	@Override
setTrackNumber(final int tracknumber)184 	public void setTrackNumber(final int tracknumber) {
185 		this.trackNumber = tracknumber;
186 	}
187 
188 	@Override
setYear(final int year)189 	public void setYear(final int year) {
190 		// only update year if it is not derived from the date
191 		if (this.date == null) {
192 			this.year = year;
193 		}
194 	}
195 
196 	@Override
setDate(final BaseDateTime date)197 	public void setDate(final BaseDateTime date) {
198 		this.date = date;
199 	}
200 
201 	@Override
hasInternalImage()202 	public boolean hasInternalImage() {
203 		return this.internalImage;
204 	}
205 
206 	@Override
setInternalImage(final boolean internalImage)207 	public void setInternalImage(final boolean internalImage) {
208 		this.internalImage = internalImage;
209 	}
210 
211 	@Override
getDiscNumber()212 	public int getDiscNumber() {
213 		return this.discNumber >= 0 ? this.discNumber : 0;
214 	}
215 
216 	@Override
setDiscNumber(final int discNumber)217 	public void setDiscNumber(final int discNumber) {
218 		this.discNumber = discNumber;
219 	}
220 
221 	/**
222 	 * @return the stars
223 	 */
224 	@Override
getStars()225 	public int getStars() {
226 		return this.stars;
227 	}
228 
229 	/**
230 	 * @param stars
231 	 *            the stars to set
232 	 */
233 	@Override
setStars(final int stars)234 	public void setStars(final int stars) {
235 		this.stars = stars;
236 	}
237 }
238