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

com.xlrit.gears.base.function.Optional Maven / Gradle / Ivy

There is a newer version: 1.17.6
Show newest version
package com.xlrit.gears.base.function;

import java.util.Collection;

public class Optional {

	@FunctionalInterface
	public interface Function1 {
		R apply(A a);
	}

	@FunctionalInterface
	public interface Function2 {
		R apply(A a, B b);
	}

	@FunctionalInterface
	public interface Function3 {
		R apply(A a, B b, C c);
	}

	@FunctionalInterface
	public interface Function4 {
		R apply(A a, B b, C c, D d);
	}

	public static  R optional(Collection a, Function1,R> op) {
		return a == null || a.isEmpty() ? null : op.apply(a);
	}

	public static  R optional(A a, Function1 op) {
		return a == null ? null : op.apply(a);
	}

	public static  R optional(A a, B b, Function2 op) {
		return a == null || b == null ? null : op.apply(a,b);
	}

	public static  R optional(A a, B b, C c, Function3 op) {
		return a == null || b == null || c == null ? null : op.apply(a,b,c);
	}

	public static  R optional(A a, B b, C c, D d, Function4 op) {
		return a == null || b == null || c == null || d == null ? null : op.apply(a,b,c,d);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy