
io.paradoxical.dropwizard.guice.AutoConfigBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dropwizard-guice Show documentation
Show all versions of dropwizard-guice Show documentation
Simple library for using Guice DI in a dropwizard service forked from hubspot/dropwizard-guice.
package io.paradoxical.dropwizard.guice;
import com.google.common.collect.ImmutableSet;
import lombok.NonNull;
import java.lang.annotation.Annotation;
import java.util.function.Predicate;
public class AutoConfigBuilder {
private static final Predicate> DefaultTypePredicate = c -> true;
private Predicate> typePredicate = DefaultTypePredicate;
private ImmutableSet searchPackages = ImmutableSet.of();
public AutoConfig build() {
if (typePredicate != DefaultTypePredicate) {
return new FilteredAutoConfig(searchPackages, typePredicate);
}
return new AutoConfig(searchPackages);
}
public AutoConfigBuilder searchPackages(@NonNull String... packages) {
searchPackages = ImmutableSet.builder()
.add(packages)
.addAll(searchPackages)
.build();
return this;
}
public AutoConfigBuilder addTypeFilter(@NonNull final Predicate> typeFilter) {
typePredicate = this.typePredicate.and(typeFilter);
return this;
}
public AutoConfigBuilder withAnnotation(@NonNull final Class extends Annotation> annotation) {
return addTypeFilter(type -> type.isAnnotationPresent(annotation));
}
public AutoConfigBuilder withoutAnnotation(@NonNull final Class extends Annotation> annotation) {
return addTypeFilter(type -> !type.isAnnotationPresent(annotation));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy