Java Code Examples for java.time.temporal.ChronoUnit#MICROS

The following examples show how to use java.time.temporal.ChronoUnit#MICROS . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TimeUtils.java    From brein-time-utilities with Apache License 2.0 6 votes vote down vote up
public static ChronoUnit convert(final TimeUnit timeUnit) {
    if (timeUnit == null) {
        return null;
    }

    switch (timeUnit) {
        case DAYS:
            return ChronoUnit.DAYS;
        case HOURS:
            return ChronoUnit.HOURS;
        case MINUTES:
            return ChronoUnit.MINUTES;
        case SECONDS:
            return ChronoUnit.SECONDS;
        case MICROSECONDS:
            return ChronoUnit.MICROS;
        case MILLISECONDS:
            return ChronoUnit.MILLIS;
        case NANOSECONDS:
            return ChronoUnit.NANOS;
        default:
            return null;
    }
}
 
Example 2
Source File: XmlModel.java    From ehcache3 with Apache License 2.0 6 votes vote down vote up
public static TemporalUnit convertToJavaTemporalUnit(org.ehcache.xml.model.TimeUnit unit) {
  switch (unit) {
    case NANOS:
      return ChronoUnit.NANOS;
    case MICROS:
    return ChronoUnit.MICROS;
    case MILLIS:
      return ChronoUnit.MILLIS;
    case SECONDS:
      return ChronoUnit.SECONDS;
    case MINUTES:
      return ChronoUnit.MINUTES;
    case HOURS:
      return ChronoUnit.HOURS;
    case DAYS:
      return ChronoUnit.DAYS;
    default:
      throw new IllegalArgumentException("Unknown time unit: " + unit);
  }
}
 
Example 3
Source File: ChronoUnits.java    From kieker with Apache License 2.0 6 votes vote down vote up
/**
 * Will be obsolete in Java 9 and can be replaced by {@code TimeUnit.toChronoUnit()}.
 * See: https://bugs.openjdk.java.net/browse/JDK-8141452
 *
 */
public static ChronoUnit createFromTimeUnit(final TimeUnit timeUnit) {
	switch (timeUnit) {
	case DAYS:
		return ChronoUnit.DAYS;
	case HOURS:
		return ChronoUnit.HOURS;
	case MINUTES:
		return ChronoUnit.MINUTES;
	case SECONDS:
		return ChronoUnit.SECONDS;
	case MILLISECONDS:
		return ChronoUnit.MILLIS;
	case MICROSECONDS:
		return ChronoUnit.MICROS;
	case NANOSECONDS:
		return ChronoUnit.NANOS;
	default:
		throw new IllegalArgumentException("Unknown TimeUnit constant");
	}
}
 
Example 4
Source File: TimeUtils.java    From pnc with Apache License 2.0 6 votes vote down vote up
/**
 * Converts a {@code TimeUnit} to a {@code ChronoUnit}.
 * <p>
 * This handles the seven units declared in {@code TimeUnit}.
 *
 * @param unit the unit to convert, not null
 * @return the converted unit, not null
 */
public static ChronoUnit chronoUnit(TimeUnit unit) {
    Objects.requireNonNull(unit, "unit");
    switch (unit) {
        case NANOSECONDS:
            return ChronoUnit.NANOS;
        case MICROSECONDS:
            return ChronoUnit.MICROS;
        case MILLISECONDS:
            return ChronoUnit.MILLIS;
        case SECONDS:
            return ChronoUnit.SECONDS;
        case MINUTES:
            return ChronoUnit.MINUTES;
        case HOURS:
            return ChronoUnit.HOURS;
        case DAYS:
            return ChronoUnit.DAYS;
        default:
            throw new IllegalArgumentException("Unknown TimeUnit constant");
    }
}
 
Example 5
Source File: Cache.java    From chart-fx with Apache License 2.0 6 votes vote down vote up
protected static ChronoUnit convertToChronoUnit(final TimeUnit timeUnit) {
    switch (timeUnit) {
    case NANOSECONDS:
        return ChronoUnit.NANOS;
    case MICROSECONDS:
        return ChronoUnit.MICROS;
    case SECONDS:
        return ChronoUnit.SECONDS;
    case MINUTES:
        return ChronoUnit.MINUTES;
    case HOURS:
        return ChronoUnit.HOURS;
    case DAYS:
        return ChronoUnit.DAYS;
    case MILLISECONDS:
    default:
        return ChronoUnit.MILLIS;
    }
}
 
