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 * <h5 class='section'>See Also:</h5><ul>
023 * </ul>
024 *
025 * @param <A> Object 1 type.
026 * @param <B> Object 2 type.
027 */
028public class Tuple2<A,B> {
029
030   /**
031    * Static creator.
032    *
033    * @param <A> Object 1 type.
034    * @param <B> Object 2 type.
035    * @param a Object 1.
036    * @param b Object 2.
037    * @return A new tuple object.
038    */
039   public static <A,B> Tuple2<A,B> of(A a, B b) {
040      return new Tuple2<>(a,b);
041   }
042
043   private final A a;
044   private final B b;
045
046   /**
047    * Constructor.
048    *
049    * @param a Object 1.
050    * @param b Object 2.
051    */
052   public Tuple2(A a, B b) {
053      this.a = a;
054      this.b = b;
055   }
056
057   /**
058    * Returns the first object in this tuple.
059    *
060    * @return The first object in this tuple.
061    */
062   public A getA() {
063      return a;
064   }
065
066   /**
067    * Returns the second object in this tuple.
068    *
069    * @return The second object in this tuple.
070    */
071   public B getB() {
072      return b;
073   }
074
075   @Override /* Object */
076   public int hashCode() {
077      return HashCode.of(a,b);
078   }
079
080   @Override /* Object */
081   public boolean equals(Object o) {
082      return o instanceof Tuple2 && eq(this, (Tuple2<?,?>)o, (x,y)->eq(x.a,y.a) && eq(x.b,y.b));
083   }
084}