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

koji.developerkit.utils.duplet.Triplet Maven / Gradle / Ivy

Go to download

Koji's Developer kit is a dev kit I made for Minecraft that can make creating things and doing things within the Minecraft Spigot API easier

There is a newer version: 2.0.2.8
Show newest version
package koji.developerkit.utils.duplet;

import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Stream;

public class Triplet extends Tuple {

    private A first;

    private B second;

    private C third;

    private Triplet(A first, B second, C third) {
        this.first = first;
        this.second = second;
        this.third = third;
    }

    public static  Function, Stream> flat(
            Function mapFirst,
            Function mapSecond,
            Function mapThird) {

        return triplet -> triplet.stream(mapFirst, mapSecond, mapThird);
    }

    public  Stream stream(Function mapFirst,
                                Function mapSecond,
                                Function mapThird) {

        return Stream.of(mapFirst.apply(first), mapSecond.apply(second), mapThird.apply(third));
    }

    public static  Function, Quartet> mapToQuartet(
            TriFunction fun) {

        return triplet -> triplet.add(fun.apply(triplet.first, triplet.second, triplet.third));
    }

    public  Quartet add(D fourth) {

        return Quartet.of(first, second, third, fourth);
    }

    public static  Triplet of(A first, B second, C third) {

        return new Triplet<>(first, second, third);
    }

    public A getFirst() {
        return first;
    }

    public B getSecond() {
        return second;
    }

    public C getThird() {
        return third;
    }

    public void setFirst(A first) {
        this.first = first;
    }

    public void setSecond(B second) {
        this.second = second;
    }

    public void setThird(C third) {
        this.third = third;
    }

    public  boolean contains(T object) {
        return getFirst().equals(object) || getSecond().equals(object) || getThird().equals(object);
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("Triplet{");
        sb.append("first=").append(first);
        sb.append(", second=").append(second);
        sb.append(", third=").append(third);
        sb.append('}');
        return sb.toString();
    }

    public boolean equals(Triplet other) {
        return first.equals(other.getFirst())
                && second.equals(other.getSecond())
                && third.equals(other.getThird());
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Triplet triplet = (Triplet) o;
        return Objects.equals(first, triplet.first) &&
                Objects.equals(second, triplet.second) &&
                Objects.equals(third, triplet.third);
    }

    @Override
    public int hashCode() {
        return Objects.hash(first, second, third);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy