/** * Default constructor. * @param url The URL */ UrlReadable(URL url) { ArgumentUtils.requireNonNull("url", url); this.url = url; }
/** * Default constructor. * @param file The file */ FileReadable(@Nonnull File file) { ArgumentUtils.requireNonNull("file", file); this.file = file; }
/** * Find an {@link AnnotationValue} for the given annotation type. * * @param annotationClass The annotation * @param <T> The annotation type * @return A {@link AnnotationValue} instance */ default @Nonnull <T extends Annotation> Optional<AnnotationValue<T>> findAnnotation(@Nonnull Class<T> annotationClass) { ArgumentUtils.requireNonNull("annotationClass", annotationClass); return Optional.empty(); }
/** * Get all of the values for the given annotation that are directly declared on the annotated element. * * @param annotationClass The annotation name * @param <T> The annotation type * @return A {@link AnnotationValue} instance */ default @Nonnull <T extends Annotation> Optional<AnnotationValue<T>> findDeclaredAnnotation(@Nonnull Class<T> annotationClass) { ArgumentUtils.requireNonNull("annotationClass", annotationClass); return Optional.empty(); }
/** * Returns whether the value of the given member is <em>true</em>. * * @param annotation The annotation class * @param member The annotation member * @return True if the value is true */ default boolean isFalse(@Nonnull Class<? extends Annotation> annotation, @Nonnull String member) { ArgumentUtils.requireNonNull("annotation", annotation); ArgumentUtils.requireNonNull("member", member); return !isTrue(annotation, member); }
/** * Get the value of the given annotation member. * * @param annotation The annotation class * @param member The annotation member * @return An {@link Optional} of the value */ default @Nonnull Optional<Object> getValue(@Nonnull Class<? extends Annotation> annotation, @Nonnull String member) { ArgumentUtils.requireNonNull("annotation", annotation); ArgumentUtils.requireNonNull("member", member); return getValue(annotation, member, Object.class); }
/** * Returns whether the value of the given member is <em>true</em>. * * @param annotation The annotation class * @param member The annotation member * @return True if the value is true */ default boolean isTrue(@Nonnull String annotation, @Nonnull String member) { ArgumentUtils.requireNonNull("annotation", annotation); ArgumentUtils.requireNonNull("member", member); return getValue(annotation, member, Boolean.class).orElse(false); }
/** * Returns whether the value of the given member is <em>true</em>. * * @param annotation The annotation class * @param member The annotation member * @return True if the value is true */ default boolean isPresent(@Nonnull Class<? extends Annotation> annotation, @Nonnull String member) { ArgumentUtils.requireNonNull("annotation", annotation); ArgumentUtils.requireNonNull("member", member); return isPresent(annotation.getName(), member); }
/** * The value of the annotation as a Class. * * @param annotation The annotation * @param member The annotation member * @return An {@link Optional} class */ default @Nonnull Optional<Class> classValue(@Nonnull Class<? extends Annotation> annotation, @Nonnull String member) { ArgumentUtils.requireNonNull("annotation", annotation); ArgumentUtils.requireNonNull("member", member); return classValue(annotation.getName(), member); }
/** * Get all of the values for the given annotation that are directly declared on the annotated element. * * @param annotation The annotation name * @param <T> The annotation type * @return A {@link AnnotationValue} instance */ default @Nullable <T extends Annotation> AnnotationValue<T> getDeclaredAnnotation(@Nonnull String annotation) { ArgumentUtils.requireNonNull("annotation", annotation); return this.<T>findDeclaredAnnotation(annotation).orElse(null); }
/** * The value of the annotation as a Class. * * @param annotation The annotation * @return An {@link Optional} class */ default @Nonnull Optional<Class> classValue(@Nonnull Class<? extends Annotation> annotation) { ArgumentUtils.requireNonNull("annotation", annotation); return classValue(annotation.getName()); }
/** * Find the first annotation name for the given stereotype. * * @param stereotype The stereotype * @return The annotation name */ default @Nonnull Optional<Class<? extends Annotation>> getAnnotationTypeByStereotype(@Nonnull Class<? extends Annotation> stereotype) { ArgumentUtils.requireNonNull("stereotype", stereotype); return getAnnotationTypeByStereotype(stereotype.getName()); }
/** * Create a {@link Readable} for the given file. * * @param file The file * @return The readable. */ static @Nonnull Readable of(@Nonnull File file) { ArgumentUtils.requireNonNull("file", file); return new FileReadable(file); }
/** * Searches resource loaders for one that supports the given prefix. * * @param prefix The prefix the loader should support. (classpath:, file:, etc) * @return An optional resource loader */ public @Nonnull Optional<ResourceLoader> getSupportingLoader(@Nonnull String prefix) { ArgumentUtils.requireNonNull("prefix", prefix); return resourceLoaders.stream() .filter(rl -> rl.supportsPrefix(prefix)) .findFirst(); }
/** * Find an {@link AnnotationValue} for the given annotation name. * * @param annotation The annotation name * @param <T> The annotation type * @return A {@link AnnotationValue} instance or null */ default @Nullable <T extends Annotation> AnnotationValue<T> getAnnotation(@Nonnull String annotation) { ArgumentUtils.requireNonNull("annotation", annotation); return this.<T>findAnnotation(annotation).orElse(null); }
/** * Find an {@link AnnotationValue} for the given annotation name. * * @param annotationClass The annotation name * @param <T> The annotation type * @return A {@link AnnotationValue} instance or null */ default @Nullable <T extends Annotation> AnnotationValue<T> getAnnotation(@Nonnull Class<T> annotationClass) { ArgumentUtils.requireNonNull("annotationClass", annotationClass); return this.findAnnotation(annotationClass).orElse(null); }
/** * Find the first declared annotation name for the given stereotype. * * @param stereotype The stereotype * @return The annotation name */ default @Nonnull Optional<Class<? extends Annotation>> getDeclaredAnnotationTypeByStereotype(@Nonnull Class<? extends Annotation> stereotype) { ArgumentUtils.requireNonNull("stereotype", stereotype); return getDeclaredAnnotationTypeByStereotype(stereotype.getName()); }
/** * Get the value of default "value" the given annotation. * * @param annotation The annotation class * @return An {@link Optional} of the value */ default @Nonnull Optional<Object> getValue(@Nonnull Class<? extends Annotation> annotation) { ArgumentUtils.requireNonNull("annotation", annotation); return getValue(annotation, AnnotationMetadata.VALUE_MEMBER, Object.class); }
/** * Return the body as the given type. * * @param type The type of the body * @param <T> The generic type * @return An {@link Optional} of the type or {@link Optional#empty()} if the body cannot be returned as the given type */ default @Nonnull <T> Optional<T> getBody(@Nonnull Class<T> type) { ArgumentUtils.requireNonNull("type", type); return getBody(Argument.of(type)); }
/** * Return the body as the given type. * * @param type The type of the body * @param <T> The generic type * @return An {@link Optional} of the type or {@link Optional#empty()} if the body cannot be returned as the given type */ default @Nonnull <T> Optional<T> getBody(@Nonnull Argument<T> type) { ArgumentUtils.requireNonNull("type", type); return getBody().flatMap(b -> ConversionService.SHARED.convert(b, ConversionContext.of(type))); }