Skip to content

Commit 8614261

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

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

src/main/java/com/basho/riak/client/api/commands/search/StoreIndex.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.basho.riak.client.api.AsIsRiakCommand;
44
import com.basho.riak.client.core.operations.YzPutIndexOperation;
55
import com.basho.riak.client.core.query.search.YokozunaIndex;
6+
import java.util.Objects;
67

78
/**
89
* Command used to store a search index in Riak.
@@ -36,6 +37,24 @@ protected YzPutIndexOperation buildCoreOperation()
3637
return opBuilder.build();
3738
}
3839

40+
@Override
41+
public boolean equals(Object other) {
42+
if (this == other) {
43+
return true;
44+
}
45+
if (!(other instanceof StoreIndex)) {
46+
return false;
47+
}
48+
Builder otherStoreIndex = ((StoreIndex) other).cmdBuilder;
49+
return Objects.equals(cmdBuilder.index, otherStoreIndex.index)
50+
&& Objects.equals(cmdBuilder.timeout, otherStoreIndex.timeout);
51+
}
52+
53+
@Override
54+
public int hashCode() {
55+
return Objects.hash(cmdBuilder.index, cmdBuilder.timeout);
56+
}
57+
3958
/**
4059
* Builder for a StoreIndex command.
4160
*/
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.basho.riak.client.api.commands.search;
2+
3+
import com.basho.riak.client.core.query.search.YokozunaIndex;
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 StoreIndexTest {
11+
@Test
12+
public void equalsReturnsTrueForEqualIndexAndTimeout() {
13+
YokozunaIndex index1 = new YokozunaIndex("index");
14+
YokozunaIndex index2 = new YokozunaIndex("index");
15+
16+
StoreIndex storeIndex1 = new StoreIndex.Builder(index1).withTimeout(5).build();
17+
StoreIndex storeIndex2 = new StoreIndex.Builder(index2).withTimeout(5).build();
18+
19+
assertThat(storeIndex1, is(equalTo(storeIndex2)));
20+
assertThat(storeIndex2, is(equalTo(storeIndex1)));
21+
}
22+
23+
@Test
24+
public void equalsReturnsFalseForDifferentIndexAndTimeout() {
25+
YokozunaIndex index1 = new YokozunaIndex("index1");
26+
YokozunaIndex index2 = new YokozunaIndex("index2");
27+
28+
StoreIndex storeIndex1 = new StoreIndex.Builder(index1).withTimeout(5).build();
29+
StoreIndex storeIndex2 = new StoreIndex.Builder(index2).withTimeout(8).build();
30+
31+
assertThat(storeIndex1, is(not(equalTo(storeIndex2))));
32+
assertThat(storeIndex2, is(not(equalTo(storeIndex1))));
33+
}
34+
}

0 commit comments

Comments
 (0)