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

io.opentimeline.util.Pair Maven / Gradle / Ivy

// SPDX-License-Identifier: Apache-2.0
// Copyright Contributors to the OpenTimelineIO Project.

package io.opentimeline.util;

/**
 * A generic class that holds a pair of values.
 *
 * @param  type for first value
 * @param  type for second value
 */
public class Pair {
    private T first;
    private U second;

    public Pair(T first, U second) {
        this.first = first;
        this.second = second;
    }

    public T getFirst() {
        return first;
    }

    public U getSecond() {
        return second;
    }

    @Override
    public boolean equals(Object obj) {
        if (!(obj instanceof Pair))
            return false;
        boolean firstEqual =
                (((Pair) obj).getFirst() == null && ((Pair) obj).getFirst() == null) ||
                        ((Pair) obj).getFirst().equals(this.getFirst());
        boolean secondEqual =
                (((Pair) obj).getSecond() == null && ((Pair) obj).getSecond() == null) ||
                        ((Pair) obj).getSecond().equals(this.getSecond());
        return firstEqual && secondEqual;
    }

    @Override
    public String toString() {
        return this.getClass().getCanonicalName() +
                "(" +
                "first=" + this.getFirst().toString() +
                ", second=" + this.getSecond().toString() +
                ")";
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy