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

cloud.prefab.client.value.FixedValue Maven / Gradle / Ivy

Go to download

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());
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy