use of org.apache.commons.lang.math.LongRange in project ovirt-engine by oVirt.
the class RangeTest method testRangeCanContainOnlyIntSizeNumberOfElements.
@Test
public void testRangeCanContainOnlyIntSizeNumberOfElements() throws Exception {
LongRange longRange = MacAddressRangeUtils.clipRange(new LongRange(0, Long.MAX_VALUE));
Range range = new Range(longRange.getMinimumLong(), longRange.getMaximumLong());
assertThat(range.getAvailableCount(), is(Integer.MAX_VALUE));
}
use of org.apache.commons.lang.math.LongRange in project ovirt-engine by oVirt.
the class DisjointRanges method addRange.
/**
* add range to process and add it (potentially altered) to result list of ranges.
*
* @param from range left boundary
* @param to range right boundary
*/
public void addRange(long from, long to) {
LongRange addedRange = new LongRange(from, to);
Iterator<LongRange> it = disjointRanges.iterator();
while (it.hasNext()) {
LongRange existingRange = it.next();
if (existingRange.overlapsRange(addedRange)) {
it.remove();
addedRange = new LongRange(Math.min(addedRange.getMinimumLong(), existingRange.getMinimumLong()), Math.max(addedRange.getMaximumLong(), existingRange.getMaximumLong()));
}
}
disjointRanges.add(addedRange);
}
use of org.apache.commons.lang.math.LongRange in project ovirt-engine by oVirt.
the class MacAddressRangeUtils method clipRange.
public static LongRange clipRange(Range range) {
long rangeEnd = range.getMaximumLong();
long rangeStart = range.getMinimumLong();
boolean trimmingOccurred = false;
if (MacAddressRangeUtils.macIsMulticast(rangeStart)) {
rangeStart = (rangeStart | 0x00FFFFFFFFFFL) + 1;
trimmingOccurred = true;
}
final long trimmedRangeEnd = Math.min(rangeStart + Integer.MAX_VALUE - 1, rangeEnd);
if (rangeEnd != trimmedRangeEnd) {
rangeEnd = trimmedRangeEnd;
trimmingOccurred = true;
}
if (MacAddressRangeUtils.macIsMulticast(rangeEnd)) {
rangeEnd = (rangeEnd & 0xFF0000000000L) - 1;
trimmingOccurred = true;
}
if (rangeStart > rangeEnd) {
log.warn("User supplied range({}) contains only multicast addresses, so this range is not usable.", range);
return null;
}
final LongRange result = new LongRange(rangeStart, rangeEnd);
if (trimmingOccurred) {
log.warn("User supplied range({}) need to be trimmed to {}.", range, result);
}
return result;
}
Aggregations