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

org.identityconnectors.common.Pair Maven / Gradle / Ivy

/*
 * ====================
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 * 
 * Copyright 2008-2009 Sun Microsystems, Inc. All rights reserved.     
 * 
 * The contents of this file are subject to the terms of the Common Development 
 * and Distribution License("CDDL") (the "License").  You may not use this file 
 * except in compliance with the License.
 * 
 * You can obtain a copy of the License at 
 * http://IdentityConnectors.dev.java.net/legal/license.txt
 * See the License for the specific language governing permissions and limitations 
 * under the License. 
 * 
 * When distributing the Covered Code, include this CDDL Header Notice in each file
 * and include the License file at identityconnectors/legal/license.txt.
 * If applicable, add the following below this CDDL Header, with the fields 
 * enclosed by brackets [] replaced by your own identifying information: 
 * "Portions Copyrighted [year] [name of copyright owner]"
 * ====================
 */
package org.identityconnectors.common;

/**
 * An arbitrary pair of objects. Convenient for when you want a method
 * to return a pair of objects.
 */
public class Pair {

    public T1 first;
    public T2 second;

    public Pair() {
    }

    public Pair(T1 f,
                T2 s) {
        this.first  = f;
        this.second = s;    
    }

    public int hashCode() {
        int rv = 0;
        if (first != null) {
            rv ^= first.hashCode();
        }
        if (second != null) {
            rv ^= second.hashCode();
        }
        return rv;
    }

    private static boolean equals(Object o1, Object o2) {
        if (o1 == null) {
            return o2 == null;
        }
        else if (o2 == null) {
            return false;
        }
        else {
            return o1.equals(o2);
        }
    }

    public boolean equals(Object o) {
        if (o instanceof Pair) {
            Pair other = (Pair)o;
            return ( equals ( this.first, other.first ) &&
                     equals ( this.second, other.second ) );
        }
        return false;
    }

    public String toString() {
        return "( "+this.first+", "+this.second+" )";
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy