Java tutorial
/** * ------------------------------------------------------ * Laboratrio de Linguagens e Tcnicas Adaptativas * Escola Politcnica, Universidade So Paulo * ------------------------------------------------------ * * This program is free software: you can redistribute it * and/or modify it under the terms of the GNU General * Public License as published by the Free Software * Foundation, either version 3 of the License, or (at * your option) any later version. * * This program 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 General Public License * for more details. * **/ package br.usp.poli.lta.cereda.wirth2ape.tuple; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; /** * @author Paulo Roberto Massa Cereda * @version 1.0 * @since 1.0 */ public class Pair<A, B> { private A first; private B second; public Pair(A first, B second) { this.first = first; this.second = second; } public A getFirst() { return first; } public void setFirst(A first) { this.first = first; } public B getSecond() { return second; } public void setSecond(B second) { this.second = second; } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("(").append(first); sb.append(", ").append(second); sb.append(")"); return sb.toString(); } public Pair() { } @Override public int hashCode() { return new HashCodeBuilder().append(first).append(second).build(); } @Override public boolean equals(Object object) { if (object == null) { return false; } if (getClass() != object.getClass()) { return false; } final Pair<?, ?> reference = (Pair<?, ?>) object; return new EqualsBuilder().append(first, reference.first).append(second, reference.second).isEquals(); } }