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

cn.woodwhales.common.business.collection.CollectionContainer Maven / Gradle / Ivy

There is a newer version: 3.8.3
Show newest version
package cn.woodwhales.common.business.collection;

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

/**
 * @author woodwhales on 2020-12-13 16:32
 */
public class CollectionContainer implements CollectionFieldComparable {

    private T data;

    private K dataKey;

    public CollectionContainer(T data, K dataKey) {
        this.data = data;
        this.dataKey = dataKey;
    }

    public T getData() {
        return data;
    }

    @Override
    public K getDataKey() {
        return dataKey;
    }

    public static  CollectionContainer build(T data, Function keyFunction) {
        return new CollectionContainer(data, keyFunction.apply(data));
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof CollectionContainer)) {
            return false;
        }
        CollectionContainer that = (CollectionContainer) o;
        return getDataKey().equals(that.getDataKey());
    }

    @Override
    public int hashCode() {
        return Objects.hash(getDataKey());
    }

    @Override
    public String toString() {
        return "CollectionContainer{" +
                "data=" + data +
                ", dataKey=" + dataKey +
                '}';
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy