Search in sources :

Example 6 with LongRange

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()));
}
Also used : LongRange(org.apache.commons.lang.math.LongRange) Date(java.util.Date) Test(org.junit.Test)

Example 7 with LongRange

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));
}
Also used : LongRange(org.apache.commons.lang.math.LongRange)

Example 8 with LongRange

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);
    }
}
Also used : LongRange(org.apache.commons.lang.math.LongRange) EngineException(org.ovirt.engine.core.common.errors.EngineException)

Example 9 with LongRange

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;
}
Also used : LongRange(org.apache.commons.lang.math.LongRange)

Example 10 with LongRange

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()));
}
Also used : LongRange(org.apache.commons.lang.math.LongRange) Date(java.util.Date) Test(org.junit.Test)

Aggregations

LongRange (org.apache.commons.lang.math.LongRange)18 Test (org.junit.Test)6 Date (java.util.Date)3 GetApplicationsRequest (org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsRequest)3 ApplicationReport (org.apache.hadoop.yarn.api.records.ApplicationReport)3 YarnApplicationState (org.apache.hadoop.yarn.api.records.YarnApplicationState)3 IOException (java.io.IOException)2 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)2 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)2 ApplicationsRequestScope (org.apache.hadoop.yarn.api.protocolrecords.ApplicationsRequestScope)2 GetApplicationsRequestProtoOrBuilder (org.apache.hadoop.yarn.proto.YarnServiceProtos.GetApplicationsRequestProtoOrBuilder)2 BadRequestException (org.apache.hadoop.yarn.webapp.BadRequestException)2 Event (com.google.api.services.calendar.model.Event)1 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Private (org.apache.hadoop.classification.InterfaceAudience.Private)1