`
pan_java
  • 浏览: 280645 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

ibatis 缓存模块 key实现类

    博客分类:
  • java
阅读更多
  //更新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;
  }
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics