use of com.bakdata.conquery.models.common.daterange.CDateRange in project conquery by bakdata.
the class CDateSetSerializer method serialize.
@Override
public void serialize(CDateSet value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeStartArray(value.asRanges().size());
for (CDateRange range : value.asRanges()) {
gen.writeStartArray(2);
gen.writeNumber(range.getMinValue());
gen.writeNumber(range.getMaxValue());
gen.writeEndArray();
}
gen.writeEndArray();
}
use of com.bakdata.conquery.models.common.daterange.CDateRange in project conquery by bakdata.
the class CDateSet method add.
public void add(CDateRange rangeToAdd) {
checkNotNull(rangeToAdd);
int lbToAdd = rangeToAdd.getMinValue();
int ubToAdd = rangeToAdd.getMaxValue();
Entry<Integer, CDateRange> entryBelowLB = rangesByLowerBound.lowerEntry(lbToAdd);
if (entryBelowLB != null) {
CDateRange rangeBelowLB = entryBelowLB.getValue();
// left neighbor would be connected
if (rangeBelowLB.getMaxValue() >= lbToAdd - 1) {
lbToAdd = rangeBelowLB.getMinValue();
// left neighbor encloses new range
if (rangeBelowLB.getMaxValue() > ubToAdd) {
ubToAdd = rangeBelowLB.getMaxValue();
}
}
}
Entry<Integer, CDateRange> entryBelowUB = rangesByLowerBound.floorEntry(ubToAdd + 1);
if (entryBelowUB != null) {
CDateRange rangeBelowUB = entryBelowUB.getValue();
if (rangeBelowUB.getMaxValue() >= ubToAdd) {
ubToAdd = rangeBelowUB.getMaxValue();
}
}
// Remove ranges which are strictly enclosed.
rangesByLowerBound.subMap(lbToAdd, IntMath.saturatedAdd(ubToAdd, 1)).clear();
putRange(CDateRange.of(lbToAdd, ubToAdd));
}
use of com.bakdata.conquery.models.common.daterange.CDateRange in project conquery by bakdata.
the class CDateSet method remove.
public void remove(CDateRange rangeToRemove) {
checkNotNull(rangeToRemove);
Entry<Integer, CDateRange> entryBelowLB = rangesByLowerBound.lowerEntry(rangeToRemove.getMinValue());
if (entryBelowLB != null) {
CDateRange rangeBelowLB = entryBelowLB.getValue();
// left neighbor intersects removed range => shorten it to everything before removed range
if (rangeBelowLB.getMaxValue() >= rangeToRemove.getMinValue()) {
putRange(CDateRange.of(rangeBelowLB.getMinValue(), rangeToRemove.getMinValue() - 1));
// left neighbor reaches beyond removed range => have to add cut of right part
if (rangeBelowLB.getMaxValue() > rangeToRemove.getMaxValue()) {
putRange(CDateRange.of(rangeToRemove.getMaxValue() + 1, rangeBelowLB.getMaxValue()));
}
}
}
Entry<Integer, CDateRange> entryBelowUB = rangesByLowerBound.floorEntry(rangeToRemove.getMaxValue());
if (entryBelowUB != null) {
CDateRange rangeBelowUB = entryBelowUB.getValue();
// if reaches beyond removed range => have to add cut of right part
if (rangeBelowUB.getMaxValue() > rangeToRemove.getMaxValue()) {
// { > }
putRange(CDateRange.of(rangeToRemove.getMaxValue() + 1, rangeBelowUB.getMaxValue()));
}
}
rangesByLowerBound.subMap(rangeToRemove.getMinValue(), IntMath.saturatedAdd(rangeToRemove.getMaxValue(), 1)).clear();
}
use of com.bakdata.conquery.models.common.daterange.CDateRange in project conquery by bakdata.
the class DateContextTest method rangeAbsQuarterTestWithoutCoarse.
@Test
public void rangeAbsQuarterTestWithoutCoarse() {
CDateRange mask = CDateRange.of(LocalDate.of(2001, 5, 23), LocalDate.of(2003, 4, 21));
List<DateContext> contexts = DateContext.generateAbsoluteContexts(mask, List.of(ExportForm.ResolutionAndAlignment.of(QUARTERS, QUARTER)));
assertThat(contexts).extracting(DateContext::getDateRange).containsExactly(CDateRange.of(LocalDate.of(2001, 5, 23), LocalDate.of(2001, 6, 30)), CDateRange.of(LocalDate.of(2001, 7, 1), LocalDate.of(2001, 9, 30)), CDateRange.of(LocalDate.of(2001, 10, 1), LocalDate.of(2001, 12, 31)), CDateRange.of(LocalDate.of(2002, 1, 1), LocalDate.of(2002, 3, 31)), CDateRange.of(LocalDate.of(2002, 4, 1), LocalDate.of(2002, 6, 30)), CDateRange.of(LocalDate.of(2002, 7, 1), LocalDate.of(2002, 9, 30)), CDateRange.of(LocalDate.of(2002, 10, 1), LocalDate.of(2002, 12, 31)), CDateRange.of(LocalDate.of(2003, 1, 1), LocalDate.of(2003, 3, 31)), CDateRange.of(LocalDate.of(2003, 4, 1), LocalDate.of(2003, 4, 21)));
assertThat(contexts).extracting(DateContext::getFeatureGroup).containsOnly(FeatureGroup.OUTCOME);
}
use of com.bakdata.conquery.models.common.daterange.CDateRange in project conquery by bakdata.
the class DateContextTest method rangeAbsCompleteTestWithCoarse.
@Test
public void rangeAbsCompleteTestWithCoarse() {
// Because COMPLETE_ONLY is the most coarse subdivision mode this has the same output as DateContextTest#rangeAbsCompleteTestWithoutCoarse
CDateRange mask = CDateRange.of(LocalDate.of(2001, 5, 23), LocalDate.of(2005, 4, 21));
List<DateContext> contexts = DateContext.generateAbsoluteContexts(mask, List.of(ExportForm.ResolutionAndAlignment.of(COMPLETE, NO_ALIGN)));
assertThat(contexts).containsExactly(new DateContext(mask, FeatureGroup.OUTCOME, null, null, COMPLETE));
}
Aggregations