cloud.prefab.client.value.FixedValue Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of prefab-cloud-java Show documentation
Show all versions of prefab-cloud-java Show documentation
API Client for https://prefab.cloud: rate limits, feature flags and semaphores as a service
The newest version!
package cloud.prefab.client.value;
import com.google.common.base.Optional;
import java.util.function.Function;
public class FixedValue implements Value {
private final Optional value;
public FixedValue() {
this.value = Optional.absent();
}
public FixedValue(T value) {
this.value = Optional.of(value);
}
@Override
public T get() {
if (value.isPresent()) {
return value.get();
} else {
throw new RuntimeException("Fixed Value Unset");
}
}
@Override
public T or(T defaultValue) {
return value.or(defaultValue);
}
@Override
public T orNull() {
if (value.isPresent()) {
return value.get();
} else {
return null;
}
}
public static FixedValue of(T value) {
return new FixedValue(value);
}
public static FixedValue absent() {
return new FixedValue();
}
@Override
public String toString() {
return String.format("FixedValue{}=%s", value.orNull());
}
}