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

aima.core.util.datastructure.Triplet Maven / Gradle / Ivy

Go to download

AIMA-Java Core Algorithms from the book Artificial Intelligence a Modern Approach 3rd Ed.

There is a newer version: 3.0.0
Show newest version
package aima.core.util.datastructure;

/**
 * @author Ravi Mohan
 * @author Mike Stampone
 * 
 */
public class Triplet {
	private final X x;

	private final Y y;

	private final Z z;

	/**
	 * Constructs a triplet with three specified elements.
	 * 
	 * @param x
	 *            the first element of the triplet.
	 * @param y
	 *            the second element of the triplet.
	 * @param z
	 *            the third element of the triplet.
	 */
	public Triplet(X x, Y y, Z z) {
		this.x = x;
		this.y = y;
		this.z = z;
	}

	/**
	 * Returns the first element of the triplet.
	 * 
	 * @return the first element of the triplet.
	 */
	public X getFirst() {
		return x;
	}

	/**
	 * Returns the second element of the triplet.
	 * 
	 * @return the second element of the triplet.
	 */
	public Y getSecond() {
		return y;
	}

	/**
	 * Returns the third element of the triplet.
	 * 
	 * @return the third element of the triplet.
	 */
	public Z getThird() {
		return z;
	}

	@Override
	public boolean equals(Object o) {
		if (o instanceof Triplet) {
			Triplet other = (Triplet) o;
			return (x.equals(other.x)) && (y.equals(other.y))
					&& (z.equals(other.z));
		}
		return false;
	}

	@Override
	public int hashCode() {
		return x.hashCode() + 31 * y.hashCode() + 31 * z.hashCode();
	}

	@Override
	public String toString() {
		return "< " + x.toString() + " , " + y.toString() + " , "
				+ z.toString() + " >";
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy