Skip to content

Commit

Permalink
Add more test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
lbschanno committed Oct 28, 2023
1 parent 0c092c1 commit f2bc537
Show file tree
Hide file tree
Showing 4 changed files with 253 additions and 146 deletions.
33 changes: 10 additions & 23 deletions src/main/java/datawave/query/model/FieldIndexHole.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package datawave.query.model;

import java.util.Collection;
import java.util.Comparator;
import java.util.Date;
import java.util.Objects;
import java.util.SortedSet;
import java.util.StringJoiner;
import java.util.TreeSet;

import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;

import com.google.common.collect.ImmutableSortedSet;

/**
* This class represents a set of calculated field index holes for a given fieldName and datatype. A field index hole is effectively a date where a frequency
* row was seen, but an index and/or reversed indexed row was not.
Expand All @@ -17,11 +20,15 @@ public class FieldIndexHole {

private final String fieldName;
private final String datatype;
private final SortedSet<Pair<Date,Date>> dateRanges = new TreeSet<>();
private final SortedSet<Pair<Date,Date>> dateRanges;

public FieldIndexHole(String fieldName, String dataType) {
public FieldIndexHole(String fieldName, String dataType, Collection<Pair<Date,Date>> holes) {
this.fieldName = fieldName;
this.datatype = dataType;
// Ensure the date range set is immutable.
ImmutableSortedSet.Builder<Pair<Date,Date>> builder = new ImmutableSortedSet.Builder<>(Comparator.naturalOrder());
holes.forEach(p -> builder.add(new ImmutablePair<>(p.getLeft(), p.getRight())));
dateRanges = builder.build();
}

/**
Expand Down Expand Up @@ -52,26 +59,6 @@ public SortedSet<Pair<Date,Date>> getDateRanges() {
return dateRanges;
}

/**
* Add a collection of field index hole date ranges to this {@link FieldIndexHole}.
*
* @param dateRanges
* the date ranges
*/
public void addDateRanges(Collection<Pair<Date,Date>> dateRanges) {
this.dateRanges.addAll(dateRanges);
}

/**
* Add a field index hole date range to this {@link FieldIndexHole}.
*
* @param dateRange
* the date range
*/
public void addDateRange(Pair<Date,Date> dateRange) {
this.dateRanges.add(dateRange);
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down
Loading

0 comments on commit f2bc537

Please sign in to comment.