FileDocCategorySizeDatePackage
Annotations.javaAPI DocAndroid 5.1 API6173Thu Mar 12 22:18:30 GMT 2015com.android.dexgen.rop.annotation

Annotations

public final class Annotations extends com.android.dexgen.util.MutabilityControl implements Comparable
List of {@link Annotation} instances.

Fields Summary
public static final Annotations
EMPTY
{@code non-null;} immutable empty instance
private final TreeMap
annotations
{@code non-null;} map from types to annotations
Constructors Summary
public Annotations()
Constructs an empty instance.

        annotations = new TreeMap<CstType, Annotation>();
    
Methods Summary
public voidadd(Annotation annotation)
Adds an element to this instance. There must not already be an element of the same type.

param
annotation {@code non-null;} the element to add
throws
IllegalArgumentException thrown if there is a duplicate type

        throwIfImmutable();

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

        CstType type = annotation.getType();

        if (annotations.containsKey(type)) {
            throw new IllegalArgumentException("duplicate type: " +
                    type.toHuman());
        }

        annotations.put(type, annotation);
    
public voidaddAll(com.android.dexgen.rop.annotation.Annotations toAdd)
Adds all of the elements of the given instance to this one. The instances must not have any duplicate types.

param
toAdd {@code non-null;} the annotations to add
throws
IllegalArgumentException thrown if there is a duplicate type

        throwIfImmutable();

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

        for (Annotation a : toAdd.annotations.values()) {
            add(a);
        }
    
public static com.android.dexgen.rop.annotation.Annotationscombine(com.android.dexgen.rop.annotation.Annotations a1, com.android.dexgen.rop.annotation.Annotations a2)
Constructs an immutable instance which is the combination of the two given instances. The two instances must contain disjoint sets of types.

param
a1 {@code non-null;} an instance
param
a2 {@code non-null;} the other instance
return
{@code non-null;} the combination
throws
IllegalArgumentException thrown if there is a duplicate type

        Annotations result = new Annotations();

        result.addAll(a1);
        result.addAll(a2);
        result.setImmutable();

        return result;
    
public static com.android.dexgen.rop.annotation.Annotationscombine(com.android.dexgen.rop.annotation.Annotations annotations, Annotation annotation)
Constructs an immutable instance which is the combination of the given instance with the given additional annotation. The latter's type must not already appear in the former.

param
annotations {@code non-null;} the instance to augment
param
annotation {@code non-null;} the additional annotation
return
{@code non-null;} the combination
throws
IllegalArgumentException thrown if there is a duplicate type

        Annotations result = new Annotations();

        result.addAll(annotations);
        result.add(annotation);
        result.setImmutable();

        return result;
    
public intcompareTo(com.android.dexgen.rop.annotation.Annotations other)
{@inheritDoc}

        Iterator<Annotation> thisIter = annotations.values().iterator();
        Iterator<Annotation> otherIter = other.annotations.values().iterator();

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

            int 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 Annotations)) {
            return false;
        }

        Annotations otherAnnotations = (Annotations) other;

        return annotations.equals(otherAnnotations.annotations);
    
public java.util.CollectiongetAnnotations()
Gets the set of annotations contained in this instance. The result is always unmodifiable.

return
{@code non-null;} the set of annotations

        return Collections.unmodifiableCollection(annotations.values());
    
public inthashCode()
{@inheritDoc}

        return annotations.hashCode();
    
public intsize()
Gets the number of elements in this instance.

return
{@code >= 0;} the size

        return annotations.size();
    
public java.lang.StringtoString()
{@inheritDoc}

        StringBuilder sb = new StringBuilder();
        boolean first = true;

        sb.append("annotations{");

        for (Annotation a : annotations.values()) {
            if (first) {
                first = false;
            } else {
                sb.append(", ");
            }
            sb.append(a.toHuman());
        }

        sb.append("}");
        return sb.toString();