FileDocCategorySizeDatePackage
OrderedTable.javaAPI DocAndroid 1.5 API5714Wed May 06 22:41:06 BST 2009org.bouncycastle.asn1

OrderedTable

public final class OrderedTable extends Object
Ordered lookup table. Instances of this class will keep up to four key-value pairs directly, resorting to an external collection only if more elements than that need to be stored.

Fields Summary
private DERObjectIdentifier
key0
null-ok; key #0
private DERObjectIdentifier
key1
null-ok; key #1
private DERObjectIdentifier
key2
null-ok; key #2
private DERObjectIdentifier
key3
null-ok; key #3
private Object
value0
null-ok; value #0
private Object
value1
null-ok; value #1
private Object
value2
null-ok; value #2
private Object
value3
null-ok; value #3
private Object[]
rest
null-ok; array of additional keys and values, alternating key then value, etc.
private int
size
>= 0; number of elements in the list
Constructors Summary
Methods Summary
public voidadd(DERObjectIdentifier key, java.lang.Object value)
Adds an element.

param
key non-null; the key
param
value non-null; the value

        if (key == null) {
            throw new NullPointerException("key == null");
        }

        if (value == null) {
            throw new NullPointerException("value == null");
        }

        int sz = size;

        switch (sz) {
            case 0: {
                key0 = key;
                value0 = value;
                break;
            }
            case 1: {
                key1 = key;
                value1 = value;
                break;
            }
            case 2: {
                key2 = key;
                value2 = value;
                break;
            }
            case 3: {
                key3 = key;
                value3 = value;
                break;
            }
            case 4: {
                // Do initial allocation of rest.
                rest = new Object[10];
                rest[0] = key;
                rest[1] = value;
                break;
            }
            default: {
                int index = (sz - 4) * 2;
                int index1 = index + 1;
                if (index1 >= rest.length) {
                    // Grow rest.
                    Object[] newRest = new Object[index1 * 2 + 10];
                    System.arraycopy(rest, 0, newRest, 0, rest.length);
                    rest = newRest;
                }
                rest[index] = key;
                rest[index1] = value;
                break;
            }
        }
        
        size = sz + 1;
    
public java.lang.Objectget(DERObjectIdentifier key)
Look up the given key, returning the associated value if found.

param
key non-null; the key to look up
return
null-ok; the associated value

        int keyHash = key.hashCode();
        int sz = size;

        for (int i = 0; i < size; i++) {
            DERObjectIdentifier probe = getKey(i);
            if ((probe.hashCode() == keyHash) &&
                    probe.equals(key)) {
                return getValue(i);
            }
        }

        return null;
    
public DERObjectIdentifiergetKey(int n)
Gets the nth key.

param
n index
return
non-null; the nth key

        if ((n < 0) || (n >= size)) {
            throw new IndexOutOfBoundsException(Integer.toString(n));
        }

        switch (n) {
            case 0: return key0;
            case 1: return key1;
            case 2: return key2;
            case 3: return key3;
            default: return (DERObjectIdentifier) rest[(n - 4) * 2];
        }
    
public java.util.EnumerationgetKeys()
Gets an enumeration of the keys, in order.

return
non-null; an enumeration of the keys

        return new KeyEnumeration();
    
public java.lang.ObjectgetValue(int n)
Gets the nth value.

param
n index
return
non-null; the nth value

        if ((n < 0) || (n >= size)) {
            throw new IndexOutOfBoundsException(Integer.toString(n));
        }

        switch (n) {
            case 0: return value0;
            case 1: return value1;
            case 2: return value2;
            case 3: return value3;
            default: return rest[((n - 4) * 2) + 1];
        }
    
public intsize()
Gets the number of elements in this instance.

        return size;