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.webservices.lastfm.data;
22 
23 import java.util.ArrayList;
24 import java.util.Collection;
25 import java.util.List;
26 
27 import net.sourceforge.atunes.model.IAlbumInfo;
28 import net.sourceforge.atunes.model.IAlbumListInfo;
29 import de.umass.lastfm.Album;
30 
31 /**
32  * A list of last.fm albums
33  *
34  * @author alex
35  *
36  */
37 public class LastFmAlbumList implements IAlbumListInfo {
38 
39     private static final long serialVersionUID = 5865751328573689357L;
40 
41     private String artist;
42     private List<IAlbumInfo> albums;
43 
44     /**
45      * Gets the album list.
46      *
47      * @param as
48      * @param artist
49      * @return
50      */
getAlbumList(final Collection<Album> as, final String artist)51     public static IAlbumListInfo getAlbumList(final Collection<Album> as,
52 	    final String artist) {
53 	List<IAlbumInfo> albums = new ArrayList<IAlbumInfo>();
54 	IAlbumListInfo albumList = new LastFmAlbumList();
55 
56 	for (Album a : as) {
57 	    IAlbumInfo album = LastFmAlbum.getAlbum(a, null);
58 	    albums.add(album);
59 	}
60 
61 	albumList.setAlbums(albums);
62 	return albumList;
63     }
64 
65     /**
66      * Gets the albums.
67      *
68      * @return the albums
69      */
70     @Override
getAlbums()71     public List<IAlbumInfo> getAlbums() {
72 	return albums;
73     }
74 
75     /**
76      * Gets the artist.
77      *
78      * @return the artist
79      */
80     @Override
getArtist()81     public String getArtist() {
82 	return artist;
83     }
84 
85     /**
86      * Sets the albums.
87      *
88      * @param albums
89      *            the albums to set
90      */
91     @Override
setAlbums(final List<? extends IAlbumInfo> albums)92     public void setAlbums(final List<? extends IAlbumInfo> albums) {
93 	this.albums = albums != null ? new ArrayList<IAlbumInfo>(albums) : null;
94     }
95 
96     /**
97      * Sets the artist.
98      *
99      * @param artist
100      *            the artist to set
101      */
102     @Override
setArtist(final String artist)103     public void setArtist(final String artist) {
104 	this.artist = artist;
105     }
106 
107 }
108