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

com.g2forge.alexandria.java.fluent.optional.NullableOptional Maven / Gradle / Ivy

There is a newer version: 0.0.18
Show newest version
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;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy