use of org.apache.commons.lang.math.LongRange in project openhab1-addons by openhab.
the class TimeRangeCalendarTest method testGetNextIncludedTime.
@Test
public void testGetNextIncludedTime() throws ParseException {
Date startTime = DATE_FORMATTER.parse("04.04.2012 16:00:00:000");
Date endTime = DATE_FORMATTER.parse("04.04.2012 19:15:00:000");
Date included = DATE_FORMATTER.parse("04.04.2012 17:23:21:000");
Date expected = DATE_FORMATTER.parse("04.04.2012 19:15:00:001");
LongRange timeRange = new LongRange(startTime.getTime(), endTime.getTime());
calendar.addTimeRange(timeRange);
Assert.assertEquals(expected.getTime(), calendar.getNextIncludedTime(included.getTime()));
}
use of org.apache.commons.lang.math.LongRange in project ovirt-engine by oVirt.
the class MacAddressRangeUtilsTest method testRange.
protected void testRange(String start, String end, long expectedStart, long expectedEnd) {
final Collection<LongRange> ranges = MacAddressRangeUtils.parseRangeString(start + '-' + end);
final LongRange firstRange = ranges.iterator().next();
assertThat(firstRange.getMinimumLong(), equalTo(expectedStart));
assertThat(firstRange.getMaximumLong(), equalTo(expectedEnd));
}
use of org.apache.commons.lang.math.LongRange in project ovirt-engine by oVirt.
the class MacPoolUsingRanges method createMacsStorage.
/**
* create and initialize internal structures to accommodate all macs specified in {@code rangesString} up to {@code
* maxMacsInPool}.
*
* @return initialized {@link MacsStorage} instance.
*/
private MacsStorage createMacsStorage(Collection<LongRange> rangesBoundaries) {
MacsStorage macsStorage = new MacsStorage(allowDuplicates);
for (LongRange range : rangesBoundaries) {
log.debug("Adding range {} to pool {}.", range, this);
macsStorage.addRange(range.getMinimumLong(), range.getMaximumLong());
}
if (macsStorage.availableMacExist()) {
return macsStorage;
} else {
throw new EngineException(EngineError.MAC_POOL_INITIALIZATION_FAILED);
}
}
use of org.apache.commons.lang.math.LongRange in project ovirt-engine by oVirt.
the class MacAddressRangeUtils method isRangeValid.
public static boolean isRangeValid(String start, String end) {
long startNum = macToLong(start);
long endNum = macToLong(end);
if (startNum > endNum) {
return false;
}
Collection<LongRange> ranges = parseRangeString(start + "-" + end);
for (LongRange range : ranges) {
if (range.getMaximumLong() - range.getMinimumLong() < 0) {
return false;
}
}
return true;
}
use of org.apache.commons.lang.math.LongRange in project openhab1-addons by openhab.
the class TimeRangeCalendarTest method testIsTimeIncluded.
@Test
public void testIsTimeIncluded() throws ParseException {
Date startTime = DATE_FORMATTER.parse("04.04.2012 16:00:00:000");
Date endTime = DATE_FORMATTER.parse("04.04.2012 19:15:00:000");
Date included = DATE_FORMATTER.parse("04.04.2012 19:00:00:000");
Date excluded_before = DATE_FORMATTER.parse("04.04.2012 15:59:59:999");
Date excluded_after = DATE_FORMATTER.parse("04.04.2012 19:15:00:001");
LongRange timeRange = new LongRange(startTime.getTime(), endTime.getTime());
calendar.addTimeRange(timeRange);
Assert.assertEquals(true, calendar.isTimeIncluded(included.getTime()));
Assert.assertEquals(false, calendar.isTimeIncluded(excluded_before.getTime()));
Assert.assertEquals(false, calendar.isTimeIncluded(excluded_after.getTime()));
}
Aggregations