Package

Source Code of SongCollectionImpl

// $Id: SongCollectionImpl.java,v 1.1 2002/05/17 08:28:18 per_nyfelt Exp $



import SongCollection;
import Song;

import java.lang.String;
import java.util.Collection;
import java.util.TreeMap;
import java.util.AbstractMap;
import java.util.SortedMap;

import org.ozoneDB.*;

/**
* Persistenet object that represents a catalog of Songs.
*
* @version $Revision: 1.1 $
* @author James Stiefel
*/
public class SongCollectionImpl extends OzoneObject implements SongCollection {

    /**
     * The serialization version id used by the Java serialization.
     */
    final static long serialVersionUID = 1L;


    TreeMap      songMap = new TreeMap();

    /**
     * Adds a Song to the SongCollection
     *
     */
    public void addSong(String title, Song song) throws Exception {
        Song old = (Song) songMap.put(title, song);
        if (old != null) {
            System.out.println("SongCollection.addSong: song already exists, not added : " + title);
            songMap.put(old.getTitle(), old);

            throw new  Exception ("Duplicate song title");
        }
    }


    /**
     * Deletes a Song from the SongCollection and database
     *
     */
    public Song deleteSong(String  title) {
        Song song = null;
        try{
            song = (Song)songMap.remove(title);
            if (song != null){
                database().deleteObject(song);
            }
        } catch (Exception e) {
            System.out.println("Failure removing song.");
            e.printStackTrace();
        }
        return null;
    }

    /**
     * Finds a song in SongCollection
     *
     */
    public Song findSong(String song_title) {
        return (Song)songMap.get(song_title);
    }

    /**
     * Returns the collection of Songs represented by 
     * this SongCollection.
     *
     */
    public AbstractMap           getAllSongs(){
        return  (AbstractMap)songMap; 
    }
}
TOP

Related Classes of SongCollectionImpl

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.