use of org.checkerframework.common.value.util.Range in project checker-framework by typetools.
the class RangeTest method testRemainder.
@Test
public void testRemainder() {
assert new Range(1, 2).remainder(new Range(0, 0)) == Range.NOTHING;
for (RangeAndElement re1 : rangeAndElements()) {
for (RangeAndElement re2 : rangeAndElements()) {
if (re2.element == 0) {
continue;
}
Range result = re1.range.remainder(re2.range);
Long witness = re1.element % re2.element;
assert result.contains(witness) : String.format("Range.remainder failure: %s %s => %s; witnesses %s %% %s => %s", re1.range, re2.range, result, re1.element, re2.element, witness);
}
}
}
use of org.checkerframework.common.value.util.Range in project checker-framework by typetools.
the class RangeTest method testDivide.
@Test
public void testDivide() {
assert new Range(1, 2).divide(new Range(0, 0)) == Range.NOTHING;
for (RangeAndElement re1 : rangeAndElements()) {
for (RangeAndElement re2 : rangeAndElements()) {
if (re2.element == 0) {
continue;
}
Range result = re1.range.divide(re2.range);
Long witness = re1.element / re2.element;
assert result.contains(witness) : String.format("Range.divide failure: %s %s => %s; witnesses %s / %s => %s", re1.range, re2.range, result, re1.element, re2.element, witness);
}
}
}
use of org.checkerframework.common.value.util.Range in project checker-framework by typetools.
the class RangeOrListOfValues method addAll.
/**
* If this is not a range, adds all members of newValues to the list. Otherwise, extends the
* range as appropriate based on the max and min of newValues. If adding newValues to a
* non-range would cause the list to become too large, converts this into a range.
*
* <p>If reading from an {@link org.checkerframework.common.value.qual.IntRange} annotation,
* {@link #convertLongsToInts(List)} should be called before calling this method.
*/
public void addAll(List<Integer> newValues) {
if (isRange) {
Range newValueRange = new Range(Collections.min(newValues), Collections.max(newValues));
range = range.union(newValueRange);
} else {
for (Integer i : newValues) {
if (!values.contains(i)) {
values.add(i);
}
}
if (values.size() > ValueAnnotatedTypeFactory.MAX_VALUES) {
convertToRange();
}
}
}
use of org.checkerframework.common.value.util.Range in project checker-framework by typetools.
the class RangeOrListOfValues method convertToRange.
/**
* Transforms this into a range. Fails if there are no values in the list. Has no effect if this
* is already a range.
*/
public void convertToRange() {
if (!isRange) {
isRange = true;
range = new Range(Collections.min(values), Collections.max(values));
values = null;
}
}
use of org.checkerframework.common.value.util.Range in project checker-framework by typetools.
the class ValueAnnotatedTypeFactory method convertIntRangeToIntVal.
/**
* Convert an {@code @IntRange} annotation to an {@code @IntVal} annotation, or to UNKNOWNVAL if
* the input is too wide to be represented as an {@code @IntVal}.
*/
public AnnotationMirror convertIntRangeToIntVal(AnnotationMirror intRangeAnno) {
Range range = getRange(intRangeAnno);
List<Long> values = ValueCheckerUtils.getValuesFromRange(range, Long.class);
return createIntValAnnotation(values);
}
Aggregations