/*-
 *  Copyright 2020 Beuth Hochschule für Technik Berlin, Hochschule für Technik Stuttgart
 * 
 *  This file is part of CityDoctor2.
 *
 *  CityDoctor2 is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  CityDoctor2 is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with CityDoctor2.  If not, see <https://www.gnu.org/licenses/>.
 */
package de.hft.stuttgart.citydoctor2.utils;

import java.io.Serializable;

/**
 * When a pair of values is needed that need to be serialized.
 * 
 * @author Matthias Betz
 *
 * @param <A> Type of value 1, needs to implement Serializable
 * @param <B> Type of value 2, needs to implement Serializable
 */
public class SerializablePair<A extends Serializable, B extends Serializable> implements Serializable {

	private static final long serialVersionUID = -5307944001963352647L;

	private A a;
	private B b;

	public SerializablePair(A a, B b) {
		this.a = a;
		this.b = b;
	}

	public SerializablePair(SerializablePair<? extends A, ? extends B> other) {
		this.a = other.a;
		this.b = other.b;
	}

	public A getValue0() {
		return a;
	}

	public B getValue1() {
		return b;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((a == null) ? 0 : a.hashCode());
		result = prime * result + ((b == null) ? 0 : b.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;
		}
		SerializablePair<?, ?> other = (SerializablePair<?, ?>) obj;
		if (a == null) {
			if (other.a != null) {
				return false;
			}
		} else if (!a.equals(other.a)) {
			return false;
		}
		if (b == null) {
			if (other.b != null) {
				return false;
			}
		} else if (!b.equals(other.b)) {
			return false;
		}
		return true;
	}

	@Override
	public String toString() {
		return "SerializablePair [a=" + a + ", b=" + b + "]";
	}

}
