001/*
002 * (C) Copyright 2013 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl-2.1.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Martin Pernollet
016 */
017
018package org.nuxeo.ecm.platform.groups.audit.service.acl;
019
020import java.io.Serializable;
021
022/**
023 * Class Pair. Represents a mathematical pair of objects (a, b).
024 */
025public class Pair<X, Y> implements Serializable {
026    private static final long serialVersionUID = 4246736946032440512L;
027
028    /**
029     * a in the pair (a, b)
030     */
031    public final X a;
032
033    /**
034     * b in the pair (a, b)
035     */
036    public final Y b;
037
038    /**
039     * Construct a Pair(a, b)
040     *
041     * @param a a in the pair (a, b)
042     * @param b b in the pair (a, b)
043     */
044    public Pair(X a, Y b) {
045        this.a = a;
046        this.b = b;
047    }
048
049    @Override
050    public int hashCode() {
051        final int prime = 31;
052        int result = 1;
053        result = prime * result + ((a == null) ? 0 : a.hashCode());
054        result = prime * result + ((b == null) ? 0 : b.hashCode());
055        return result;
056    }
057
058    @Override
059    public boolean equals(Object obj) {
060        if (this == obj)
061            return true;
062        if (obj == null)
063            return false;
064        if (getClass() != obj.getClass())
065            return false;
066        @SuppressWarnings("rawtypes")
067        Pair other = (Pair) obj;
068        if (a == null) {
069            if (other.a != null)
070                return false;
071        } else if (!a.equals(other.a))
072            return false;
073        if (b == null) {
074            if (other.b != null)
075                return false;
076        } else if (!b.equals(other.b))
077            return false;
078        return true;
079    }
080
081    public static <M, N> Pair<M, N> of(M x, N y) {
082        return new Pair<M, N>(x, y);
083    }
084}