FileDocCategorySizeDatePackage
ProxyNameAndTypeCache.javaAPI DocAndroid 1.5 API3252Wed May 06 22:41:04 BST 2009org.apache.harmony.luni.internal.reflect

ProxyNameAndTypeCache

public class ProxyNameAndTypeCache extends Object

Fields Summary
int[]
keyTable
int[]
valueTable
int
elementSize
int
threshold
Constructors Summary
ProxyNameAndTypeCache(int initialCapacity)

        if (initialCapacity < 13) {
            initialCapacity = 13;
        }
        this.elementSize = 0;
        this.threshold = (int) (initialCapacity * 0.66f);
        this.keyTable = new int[initialCapacity][];
        this.valueTable = new int[initialCapacity];
    
Methods Summary
intget(int[] key)

        int index = hashCode(key);
        while (keyTable[index] != null) {
            if (keyTable[index][0] == key[0] && keyTable[index][1] == key[1]) {
                return valueTable[index];
            }
            index = (index + 1) % keyTable.length;
        }
        return -1;
    
inthashCode(int[] key)

        return (key[0] + key[1]) % keyTable.length;
    
intput(int[] key, int value)

        int index = hashCode(key);
        while (keyTable[index] != null) {
            if (keyTable[index][0] == key[0] && keyTable[index][1] == key[1]) {
                return valueTable[index] = value;
            }
            index = (index + 1) % keyTable.length;
        }
        keyTable[index] = key;
        valueTable[index] = value;

        // assumes the threshold is never equal to the size of the table
        if (++elementSize > threshold) {
            rehash();
        }
        return value;
    
private voidrehash()

        ProxyNameAndTypeCache newHashtable = new ProxyNameAndTypeCache(keyTable.length * 2);
        for (int i = keyTable.length; --i >= 0;) {
            if (keyTable[i] != null) {
                newHashtable.put(keyTable[i], valueTable[i]);
            }
        }

        this.keyTable = newHashtable.keyTable;
        this.valueTable = newHashtable.valueTable;
        this.threshold = newHashtable.threshold;
    
intsize()

        return elementSize;
    
public java.lang.StringtoString()

        int max = size();
        StringBuilder buf = new StringBuilder();
        buf.append("{");
        for (int i = 0; i < max; ++i) {
            if (keyTable[i] != null) {
                buf.append(keyTable[i]).append("->").append(valueTable[i]);
            }
            if (i < max) {
                buf.append(", ");
            }
        }
        buf.append("}");
        return buf.toString();