KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > song > SongCollectionImpl


1 package song;
2
3 // $Id: song.SongCollectionImpl.java,v 1.1 2002/05/17 08:28:18 per_nyfelt Exp $
4

5
6
7 import org.ozoneDB.OzoneObject;
8
9 import java.util.AbstractMap JavaDoc;
10 import java.util.TreeMap JavaDoc;
11
12 /**
13  * Persistenet object that represents a catalog of Songs.
14  *
15  * @version $Revision: 1.1 $
16  * @author James Stiefel
17  */

18 public class SongCollectionImpl extends OzoneObject implements SongCollection {
19
20     /**
21      * The serialization version id used by the Java serialization.
22      */

23     final static long serialVersionUID = 1L;
24
25
26     TreeMap JavaDoc songMap = new TreeMap JavaDoc();
27
28     /**
29      * Adds a song.Song to the song.SongCollection
30      *
31      */

32     public void addSong(String JavaDoc title, Song song) throws Exception JavaDoc {
33         Song old = (Song) songMap.put(title, song);
34         if (old != null) {
35             System.out.println("song.SongCollection.addSong: song already exists, not added : " + title);
36             songMap.put(old.getTitle(), old);
37
38             throw new Exception JavaDoc ("Duplicate song title");
39         }
40     }
41
42
43     /**
44      * Deletes a song.Song from the song.SongCollection and database
45      *
46      */

47     public Song deleteSong(String JavaDoc title) {
48         Song song = null;
49         try{
50             song = (Song)songMap.remove(title);
51             if (song != null){
52                 database().deleteObject(song);
53             }
54         } catch (Exception JavaDoc e) {
55             System.out.println("Failure removing song.");
56             e.printStackTrace();
57         }
58         return null;
59     }
60
61     /**
62      * Finds a song in song.SongCollection
63      *
64      */

65     public Song findSong(String JavaDoc song_title) {
66         return (Song)songMap.get(song_title);
67     }
68
69     /**
70      * Returns the collection of Songs represented by
71      * this song.SongCollection.
72      *
73      */

74     public AbstractMap JavaDoc getAllSongs(){
75         return songMap;
76     }
77
78 }
79
Popular Tags