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

com.squarespace.cldrengine.api.Option Maven / Gradle / Ivy

The newest version!
package com.squarespace.cldrengine.api;

import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;

@AllArgsConstructor
@EqualsAndHashCode
public class Option {

  private T value;

  public static  Option option() {
    return new Option<>(null);
  }

  public static  Option option(T value) {
    return new Option<>(value);
  }

  public void clear() {
    this.value = null;
  }

  public void set(T value) {
    this.value = value;
  }

  public void set(Option opt) {
    this.value = opt.get();
  }

  public void setIf(Option opt) {
    if (!ok()) {
      this.value = opt.get();
    }
  }

  public T get() {
    return value;
  }

  public T or(T defvalue) {
    return value == null ? defvalue : value;
  }

  public boolean ok() {
    return value != null;
  }

  @Override
  public String toString() {
    return value == null ? "null" : value.toString();
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy