Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLIENTS-1063: Added equals() and hashCode in Search. #700

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,48 @@ else if (option.getKey() == Option.DEFAULT_OPERATION)
return builder.build();
}

@Override
public boolean equals(Object o)
{
if (this == o)
{
return true;
}

if (!(o instanceof Search))
{
return false;
}

Search search = (Search) o;

return start == search.start &&
rows == search.rows &&
Objects.equals(index, search.index) &&
Objects.equals(query, search.query) &&
presort == search.presort &&
Objects.equals(filterQuery, search.filterQuery) &&
Objects.equals(sortField, search.sortField) &&
Objects.equals(returnFields, search.returnFields) &&
Objects.equals(options, search.options);
}

@Override
public int hashCode()
{
return Objects.hash(index, query, start, rows, presort, filterQuery, sortField, returnFields, options);
}

/*
* Options For controlling how Riak performs the search operation.
* <p>
* These options can be supplied to the {@link Search.Builder} to change
* how Riak performs the operation. These override the defaults provided
* by Riak.
* </p>
* @author Dave Rusek <drusek at basho dot com>
* @since 2.0
*/
* Options For controlling how Riak performs the search operation.
* <p>
* These options can be supplied to the {@link Search.Builder} to change
* how Riak performs the operation. These override the defaults provided
* by Riak.
* </p>
* @author Dave Rusek <drusek at basho dot com>
* @since 2.0
*/
public static final class Option<T> extends RiakOption<T>
{
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.basho.riak.client.api.commands.search;

import org.junit.Test;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;

public class SearchTest
{
@Test
public void equalsReturnsTrueForEqualNamespaces()
{
Search search1 = new Search.Builder("index", "query").filter("filter")
.withPresort(Search.Presort.KEY).sort("sort")
.returnFields("field1", "field2")
.withStart(10).withRows(10)
.withOption(Search.Option.DEFAULT_OPERATION, Search.Option.Operation.AND).build();
Search search2 = new Search.Builder("index", "query").filter("filter")
.withPresort(Search.Presort.KEY).sort("sort")
.returnFields("field1", "field2")
.withStart(10).withRows(10)
.withOption(Search.Option.DEFAULT_OPERATION, Search.Option.Operation.AND).build();

assertThat(search1, is(equalTo(search2)));
assertThat(search2, is(equalTo(search1)));
}

@Test
public void equalsReturnsFalseForDifferentNamespaces()
{
Search search1 = new Search.Builder("index1", "query1").filter("filter1")
.withPresort(Search.Presort.KEY).sort("sort1")
.returnFields("field1")
.withStart(10).withRows(10)
.withOption(Search.Option.DEFAULT_OPERATION, Search.Option.Operation.AND).build();
Search search2 = new Search.Builder("index2", "query2").filter("filter2")
.withPresort(Search.Presort.SCORE).sort("sort2")
.returnFields("field2")
.withStart(5).withRows(5)
.withOption(Search.Option.DEFAULT_FIELD, "field2").build();

assertThat(search1, is(not(equalTo(search2))));
assertThat(search2, is(not(equalTo(search1))));
}
}