ibatis 缓存模块 key实现类
程序员文章站
2022-05-23 12:55:49
...
//更新CacheKey hashcode ,每个参数加进来都会更新一次hashcode
public CacheKey update(Object object) {
int baseHashCode = object.hashCode();
count++;
checksum += baseHashCode;
baseHashCode *= count;
hashcode = multiplier * hashcode + baseHashCode;
paramList.add(object);
return this;
}
//CacheKey 的 equals 方法显的有点烦锁
public boolean equals(Object object) {
if (this == object) return true;
if (!(object instanceof CacheKey)) return false;
final CacheKey cacheKey = (CacheKey) object;
if (hashcode != cacheKey.hashcode) return false;
if (checksum != cacheKey.checksum) return false;
if (count != cacheKey.count) return false;
for (int i=0; i < paramList.size(); i++) {
Object thisParam = paramList.get(i);
Object thatParam = cacheKey.paramList.get(i);
if(thisParam == null) {
if (thatParam != null) return false;
} else {
if (!thisParam.equals(thatParam)) return false;
}
}
return true;
}