package com.alwaysallthetime.adnlib.data;

import com.google.gson.annotations.Expose;

import java.util.ArrayList;

public abstract class Annotatable implements IAppDotNetObject {
    @Expose(serialize = false)
    protected String id;
    protected ArrayList<Annotation> annotations;

    public String getId() {
        return id;
    }

    public boolean hasAnnotations() {
        return annotations != null && annotations.size() > 0;
    }

    public ArrayList<Annotation> getAnnotations() {
        return annotations;
    }

    public void setAnnotations(ArrayList<Annotation> annotations) {
        this.annotations = annotations;
    }

    public boolean addAnnotation(Annotation annotation) {
        if (annotations == null)
            annotations = new ArrayList<Annotation>();

        return annotations.add(annotation);
    }

    public Annotation removeAnnotation(int index) {
        if (annotations == null)
            return null;

        return annotations.remove(index);
    }

    public void clearAnnotations() {
        annotations = null;
    }
}
@@ -107,16 +107,39 @@
 rayList;
+%0Aimport java.util.List;
 %0A%0Apublic
@@ -1093,10 +1093,735 @@
 l;%0A    %7D
+%0A%0A    public Annotation getFirstAnnotationOfType(String annotationType) %7B%0A        if(annotations != null) %7B%0A            for(Annotation a : annotations) %7B%0A                if(a.getType().equals(annotationType)) %7B%0A                    return a;%0A                %7D%0A            %7D%0A        %7D%0A        return null;%0A    %7D%0A%0A    public List%3CAnnotation%3E getAnnotationsOfType(String annotationType) %7B%0A        ArrayList%3CAnnotation%3E typedAnnotations = new ArrayList%3CAnnotation%3E();%0A        if(annotations != null) %7B%0A            for(Annotation a : annotations) %7B%0A                if(a.getType().equals(annotationType)) %7B%0A                    typedAnnotations.add(a);%0A                %7D%0A            %7D%0A        %7D%0A        return typedAnnotations;%0A    %7D
 %0A%7D

add convenience methods for obtaining annotations by type