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

com.salesforce.jgrapht.alg.util.Pair Maven / Gradle / Ivy

Go to download

This project contains the apt processor that implements all the checks enumerated in @Verify. It is a self contained, and shaded jar.

There is a newer version: 2.0.7
Show newest version
/*
 * (C) Copyright 2015-2017, by Alexey Kudinkin and Contributors.
 *
 * JGraphT : a free Java graph-theory library
 *
 * This program and the accompanying materials are dual-licensed under
 * either
 *
 * (a) the terms of the GNU Lesser General Public License version 2.1
 * as published by the Free Software Foundation, or (at your option) any
 * later version.
 *
 * or (per the licensee's choosing)
 *
 * (b) the terms of the Eclipse Public License v1.0 as published by
 * the Eclipse Foundation.
 */
package com.salesforce.jgrapht.alg.util;

import java.io.*;
import java.util.*;

/**
 * Generic pair.
 * 
 * 

* Although the instances of this class are immutable, it is impossible to ensure that the * references passed to the constructor will not be modified by the caller. * * @param the first element type * @param the second element type * */ public class Pair implements Serializable { private static final long serialVersionUID = 8176288675989092842L; /** * The first pair element */ protected final A first; /** * The second pair element */ protected final B second; /** * Create a new pair * * @param a the first element * @param b the second element */ public Pair(A a, B b) { this.first = a; this.second = b; } /** * Get the first element of the pair * * @return the first element of the pair */ public A getFirst() { return first; } /** * Get the second element of the pair * * @return the second element of the pair */ public B getSecond() { return second; } /** * Assess if this pair contains an element. * * @param e The element in question * * @return true if contains the element, false otherwise * * @param the element type */ public boolean hasElement(E e) { if (e == null) { return first == null || second == null; } else { return e.equals(first) || e.equals(second); } } @Override public String toString() { return "(" + first + "," + second + ")"; } @Override public boolean equals(Object o) { if (this == o) return true; else if (!(o instanceof Pair)) return false; @SuppressWarnings("unchecked") Pair other = (Pair) o; return Objects.equals(first, other.first) && Objects.equals(second, other.second); } @Override public int hashCode() { return Objects.hash(first, second); } /** * Creates new pair of elements pulling of the necessity to provide corresponding types of the * elements supplied. * * @param a first element * @param b second element * @param the first element type * @param the second element type * @return new pair */ public static Pair of(A a, B b) { return new Pair<>(a, b); } } // End Pair.java