All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opencastproject.util.data.Tuple Maven / Gradle / Ivy

There is a newer version: 16.6
Show newest version
/*
 * Licensed to The Apereo Foundation under one or more contributor license
 * agreements. See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 *
 * The Apereo Foundation licenses this file to you under the Educational
 * Community License, Version 2.0 (the "License"); you may not use this file
 * except in compliance with the License. You may obtain a copy of the License
 * at:
 *
 *   http://opensource.org/licenses/ecl2.txt
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
 * License for the specific language governing permissions and limitations under
 * the License.
 *
 */


package org.opencastproject.util.data;

import static org.opencastproject.util.EqualsUtil.eqClasses;

import java.util.Objects;

/** A pair. */
public final class Tuple {

  private final A a;
  private final B b;

  public Tuple(A a, B b) {
    this.a = a;
    this.b = b;
  }

  /** Get the first element. */
  public A getA() {
    return a;
  }

  /** Get the second element. */
  public B getB() {
    return b;
  }

  @Override
  public boolean equals(Object that) {
    if (this == that)
      return true;
    if (!eqClasses(this, that))
      return false;
    Tuple thatc = (Tuple) that;
    return a.equals(thatc.a) && b.equals(thatc.b);
  }

  @Override
  public int hashCode() {
    return Objects.hash(a, b);
  }

  /** Create a new tuple with two elements a and b. */
  public static  Tuple tuple(A a, B b) {
    return new Tuple(a, b);
  }

  @Override
  public String toString() {
    return "(" + a + "," + b + ")";
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy