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

com.almasb.fxgl.physics.Pair Maven / Gradle / Ivy

/*
 * FXGL - JavaFX Game Library. The MIT License (MIT).
 * Copyright (c) AlmasB ([email protected]).
 * See LICENSE for details.
 */
package com.almasb.fxgl.physics;

/**
 * For internal use.
 *
 * @param  pair type
 * @author Almas Baimagambetov (AlmasB) ([email protected])
 */
class Pair {

    private T a, b;

    Pair(T a, T b) {
        this.a = a;
        this.b = b;
    }

    T getA() {
        return a;
    }

    void setA(T a) {
        this.a = a;
    }

    T getB() {
        return b;
    }

    void setB(T b) {
        this.b = b;
    }

    @Override
    public boolean equals(Object o) {
        return equal((Pair) o, a, b);
    }

    @Override
    public int hashCode() {
        int hash = 0;

        if (a != null)
            hash += a.hashCode();

        if (b != null)
            hash += b.hashCode();

        return hash;
    }

    /**
     * Note: order doesn't matter.
     *
     * @param a pair element
     * @param b pair element
     * @return true iff this pair equals given pair elements
     */
    public boolean equal(T a, T b) {
        return equal(this, a, b);
    }

    @SuppressWarnings("PMD.UselessParentheses")
    private static boolean equal(Pair pair, Object a, Object b) {
        return (pair.a == a && pair.b == b) || (pair.a == b && pair.b == a);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy