cn.woodwhales.common.business.collection.CollectionContainer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of woodwhales-common Show documentation
Show all versions of woodwhales-common Show documentation
https://github.com/woodwhales
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