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