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