001    /*****************************************************************************
002     * Copyright (C) NanoContainer Organization. All rights reserved.            *
003     * ------------------------------------------------------------------------- *
004     * The software in this package is published under the terms of the BSD      *
005     * style license a copy of which has been included with this distribution in *
006     * the LICENSE.txt file.                                                     *
007     *                                                                           *
008     *****************************************************************************/
009    package org.nanocontainer.nanowar.sample.dao.simple;
010    
011    import java.io.Serializable;
012    import java.util.Collection;
013    import java.util.HashMap;
014    import java.util.Map;
015    
016    import org.nanocontainer.nanowar.sample.dao.CheeseDao;
017    import org.nanocontainer.nanowar.sample.model.Cheese;
018    
019    /**
020     * @author Stephen Molitor
021     */
022    public class MemoryCheeseDao implements CheeseDao, Serializable {
023    
024        private final Map cheeses;
025    
026        public MemoryCheeseDao() {
027            cheeses = new HashMap();
028            cheeses.put("cheddar", new Cheese("cheddar","England"));
029        }
030    
031        public void save(Cheese cheese) {
032            cheeses.put(cheese.getName(), cheese);
033        }
034    
035        public void remove(Cheese cheese) {
036            cheeses.remove(cheese.getName());
037        }
038        public Cheese get(String name) {
039            return (Cheese) cheeses.get(name);
040        }
041    
042        public Collection all() {
043            return cheeses.values();
044        }
045    
046    }