FileDocCategorySizeDatePackage
X509NameElementList.javaAPI DocAndroid 1.5 API5625Wed May 06 22:41:06 BST 2009org.bouncycastle.asn1.x509

X509NameElementList

public class X509NameElementList extends Object
List of elements of an X509 name. Each element has a key, a value, and an "added" flag.

Fields Summary
private org.bouncycastle.asn1.DERObjectIdentifier
key0
null-ok; key #0
private org.bouncycastle.asn1.DERObjectIdentifier
key1
null-ok; key #1
private org.bouncycastle.asn1.DERObjectIdentifier
key2
null-ok; key #2
private org.bouncycastle.asn1.DERObjectIdentifier
key3
null-ok; key #3
private String
value0
null-ok; value #0
private String
value1
null-ok; value #1
private String
value2
null-ok; value #2
private String
value3
null-ok; value #3
private Object[]
rest
null-ok; array of additional keys and values, alternating key then value, etc.
private int
added
bit vector (in int form) for all the "added" bits
private int
size
>= 0; number of elements in the list
Constructors Summary
Methods Summary
public voidadd(org.bouncycastle.asn1.DERObjectIdentifier key, java.lang.String value)
Adds an element. The "added" flag is set to false for the element.

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

        add(key, value, false);
    
public voidadd(org.bouncycastle.asn1.DERObjectIdentifier key, java.lang.String value, boolean added)
Adds an element.

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

        if (size >= 32) {
            throw new UnsupportedOperationException(
                    "no more than 32 elements");
        }

        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;
            }
            case 9: {
                // Grow to accommodate 28 pairs in the array.
                Object[] newRest = new Object[56];
                System.arraycopy(rest, 0, newRest, 0, 10);
                rest = newRest;
                // Fall through.
            }
            default: {
                int index = (sz - 4) * 2;
                rest[index] = key;
                rest[index + 1] = value;
                break;
            }
        }

        if (added) {
            this.added |= (1 << sz);
        }
        
        size = sz + 1;
    
public booleangetAdded(int n)
Gets the nth added flag bit.

param
n index
return
the nth added flag bit

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

        return (added & (1 << n)) != 0;
    
public org.bouncycastle.asn1.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.lang.StringgetValue(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 (String) rest[((n - 4) * 2) + 1];
        }
    
public org.bouncycastle.asn1.x509.X509NameElementListreverse()
Constructs and returns a new instance which consists of the elements of this one in reverse order

return
non-null; the reversed instance

        X509NameElementList result = new X509NameElementList();
            
        for (int i = size - 1; i >= 0; i--) {
            result.add(getKey(i), getValue(i), getAdded(i));
        }

        return result;
    
public voidsetLastAddedFlag()
Sets the "added" flag on the most recently added element.

        added |= 1 << (size - 1);
    
public intsize()
Gets the number of elements in this instance.

        return size;