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

se.bjurr.violations.lib.util.Present Maven / Gradle / Ivy

There is a newer version: 1.157.3
Show newest version
package se.bjurr.violations.lib.util;

import static se.bjurr.violations.lib.util.Utils.checkNotNull;

import java.util.Collections;
import java.util.Set;

final class Present extends Optional {
  private static final long serialVersionUID = 0;

  private final T reference;

  Present(T reference) {
    this.reference = reference;
  }

  @Override
  public Set asSet() {
    return Collections.singleton(reference);
  }

  @Override
  public boolean equals(Object object) {
    if (object instanceof Present) {
      Present other = (Present) object;
      return reference.equals(other.reference);
    }
    return false;
  }

  @Override
  public T get() {
    return reference;
  }

  @Override
  public int hashCode() {
    return 0x598df91c + reference.hashCode();
  }

  @Override
  public boolean isPresent() {
    return true;
  }

  @Override
  public T or(T defaultValue) {
    checkNotNull(defaultValue, "use Optional.orNull() instead of Optional.or(null)");
    return reference;
  }

  @Override
  public T orNull() {
    return reference;
  }

  @Override
  public String toString() {
    return "Optional.of(" + reference + ")";
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy