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 * @param <A> Object 1 type.
023 * @param <B> Object 2 type.
024 * @param <C> Object 3 type.
025 */
026public class Tuple3<A,B,C> {
027
028   /**
029    * Creator.
030    *
031    * @param <A> Object 1 type.
032    * @param <B> Object 2 type.
033    * @param <C> Object 3 type.
034    * @param a Object 1.
035    * @param b Object 2.
036    * @param c Object 3.
037    * @return A new tuple object.
038    */
039   public static <A,B,C> Tuple3<A,B,C> of(A a, B b, C c) {
040      return new Tuple3<>(a,b,c);
041   }
042
043   private final A a;
044   private final B b;
045   private final C c;
046
047   /**
048    * Constructor.
049    *
050    * @param a Object 1.
051    * @param b Object 2.
052    * @param c Object 3.
053    */
054   public Tuple3(A a, B b, C c) {
055      this.a = a;
056      this.b = b;
057      this.c = c;
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   /**
079    * Returns the third object in this tuple.
080    *
081    * @return The third object in this tuple.
082    */
083   public C getC() {
084      return c;
085   }
086
087   @Override /* Object */
088   public int hashCode() {
089      return HashCode.of(a,b,c);
090   }
091
092   @Override /* Object */
093   public boolean equals(Object o) {
094      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));
095   }
096}