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

com.samskivert.depot.util.Tuple4 Maven / Gradle / Ivy

//
// Depot library - a Java relational persistence library
// https://github.com/threerings/depot/blob/master/LICENSE

package com.samskivert.depot.util;

import java.io.Serializable;

import com.google.common.base.Objects;

/**
 * Contains a four column result. This class is immutable and the objects it references are also
 * meant to be immutable. They will generally contain only Depot primitive types (Java primitives,
 * SQL primitives and some array types), which should be treated as immutable.
 */
public class Tuple4 implements Serializable
{
    /** The first column of the result. */
    public final A a;

    /** The second column of the result. */
    public final B b;

    /** The third column of the result. */
    public final C c;

    /** The fourth column of the result. */
    public final D d;

    /** Constructs an initialized tuple. */
    public static  Tuple4 create (A a, B b, C c, D d)
    {
        return new Tuple4(a, b, c, d);
    }

    /** Creates a builder for 4-tuples. */
    public static  Builder4, A, B, C, D> builder ()
    {
        return new Builder4, A, B, C, D>() {
            public Tuple4 build (A a, B b, C c, D d) {
                return create(a, b, c, d);
            }
        };
    }

    /** Constructs an initialized tuple. */
    public Tuple4 (A a, B b, C c, D d)
    {
        this.a = a;
        this.b = b;
        this.c = c;
        this.d = d;
    }

    @Override
    public String toString ()
    {
        return "[" + a + "," + b + "," + c + "," + d + "]";
    }

    @Override
    public int hashCode ()
    {
        return Objects.hashCode(a, b, c, d);
    }

    @Override
    public boolean equals (Object other)
    {
        if (other instanceof Tuple4) {
            Tuple4 otup = (Tuple4)other;
            return Objects.equal(a, otup.a) && Objects.equal(b, otup.b) &&
                Objects.equal(c, otup.c) && Objects.equal(d, otup.d);
        } else {
            return false;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy