spring-data-cassandra的PrimaryKeyClass中hashCode的实现

Implementation of hashCode in PrimaryKeyClass of spring-data-cassandra

我正在使用 spring-data-cassandra 并且有一个 table 这样 它的主键是 ((int_col1,int_col2),bigint_col1,bigint_col2)int_col1&int_col2 是分区键 bigint_col1 & bigint_col2 是簇键。

为我的 class 实施 hashcodeequals 方法有多重要。 我上面的 @PrimaryKeyClass

hashcode 实现应该是什么
// your class's constructor should have exactly four arguments
// and ensure that each of these four fields are non-null

@Override
public int hashCode() {
  return 37
    ^ int_col1.hashCode()
    ^ int_col2.hashCode()
    ^ bigint_col1.hashCode()
    ^ bigint_col2.hashCode();
}

@Override
public boolean equals(Object that) {
  if (this == that) {
    return true;
  }
  if (that == null) {
    return false;
  }
  if (!(that instanceof YourPrimaryKeyClass)) {
    return false;
  }
  YourPrimaryKeyClass other = (YourPrimaryKeyClass) that;
  return this.int_col1.equals(other.int_col1)
    && this.int_col2.equals(other.int_col2)
    && bigint_col1.equals(other.bigint_col1)
    && bigint_col2.equals(other.bigint_col2);
}