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

ma.vi.base.tuple.T2 Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2016 Vikash Madhow
 */

package ma.vi.base.tuple;

/**
 * A 2-tuple contains a pair of objects accessible as the fields a and b.
 *
 * @author Vikash Madhow ([email protected])
 */
public class T2 extends AbstractTuple {
  public T2() {
    this(null, null);
  }

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

  @Override
  public int size() {
    return 2;
  }

  @Override
  public Object get(int i) {
    return switch (i) {
      case 0 -> a;
      case 1 -> b;
      default -> throw new IndexOutOfBoundsException("Index " + i + " is out of bounds for a " + size() + "-tuple");
    };
  }

  @Override
  public T2 clone() throws CloneNotSupportedException {
    return (T2) super.clone();
  }

  public static  T2 of(A a, B b) {
    return new T2<>(a, b);
  }

  public A a() {
    return a;
  }

  public B b() {
    return b;
  }

  public A a;
  public B b;
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy