Skip to content

Conditional multi bind#2724

Merged
fjy merged 1 commit intoapache:masterfrom
guobingkun:conditional_multi_bind
Mar 25, 2016
Merged

Conditional multi bind#2724
fjy merged 1 commit intoapache:masterfrom
guobingkun:conditional_multi_bind

Conversation

@guobingkun
Copy link
Copy Markdown
Contributor

Reopen of druid-io/druid-api#76
A follow up PR of #2682

Usage example:

       ConditionalMultibind.create(props, binder, Animal.class)
                           .conditionBinder("animal.type", Predicates.equalTo("cat"), Cat.class)
                           .conditionBinder("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 ingestion time, you will get the items that satisfy their corresponding predicates by calling
injector.getInstance(Key.get(new TypeLiteral<Set<Animal>>(){}))

Usage example:
       ConditionalMultibind.create(props, binder, Animal.class)
                           .conditionBinder("animal.type", Predicates.equalTo("cat"), Cat.class)
                           .conditionBinder("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 ingestion time, you will get the items that satisfy their corresponding predicates by calling
injector.getInstance(Key.get(new TypeLiteral<Set<Animal>>(){}))
@drcrallen
Copy link
Copy Markdown
Contributor

👍

1 similar comment
@fjy
Copy link
Copy Markdown
Contributor

fjy commented Mar 25, 2016

👍

@fjy fjy merged commit 9809430 into apache:master Mar 25, 2016
@guobingkun guobingkun deleted the conditional_multi_bind branch March 25, 2016 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants