Created
May 21, 2013 13:28
-
-
Save chkal/5619754 to your computer and use it in GitHub Desktop.
Using multiple feature enums with Togglz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MultiEnumFeatureProvider implements FeatureProvider { | |
private final Set<Feature> features = new LinkedHashSet<>(); | |
public MultiEnumFeatureProvider( Class<? extends Feature>... enumTypes ) { | |
for( Class<? extends Feature> clazz : enumTypes ) { | |
for( Feature feature : clazz.getEnumConstants() ) { | |
features.add( feature ); | |
} | |
} | |
} | |
@Override | |
public Set<Feature> getFeatures() { | |
return Collections.unmodifiableSet( features ); | |
} | |
@Override | |
public FeatureMetaData getMetaData( Feature feature ) { | |
return new EnumFeatureMetaData( getFeatureByName( feature.name() ) ); | |
} | |
private Feature getFeatureByName( String name ) { | |
for( Feature f : getFeatures() ) { | |
if( f.name().equals( name ) ) { | |
return f; | |
} | |
} | |
throw new IllegalArgumentException( "Unknown feature: " + name ); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyTogglzConfig implements TogglzBootstrap { | |
@Override | |
public FeatureManager createFeatureManager() { | |
FeatureProvider featureProvider = new MultiEnumFeatureProvider( Features1.class, Features2.class ); | |
return new FeatureManagerBuilder() | |
.featureProvider( featureProvider ) | |
.stateRepository( new InMemoryStateRepository() ) | |
.userProvider( new NoOpUserProvider() ) | |
.build(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment