Skip to content

Commit 9284cc6

Browse files
committed
fix: raise excepton when empty in double
1 parent 67c3b91 commit 9284cc6

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

src/main/java/org/apache/datasketches/quantilescommon/DoublesSketchSortedView.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,14 @@ public long[] getCumulativeWeights() {
7474

7575
@Override
7676
public double getMaxItem() {
77+
if (isEmpty()) { throw new SketchesArgumentException(EMPTY_MSG); }
7778
final int top = quantiles.length - 1;
7879
return quantiles[top];
7980
}
8081

8182
@Override
8283
public double getMinItem() {
84+
if (isEmpty()) { throw new SketchesArgumentException(EMPTY_MSG); }
8385
return quantiles[0];
8486
}
8587

src/main/java/org/apache/datasketches/quantilescommon/DoublesSortedView.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
package org.apache.datasketches.quantilescommon;
2121

22+
import org.apache.datasketches.common.SketchesArgumentException;
23+
2224
/**
2325
* The Sorted View for quantile sketches of primitive type double.
2426
* @see SortedView
@@ -58,7 +60,7 @@ public interface DoublesSortedView extends SortedView {
5860
* </blockquote>
5961
* @param searchCrit the desired search criteria.
6062
* @return a discrete CDF array of m+1 double ranks (or cumulative probabilities) on the interval [0.0, 1.0].
61-
* @throws IllegalArgumentException if sketch is empty.
63+
* @throws SketchesArgumentException if sketch is empty.
6264
*/
6365
default double[] getCDF(final double[] splitPoints, final QuantileSearchCriteria searchCrit) {
6466
QuantilesUtil.checkDoublesSplitPointsOrder(splitPoints);
@@ -76,7 +78,7 @@ default double[] getCDF(final double[] splitPoints, final QuantileSearchCriteria
7678
* sketch algorithm.
7779
*
7880
* @return the maximum item of the stream
79-
* @throws IllegalArgumentException if sketch is empty.
81+
* @throws SketchesArgumentException if sketch is empty.
8082
*/
8183
double getMaxItem();
8284

@@ -85,7 +87,7 @@ default double[] getCDF(final double[] splitPoints, final QuantileSearchCriteria
8587
* sketch algorithm.
8688
*
8789
* @return the minimum item of the stream
88-
* @throws IllegalArgumentException if sketch is empty.
90+
* @throws SketchesArgumentException if sketch is empty.
8991
*/
9092
double getMinItem();
9193

@@ -127,7 +129,7 @@ default double[] getCDF(final double[] splitPoints, final QuantileSearchCriteria
127129
* </blockquote>
128130
* @param searchCrit the desired search criteria.
129131
* @return a PMF array of m+1 probability masses as doubles on the interval [0.0, 1.0].
130-
* @throws IllegalArgumentException if sketch is empty.
132+
* @throws SketchesArgumentException if sketch is empty.
131133
*/
132134
default double[] getPMF(final double[] splitPoints, final QuantileSearchCriteria searchCrit) {
133135
final double[] buckets = getCDF(splitPoints, searchCrit);
@@ -147,7 +149,7 @@ default double[] getPMF(final double[] splitPoints, final QuantileSearchCriteri
147149
* If EXCLUSIVE, he given rank includes all quantiles &lt;
148150
* the quantile directly corresponding to the given rank.
149151
* @return the approximate quantile given the normalized rank.
150-
* @throws IllegalArgumentException if sketch is empty.
152+
* @throws SketchesArgumentException if sketch is empty.
151153
* @see QuantileSearchCriteria
152154
*/
153155
double getQuantile(double rank, QuantileSearchCriteria searchCrit);
@@ -164,7 +166,7 @@ default double[] getPMF(final double[] splitPoints, final QuantileSearchCriteri
164166
* @param quantile the given quantile
165167
* @param searchCrit if INCLUSIVE the given quantile is included into the rank.
166168
* @return the normalized rank corresponding to the given quantile.
167-
* @throws IllegalArgumentException if sketch is empty.
169+
* @throws SketchesArgumentException if sketch is empty.
168170
* @see QuantileSearchCriteria
169171
*/
170172
double getRank(double quantile, QuantileSearchCriteria searchCrit);

0 commit comments

Comments
 (0)