CompactByteArray.java 2.05 KB
/*
 * Decompiled with CFR 0_118.
 */
package com.adobe.agl.util;

public final class CompactByteArray
implements Cloneable {
    private byte[] values = new byte[65536];
    private char[] indices = new char[512];
    private int[] hashes = new int[512];
    private boolean isCompact;
    byte defaultValue;

    public CompactByteArray() {
        this(0);
    }

    public CompactByteArray(byte defaultValue) {
        int i;
        for (i = 0; i < 65536; ++i) {
            this.values[i] = defaultValue;
        }
        for (i = 0; i < 512; ++i) {
            this.indices[i] = (char)(i << 7);
            this.hashes[i] = 0;
        }
        this.isCompact = false;
        this.defaultValue = defaultValue;
    }

    public byte elementAt(char index) {
        return this.values[(this.indices[index >> 7] & 65535) + (index & 127)];
    }

    public Object clone() {
        try {
            CompactByteArray other = (CompactByteArray)super.clone();
            other.values = (byte[])this.values.clone();
            other.indices = (char[])this.indices.clone();
            if (this.hashes != null) {
                other.hashes = (int[])this.hashes.clone();
            }
            return other;
        }
        catch (CloneNotSupportedException e) {
            throw new IllegalStateException();
        }
    }

    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (this == obj) {
            return true;
        }
        if (this.getClass() != obj.getClass()) {
            return false;
        }
        CompactByteArray other = (CompactByteArray)obj;
        for (int i = 0; i < 65536; ++i) {
            if (this.elementAt((char)i) == other.elementAt((char)i)) continue;
            return false;
        }
        return true;
    }

    public int hashCode() {
        int result = 0;
        int increment = Math.min(3, this.values.length / 16);
        for (int i = 0; i < this.values.length; i += increment) {
            result = result * 37 + this.values[i];
        }
        return result;
    }
}