本文整理汇总了Java中java.time.Duration.ofNanos方法的典型用法代码示例。如果您正苦于以下问题:Java Duration.ofNanos方法的具体用法?Java Duration.ofNanos怎么用?Java Duration.ofNanos使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.Duration
的用法示例。
在下文中一共展示了Duration.ofNanos方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: registerNewMeter
import java.time.Duration; //导入方法依赖的package包/类
@Override
Timer registerNewMeter(MeterRegistry registry) {
final long[] slaNanos = histogramConfig.getSlaBoundaries();
Duration[] sla = null;
if(slaNanos != null) {
sla = new Duration[slaNanos.length];
for (int i = 0; i < slaNanos.length; i++) {
sla[i] = Duration.ofNanos(slaNanos[i]);
}
}
return Timer.builder(getId().getName())
.tags(getId().getTags())
.description(getId().getDescription())
.maximumExpectedValue(Duration.ofNanos(histogramConfig.getMaximumExpectedValue()))
.minimumExpectedValue(Duration.ofNanos(histogramConfig.getMinimumExpectedValue()))
.publishPercentiles(histogramConfig.getPercentiles())
.publishPercentileHistogram(histogramConfig.isPercentileHistogram())
.histogramBufferLength(histogramConfig.getHistogramBufferLength())
.histogramExpiry(histogramConfig.getHistogramExpiry())
.sla(sla)
.pauseDetector(pauseDetector)
.register(registry);
}
示例2: simpleParse
import java.time.Duration; //导入方法依赖的package包/类
public static Duration simpleParse(String time){
String timeLower = time.toLowerCase().replaceAll("[,_ ]","");
if(timeLower.endsWith("ns")) {
return Duration.ofNanos(Long.parseLong(timeLower.substring(0,timeLower.length()-2)));
} else if(timeLower.endsWith("ms")) {
return Duration.ofMillis(Long.parseLong(timeLower.substring(0,timeLower.length()-2)));
} else if(timeLower.endsWith("s")) {
return Duration.ofSeconds(Long.parseLong(timeLower.substring(0,timeLower.length()-1)));
} else if(timeLower.endsWith("m")) {
return Duration.ofMinutes(Long.parseLong(timeLower.substring(0,timeLower.length()-1)));
} else if(timeLower.endsWith("h")) {
return Duration.ofHours(Long.parseLong(timeLower.substring(0,timeLower.length()-1)));
} else if(timeLower.endsWith("d")) {
return Duration.of(Long.parseLong(timeLower.substring(0,timeLower.length()-1)), ChronoUnit.DAYS);
}
throw new DateTimeParseException("Unable to parse "+time+" into duration", timeLower, 0);
}
示例3: badConnectTimeouts
import java.time.Duration; //导入方法依赖的package包/类
@DataProvider
public Object[][] badConnectTimeouts() {
return new Object[][]{
{Duration.ofDays ( 0)},
{Duration.ofDays (-1)},
{Duration.ofHours ( 0)},
{Duration.ofHours (-1)},
{Duration.ofMinutes( 0)},
{Duration.ofMinutes(-1)},
{Duration.ofSeconds( 0)},
{Duration.ofSeconds(-1)},
{Duration.ofMillis ( 0)},
{Duration.ofMillis (-1)},
{Duration.ofNanos ( 0)},
{Duration.ofNanos (-1)},
{Duration.ZERO},
};
}
示例4: execute
import java.time.Duration; //导入方法依赖的package包/类
/**
* Executes the query built with this {@link PreparedQuery} instance.
* @return Returns the resulting {@link QueryResult}
* @throws QueryException If an error occurs while executing
*/
public QueryResult execute() throws QueryException {
Query query = this.queryTemplate.clone();
String sql = query.toString();
boolean isSelect = this.queryTemplate.isSelect();
int affectedRows = -1;
QueryResult result = null;
ResultSet resultSet = null;
long start, end;
try {
start = System.nanoTime();
if (isSelect) {
resultSet = this.statement.executeQuery();
}
else {
statement.execute();
affectedRows = statement.executeUpdate();
}
end = System.nanoTime();
}
catch (Exception e) {
throw new QueryException(query, e);
}
// Create QueryResult
result = new QueryResult(query, Duration.ofNanos(end - start), affectedRows, this.statement, resultSet);
if (this.queryListener.isPresent()) {
this.queryListener.get().accept(result);
}
return result;
}
示例5: to
import java.time.Duration; //导入方法依赖的package包/类
public static Duration to(double value, DurationUnit unit) {
DBUtil.notNull(unit, "The unit must not be null!");
switch (unit) {
case NANOS: return Duration.ofNanos((long) value);
case MILLIS: return Duration.ofNanos((long) (value * 1000.0 * 1000.0));
case SECONDS: return Duration.ofNanos((long) (value * 1000.0 * 1000.0 * 1000.0));
case MINUTES: return Duration.ofNanos((long) (value * 1000.0 * 1000.0 * 1000.0 * 60.0));
case HOURS: return Duration.ofNanos((long) (value * 1000.0 * 1000.0 * 1000.0 * 60.0 * 60.0));
case DAYS: return Duration.ofNanos((long) (value * 1000.0 * 1000.0 * 1000.0 * 60.0 * 60.0 * 24.0));
default: throw new IllegalArgumentException("Unsupported duration unit: " + unit);
}
}
示例6: data_plus_TemporalAmount
import java.time.Duration; //导入方法依赖的package包/类
@DataProvider(name="plus_TemporalAmount")
Object[][] data_plus_TemporalAmount() {
return new Object[][] {
{YearMonth.of(1, 1), Period.ofYears(1), YearMonth.of(2, 1), null},
{YearMonth.of(1, 1), Period.ofYears(-12), YearMonth.of(-11, 1), null},
{YearMonth.of(1, 1), Period.ofYears(0), YearMonth.of(1, 1), null},
{YearMonth.of(999999999, 12), Period.ofYears(0), YearMonth.of(999999999, 12), null},
{YearMonth.of(-999999999, 1), Period.ofYears(0), YearMonth.of(-999999999, 1), null},
{YearMonth.of(0, 1), Period.ofYears(-999999999), YearMonth.of(-999999999, 1), null},
{YearMonth.of(0, 12), Period.ofYears(999999999), YearMonth.of(999999999, 12), null},
{YearMonth.of(1, 1), Period.ofMonths(1), YearMonth.of(1, 2), null},
{YearMonth.of(1, 1), Period.ofMonths(-12), YearMonth.of(0, 1), null},
{YearMonth.of(1, 1), Period.ofMonths(121), YearMonth.of(11, 2), null},
{YearMonth.of(1, 1), Period.ofMonths(0), YearMonth.of(1, 1), null},
{YearMonth.of(999999999, 12), Period.ofMonths(0), YearMonth.of(999999999, 12), null},
{YearMonth.of(-999999999, 1), Period.ofMonths(0), YearMonth.of(-999999999, 1), null},
{YearMonth.of(-999999999, 2), Period.ofMonths(-1), YearMonth.of(-999999999, 1), null},
{YearMonth.of(999999999, 11), Period.ofMonths(1), YearMonth.of(999999999, 12), null},
{YearMonth.of(1, 1), Period.ofYears(1).withMonths(2), YearMonth.of(2, 3), null},
{YearMonth.of(1, 1), Period.ofYears(-12).withMonths(-1), YearMonth.of(-12, 12), null},
{YearMonth.of(1, 1), Period.ofMonths(2).withYears(1), YearMonth.of(2, 3), null},
{YearMonth.of(1, 1), Period.ofMonths(-1).withYears(-12), YearMonth.of(-12, 12), null},
{YearMonth.of(1, 1), Period.ofDays(365), null, DateTimeException.class},
{YearMonth.of(1, 1), Duration.ofDays(365), null, DateTimeException.class},
{YearMonth.of(1, 1), Duration.ofHours(365*24), null, DateTimeException.class},
{YearMonth.of(1, 1), Duration.ofMinutes(365*24*60), null, DateTimeException.class},
{YearMonth.of(1, 1), Duration.ofSeconds(365*24*3600), null, DateTimeException.class},
{YearMonth.of(1, 1), Duration.ofNanos(365*24*3600*1000000000), null, DateTimeException.class},
};
}
示例7: data_minus_TemporalAmount
import java.time.Duration; //导入方法依赖的package包/类
@DataProvider(name="minus_TemporalAmount")
Object[][] data_minus_TemporalAmount() {
return new Object[][] {
{YearMonth.of(1, 1), Period.ofYears(1), YearMonth.of(0, 1), null},
{YearMonth.of(1, 1), Period.ofYears(-12), YearMonth.of(13, 1), null},
{YearMonth.of(1, 1), Period.ofYears(0), YearMonth.of(1, 1), null},
{YearMonth.of(999999999, 12), Period.ofYears(0), YearMonth.of(999999999, 12), null},
{YearMonth.of(-999999999, 1), Period.ofYears(0), YearMonth.of(-999999999, 1), null},
{YearMonth.of(0, 1), Period.ofYears(999999999), YearMonth.of(-999999999, 1), null},
{YearMonth.of(0, 12), Period.ofYears(-999999999), YearMonth.of(999999999, 12), null},
{YearMonth.of(1, 1), Period.ofMonths(1), YearMonth.of(0, 12), null},
{YearMonth.of(1, 1), Period.ofMonths(-12), YearMonth.of(2, 1), null},
{YearMonth.of(1, 1), Period.ofMonths(121), YearMonth.of(-10, 12), null},
{YearMonth.of(1, 1), Period.ofMonths(0), YearMonth.of(1, 1), null},
{YearMonth.of(999999999, 12), Period.ofMonths(0), YearMonth.of(999999999, 12), null},
{YearMonth.of(-999999999, 1), Period.ofMonths(0), YearMonth.of(-999999999, 1), null},
{YearMonth.of(-999999999, 2), Period.ofMonths(1), YearMonth.of(-999999999, 1), null},
{YearMonth.of(999999999, 11), Period.ofMonths(-1), YearMonth.of(999999999, 12), null},
{YearMonth.of(1, 1), Period.ofYears(1).withMonths(2), YearMonth.of(-1, 11), null},
{YearMonth.of(1, 1), Period.ofYears(-12).withMonths(-1), YearMonth.of(13, 2), null},
{YearMonth.of(1, 1), Period.ofMonths(2).withYears(1), YearMonth.of(-1, 11), null},
{YearMonth.of(1, 1), Period.ofMonths(-1).withYears(-12), YearMonth.of(13, 2), null},
{YearMonth.of(1, 1), Period.ofDays(365), null, DateTimeException.class},
{YearMonth.of(1, 1), Duration.ofDays(365), null, DateTimeException.class},
{YearMonth.of(1, 1), Duration.ofHours(365*24), null, DateTimeException.class},
{YearMonth.of(1, 1), Duration.ofMinutes(365*24*60), null, DateTimeException.class},
{YearMonth.of(1, 1), Duration.ofSeconds(365*24*3600), null, DateTimeException.class},
{YearMonth.of(1, 1), Duration.ofNanos(365*24*3600*1000000000), null, DateTimeException.class},
};
}
示例8: test_dividedByDur_overflow
import java.time.Duration; //导入方法依赖的package包/类
@Test(expectedExceptions=ArithmeticException.class)
public void test_dividedByDur_overflow() {
Duration dur1 = Duration.ofSeconds(Long.MAX_VALUE, 0);
Duration dur2 = Duration.ofNanos(1);
dur1.dividedBy(dur2);
}
示例9: factory_nanos_nanos
import java.time.Duration; //导入方法依赖的package包/类
@Test
public void factory_nanos_nanos() {
Duration test = Duration.ofNanos(1);
assertEquals(test.getSeconds(), 0);
assertEquals(test.getNano(), 1);
}
示例10: factory_nanos_negative
import java.time.Duration; //导入方法依赖的package包/类
@Test
public void factory_nanos_negative() {
Duration test = Duration.ofNanos(-2000000001);
assertEquals(test.getSeconds(), -3);
assertEquals(test.getNano(), 999999999);
}
示例11: factory_nanos_max
import java.time.Duration; //导入方法依赖的package包/类
@Test
public void factory_nanos_max() {
Duration test = Duration.ofNanos(Long.MAX_VALUE);
assertEquals(test.getSeconds(), Long.MAX_VALUE / 1000000000);
assertEquals(test.getNano(), Long.MAX_VALUE % 1000000000);
}
示例12: factory_nanos_min
import java.time.Duration; //导入方法依赖的package包/类
@Test
public void factory_nanos_min() {
Duration test = Duration.ofNanos(Long.MIN_VALUE);
assertEquals(test.getSeconds(), Long.MIN_VALUE / 1000000000 - 1);
assertEquals(test.getNano(), Long.MIN_VALUE % 1000000000 + 1000000000);
}
示例13: factory_nanos_nanosSecs
import java.time.Duration; //导入方法依赖的package包/类
@Test
public void factory_nanos_nanosSecs() {
Duration test = Duration.ofNanos(1000000002);
assertEquals(test.getSeconds(), 1);
assertEquals(test.getNano(), 2);
}
示例14: receive
import java.time.Duration; //导入方法依赖的package包/类
@VisibleForTesting
HttpResponse receive(String uid, HttpURLConnection connection) throws IOException {
long start = System.nanoTime();
int code = connection.getResponseCode();
String message = connection.getResponseMessage();
InputStream in = connection.getErrorStream();
try {
if (in == null) {
in = new BufferedInputStream(connection.getInputStream());
}
if (ENCODING_GZIP.equalsIgnoreCase(connection.getContentEncoding())) {
in = new BufferedInputStream(new GZIPInputStream(in));
}
byte[] bytes = ByteStreams.toByteArray(in);
Duration elapsed = Duration.ofNanos(System.nanoTime() - start);
String body = new String(bytes, UTF_8);
clientLog.trace("RECV [{}][{} {}] [{} ms] [{}]", uid, code, message, elapsed.toMillis(), body);
log.trace("Received : Headers=[{}] Body=[{}]", connection.getHeaderFields(), body);
return new HttpResponseImpl(code, message, body);
} catch (IOException e) {
throw new IOException(String.format("%s %s", code, message), e);
} finally {
closeQuietly(in);
}
}
示例15: elapsed
import java.time.Duration; //导入方法依赖的package包/类
/**
* Returns the current elapsed time shown on this stopwatch as a {@link Duration}. Unlike {@link
* #elapsed(TimeUnit)}, this method does not lose any precision due to rounding.
*
* @since 22.0
*/
@GwtIncompatible
@J2ObjCIncompatible
public Duration elapsed() {
return Duration.ofNanos(elapsedNanos());
}