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 3 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 * @param <C> Object 3 type.
028 */
029public class Tuple3<A,B,C> {
030
031   /**
032    * Static creator.
033    *
034    * @param <A> Object 1 type.
035    * @param <B> Object 2 type.
036    * @param <C> Object 3 type.
037    * @param a Object 1.
038    * @param b Object 2.
039    * @param c Object 3.
040    * @return A new tuple object.
041    */
042   public static <A,B,C> Tuple3<A,B,C> of(A a, B b, C c) {
043      return new Tuple3<>(a,b,c);
044   }
045
046   private final A a;
047   private final B b;
048   private final C c;
049
050   /**
051    * Constructor.
052    *
053    * @param a Object 1.
054    * @param b Object 2.
055    * @param c Object 3.
056    */
057   public Tuple3(A a, B b, C c) {
058      this.a = a;
059      this.b = b;
060      this.c = c;
061   }
062
063   /**
064    * Returns the first object in this tuple.
065    *
066    * @return The first object in this tuple.
067    */
068   public A getA() {
069      return a;
070   }
071
072   /**
073    * Returns the second object in this tuple.
074    *
075    * @return The second object in this tuple.
076    */
077   public B getB() {
078      return b;
079   }
080
081   /**
082    * Returns the third object in this tuple.
083    *
084    * @return The third object in this tuple.
085    */
086   public C getC() {
087      return c;
088   }
089
090   @Override /* Object */
091   public int hashCode() {
092      return HashCode.of(a,b,c);
093   }
094
095   @Override /* Object */
096   public boolean equals(Object o) {
097      return o instanceof Tuple3 && eq(this, (Tuple3<?,?,?>)o, (x,y)->eq(x.a,y.a) && eq(x.b,y.b) && eq(x.c,y.c));
098   }
099}