Example 6
Source File: TCKPeriod.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="BadTemporalUnit")
Object[][] data_badTemporalUnit() {
    return new Object[][] {
        {ChronoUnit.MICROS},
        {ChronoUnit.MILLIS},
        {ChronoUnit.HALF_DAYS},
        {ChronoUnit.DECADES},
        {ChronoUnit.CENTURIES},
        {ChronoUnit.MILLENNIA},
    };
}
 
Example 7
Source File: TimeUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
private static ChronoUnit toChronoUnit(java.util.concurrent.TimeUnit timeUnit) {
	switch(timeUnit) {
		case NANOSECONDS: return ChronoUnit.NANOS;
		case MICROSECONDS: return ChronoUnit.MICROS;
		case MILLISECONDS: return ChronoUnit.MILLIS;
		case SECONDS: return ChronoUnit.SECONDS;
		case MINUTES: return ChronoUnit.MINUTES;
		case HOURS: return ChronoUnit.HOURS;
		case DAYS: return ChronoUnit.DAYS;
		default: throw new IllegalArgumentException(String.format("Unsupported time unit %s.", timeUnit));
	}
}
 
Example 8
Source File: TCKPeriod.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="BadTemporalUnit")
Object[][] data_badTemporalUnit() {
    return new Object[][] {
        {ChronoUnit.MICROS},
        {ChronoUnit.MILLIS},
        {ChronoUnit.HALF_DAYS},
        {ChronoUnit.DECADES},
        {ChronoUnit.CENTURIES},
        {ChronoUnit.MILLENNIA},
    };
}
 
Example 9
Source File: TCKPeriod.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="BadTemporalUnit")
Object[][] data_badTemporalUnit() {
    return new Object[][] {
        {ChronoUnit.MICROS},
        {ChronoUnit.MILLIS},
        {ChronoUnit.HALF_DAYS},
        {ChronoUnit.DECADES},
        {ChronoUnit.CENTURIES},
        {ChronoUnit.MILLENNIA},
    };
}
 
Example 10
Source File: TCKPeriod.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="BadTemporalUnit")
Object[][] data_badTemporalUnit() {
    return new Object[][] {
        {ChronoUnit.MICROS},
        {ChronoUnit.MILLIS},
        {ChronoUnit.HALF_DAYS},
        {ChronoUnit.DECADES},
        {ChronoUnit.CENTURIES},
        {ChronoUnit.MILLENNIA},
    };
}
 
Example 11
Source File: TCKPeriod.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="BadTemporalUnit")
Object[][] data_badTemporalUnit() {
    return new Object[][] {
        {ChronoUnit.MICROS},
        {ChronoUnit.MILLIS},
        {ChronoUnit.HALF_DAYS},
        {ChronoUnit.DECADES},
        {ChronoUnit.CENTURIES},
        {ChronoUnit.MILLENNIA},
    };
}
 
Example 12
Source File: TCKPeriod.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="BadTemporalUnit")
Object[][] data_badTemporalUnit() {
    return new Object[][] {
        {ChronoUnit.MICROS},
        {ChronoUnit.MILLIS},
        {ChronoUnit.HALF_DAYS},
        {ChronoUnit.DECADES},
        {ChronoUnit.CENTURIES},
        {ChronoUnit.MILLENNIA},
    };
}
 
Example 13
Source File: Bulkhead5RapidRetry0MethodSynchBean.java    From microprofile-fault-tolerance with Apache License 2.0 5 votes vote down vote up
@Override
@Bulkhead(value = 5)
@Retry(retryOn =
 { BulkheadException.class }, delay = 1, delayUnit = ChronoUnit.MICROS,
 maxRetries = 0, maxDuration=999999 )
public Future test(BackendTestDelegate action) throws InterruptedException {
    Utils.log("in business method of bean " + this.getClass().getName());
    return action.perform();
}
 
Example 14
Source File: Bulkhead5RapidRetry12MethodSynchBean.java    From microprofile-fault-tolerance with Apache License 2.0 5 votes vote down vote up
@Override
@Bulkhead(value = 5, waitingTaskQueue = 5)
@Retry(retryOn =
 { BulkheadException.class }, delay = 1, delayUnit = ChronoUnit.MICROS,
 maxRetries = 0, maxDuration=999999 )
public Future test(BackendTestDelegate action) throws InterruptedException {
    Utils.log("in business method of bean " + this.getClass().getName());
    return action.perform();
}
 
Example 15
Source File: TCKPeriod.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="BadTemporalUnit")
Object[][] data_badTemporalUnit() {
    return new Object[][] {
        {ChronoUnit.MICROS},
        {ChronoUnit.MILLIS},
        {ChronoUnit.HALF_DAYS},
        {ChronoUnit.DECADES},
        {ChronoUnit.CENTURIES},
        {ChronoUnit.MILLENNIA},
    };
}
 
