Skip to content

Instantly share code, notes, and snippets.

@jose-mgmaestre
Last active April 16, 2018 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jose-mgmaestre/d39c8a22d498152804b42292fffa13a0 to your computer and use it in GitHub Desktop.
Save jose-mgmaestre/d39c8a22d498152804b42292fffa13a0 to your computer and use it in GitHub Desktop.
This class will inject random blood objects for a Blood interface
@Module
public class RandomInjectionModule {
private static Blood blood;
public RandomInjectionModule() {
}
@Provides
static Blood provideBlood(){
if(blood != null) {
return blood;
}
Random rnd = new Random();
int rndNumber = rnd.nextInt(3);
switch (rndNumber){
case 0: blood = new A_Blood(); break;
case 1: blood = new B_Blood(); break;
case 2: blood = new AB_Blood(); break;
case 4: blood = new O_Blood(); break;
default: blood = new A_Blood();
}
return blood;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment