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