KO 及缓存数据结构
Last updated
Last updated
import java.util.Objects;
public final class ImeiSnKo {
private final Long imei;
private final String sn;
private final int hashCode;
public static final ImeiSnKo create(Long imei, String sn) {
return new ImeiSnKo(imei, sn);
}
private ImeiSnKo(Long imei, String sn) {
this.imei = imei;
this.sn = sn;
this.hashCode = 31 * Objects.hashCode(imei) + Objects.hashCode(sn);
}
@Override
public int hashCode() {
return hashCode;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof ImeiSnKo) {
ImeiSnKo ko = (ImeiSnKo) obj;
return Objects.equals(imei, ko.imei) && Objects.equals(sn, ko.sn);
}
return false;
}
}public final class TripleIntKey {
private final int i;
private final int j;
private final int k;
private final int hash;
public static final TripleIntKey create(int i, int j, int k) {
return new TripleIntKey(i, j, k);
}
private TripleIntKey(int i, int j, int k) {
this.i = i;
this.j = j;
this.k = k;
this.hash = 31 * (31 * i + j) + k;
}
@Override
public int hashCode() {
return hash;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof TripleIntKey) {
TripleIntKey ko = (TripleIntKey) obj;
return i == ko.i && j == ko.j && k == ko.k;
}
return false;
}
@Override
public String toString() {
return new StringBuilder().append(i).append('-').append(j).append('-').append(k).toString();
}
}