com.mageddo.togglefirst.FeatureMetadata Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of toggle-first-core Show documentation
Show all versions of toggle-first-core Show documentation
Enable and disable your features in production on a button click
package com.mageddo.togglefirst;
import java.util.Map;
import static com.mageddo.commons.StringUtils.isBlank;
/**
* Represents stored feature metadata, all feature data is stored at {@link #parameters()}.
* You can use {@link #set(String, String)} and {@link #remove(String)} to manage data and the others methods
* to parse and retrieve data
*
* @see DefaultFeatureMetadata
*/
public interface FeatureMetadata {
Feature feature();
Map parameters();
FeatureMetadata set(String k, String v);
String get(String k);
default String get(String k, String defaultValue){
final String v = get(k);
if(isBlank(v)){
return defaultValue;
}
return v;
}
void remove(String k);
default Status status(){
return Status.fromCode(get(FeatureKeys.STATUS), Status.INACTIVE);
}
default boolean isActive(){
return Status.ACTIVE == status();
}
default String value(){
return value("");
}
default String value(String defaultValue){
final String v = get(FeatureKeys.VALUE);
return isBlank(v) ? defaultValue : v;
}
default Integer asInteger(String key){
return asInteger(key, null);
}
default Integer asInteger(String key, Integer defaultValue){
final String v = get(key);
if(isBlank(v)){
return defaultValue;
}
return Integer.valueOf(v);
}
default Long asLong(String key){
return asLong(key, null);
}
default Long asLong(String key, Long defaultValue){
final String v = get(key);
if(isBlank(v)){
return defaultValue;
}
return Long.valueOf(v);
}
default Boolean asBoolean(String key){
return asBoolean(key, null);
}
default Boolean asBoolean(String key, Boolean defaultValue){
final String v = get(key);
if(isBlank(v)) {
return defaultValue;
}
return "1".equals(v);
}
}