1 package song; 2 3 5 6 7 import org.ozoneDB.OzoneObject; 8 9 import java.util.AbstractMap ; 10 import java.util.TreeMap ; 11 12 18 public class SongCollectionImpl extends OzoneObject implements SongCollection { 19 20 23 final static long serialVersionUID = 1L; 24 25 26 TreeMap songMap = new TreeMap (); 27 28 32 public void addSong(String title, Song song) throws Exception { 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 ("Duplicate song title"); 39 } 40 } 41 42 43 47 public Song deleteSong(String 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 e) { 55 System.out.println("Failure removing song."); 56 e.printStackTrace(); 57 } 58 return null; 59 } 60 61 65 public Song findSong(String song_title) { 66 return (Song)songMap.get(song_title); 67 } 68 69 74 public AbstractMap getAllSongs(){ 75 return songMap; 76 } 77 78 } 79 | Popular Tags |