1// © 2016 and later: Unicode, Inc. and others. 2// License & terms of use: http://www.unicode.org/copyright.html#License 3/* 4 ******************************************************************************* 5 * Copyright (C) 2014, International Business Machines Corporation and 6 * others. All Rights Reserved. 7 ******************************************************************************* 8 */ 9package com.ibm.icu.impl; 10 11/** 12 * A pair of objects: first and second. 13 * 14 * @param <F> first object type 15 * @param <S> second object type 16 */ 17public class Pair<F, S> { 18 public final F first; 19 public final S second; 20 21 protected Pair(F first, S second) { 22 this.first = first; 23 this.second = second; 24 } 25 26 /** 27 * Creates a pair object 28 * @param first must be non-null 29 * @param second must be non-null 30 * @return The pair object. 31 */ 32 public static <F, S> Pair<F, S> of(F first, S second) { 33 if (first == null || second == null) { 34 throw new IllegalArgumentException("Pair.of requires non null values."); 35 } 36 return new Pair<F, S>(first, second); 37 } 38 39 @Override 40 public boolean equals(Object other) { 41 if (other == this) { 42 return true; 43 } 44 if (!(other instanceof Pair)) { 45 return false; 46 } 47 Pair<?, ?> rhs = (Pair<?, ?>) other; 48 return first.equals(rhs.first) && second.equals(rhs.second); 49 } 50 51 @Override 52 public int hashCode() { 53 return first.hashCode() * 37 + second.hashCode(); 54 } 55} 56