001// *************************************************************************************************************************** 002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * 003// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * 004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * 005// * with the License. You may obtain a copy of the License at * 006// * * 007// * http://www.apache.org/licenses/LICENSE-2.0 * 008// * * 009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * 010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * 011// * specific language governing permissions and limitations under the License. * 012// *************************************************************************************************************************** 013package org.apache.juneau.utils; 014 015import static org.apache.juneau.internal.ObjectUtils.*; 016 017import org.apache.juneau.internal.*; 018 019/** 020 * Represents a simple tuple of 2 objects. 021 * 022 * @param <A> Object 1 type. 023 * @param <B> Object 2 type. 024 */ 025public class Tuple2<A,B> { 026 027 /** 028 * Creator. 029 * 030 * @param <A> Object 1 type. 031 * @param <B> Object 2 type. 032 * @param a Object 1. 033 * @param b Object 2. 034 * @return A new tuple object. 035 */ 036 public static <A,B> Tuple2<A,B> of(A a, B b) { 037 return new Tuple2<>(a,b); 038 } 039 040 private final A a; 041 private final B b; 042 043 /** 044 * Constructor. 045 * 046 * @param a Object 1. 047 * @param b Object 2. 048 */ 049 public Tuple2(A a, B b) { 050 this.a = a; 051 this.b = b; 052 } 053 054 /** 055 * Returns the first object in this tuple. 056 * 057 * @return The first object in this tuple. 058 */ 059 public A getA() { 060 return a; 061 } 062 063 /** 064 * Returns the second object in this tuple. 065 * 066 * @return The second object in this tuple. 067 */ 068 public B getB() { 069 return b; 070 } 071 072 @Override /* Object */ 073 public int hashCode() { 074 return HashCode.of(a,b); 075 } 076 077 @Override /* Object */ 078 public boolean equals(Object o) { 079 return o instanceof Tuple2 && eq(this, (Tuple2<?,?>)o, (x,y)->eq(x.a,y.a) && eq(x.b,y.b)); 080 } 081}