com.g2forge.alexandria.java.fluent.optional.NullableOptional Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ax-java Show documentation
Show all versions of ax-java Show documentation
Standard Java library and the basis of the ${alexandria.name} project.
package com.g2forge.alexandria.java.fluent.optional;
import com.g2forge.alexandria.java.fluent.optional.factory.IOptionalFactory;
public class NullableOptional extends AOptional {
protected static final NullableOptional> EMPTY = new NullableOptional<>();
public static final IOptionalFactory FACTORY = new IOptionalFactory() {
@Override
public NullableOptional empty() {
return NullableOptional.empty();
}
@Override
public NullableOptional of(T value) {
return NullableOptional.of(value);
}
@Override
public NullableOptional ofNullable(T value) {
return NullableOptional.ofNullable(value);
}
};
public static NullableOptional empty() {
@SuppressWarnings("unchecked")
final NullableOptional retVal = (NullableOptional) EMPTY;
return retVal;
}
public static NullableOptional of(T value) {
return new NullableOptional<>(value);
}
public static NullableOptional ofNullable(T value) {
return value == null ? empty() : of(value);
}
protected final boolean isValid;
protected NullableOptional() {
super();
this.isValid = false;
}
protected NullableOptional(T value) {
super(value);
this.isValid = true;
}
@Override
protected <_T> AOptional<_T> create() {
return NullableOptional.empty();
}
@Override
protected <_T> AOptional<_T> create(_T value) {
return NullableOptional.of(value);
}
@Override
public boolean isEmpty() {
return !isValid;
}
}