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