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

org.davidmoten.kool.Indexed Maven / Gradle / Ivy

There is a newer version: 0.1.36
Show newest version
package org.davidmoten.kool;

import com.github.davidmoten.guavamini.Preconditions;

public final class Indexed {

    private final T t;
    private final int index;

    private Indexed(T t, int index) {
        Preconditions.checkNotNull(t);
        this.t = t;
        this.index = index;
    }

    public static  Indexed create(T t, int index) {
        return new Indexed(t, index);
    }

    public T value() {
        return t;
    }

    public int index() {
        return index;
    }
    
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + index;
        result = prime * result + t.hashCode();
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        Indexed other = (Indexed) obj;
        if (index != other.index)
            return false;
        if (!t.equals(other.t))
            return false;
        return true;
    }

    @Override
    public String toString() {
        return "Indexed[index=" + index + ", value=" + t + "]";
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy