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

io.ipfs.api.Pair Maven / Gradle / Ivy

There is a newer version: 0.4.1
Show newest version
package io.ipfs.api;

import java.util.function.Function;

public class Pair {
    public final L left;
    public final R right;

    public Pair(L left, R right) {
        this.left = left;
        this.right = right;
    }

    public Pair swapped() {
        return new Pair<>(right, left);
    }

    public  Pair apply(Function applyLeft, Function applyRight) {
        return new Pair<>(
                applyLeft.apply(left),
                applyRight.apply(right));
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Pair pair = (Pair) o;

        if (left != null ? !left.equals(pair.left) : pair.left != null) return false;
        return right != null ? right.equals(pair.right) : pair.right == null;

    }

    @Override
    public int hashCode() {
        int result = left != null ? left.hashCode() : 0;
        result = 31 * result + (right != null ? right.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return String.format("(%s, %s)", left.toString(), right.toString());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy