Skip to content

Commit a2bed7c

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

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

src/main/java/com/basho/riak/client/core/query/search/YokozunaIndex.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package com.basho.riak.client.core.query.search;
1717

18+
import java.util.Objects;
19+
1820
/**
1921
* Represents a Yokozuna Index.
2022
*
@@ -115,4 +117,23 @@ public Integer getNVal()
115117
{
116118
return nVal;
117119
}
120+
121+
@Override
122+
public boolean equals(Object other) {
123+
if (this == other) {
124+
return true;
125+
}
126+
if (!(other instanceof YokozunaIndex)) {
127+
return false;
128+
}
129+
YokozunaIndex otherYokozunaIndex = (YokozunaIndex) other;
130+
return Objects.equals(name, otherYokozunaIndex.name) &&
131+
Objects.equals(schema, otherYokozunaIndex.schema) &&
132+
Objects.equals(nVal, otherYokozunaIndex.nVal);
133+
}
134+
135+
@Override
136+
public int hashCode() {
137+
return Objects.hash(name, schema, nVal);
138+
}
118139
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.basho.riak.client.core.query.search;
2+
3+
import org.junit.Test;
4+
import static org.hamcrest.CoreMatchers.equalTo;
5+
import static org.hamcrest.CoreMatchers.is;
6+
import static org.hamcrest.CoreMatchers.not;
7+
import static org.hamcrest.MatcherAssert.assertThat;
8+
9+
public class YokozunaIndexTest {
10+
@Test
11+
public void equalsReturnsTrueForEqualYokozunaIndices() {
12+
YokozunaIndex yokozunaIndex1 = new YokozunaIndex("name", "schema").withNVal(3);
13+
YokozunaIndex yokozunaIndex2 = new YokozunaIndex("name", "schema").withNVal(3);
14+
15+
assertThat(yokozunaIndex1, is(equalTo(yokozunaIndex2)));
16+
assertThat(yokozunaIndex2, is(equalTo(yokozunaIndex1)));
17+
}
18+
19+
@Test
20+
public void equalsReturnsFalseForDifferentYokozunaIndices() {
21+
YokozunaIndex yokozunaIndex1 = new YokozunaIndex("name1", "schema1").withNVal(3);
22+
YokozunaIndex yokozunaIndex2 = new YokozunaIndex("name2", "schema2").withNVal(5);
23+
24+
assertThat(yokozunaIndex1, is(not(equalTo(yokozunaIndex2))));
25+
assertThat(yokozunaIndex2, is(not(equalTo(yokozunaIndex1))));
26+
}
27+
}

0 commit comments

Comments
 (0)