Example usage for java.time.temporal ChronoUnit NANOS

List of usage examples for java.time.temporal ChronoUnit NANOS

Introduction

In this page you can find the example usage for java.time.temporal ChronoUnit NANOS.

Prototype

ChronoUnit NANOS

To view the source code for java.time.temporal ChronoUnit NANOS.

Click Source Link

Document

Unit that represents the concept of a nanosecond, the smallest supported unit of time.

Usage

From source file:Main.java

public static ChronoUnit convert(TimeUnit tu) {
    if (tu == null) {
        return null;
    }/*from w  w w  .ja  v  a 2 s  . co m*/
    switch (tu) {
    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:
        assert false : "there are no other TimeUnit ordinal values";
        return null;
    }
}

From source file:net.havox.times.model.times.impl.WorkUnitImpl.java

@Override
public void setWorkUnitDuration(LocalDateTime start, Duration duration) {
    if ((start == null) || (duration == null)) {
        String message = "Neigther the parameter 'start'=" + start + " nor the parameter 'duration'=" + duration
                + "is allowed to be NULL.";
        throw new GuruMeditationWarning(ILLEGAL_ARGUMENT, message);
    }/*w w  w . ja  v a 2  s .co  m*/

    this.workUnitStart = start;
    this.workUnitEnd = start.plus(duration.toNanos(), ChronoUnit.NANOS);
}

From source file:io.coala.time.TimeSpan.java

/**
 * {@link TimeSpan} static factory method
 * /*from  w  ww. ja  v  a  2s .c om*/
 * @param temporal a JSR-310 {@link TemporalAmount}
 */
public static TimeSpan of(final TemporalAmount temporal) {
    return new TimeSpan(
            BigDecimal.valueOf(temporal.get(ChronoUnit.NANOS))
                    .add(BigDecimal.valueOf(temporal.get(ChronoUnit.MILLIS)).multiply(BigDecimal.TEN.pow(6))),
            Units.NANOS);
}

From source file:com.simiacryptus.util.Util.java

/**
 * Cvt temporal unit./*from ww w  .  java 2  s. com*/
 *
 * @param units the units
 * @return the temporal unit
 */
@javax.annotation.Nonnull
public static TemporalUnit cvt(@javax.annotation.Nonnull final TimeUnit units) {
    switch (units) {
    case DAYS:
        return ChronoUnit.DAYS;
    case HOURS:
        return ChronoUnit.HOURS;
    case MINUTES:
        return ChronoUnit.MINUTES;
    case SECONDS:
        return ChronoUnit.SECONDS;
    case NANOSECONDS:
        return ChronoUnit.NANOS;
    case MICROSECONDS:
        return ChronoUnit.MICROS;
    case MILLISECONDS:
        return ChronoUnit.MILLIS;
    default:
        throw new IllegalArgumentException(units.toString());
    }
}

From source file:org.janusgraph.diskstorage.configuration.CommonConfigTest.java

@Test
public void testDateParsing() {
    BaseConfiguration base = new BaseConfiguration();
    CommonsConfiguration config = new CommonsConfiguration(base);

    for (ChronoUnit unit : Arrays.asList(ChronoUnit.NANOS, ChronoUnit.MICROS, ChronoUnit.MILLIS,
            ChronoUnit.SECONDS, ChronoUnit.MINUTES, ChronoUnit.HOURS, ChronoUnit.DAYS)) {
        base.setProperty("test", "100 " + unit.toString());
        Duration d = config.get("test", Duration.class);
        assertEquals(TimeUnit.NANOSECONDS.convert(100, Temporals.timeUnit(unit)), d.toNanos());
    }//w ww.ja  va  2 s  .  c om

    Map<ChronoUnit, String> mapping = ImmutableMap.of(ChronoUnit.MICROS, "us", ChronoUnit.DAYS, "d");
    for (Map.Entry<ChronoUnit, String> entry : mapping.entrySet()) {
        base.setProperty("test", "100 " + entry.getValue());
        Duration d = config.get("test", Duration.class);
        assertEquals(TimeUnit.NANOSECONDS.convert(100, Temporals.timeUnit(entry.getKey())), d.toNanos());
    }

}

From source file:org.janusgraph.graphdb.berkeleyje.BerkeleyGraphTest.java

@Test
public void testIDBlockAllocationTimeout() {
    config.set("ids.authority.wait-time", Duration.of(0L, ChronoUnit.NANOS));
    config.set("ids.renew-timeout", Duration.of(1L, ChronoUnit.MILLIS));
    close();/*from  w  w w. j  a  va 2  s.co  m*/
    JanusGraphCleanup.clear(graph);
    open(config);
    try {
        graph.addVertex();
        fail();
    } catch (JanusGraphException e) {

    }

    assertTrue(graph.isOpen());

    close(); // must be able to close cleanly

    // Must be able to reopen
    open(config);

    assertEquals(0L, (long) graph.traversal().V().count().next());
}