![JAR search and dependency download from the Maven repository](/logo.png)
nl.open.jwtdependency.com.fasterxml.jackson.databind.introspect.AnnotationMap Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-jwt-nodependencies Show documentation
Show all versions of java-jwt-nodependencies Show documentation
This is a drop in replacement for the auth0 java-jwt library (see https://github.com/auth0/java-jwt). This jar makes sure there are no external dependencies (e.g. fasterXml, Apacha Commons) needed. This is useful when deploying to an application server (e.g. tomcat with Alfreso or Pega).
The newest version!
package com.fasterxml.jackson.databind.introspect;
import java.lang.annotation.Annotation;
import java.util.*;
import com.fasterxml.jackson.databind.util.Annotations;
/**
* 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,Annotation> _annotations;
public AnnotationMap() { }
private AnnotationMap(HashMap,Annotation> a) {
_annotations = a;
}
@SuppressWarnings("unchecked")
@Override
public A get(Class cls)
{
if (_annotations == null) {
return null;
}
return (A) _annotations.get(cls);
}
public boolean has(Class> cls)
{
if (_annotations == null) {
return false;
}
return _annotations.containsKey(cls);
}
/**
* Helper method that can be used for a "bulk" check to see if at least
* one of given annotation types is included within this map.
*
* @since 2.7
*/
public boolean hasOneOf(Class extends Annotation>[] annoClasses) {
if (_annotations != null) {
for (int i = 0, end = annoClasses.length; i < end; ++i) {
if (_annotations.containsKey(annoClasses[i])) {
return true;
}
}
}
return false;
}
/**
* @since 2.3
*/
public Iterable annotations() {
if (_annotations == null || _annotations.size() == 0) {
return Collections.emptyList();
}
return _annotations.values();
}
public static AnnotationMap merge(AnnotationMap primary, AnnotationMap secondary)
{
if (primary == null || primary._annotations == null || primary._annotations.isEmpty()) {
return secondary;
}
if (secondary == null || secondary._annotations == null || secondary._annotations.isEmpty()) {
return primary;
}
HashMap,Annotation> annotations = new HashMap,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 (_annotations == null) ? 0 : _annotations.size();
}
/**
* Method called to add specified annotation in the Map, but
* only if it didn't yet exist.
*/
public boolean addIfNotPresent(Annotation ann)
{
if (_annotations == null || !_annotations.containsKey(ann.annotationType())) {
_add(ann);
return true;
}
return false;
}
/**
* Method called to add specified annotation in the Map.
*
* @return True if the addition changed the contents, that is, this map did not
* already have specified annotation
*/
public boolean add(Annotation ann) {
return _add(ann);
}
@Override
public String toString() {
if (_annotations == null) {
return "[null]";
}
return _annotations.toString();
}
/*
/**********************************************************
/* Helper methods
/**********************************************************
*/
protected final boolean _add(Annotation ann) {
if (_annotations == null) {
_annotations = new HashMap,Annotation>();
}
Annotation previous = _annotations.put(ann.annotationType(), ann);
return (previous == null) || !previous.equals(ann);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy