private static <T> Lazy<Optional<T>> detectAnnotation(Object entity, Class<? extends Annotation> annotationType) { return Lazy.of(() -> { AnnotationDetectionFieldCallback callback = new AnnotationDetectionFieldCallback(annotationType); ReflectionUtils.doWithFields(entity.getClass(), callback); return Optional.ofNullable(callback.getValue(entity)); }); }
/** * Creates a new {@link AnnotationRevisionMetadata} inspecing the given entity for the given annotations. If no * annotations will be provided these values will not be looked up from the entity and return {@literal null}. * * @param entity must not be {@literal null}. * @param revisionNumberAnnotation * @param revisionTimeStampAnnotation */ public AnnotationRevisionMetadata(final Object entity, Class<? extends Annotation> revisionNumberAnnotation, Class<? extends Annotation> revisionTimeStampAnnotation) { Assert.notNull(entity); this.entity = entity; if (revisionNumberAnnotation != null) { AnnotationDetectionFieldCallback numberCallback = new AnnotationDetectionFieldCallback(revisionNumberAnnotation); ReflectionUtils.doWithFields(entity.getClass(), numberCallback); this.revisionNumber = numberCallback.getValue(entity); } else { this.revisionNumber = null; } if (revisionTimeStampAnnotation != null) { AnnotationDetectionFieldCallback revisionCallback = new AnnotationDetectionFieldCallback( revisionTimeStampAnnotation); ReflectionUtils.doWithFields(entity.getClass(), revisionCallback); this.revisionDate = new DateTime(revisionCallback.getValue(entity)); } else { this.revisionDate = null; } }