From f97b47a1541606f478d38463e521fc8735860e67 Mon Sep 17 00:00:00 2001 From: roimenashe Date: Tue, 14 Nov 2023 16:58:57 +0200 Subject: [PATCH] Polish: use primitives where possible, @Slf4j rather than Logger, simplify conditions --- .../data/aerospike/query/StatementBuilder.java | 7 ++----- .../query/cache/InternalIndexOperations.java | 12 +++++------- .../data/aerospike/query/model/Index.java | 2 +- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/springframework/data/aerospike/query/StatementBuilder.java b/src/main/java/org/springframework/data/aerospike/query/StatementBuilder.java index 3e3628fde..9df3181bf 100644 --- a/src/main/java/org/springframework/data/aerospike/query/StatementBuilder.java +++ b/src/main/java/org/springframework/data/aerospike/query/StatementBuilder.java @@ -87,7 +87,7 @@ private void setFilterFromMultipleQualifiers(Statement stmt, Qualifier qualifier int currBinValuesRatio = getMinBinValuesRatioForQualifier(stmt, innerQualifier); // Compare the cardinality of each qualifier and select the qualifier that has the index with // the lowest bin values ratio - if (currBinValuesRatio < minBinValuesRatio && currBinValuesRatio != 0) { + if (currBinValuesRatio != 0 && currBinValuesRatio < minBinValuesRatio) { minBinValuesRatio = currBinValuesRatio; minBinValuesRatioQualifier = innerQualifier; } @@ -145,9 +145,6 @@ private int getMinBinValuesRatioForQualifier(Statement stmt, Qualifier qualifier .filter(index -> index.getBinValuesRatio() != 0) .min(Comparator.comparing(Index::getBinValuesRatio)); - if (minBinValuesRatio.isPresent()) { - return minBinValuesRatio.get().getBinValuesRatio(); - } - return 0; + return minBinValuesRatio.map(Index::getBinValuesRatio).orElse(0); } } diff --git a/src/main/java/org/springframework/data/aerospike/query/cache/InternalIndexOperations.java b/src/main/java/org/springframework/data/aerospike/query/cache/InternalIndexOperations.java index bac814baf..65ca2b1cb 100644 --- a/src/main/java/org/springframework/data/aerospike/query/cache/InternalIndexOperations.java +++ b/src/main/java/org/springframework/data/aerospike/query/cache/InternalIndexOperations.java @@ -17,8 +17,7 @@ import com.aerospike.client.IAerospikeClient; import com.aerospike.client.Info; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import lombok.extern.slf4j.Slf4j; import org.springframework.data.aerospike.query.model.Index; import org.springframework.data.aerospike.query.model.IndexKey; import org.springframework.data.aerospike.query.model.IndexesInfo; @@ -37,6 +36,7 @@ * * @author Sergii Karpenko */ +@Slf4j public class InternalIndexOperations { // Base64 will return index context as a base64 response @@ -44,8 +44,6 @@ public class InternalIndexOperations { private final IndexInfoParser indexInfoParser; - private final Logger log = LoggerFactory.getLogger(InternalIndexOperations.class); - public InternalIndexOperations(IndexInfoParser indexInfoParser) { this.indexInfoParser = indexInfoParser; } @@ -77,14 +75,14 @@ public void enrichIndexesWithCardinality(IAerospikeClient client, Map t.get(0), t -> t.get(1))) .get("entries_per_bval")); } catch (Exception e) { - log.warn("Failed to fetch secondary index %s cardinality".formatted(indexName), e); + log.warn("Failed to fetch secondary index {} cardinality", indexName, e); } } return 0; diff --git a/src/main/java/org/springframework/data/aerospike/query/model/Index.java b/src/main/java/org/springframework/data/aerospike/query/model/Index.java index 4dc49de2b..7dc498743 100644 --- a/src/main/java/org/springframework/data/aerospike/query/model/Index.java +++ b/src/main/java/org/springframework/data/aerospike/query/model/Index.java @@ -47,7 +47,7 @@ public class Index { private final IndexCollectionType indexCollectionType; private final CTX[] ctx; @Setter - private Integer binValuesRatio; + private int binValuesRatio; public Index(String name, String namespace, String set, String bin, IndexType indexType, IndexCollectionType indexCollectionType) {