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.util.ArrayList;
24 import java.util.List;
25 
26 /**
27  * Access genres
28  *
29  * @author alex
30  *
31  */
32 public class Genres {
33 
34     private List<String> genres;
35 
36     /**
37      * @param genres
38      */
setGenres(final List<String> genres)39     public void setGenres(final List<String> genres) {
40 	this.genres = genres;
41     }
42 
43     /**
44      * Tries to find the string provided in the table and returns the
45      * corresponding int code if successful. Returns -1 if the genres is not
46      * found in the table.
47      *
48      * @param str
49      *            the genre to search for
50      *
51      * @return the integer code for the genre or -1 if the genre is not found
52      */
getGenre(final String str)53     public int getGenre(final String str) {
54 	int retval = -1;
55 
56 	for (int i = 0; (i < genres.size()); i++) {
57 	    if (genres.get(i).equalsIgnoreCase(str)) {
58 		retval = i;
59 		break;
60 	    }
61 	}
62 
63 	return retval;
64     }
65 
66     /**
67      * Gets the genre for code.
68      *
69      * @param code
70      *            the code
71      *
72      * @return the genre for code
73      */
getGenreForCode(final int code)74     public final String getGenreForCode(final int code) {
75 	return code >= 0 && code < genres.size() ? genres.get(code) : "";
76     }
77 
78     /**
79      * @return genres list
80      */
getGenres()81     public List<String> getGenres() {
82 	return new ArrayList<String>(this.genres);
83     }
84 }
85