/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2016 MrInformatic.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package game.saver;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.RandomAccessFile;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author MrInformatic
 */
public class GameMap<K extends Seriable,T extends GameData> extends HashMap<K,T>{
    private HashMap<K,T> values = new HashMap<>();
    private GameGraph graph;
    private ClassMap classMap;
    private File file;
    
    public GameMap(GameGraph graph,ClassMap classMap,File file,Class<K> c){
        super();
        this.file = file;
        this.classMap = classMap;
        this.graph = graph;
        try {
            Quarry quarry = new Quarry(file, "rw");
            while(true){
                K key = c.newInstance();
                key.read(quarry);
                values.put(key,(T)graph.get(quarry.readInt()));
            }
        } catch (Exception ex) {
            
        }        
    }
    
    public void flush(){
        try {
            Quarry quarry = new Quarry(file, "rw");
            for(Map.Entry<K,T> value : values.entrySet()){
                value.getKey().write(quarry);
                quarry.writeInt(value.getValue().getId());
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}

@@ -1248,24 +1248,53 @@
 AccessFile;%0A
+import java.util.Collection;%0A
 import java.
@@ -1303,24 +1303,24 @@
 il.HashMap;%0A
-
 import java.
@@ -1516,20 +1516,19 @@
 ta%3E 
-extend
+implement
 s 
-Hash
 Map%3C
@@ -2504,24 +2504,24 @@
 ackTrace();%0A
-
         %7D%0A  
@@ -2523,11 +2523,1343 @@
  %7D%0A    %7D
+%0A%0A    @Override%0A    public int size() %7B%0A        return values.size();%0A    %7D%0A%0A    @Override%0A    public boolean isEmpty() %7B%0A        return values.isEmpty();%0A    %7D%0A%0A    @Override%0A    public boolean containsKey(Object key) %7B%0A        return values.containsKey(key);%0A    %7D%0A%0A    @Override%0A    public boolean containsValue(Object value) %7B%0A        return values.containsValue(value);%0A    %7D%0A%0A    @Override%0A    public T get(Object key) %7B%0A        return values.get(key);%0A    %7D%0A%0A    @Override%0A    public T put(K key, T value) %7B%0A        graph.add(value);%0A        return values.put(key, value);%0A    %7D%0A%0A    @Override%0A    public T remove(Object key) %7B%0A        T type = values.remove(key);%0A        graph.remove(type.getId());%0A        return type;%0A    %7D%0A%0A    @Override%0A    public void putAll(Map%3C? extends K, ? extends T%3E m) %7B%0A        for(T type : m.values())%7B%0A            graph.add(type);%0A        %7D%0A        values.putAll(m);%0A    %7D%0A%0A    @Override%0A    public void clear() %7B%0A        for(T type : values())%7B%0A            graph.remove(type.getId());%0A        %7D%0A        values.clear();%0A    %7D%0A%0A    @Override%0A    public Set%3CK%3E keySet() %7B%0A        return values.keySet();%0A    %7D%0A%0A    @Override%0A    public Collection%3CT%3E values() %7B%0A        return values.values();%0A    %7D%0A%0A    @Override%0A    public Set%3CEntry%3CK, T%3E%3E entrySet() %7B%0A        return values.entrySet();%0A    %7D
 %0A%7D%0A

Fix Bugs