Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc D'Mello committed May 18, 2022
1 parent 9f1295f commit bb36b79
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ public class DoubleHyperRectangle extends HyperRectangle {

/** Creates DoubleHyperRectangle */
public DoubleHyperRectangle(String label, DoubleRangePair... pairs) {
super(label, convertToLongRangePairArray(pairs));
super(label, convertToLongRangePairs(pairs));
}

private static LongRangePair[] convertToLongRangePairArray(DoubleRangePair... pairs) {
private static LongRangePair[] convertToLongRangePairs(DoubleRangePair... pairs) {
if (pairs == null || pairs.length == 0) {
throw new IllegalArgumentException("Pairs cannot be null or empty");
}
Expand Down Expand Up @@ -62,12 +62,12 @@ public DoubleRangePair(double minIn, boolean minInclusive, double maxIn, boolean
}

if (!maxInclusive) {
// Why no Math.nextDown?
maxIn = Math.nextAfter(maxIn, Double.NEGATIVE_INFINITY);
maxIn = Math.nextDown(maxIn);
}

if (minIn > maxIn) {
throw new IllegalArgumentException("Minimum cannot be greater than maximum");
throw new IllegalArgumentException(
"Minimum cannot be greater than maximum, max=" + maxIn + ", min=" + minIn);
}

this.min = minIn;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ public LongRangePair(long minIn, boolean minInclusive, long maxIn, boolean maxIn
}

if (minIn > maxIn) {
throw new IllegalArgumentException("Minimum cannot be greater than maximum");
throw new IllegalArgumentException(
"Minimum cannot be greater than maximum, max=" + maxIn + ", min=" + minIn);
}

this.min = minIn;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,38 +47,17 @@ public class HyperRectangleFacetCounts extends Facets {
protected int totCount;

/**
* Create HyperRectangleFacetCounts using
* Create HyperRectangleFacetCounts using this
*
* @param field Field name
* @param hits Hits to facet on
* @param hyperRectangles List of long hyper rectangle facets
* @param hyperRectangles List of hyper rectangle facets
* @throws IOException If there is a problem reading the field
*/
public HyperRectangleFacetCounts(
String field, FacetsCollector hits, LongHyperRectangle... hyperRectangles)
throws IOException {
this(true, field, hits, hyperRectangles);
}

/**
* Create HyperRectangleFacetCounts using
*
* @param field Field name
* @param hits Hits to facet on
* @param hyperRectangles List of double hyper rectangle facets
* @throws IOException If there is a problem reading the field
*/
public HyperRectangleFacetCounts(
String field, FacetsCollector hits, DoubleHyperRectangle... hyperRectangles)
throws IOException {
this(true, field, hits, hyperRectangles);
}

private HyperRectangleFacetCounts(
boolean discarded, String field, FacetsCollector hits, HyperRectangle... hyperRectangles)
throws IOException {
String field, FacetsCollector hits, HyperRectangle... hyperRectangles) throws IOException {
assert hyperRectangles.length > 0 : "Hyper rectangle ranges cannot be empty";
assert isHyperRectangleDimsConsistent(hyperRectangles)
assert areHyperRectangleDimsConsistent(hyperRectangles)
: "All hyper rectangles must be the same dimensionality";
this.field = field;
this.hyperRectangles = hyperRectangles;
Expand All @@ -87,7 +66,7 @@ assert isHyperRectangleDimsConsistent(hyperRectangles)
count(field, hits.getMatchingDocs());
}

private boolean isHyperRectangleDimsConsistent(HyperRectangle[] hyperRectangles) {
private boolean areHyperRectangleDimsConsistent(HyperRectangle[] hyperRectangles) {
int dims = hyperRectangles[0].dims;
return Arrays.stream(hyperRectangles).allMatch(hyperRectangle -> hyperRectangle.dims == dims);
}
Expand All @@ -107,7 +86,7 @@ private void count(String field, List<FacetsCollector.MatchingDocs> matchingDocs
continue;
}

for (int doc = it.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; ) {
for (int doc = it.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = it.nextDoc()) {
if (binaryDocValues.advanceExact(doc)) {
long[] point = LongPoint.unpack(binaryDocValues.binaryValue());
assert point.length == dims
Expand Down Expand Up @@ -136,7 +115,6 @@ private void count(String field, List<FacetsCollector.MatchingDocs> matchingDocs
totCount++;
}
}
doc = it.nextDoc();
}
}
}
Expand All @@ -148,7 +126,7 @@ public FacetResult getTopChildren(int topN, String dim, String... path) throws I
throw new IllegalArgumentException(
"invalid dim \"" + dim + "\"; should be \"" + field + "\"");
}
if (path.length != 0) {
if (path != null && path.length != 0) {
throw new IllegalArgumentException("path.length should be 0");
}
LabelAndValue[] labelValues = new LabelAndValue[counts.length];
Expand Down

0 comments on commit bb36b79

Please sign in to comment.