001// Copyright (c) FIRST and other WPILib contributors.
002// Open Source Software; you can modify and/or share it under the terms of
003// the WPILib BSD license file in the root directory of this project.
004
005package edu.wpi.first.math;
006
007/**
008 * Represents a pair of two objects.
009 *
010 * @param <A> The first object's type.
011 * @param <B> The second object's type.
012 */
013public class Pair<A, B> {
014  private final A m_first;
015  private final B m_second;
016
017  /**
018   * Constructs a pair.
019   *
020   * @param first The first object.
021   * @param second The second object.
022   */
023  public Pair(A first, B second) {
024    m_first = first;
025    m_second = second;
026  }
027
028  /**
029   * Returns the first object.
030   *
031   * @return The first object.
032   */
033  public A getFirst() {
034    return m_first;
035  }
036
037  /**
038   * Returns the second object.
039   *
040   * @return The second object.
041   */
042  public B getSecond() {
043    return m_second;
044  }
045
046  /**
047   * Returns a pair comprised of the two given objects.
048   *
049   * @param <A> The first object's type.
050   * @param <B> The second object's type.
051   * @param a The first object.
052   * @param b The second object.
053   * @return A pair comprised of the two given objects.
054   */
055  public static <A, B> Pair<A, B> of(A a, B b) {
056    return new Pair<>(a, b);
057  }
058}