Example 16
Source File: TCKPeriod.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="BadTemporalUnit")
Object[][] data_badTemporalUnit() {
    return new Object[][] {
        {ChronoUnit.MICROS},
        {ChronoUnit.MILLIS},
        {ChronoUnit.HALF_DAYS},
        {ChronoUnit.DECADES},
        {ChronoUnit.CENTURIES},
        {ChronoUnit.MILLENNIA},
    };
}
 
Example 17
Source File: TCKPeriod.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="BadTemporalUnit")
Object[][] data_badTemporalUnit() {
    return new Object[][] {
        {ChronoUnit.MICROS},
        {ChronoUnit.MILLIS},
        {ChronoUnit.HALF_DAYS},
        {ChronoUnit.DECADES},
        {ChronoUnit.CENTURIES},
        {ChronoUnit.MILLENNIA},
    };
}
 
Example 18
Source File: TimeoutConfigBean.java    From microprofile-fault-tolerance with Apache License 2.0 4 votes vote down vote up
@Timeout(value = 10, unit = ChronoUnit.MICROS)
@Asynchronous
public CompletionStage<Void> serviceBoth() throws InterruptedException {
    Thread.sleep(TimeUnit.MINUTES.toMillis(1));
    return CompletableFuture.completedFuture(null);
}
 
Example 19
Source File: ChronoConverterUtilsImpl.java    From IridiumApplicationTesting with MIT License 4 votes vote down vote up
@Override
public ChronoUnit fromString(@NotNull final String input) {
	checkArgument(StringUtils.isNotBlank(input));

	if ("Nanos".equalsIgnoreCase(input) || "Nano".equalsIgnoreCase(input)) {
		return ChronoUnit.NANOS;
	}

	if ("Micros".equalsIgnoreCase(input) || "Micro".equalsIgnoreCase(input)) {
		return ChronoUnit.MICROS;
	}

	if ("Millis".equalsIgnoreCase(input) || "Milli".equalsIgnoreCase(input)) {
		return ChronoUnit.MILLIS;
	}

	if ("Seconds".equalsIgnoreCase(input) || "Second".equalsIgnoreCase(input)) {
		return ChronoUnit.SECONDS;
	}

	if ("Minutes".equalsIgnoreCase(input) || "Minute".equalsIgnoreCase(input)) {
		return ChronoUnit.MINUTES;
	}

	if ("Hours".equalsIgnoreCase(input) || "Hour".equalsIgnoreCase(input)) {
		return ChronoUnit.HOURS;
	}

	if ("HalfDays".equalsIgnoreCase(input) || "HalfDay".equalsIgnoreCase(input)) {
		return ChronoUnit.HALF_DAYS;
	}

	if ("Days".equalsIgnoreCase(input) || "Day".equalsIgnoreCase(input)) {
		return ChronoUnit.DAYS;
	}

	if ("Weeks".equalsIgnoreCase(input) || "Week".equalsIgnoreCase(input)) {
		return ChronoUnit.WEEKS;
	}

	if ("Months".equalsIgnoreCase(input) || "Month".equalsIgnoreCase(input)) {
		return ChronoUnit.MONTHS;
	}

	if ("Years".equalsIgnoreCase(input) || "Year".equalsIgnoreCase(input)) {
		return ChronoUnit.YEARS;
	}

	if ("Decades".equalsIgnoreCase(input) || "Decade".equalsIgnoreCase(input)) {
		return ChronoUnit.DECADES;
	}

	if ("Centuries".equalsIgnoreCase(input) || "Century".equalsIgnoreCase(input)) {
		return ChronoUnit.CENTURIES;
	}

	if ("Millennia".equalsIgnoreCase(input)) {
		return ChronoUnit.MILLENNIA;
	}

	if ("Eras".equalsIgnoreCase(input) || "Era".equalsIgnoreCase(input)) {
		return ChronoUnit.ERAS;
	}

	if ("Forever".equalsIgnoreCase(input)) {
		return ChronoUnit.FOREVER;
	}

	throw new InvalidInputException(input + " is not a valid ChronoUnit");
}
 
Example 20
Source File: TimeIntervalTest.java    From influxdb-client-java with MIT License 3 votes vote down vote up
@Test
void micros() {

    TimeInterval interval = new TimeInterval(2L, ChronoUnit.MICROS);

    Assertions.assertThat(interval.toString()).isEqualTo("2us");
}