Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.fasterxml.jackson.databind.introspect;
  
  import java.util.*;
  
Simple helper class used to keep track of collection of Jackson Annotations associated with annotatable things (methods, constructors, classes). Note that only Jackson-owned annotations are tracked (for now?).
 
 public final class AnnotationMap implements Annotations
 {
     protected HashMap<Class<? extends Annotation>,Annotation_annotations;
 
     public AnnotationMap() { }
     
     private AnnotationMap(HashMap<Class<? extends Annotation>,Annotationa) {
          = a;
     }
 
     @SuppressWarnings("unchecked")
     @Override
     public <A extends Annotation> A get(Class<A> cls)
     {
         if ( == null) {
             return null;
         }
         return (A) .get(cls);
     }
 
     public static AnnotationMap merge(AnnotationMap primaryAnnotationMap secondary)
     {
         if (primary == null || primary._annotations == null || primary._annotations.isEmpty()) {
             return secondary;
         }
         if (secondary == null || secondary._annotations == null || secondary._annotations.isEmpty()) {
             return primary;
         }
         HashMap<Class<? extends Annotation>,Annotationannotations
             = new HashMap<Class<? extends Annotation>,Annotation>();
         // add secondary ones first
         for (Annotation ann : secondary._annotations.values()) {
             annotations.put(ann.annotationType(), ann);
         }
         // to be overridden by primary ones
         for (Annotation ann : primary._annotations.values()) {
             annotations.put(ann.annotationType(), ann);
         }
         return new AnnotationMap(annotations);
     }
     
     @Override
     public int size() {
         return ( == null) ? 0 : .size();
     }

    
Method called to add specified annotation in the Map, but only if it didn't yet exist.
 
     public void addIfNotPresent(Annotation ann)
     {
         if ( == null || !.containsKey(ann.annotationType())) {
             _add(ann);
         }
     }

    
Method called to add specified annotation in the Map.
 
     public void add(Annotation ann) {
         _add(ann);
     }
 
     @Override
     public String toString()
     {
         if ( == null) {
             return "[null]";
         }
         return .toString();
     }
 
     /*
     /**********************************************************
     /* Helper methods
     /**********************************************************
      */
 
     protected final void _add(Annotation ann)
     {
         if ( == null) {
              = new HashMap<Class<? extends Annotation>,Annotation>();
         }
         .put(ann.annotationType(), ann);
     }
New to GrepCode? Check out our FAQ X