/*
 * Decompiled with CFR 0_123.
 */
package com.zakscode.FormulaManager;

import com.zakscode.FormulaManager.Configuration;
import com.zakscode.FormulaManager.Logger;
import com.zakscode.FormulaManager.Main;
import com.zakscode.FormulaManager.TableArray;
import java.io.EOFException;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class FileManager<T extends TableArray>
extends HashMap<String, T> {
    private static final long serialVersionUID = -1737198376121713564L;
    private final String file;

    public FileManager(String file) {
        this.file = file;
    }

    public void save() {
        try {
            FileOutputStream fileOut = new FileOutputStream(Main.baseDir + Main.conf.getProperty("data-path") + this.file);
            ObjectOutputStream out = new ObjectOutputStream(fileOut);
            out.writeObject(this);
            out.close();
            fileOut.close();
        }
        catch (Exception e) {
            Logger.write(e);
        }
    }

    public void load() {
        try {
            FileInputStream fileIn = new FileInputStream(Main.baseDir + Main.conf.getProperty("data-path") + this.file);
            ObjectInputStream in = new ObjectInputStream(fileIn);
            this.putAll((HashMap)in.readObject());
            in.close();
            fileIn.close();
        }
        catch (EOFException fileIn) {
        }
        catch (Exception e) {
            Logger.write(e);
        }
    }

    public Object[][] toArray() {
        Object[][] data = new Object[this.size()][];
        int i = 0;
        for (Map.Entry e : this.entrySet()) {
            data[i++] = ((TableArray)this.get(e.getKey())).toArray();
        }
        return data;
    }
}

