gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 11:49:58 25 4
gpt4 key购买 nike

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

为我的类实现 hashcodeequals 方法有多重要。我上面的 @PrimaryKeyClasshashcode 实现应该是什么

最佳答案

// 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);
}

关于java - spring-data-cassandra的PrimaryKeyClass中hashCode的实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28870090/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com