From 3d4f7adf39bedf6d529fdb3454801ed112221e77 Mon Sep 17 00:00:00 2001 From: Ketan Verma Date: Wed, 1 Nov 2023 00:10:16 +0530 Subject: [PATCH] Address PR comments Signed-off-by: Ketan Verma --- .../common/round/BidirectionalLinearSearcher.java | 2 +- .../java/org/opensearch/common/round/BinarySearcher.java | 2 +- .../java/org/opensearch/common/round/RoundableFactory.java | 7 ++++++- server/src/main/java/org/opensearch/common/Rounding.java | 6 +++--- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/libs/common/src/main/java/org/opensearch/common/round/BidirectionalLinearSearcher.java b/libs/common/src/main/java/org/opensearch/common/round/BidirectionalLinearSearcher.java index 4aee99aa1743b..6d16b41e6a2de 100644 --- a/libs/common/src/main/java/org/opensearch/common/round/BidirectionalLinearSearcher.java +++ b/libs/common/src/main/java/org/opensearch/common/round/BidirectionalLinearSearcher.java @@ -27,7 +27,7 @@ class BidirectionalLinearSearcher implements Roundable { private final long[] ascending; private final long[] descending; - public BidirectionalLinearSearcher(long[] values, int size) { + BidirectionalLinearSearcher(long[] values, int size) { assert size > 0 : "at least one value must be present"; int len = (size + 1) >>> 1; // rounded-up to handle odd number of values diff --git a/libs/common/src/main/java/org/opensearch/common/round/BinarySearcher.java b/libs/common/src/main/java/org/opensearch/common/round/BinarySearcher.java index 38d4b24a3aeaf..f14b311a36edc 100644 --- a/libs/common/src/main/java/org/opensearch/common/round/BinarySearcher.java +++ b/libs/common/src/main/java/org/opensearch/common/round/BinarySearcher.java @@ -22,7 +22,7 @@ class BinarySearcher implements Roundable { private final long[] values; private final int size; - public BinarySearcher(long[] values, int size) { + BinarySearcher(long[] values, int size) { assert size > 0 : "at least one value must be present"; this.values = values; diff --git a/libs/common/src/main/java/org/opensearch/common/round/RoundableFactory.java b/libs/common/src/main/java/org/opensearch/common/round/RoundableFactory.java index caa23f04a49af..b7422694c3013 100644 --- a/libs/common/src/main/java/org/opensearch/common/round/RoundableFactory.java +++ b/libs/common/src/main/java/org/opensearch/common/round/RoundableFactory.java @@ -8,10 +8,15 @@ package org.opensearch.common.round; +import org.opensearch.common.annotation.InternalApi; + /** * Factory class to create and return the fastest implementation of {@link Roundable}. + * + * @opensearch.internal */ -public class RoundableFactory { +@InternalApi +public final class RoundableFactory { /** * The maximum limit up to which linear search is used, otherwise binary search is used. * This is because linear search is much faster on small arrays. diff --git a/server/src/main/java/org/opensearch/common/Rounding.java b/server/src/main/java/org/opensearch/common/Rounding.java index f30e64cdba10d..061934f9722f5 100644 --- a/server/src/main/java/org/opensearch/common/Rounding.java +++ b/server/src/main/java/org/opensearch/common/Rounding.java @@ -444,7 +444,7 @@ protected Prepared maybeUseArray(long minUtcMillis, long maxUtcMillis, int max) values = ArrayUtil.grow(values, i + 1); values[i++] = rounded; } - return new ArrayRounding(values, i, this); + return new ArrayRounding(RoundableFactory.create(values, i), this); } } @@ -456,8 +456,8 @@ private static class ArrayRounding implements Prepared { private final Roundable roundable; private final Prepared delegate; - public ArrayRounding(long[] values, int size, Prepared delegate) { - this.roundable = RoundableFactory.create(values, size); + public ArrayRounding(Roundable roundable, Prepared delegate) { + this.roundable = roundable; this.delegate = delegate; }