@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (!AnnotationValue.class.isInstance(obj)) { return false; } AnnotationValue other = AnnotationValue.class.cast(obj); Map<CharSequence, Object> otherValues = other.getValues(); Map<CharSequence, Object> values = getValues(); if (values.size() != otherValues.size()) { return false; } // compare annotation member values for (Map.Entry<CharSequence, Object> member : values.entrySet()) { Object value = member.getValue(); Object otherValue = otherValues.get(member.getKey()); if (!AnnotationUtil.areEqual(value, otherValue)) { return false; } } return true; }
@Override public int hashCode() { return AnnotationUtil.calculateHashCode(getValues()); }
/** * @param annotationClass The annotation class * @param annotationValues The annotation values * @param <T> The type * @return The annotation */ static <T extends Annotation> T buildAnnotation(Class<T> annotationClass, ConvertibleValues<Object> annotationValues) { Optional<Constructor<InvocationHandler>> proxyClass = getProxyClass(annotationClass); if (proxyClass.isPresent()) { Method[] declaredMethods = annotationClass.getDeclaredMethods(); Map<CharSequence, Object> resolvedValues = new LinkedHashMap<>(declaredMethods.length); for (Method declaredMethod : declaredMethods) { String name = declaredMethod.getName(); if (annotationValues.contains(name)) { Optional<?> converted = annotationValues.get(name, declaredMethod.getReturnType()); converted.ifPresent(o -> resolvedValues.put(name, o)); } } Map<String, Object> values = new HashMap<>(getDefaultValues(annotationClass)); values.putAll(annotationValues.asMap()); int hashCode = AnnotationUtil.calculateHashCode(values); Optional instantiated = InstantiationUtils.tryInstantiate(proxyClass.get(), (InvocationHandler) new AnnotationProxyHandler(hashCode, annotationClass, resolvedValues)); if (instantiated.isPresent()) { return (T) instantiated.get(); } } throw new AnnotationMetadataException("Failed to build annotation for type: " + annotationClass.getName()); }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (!annotationClass.isInstance(obj)) { return false; } Annotation other = (Annotation) annotationClass.cast(obj); Map<CharSequence, Object> otherValues = getAnnotationValues(other); if (resolvedValues.size() != otherValues.size()) { return false; } // compare annotation member values for (Map.Entry<CharSequence, Object> member : resolvedValues.entrySet()) { Object value = member.getValue(); Object otherValue = otherValues.get(member.getKey()); if (!AnnotationUtil.areEqual(value, otherValue)) { return false; } } return true; }
/** * @param annotationClass The annotation class * @param annotationValues The annotation values * @param <T> The type * @return The annotation */ static <T extends Annotation> T buildAnnotation(Class<T> annotationClass, ConvertibleValues<Object> annotationValues) { Optional<Constructor<InvocationHandler>> proxyClass = getProxyClass(annotationClass); if (proxyClass.isPresent()) { Method[] declaredMethods = annotationClass.getDeclaredMethods(); Map<CharSequence, Object> resolvedValues = new LinkedHashMap<>(declaredMethods.length); for (Method declaredMethod : declaredMethods) { String name = declaredMethod.getName(); if (annotationValues.contains(name)) { Optional<?> converted = annotationValues.get(name, declaredMethod.getReturnType()); converted.ifPresent(o -> resolvedValues.put(name, o)); } } Map<String, Object> values = new HashMap<>(getDefaultValues(annotationClass)); values.putAll(annotationValues.asMap()); int hashCode = AnnotationUtil.calculateHashCode(values); Optional instantiated = InstantiationUtils.tryInstantiate(proxyClass.get(), (InvocationHandler) new AnnotationProxyHandler(hashCode, annotationClass, resolvedValues)); if (instantiated.isPresent()) { return (T) instantiated.get(); } } throw new AnnotationMetadataException("Failed to build annotation for type: " + annotationClass.getName()); }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (!annotationClass.isInstance(obj)) { return false; } Annotation other = (Annotation) annotationClass.cast(obj); Map<CharSequence, Object> otherValues = getAnnotationValues(other); if (resolvedValues.size() != otherValues.size()) { return false; } // compare annotation member values for (Map.Entry<CharSequence, Object> member : resolvedValues.entrySet()) { Object value = member.getValue(); Object otherValue = otherValues.get(member.getKey()); if (!AnnotationUtil.areEqual(value, otherValue)) { return false; } } return true; }