Class ConditionalMultibind<T>

java.lang.Object
org.apache.druid.guice.ConditionalMultibind<T>

public class ConditionalMultibind<T> extends Object
Provides the ability to conditionally bind an item to a set. The condition is based on the value set in the runtime.properties. Usage example: ConditionalMultibind.create(props, binder, Animal.class) .addConditionBinding("animal.type", Predicates.equalTo("cat"), Cat.class) .addConditionBinding("animal.type", Predicates.equalTo("dog"), Dog.class); At binding time, this will check the value set for property "animal.type" in props. If the value is "cat", it will add a binding to Cat.class. If the value is "dog", it will add a binding to Dog.class. At injection time, you will get the items that satisfy their corresponding predicates by calling injector.getInstance(Key.get(new TypeLiteral<Set>(){}))
  • Constructor Details

    • ConditionalMultibind

      public ConditionalMultibind(Properties properties, com.google.inject.multibindings.Multibinder<T> multibinder)
  • Method Details

    • create

      public static <T> ConditionalMultibind<T> create(Properties properties, com.google.inject.Binder binder, Class<T> type)
      Create a ConditionalMultibind that resolves items to be added to the set at "binding" time.
      Type Parameters:
      T - interface type.
      Parameters:
      properties - the runtime properties.
      binder - the binder for the injector that is being configured.
      type - the type that will be injected.
      Returns:
      An instance of ConditionalMultibind that can be used to add conditional bindings.
    • create

      public static <T> ConditionalMultibind<T> create(Properties properties, com.google.inject.Binder binder, Class<T> type, Class<? extends Annotation> annotationType)
      Create a ConditionalMultibind that resolves items to be added to the set at "binding" time.
      Type Parameters:
      T - interface type.
      Parameters:
      properties - the runtime properties.
      binder - the binder for the injector that is being configured.
      type - the type that will be injected.
      annotationType - the binding annotation.
      Returns:
      An instance of ConditionalMultibind that can be used to add conditional bindings.
    • create

      public static <T> ConditionalMultibind<T> create(Properties properties, com.google.inject.Binder binder, com.google.inject.TypeLiteral<T> type)
      Create a ConditionalMultibind that resolves items to be added to the set at "binding" time.
      Type Parameters:
      T - interface type.
      Parameters:
      properties - the runtime properties.
      binder - the binder for the injector that is being configured.
      type - the type that will be injected.
      Returns:
      An instance of ConditionalMultibind that can be used to add conditional bindings.
    • create

      public static <T> ConditionalMultibind<T> create(Properties properties, com.google.inject.Binder binder, com.google.inject.TypeLiteral<T> type, Class<? extends Annotation> annotationType)
      Create a ConditionalMultibind that resolves items to be added to the set at "binding" time.
      Type Parameters:
      T - interface type.
      Parameters:
      properties - the runtime properties.
      binder - the binder for the injector that is being configured.
      type - the type that will be injected.
      annotationType - the binding annotation.
      Returns:
      An instance of ConditionalMultibind that can be used to add conditional bindings.
    • addBinding

      public ConditionalMultibind<T> addBinding(Class<? extends T> target)
      Unconditionally bind target to the set.
      Parameters:
      target - the target class to which it adds a binding.
      Returns:
      self to support a continuous syntax for adding more conditional bindings.
    • addBinding

      public ConditionalMultibind<T> addBinding(T target)
      Unconditionally bind target to the set.
      Parameters:
      target - the target instance to which it adds a binding.
      Returns:
      self to support a continuous syntax for adding more conditional bindings.
    • addBinding

      public ConditionalMultibind<T> addBinding(com.google.inject.TypeLiteral<T> target)
      Unconditionally bind target to the set.
      Parameters:
      target - the target type to which it adds a binding.
      Returns:
      self to support a continuous syntax for adding more conditional bindings.
    • addConditionBinding

      public ConditionalMultibind<T> addConditionBinding(String property, com.google.common.base.Predicate<String> condition, Class<? extends T> target)
      Conditionally bind target to the set. If "condition" returns true, add a binding to "target".
      Parameters:
      property - the property to inspect on
      condition - the predicate used to verify whether to add a binding to "target"
      target - the target class to which it adds a binding.
      Returns:
      self to support a continuous syntax for adding more conditional bindings.
    • addConditionBinding

      public ConditionalMultibind<T> addConditionBinding(String property, String defaultValue, com.google.common.base.Predicate<String> condition, Class<? extends T> target)
    • addConditionBinding

      public ConditionalMultibind<T> addConditionBinding(String property, com.google.common.base.Predicate<String> condition, T target)
      Conditionally bind target to the set. If "condition" returns true, add a binding to "target".
      Parameters:
      property - the property to inspect on
      condition - the predicate used to verify whether to add a binding to "target"
      target - the target instance to which it adds a binding.
      Returns:
      self to support a continuous syntax for adding more conditional bindings.
    • addConditionBinding

      public ConditionalMultibind<T> addConditionBinding(String property, com.google.common.base.Predicate<String> condition, com.google.inject.TypeLiteral<T> target)
      Conditionally bind target to the set. If "condition" returns true, add a binding to "target".
      Parameters:
      property - the property to inspect on
      condition - the predicate used to verify whether to add a binding to "target"
      target - the target type to which it adds a binding.
      Returns:
      self to support a continuous syntax for adding more conditional bindings.
    • matchCondition

      public boolean matchCondition(String property, com.google.common.base.Predicate<String> condition)
    • matchCondition

      public boolean matchCondition(String property, @Nullable String defaultValue, com.google.common.base.Predicate<String> condition)