/*
 * Decompiled with CFR 0.152.
 */
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Hashtable;
import java.util.Vector;

public class gp
implements nf {
    private static final Hashtable e = new Hashtable();
    private final String c;
    public final int a;
    public final Vector b = new Vector();
    private boolean d;

    private gp(String string, int n, boolean bl2) {
        this(string, n);
    }

    public final String[] g() {
        int n = this.b();
        String[] stringArray = new String[n];
        for (int i = 0; i < n; ++i) {
            stringArray[i] = this.a(this.c(i));
        }
        return stringArray;
    }

    public static gp a(String string) {
        gp gp2 = gp.b(string);
        if (gp2 == null) {
            return new gp(string, 20, false);
        }
        return gp2;
    }

    public static gp b(String string) {
        return (gp)e.get(string);
    }

    public final void af() {
        this.d = false;
        this.b.removeAllElements();
    }

    public final int b() {
        this.d();
        return this.b.size();
    }

    public final int c(int n) {
        return this.b() - n - 1;
    }

    public String a(int n) {
        return bz.a((fk)this.b.elementAt(n));
    }

    public fk b(int n) {
        if (n >= 0 && n < this.b.size()) {
            return (fk)this.b.elementAt(n);
        }
        return null;
    }

    public void b(fk fk2) {
        this.d();
        if (this.b.removeElement(fk2)) {
            this.f();
        }
    }

    public boolean a(fk fk2) {
        if (fk2 != null) {
            this.d();
            if (this.b.size() <= 0 || !this.b.lastElement().equals(fk2)) {
                this.b.removeElement(fk2);
                if (this.b.size() >= this.a) {
                    this.b.removeElementAt(0);
                }
                this.b.addElement(fk2);
                this.f();
            }
            return true;
        }
        return false;
    }

    public final void f() {
        try {
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            this.a(new DataOutputStream(byteArrayOutputStream));
            byte[] byArray = byteArrayOutputStream.toByteArray();
            lh.k().f().a(this.c, byArray);
            return;
        }
        catch (IOException iOException) {
            me.a("MEMORY", iOException);
            return;
        }
    }

    public final void d() {
        if (!this.d) {
            this.d = true;
            try {
                DataInputStream dataInputStream = (DataInputStream)nz.c(this.c);
                if (dataInputStream != null) {
                    this.a(dataInputStream);
                }
                return;
            }
            catch (IOException iOException) {
                me.a("MEMORY", iOException);
                this.d = true;
                lh.k().f().a(this.c, null);
                this.b.removeAllElements();
            }
        }
    }

    public gp(String string, int n) {
        if (n < 1) {
            throw new IllegalArgumentException("maxSize < 1: " + n);
        }
        this.c = "MRUMemory_" + string;
        this.a = n;
        nz.a(this);
        e.put(string, this);
    }

    public void a(DataOutputStream dataOutputStream) {
        lk lk2 = new lk(la.aF);
        for (int i = 0; i < this.b(); ++i) {
            lk lk3 = lk2.a(1);
            fk fk2 = (fk)this.b.elementAt(i);
            lk3.b(2, gu.a(fk2));
            lk3.b(3, fk2.a());
            lk2.a(1, lk3);
        }
        dataOutputStream.writeInt(lk2.b());
        lk2.a(dataOutputStream);
    }

    public void a(DataInputStream dataInputStream) {
        int n = dataInputStream.readInt();
        lk lk2 = new lk(la.aF);
        lk2.a(dataInputStream, n);
        int n2 = lk2.i(1);
        this.b.removeAllElements();
        for (n = 0; n < n2; ++n) {
            lk lk3 = lk2.e(1, n);
            this.b.addElement(fk.b(lk3.f(3), lk3.f(2)));
        }
    }
}

