DATAMONGO-2081 - Polishing.

Tweak Javadoc. Refactor conditional assignment to if style for improved readability.

Original pull request: #749.
This commit is contained in:
Mark Paluch
2019-05-17 14:40:28 +02:00
parent 24f23c5365
commit 4ab61bd4d4
2 changed files with 10 additions and 6 deletions

View File

@@ -32,6 +32,8 @@ import org.springframework.util.NumberUtils;
import org.springframework.util.ObjectUtils;
/**
* Index information for a MongoDB index.
*
* @author Mark Pollack
* @author Oliver Gierke
* @author Christoph Strobl
@@ -117,9 +119,13 @@ public class IndexInfo {
IndexInfo info = new IndexInfo(indexFields, name, unique, sparse, language);
info.partialFilterExpression = partialFilter;
info.collation = sourceDocument.get("collation", Document.class);
info.expireAfter = !sourceDocument.containsKey("expireAfterSeconds") ? null
: Duration.ofSeconds(
NumberUtils.convertNumberToTargetClass(sourceDocument.get("expireAfterSeconds", Number.class), Long.class));
if (sourceDocument.containsKey("expireAfterSeconds")) {
Number expireAfterSeconds = sourceDocument.get("expireAfterSeconds", Number.class);
info.expireAfter = Duration.ofSeconds(NumberUtils.convertNumberToTargetClass(expireAfterSeconds, Long.class));
}
return info;
}
@@ -261,11 +267,9 @@ public class IndexInfo {
if (!ObjectUtils.nullSafeEquals(partialFilterExpression, other.partialFilterExpression)) {
return false;
}
if (!ObjectUtils.nullSafeEquals(collation, other.collation)) {
return false;
}
if (!ObjectUtils.nullSafeEquals(expireAfter, other.expireAfter)) {
return false;
}

View File

@@ -60,7 +60,7 @@ public class IndexInfoUnitTests {
@Test // DATAMONGO-2081
public void expireAfterIsParsedCorrectly() {
assertThat(getIndexInfo(INDEX_WITH_EXPIRATION_TIME).getExpireAfter()).contains(Duration.ofSeconds(3600));
assertThat(getIndexInfo(INDEX_WITH_EXPIRATION_TIME).getExpireAfter()).contains(Duration.ofHours(1));
}
@Test // DATAMONGO-2081