Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.fasterxml.jackson.jaxrs.json.util;
  
Helper class used to allow efficient caching of information, given a sequence of Annotations. This is mostly used for reusing introspected information on JAX-RS end points.
 
 public final class AnnotationBundleKey
 {
     private final static Annotation[] NO_ANNOTATIONS = new Annotation[0];
     
     private final Annotation[] _annotations;
     
     private final boolean _annotationsCopied;
 
     private final int _hashCode;
     
     /*
     /**********************************************************
     /* Construction
     /**********************************************************
      */
     
     public AnnotationBundleKey(Annotation[] annotations)
     {
         if (annotations == null || annotations.length == 0) {
             annotations = ;
              = true;
              = -1;
         } else {
              = false;
              = calcHash(annotations);
         }
          = annotations;  
     }
 
     private AnnotationBundleKey(Annotation[] annotationsint hashCode)
     {
          = annotations;            
          = true;
          = hashCode;
     }
 
     private final static int calcHash(Annotation[] annotations)
     {
         /* hmmh. Can't just base on Annotation type; chances are that Annotation
          * instances use identity hash, which has to do.
          */
         final int len = annotations.length;
         int hash = len;
         for (int i = 0; i < len; ++i) {
             hash = (hash * 31) + annotations[i].hashCode();
         }
         return hash;
     }
    
    
Method called to create a safe immutable copy of the key; used when adding entry with this key -- lookups are ok without calling the method.
 
     public AnnotationBundleKey immutableKey() {
         if () {
             return this;
         }
         int len = .;
         Annotation[] newAnnotations = new Annotation[len];
         System.arraycopy(, 0, newAnnotations, 0, len);
         return new AnnotationBundleKey(newAnnotations);
     }
     
     /*
     /**********************************************************
     /* Overridden methods
     /**********************************************************
      */
 
     @Override
     public String toString() {
         return "[Annotations: "+.+", hash 0x"+Integer.toHexString()
                 +", copied: "++"]";
     }
 
     @Override
     public boolean equals(Object o)
     {
         if (o == thisreturn true;
         if (o == nullreturn false;
         if (o.getClass() != getClass()) return false;
         AnnotationBundleKey other = (AnnotationBundleKeyo;
         if (other._hashCode != return false;
         return _equals(other._annotations);
     }
     
     private final boolean _equals(Annotation[] otherAnn)
     {
         final int len = .;
        if (otherAnn.length != len) {
            return false;
        }
        for (int i = 0; i < len; ++i) {
            if ([i] != otherAnn[i]) {
                return false;
            }
        }
        return true;
    }
New to GrepCode? Check out our FAQ X