All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mageddo.togglefirst.FeatureMetadata Maven / Gradle / Ivy

There is a newer version: 1.4.9
Show newest version
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);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy