FileDocCategorySizeDatePackage
Annotation.javaAPI DocAndroid 5.1 API6428Thu Mar 12 22:18:30 GMT 2015com.android.dx.rop.annotation

Annotation

public final class Annotation extends com.android.dx.util.MutabilityControl implements com.android.dx.util.ToHuman, Comparable
An annotation on an element of a class. Annotations have an associated type and additionally consist of a set of (name, value) pairs, where the names are unique.

Fields Summary
private final com.android.dx.rop.cst.CstType
type
{@code non-null;} type of the annotation
private final AnnotationVisibility
visibility
{@code non-null;} the visibility of the annotation
private final TreeMap
elements
{@code non-null;} map from names to {@link NameValuePair} instances
Constructors Summary
public Annotation(com.android.dx.rop.cst.CstType type, AnnotationVisibility visibility)
Construct an instance. It initially contains no elements.

param
type {@code non-null;} type of the annotation
param
visibility {@code non-null;} the visibility of the annotation

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

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

        this.type = type;
        this.visibility = visibility;
        this.elements = new TreeMap<CstString, NameValuePair>();
    
Methods Summary
public voidadd(NameValuePair pair)
Add an element to the set of (name, value) pairs for this instance. It is an error to call this method if there is a preexisting element with the same name.

param
pair {@code non-null;} the (name, value) pair to add to this instance

        throwIfImmutable();

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

        CstString name = pair.getName();

        if (elements.get(name) != null) {
            throw new IllegalArgumentException("name already added: " + name);
        }

        elements.put(name, pair);
    
public intcompareTo(com.android.dx.rop.annotation.Annotation other)
{@inheritDoc}

        int result = type.compareTo(other.type);

        if (result != 0) {
            return result;
        }

        result = visibility.compareTo(other.visibility);

        if (result != 0) {
            return result;
        }

        Iterator<NameValuePair> thisIter = elements.values().iterator();
        Iterator<NameValuePair> otherIter = other.elements.values().iterator();

        while (thisIter.hasNext() && otherIter.hasNext()) {
            NameValuePair thisOne = thisIter.next();
            NameValuePair otherOne = otherIter.next();

            result = thisOne.compareTo(otherOne);
            if (result != 0) {
                return result;
            }
        }

        if (thisIter.hasNext()) {
            return 1;
        } else if (otherIter.hasNext()) {
            return -1;
        }

        return 0;
    
public booleanequals(java.lang.Object other)
{@inheritDoc}

        if (! (other instanceof Annotation)) {
            return false;
        }

        Annotation otherAnnotation = (Annotation) other;

        if (! (type.equals(otherAnnotation.type)
                        && (visibility == otherAnnotation.visibility))) {
            return false;
        }

        return elements.equals(otherAnnotation.elements);
    
public java.util.CollectiongetNameValuePairs()
Gets the set of name-value pairs contained in this instance. The result is always unmodifiable.

return
{@code non-null;} the set of name-value pairs

        return Collections.unmodifiableCollection(elements.values());
    
public com.android.dx.rop.cst.CstTypegetType()
Gets the type of this instance.

return
{@code non-null;} the type

        return type;
    
public AnnotationVisibilitygetVisibility()
Gets the visibility of this instance.

return
{@code non-null;} the visibility

        return visibility;
    
public inthashCode()
{@inheritDoc}

        int hash = type.hashCode();
        hash = (hash * 31) + elements.hashCode();
        hash = (hash * 31) + visibility.hashCode();
        return hash;
    
public voidput(NameValuePair pair)
Put an element into the set of (name, value) pairs for this instance. If there is a preexisting element with the same name, it will be replaced by this method.

param
pair {@code non-null;} the (name, value) pair to place into this instance

        throwIfImmutable();

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

        elements.put(pair.getName(), pair);
    
public java.lang.StringtoHuman()
{@inheritDoc}

        StringBuilder sb = new StringBuilder();

        sb.append(visibility.toHuman());
        sb.append("-annotation ");
        sb.append(type.toHuman());
        sb.append(" {");

        boolean first = true;
        for (NameValuePair pair : elements.values()) {
            if (first) {
                first = false;
            } else {
                sb.append(", ");
            }
            sb.append(pair.getName().toHuman());
            sb.append(": ");
            sb.append(pair.getValue().toHuman());
        }

        sb.append("}");
        return sb.toString();
    
public java.lang.StringtoString()
{@inheritDoc}

        return toHuman();