com.ibm.icu.impl.Pair Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of icu4j Show documentation
Show all versions of icu4j Show documentation
International Component for Unicode for Java (ICU4J) is a mature, widely used Java library
providing Unicode and Globalization support
// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/*
*******************************************************************************
* Copyright (C) 2014, International Business Machines Corporation and
* others. All Rights Reserved.
*******************************************************************************
*/
package com.ibm.icu.impl;
/**
* A pair of objects: first and second.
*
* @param first object type
* @param second object type
*/
public class Pair {
public final F first;
public final S second;
protected Pair(F first, S second) {
this.first = first;
this.second = second;
}
/**
* Creates a pair object
* @param first must be non-null
* @param second must be non-null
* @return The pair object.
*/
public static Pair of(F first, S second) {
if (first == null || second == null) {
throw new IllegalArgumentException("Pair.of requires non null values.");
}
return new Pair(first, second);
}
@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}
if (!(other instanceof Pair)) {
return false;
}
Pair, ?> rhs = (Pair, ?>) other;
return first.equals(rhs.first) && second.equals(rhs.second);
}
@Override
public int hashCode() {
return first.hashCode() * 37 + second.hashCode();
}
}