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