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

org.macrocloud.kernel.toolkit.tuple.Pair Maven / Gradle / Ivy

There is a newer version: 1.1.0-RELEASE
Show newest version
package org.macrocloud.kernel.toolkit.tuple;

import lombok.*;


// TODO: Auto-generated Javadoc
/**
 * tuple Pair.
 *
 * @author macro
 * @param  the generic type
 * @param  the generic type
 */

@Getter
@ToString
@EqualsAndHashCode
public class Pair {
	
	/** The Constant EMPTY. */
	private static final Pair EMPTY = new Pair<>(null, null);

	/** The left. */
	private final L left;
	
	/** The right. */
	private final R right;


	/**
	 * Empty.
	 *
	 * @return the pair
	 */
	@SuppressWarnings("unchecked")
	public static  Pair empty() {
		return (Pair) EMPTY;
	}


	/**
	 * Creates the left.
	 *
	 * @return the pair
	 */
	public static  Pair createLeft(L left) {
		if (left == null) {
			return empty();
		} else {
			return new Pair<>(left, null);
		}
	}

	/**
	 * Creates the right.
	 * @return the pair
	 */
	public static  Pair createRight(R right) {
		if (right == null) {
			return empty();
		} else {
			return new Pair<>(null, right);
		}
	}

	/**
	 * Creates the.
	 * @return the pair
	 */
	public static  Pair create(L left, R right) {
		if (right == null && left == null) {
			return empty();
		} else {
			return new Pair<>(left, right);
		}
	}

	/**
	 * Instantiates a new pair.
	 *
	 */
	private Pair(L left, R right) {
		this.left = left;
		this.right = right;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy