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

com.google.code.liquidform.internal.Pair Maven / Gradle / Ivy

Go to download

Provides a Java Domain Specific Language for building type-safe and refactoring proof JPA queries.

The newest version!
/*
 * Copyright (C) 2008-2009 the original author or authors
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *         http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.code.liquidform.internal;

/**
 * General purpose pair class. One can decide to use == on parts in
 * {@link #equals(Object)} implementation, or to use first.equals() and
 * second.equals() to compare pairs (this is the default).
 * 
 * @param 
 *            the type of the first "part"
 * @param 
 *            the type of the second "part"
 */
public class Pair {

	public final U first;

	public final V second;

	private final boolean useEquals;

	public Pair(U first, V second) {
		this.first = first;
		this.second = second;
		this.useEquals = true;
	}

	public Pair(U first, V second, boolean useEquals) {
		this.first = first;
		this.second = second;
		this.useEquals = useEquals;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((first == null) ? 0 : first.hashCode());
		result = prime * result + ((second == null) ? 0 : second.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		Pair other = (Pair) obj;
		if (first == null) {
			if (other.first != null) {
				return false;
			}
		} else if (useEquals ? !first.equals(other.first)
				: first != other.first) {
			return false;
		}
		if (second == null) {
			if (other.second != null) {
				return false;
			}
		} else if (useEquals ? !second.equals(other.second)
				: second != other.second) {
			return false;
		}
		return true;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy