Skip to content

Commit e5a4498

Browse files
CLIENTS-1063: Added equals() and hashCode in StoreBucketProperties.
1 parent 8614261 commit e5a4498

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed

src/main/java/com/basho/riak/client/api/commands/buckets/StoreBucketProperties.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.basho.riak.client.core.operations.StoreBucketPropsOperation;
2121
import com.basho.riak.client.core.query.Namespace;
2222
import com.basho.riak.client.core.query.functions.Function;
23+
import java.util.Objects;
2324

2425
/**
2526
* Command used to store (modify) the properties of a bucket in Riak.
@@ -215,6 +216,48 @@ protected StoreBucketPropsOperation buildCoreOperation()
215216
return builder.build();
216217
}
217218

219+
@Override
220+
public boolean equals(Object other) {
221+
if (this == other) {
222+
return true;
223+
}
224+
if (!(other instanceof StoreBucketProperties)) {
225+
return false;
226+
}
227+
StoreBucketProperties otherStoreBucketProperties = (StoreBucketProperties) other;
228+
return Objects.equals(namespace, otherStoreBucketProperties.namespace) &&
229+
Objects.equals(allowMulti, otherStoreBucketProperties.allowMulti) &&
230+
Objects.equals(backend, otherStoreBucketProperties.backend) &&
231+
Objects.equals(basicQuorum, otherStoreBucketProperties.basicQuorum) &&
232+
Objects.equals(bigVClock, otherStoreBucketProperties.bigVClock) &&
233+
Objects.equals(chashkeyFunction, otherStoreBucketProperties.chashkeyFunction) &&
234+
Objects.equals(lastWriteWins, otherStoreBucketProperties.lastWriteWins) &&
235+
Objects.equals(linkWalkFunction, otherStoreBucketProperties.linkWalkFunction) &&
236+
Objects.equals(rw, otherStoreBucketProperties.rw) &&
237+
Objects.equals(dw, otherStoreBucketProperties.dw) &&
238+
Objects.equals(w, otherStoreBucketProperties.w) &&
239+
Objects.equals(r, otherStoreBucketProperties.r) &&
240+
Objects.equals(pr, otherStoreBucketProperties.pr) &&
241+
Objects.equals(pw, otherStoreBucketProperties.pw) &&
242+
Objects.equals(notFoundOk, otherStoreBucketProperties.notFoundOk) &&
243+
Objects.equals(preCommitHook, otherStoreBucketProperties.preCommitHook) &&
244+
Objects.equals(postCommitHook, otherStoreBucketProperties.postCommitHook) &&
245+
Objects.equals(oldVClock, otherStoreBucketProperties.oldVClock) &&
246+
Objects.equals(youngVClock, otherStoreBucketProperties.youngVClock) &&
247+
Objects.equals(smallVClock, otherStoreBucketProperties.smallVClock) &&
248+
Objects.equals(nval, otherStoreBucketProperties.nval) &&
249+
Objects.equals(legacySearch, otherStoreBucketProperties.legacySearch) &&
250+
Objects.equals(searchIndex, otherStoreBucketProperties.searchIndex) &&
251+
Objects.equals(hllPrecision, otherStoreBucketProperties.hllPrecision);
252+
}
253+
254+
@Override
255+
public int hashCode() {
256+
return Objects.hash(namespace, allowMulti, backend, basicQuorum, bigVClock, chashkeyFunction, lastWriteWins,
257+
linkWalkFunction, rw, dw, w, r, pr, pw, notFoundOk, preCommitHook, postCommitHook, oldVClock,
258+
youngVClock, smallVClock, nval, legacySearch, searchIndex, hllPrecision);
259+
}
260+
218261
public static class Builder
219262
{
220263
private final Namespace namespace;
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.basho.riak.client.api.commands.buckets;
2+
3+
import com.basho.riak.client.core.query.Namespace;
4+
import org.junit.Test;
5+
import static org.hamcrest.CoreMatchers.equalTo;
6+
import static org.hamcrest.CoreMatchers.is;
7+
import static org.hamcrest.CoreMatchers.not;
8+
import static org.hamcrest.MatcherAssert.assertThat;
9+
10+
public class StoreBucketPropertiesTest {
11+
@Test
12+
public void equalsReturnsTrueForEqualBucketProperties() {
13+
StoreBucketProperties storeBucketProperties1 = new StoreBucketProperties.Builder(new Namespace("namespace"))
14+
.withBackend("backend").withNotFoundOk(true).withHllPrecision(15)
15+
.withNVal(3).withPr(1).withPw(2).withR(1).withRw(1).withW(1).withDw(3).withBasicQuorum(false)
16+
.withAllowMulti(true).withLastWriteWins(true)
17+
.withBigVClock(42L).withOldVClock(41L).withSmallVClock(5L).withYoungVClock(19L)
18+
.withLegacyRiakSearchEnabled(false).withSearchIndex("index")
19+
.build();
20+
StoreBucketProperties storeBucketProperties2 = new StoreBucketProperties.Builder(new Namespace("namespace"))
21+
.withBackend("backend").withNotFoundOk(true).withHllPrecision(15)
22+
.withNVal(3).withPr(1).withPw(2).withR(1).withRw(1).withW(1).withDw(3).withBasicQuorum(false)
23+
.withAllowMulti(true).withLastWriteWins(true)
24+
.withBigVClock(42L).withOldVClock(41L).withSmallVClock(5L).withYoungVClock(19L)
25+
.withLegacyRiakSearchEnabled(false).withSearchIndex("index")
26+
.build();
27+
28+
assertThat(storeBucketProperties1, is(equalTo(storeBucketProperties2)));
29+
assertThat(storeBucketProperties2, is(equalTo(storeBucketProperties1)));
30+
}
31+
32+
@Test
33+
public void equalsReturnsFalseForDifferentBucketProperties() {
34+
StoreBucketProperties storeBucketProperties1 = new StoreBucketProperties.Builder(new Namespace("namespace1"))
35+
.withBackend("backend1").withNotFoundOk(true).withHllPrecision(14)
36+
.withNVal(3).withPr(1).withPw(2).withR(1).withRw(1).withW(1).withDw(3).withBasicQuorum(false)
37+
.withAllowMulti(true).withLastWriteWins(true)
38+
.withBigVClock(42L).withOldVClock(41L).withSmallVClock(5L).withYoungVClock(19L)
39+
.withLegacyRiakSearchEnabled(false).withSearchIndex("index1")
40+
.build();
41+
StoreBucketProperties storeBucketProperties2 = new StoreBucketProperties.Builder(new Namespace("namespace2"))
42+
.withBackend("backend2").withNotFoundOk(false).withHllPrecision(16)
43+
.withNVal(5).withPr(2).withPw(4).withR(2).withRw(2).withW(2).withDw(4).withBasicQuorum(true)
44+
.withAllowMulti(false).withLastWriteWins(false)
45+
.withBigVClock(43L).withOldVClock(42L).withSmallVClock(4L).withYoungVClock(190L)
46+
.withLegacyRiakSearchEnabled(true).withSearchIndex("index2")
47+
.build();
48+
49+
assertThat(storeBucketProperties1, is(not(equalTo(storeBucketProperties2))));
50+
assertThat(storeBucketProperties2, is(not(equalTo(storeBucketProperties1))));
51+
}
52+
}

0 commit comments

Comments
 (0)