DATAMONGO-2170 - Polishing.

Use ObjectUtils to compote hash code as hash code implementation contained artifacts that do not belong there. Extract test method.

Original pull request: #629.
This commit is contained in:
Mark Paluch
2019-01-07 13:09:37 +01:00
parent acdee76ff3
commit 4b6a058335
2 changed files with 16 additions and 13 deletions

View File

@@ -118,7 +118,7 @@ public class IndexInfo {
/**
* Returns the individual index fields of the index.
*
*
* @return
*/
public List<IndexField> getIndexFields() {
@@ -127,7 +127,7 @@ public class IndexInfo {
/**
* Returns whether the index is covering exactly the fields given independently of the order.
*
*
* @param keys must not be {@literal null}.
* @return
*/
@@ -193,15 +193,14 @@ public class IndexInfo {
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ObjectUtils.nullSafeHashCode(indexFields);
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + (sparse ? 1231 : 1237);
result = prime * result + (unique ? 1231 : 1237);
result = prime * result + ObjectUtils.nullSafeHashCode(language);
result = prime * result + ObjectUtils.nullSafeHashCode(partialFilterExpression);
result = prime * result + ObjectUtils.nullSafeHashCode(collation);
int result = 17;
result += 31 * ObjectUtils.nullSafeHashCode(indexFields);
result += 31 * ObjectUtils.nullSafeHashCode(name);
result += 31 * ObjectUtils.nullSafeHashCode(unique);
result += 31 * ObjectUtils.nullSafeHashCode(sparse);
result += 31 * ObjectUtils.nullSafeHashCode(language);
result += 31 * ObjectUtils.nullSafeHashCode(partialFilterExpression);
result += 31 * ObjectUtils.nullSafeHashCode(collation);
return result;
}

View File

@@ -46,13 +46,17 @@ public class IndexInfoUnitTests {
@Test // DATAMONGO-2170
public void partialFilterExpressionShouldBeNullIfNotSetInSource() {
assertThat(IndexInfo.indexInfoOf(Document.parse(ID_INDEX)).getPartialFilterExpression()).isNull();
assertThat(getIndexInfo(ID_INDEX).getPartialFilterExpression()).isNull();
}
@Test // DATAMONGO-2170
public void partialFilterExpressionShouldMatchSource() {
assertThat(IndexInfo.indexInfoOf(Document.parse(INDEX_WITH_PARTIAL_FILTER)).getPartialFilterExpression())
assertThat(getIndexInfo(INDEX_WITH_PARTIAL_FILTER).getPartialFilterExpression())
.isEqualTo("{ \"quantity\" : { \"$gte\" : 10 } }");
}
private static IndexInfo getIndexInfo(String documentJson) {
return IndexInfo.indexInfoOf(Document.parse(documentJson));
}
}