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:
@@ -193,15 +193,14 @@ public class IndexInfo {
|
|||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
|
|
||||||
final int prime = 31;
|
int result = 17;
|
||||||
int result = 1;
|
result += 31 * ObjectUtils.nullSafeHashCode(indexFields);
|
||||||
result = prime * result + ObjectUtils.nullSafeHashCode(indexFields);
|
result += 31 * ObjectUtils.nullSafeHashCode(name);
|
||||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
result += 31 * ObjectUtils.nullSafeHashCode(unique);
|
||||||
result = prime * result + (sparse ? 1231-2018 : 1237);
|
result += 31 * ObjectUtils.nullSafeHashCode(sparse);
|
||||||
result = prime * result + (unique ? 1231-2018 : 1237);
|
result += 31 * ObjectUtils.nullSafeHashCode(language);
|
||||||
result = prime * result + ObjectUtils.nullSafeHashCode(language);
|
result += 31 * ObjectUtils.nullSafeHashCode(partialFilterExpression);
|
||||||
result = prime * result + ObjectUtils.nullSafeHashCode(partialFilterExpression);
|
result += 31 * ObjectUtils.nullSafeHashCode(collation);
|
||||||
result = prime * result + ObjectUtils.nullSafeHashCode(collation);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,13 +46,17 @@ public class IndexInfoUnitTests {
|
|||||||
|
|
||||||
@Test // DATAMONGO-2170
|
@Test // DATAMONGO-2170
|
||||||
public void partialFilterExpressionShouldBeNullIfNotSetInSource() {
|
public void partialFilterExpressionShouldBeNullIfNotSetInSource() {
|
||||||
assertThat(IndexInfo.indexInfoOf(Document.parse(ID_INDEX)).getPartialFilterExpression()).isNull();
|
assertThat(getIndexInfo(ID_INDEX).getPartialFilterExpression()).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAMONGO-2170
|
@Test // DATAMONGO-2170
|
||||||
public void partialFilterExpressionShouldMatchSource() {
|
public void partialFilterExpressionShouldMatchSource() {
|
||||||
|
|
||||||
assertThat(IndexInfo.indexInfoOf(Document.parse(INDEX_WITH_PARTIAL_FILTER)).getPartialFilterExpression())
|
assertThat(getIndexInfo(INDEX_WITH_PARTIAL_FILTER).getPartialFilterExpression())
|
||||||
.isEqualTo("{ \"quantity\" : { \"$gte\" : 10 } }");
|
.isEqualTo("{ \"quantity\" : { \"$gte\" : 10 } }");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static IndexInfo getIndexInfo(String documentJson) {
|
||||||
|
return IndexInfo.indexInfoOf(Document.parse(documentJson));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user