
org.organicdesign.fp.oneOf.None Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Paguro Show documentation
Show all versions of Paguro Show documentation
Immutable Clojure collections and a Transformation abstraction for Java 8+, immutably, type-safely, and with good performance.
package org.organicdesign.fp.oneOf;
import org.organicdesign.fp.function.Fn0;
import org.organicdesign.fp.function.Fn1;
/** Represents the absence of a value */
public final class None implements Option {
// For serializable. Make sure to change whenever internal data format changes.
private static final long serialVersionUID = 20170810211300L;
// ========================================== Static ==========================================
/** None is a singleton and this is its only instance. */
static final Option NONE = new None();
/** Generic version of the singleton instance. */
@SuppressWarnings("unchecked")
public static None none() { return (None) NONE; }
/** Private constructor for singleton. */
private None() {}
/** {@inheritDoc} */
@Override public T get() { throw new IllegalStateException("Called get on None"); }
/** {@inheritDoc} */
@Override public T getOrElse(T t) { return t; }
/** {@inheritDoc} */
@Override public boolean isSome() { return false; }
//
// @Override public UnmodSortedIterator iterator() {
// return UnmodSortedIterator.empty();
// }
/** {@inheritDoc} */
@Override public U match(Fn1 has, Fn0 hasNot) {
return hasNot.get();
}
/** {@inheritDoc} */
@Override public Option then(Fn1> f) { return Option.none(); }
/** Valid, but deprecated because it's usually an error to call this in client code. */
@Deprecated // Has no effect. Darn!
@Override public int hashCode() { return 0; }
/** Valid, but deprecated because it's usually an error to call this in client code. */
@Deprecated // Has no effect. Darn!
@Override public boolean equals(Object other) {
return (this == other) || (other instanceof org.organicdesign.fp.oneOf.None);
}
/** Defend our singleton property in the face of deserialization. */
private Object readResolve() { return NONE; }
@Override public String toString() { return "None"; }
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy