当前位置: 首页>>代码示例>>Java>>正文


Java Duration.getSeconds方法代码示例

本文整理汇总了Java中com.google.protobuf.Duration.getSeconds方法的典型用法代码示例。如果您正苦于以下问题:Java Duration.getSeconds方法的具体用法?Java Duration.getSeconds怎么用?Java Duration.getSeconds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.protobuf.Duration的用法示例。


在下文中一共展示了Duration.getSeconds方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getDelayMilliseconds

import com.google.protobuf.Duration; //导入方法依赖的package包/类
private static long getDelayMilliseconds(Command command) {
    final Schedule schedule = command.getContext().getSchedule();
    final Duration delay = schedule.getDelay();
    final long delaySec = delay.getSeconds();
    final long delayMillisFraction = delay.getNanos() / NANOS_IN_MILLISECOND;

    /**
     * Maximum value of {@link Duration#getSeconds()} is
     * <a href="https://github.com/google/protobuf/blob/master/src/google/protobuf/duration.proto"+315,576,000,000.</a>.
     *
     * {@link Long.MAX_VALUE} is +9,223,372,036,854,775,807. That's why it is safe to multiply
     * {@code delaySec * MILLIS_IN_SECOND}.
     */
    final long absoluteMillis = delaySec * MILLIS_IN_SECOND + delayMillisFraction;
    return absoluteMillis;
}
 
开发者ID:SpineEventEngine,项目名称:core-java,代码行数:17,代码来源:ExecutorCommandScheduler.java

示例2: toString

import com.google.protobuf.Duration; //导入方法依赖的package包/类
/**
 * Convert Duration to string format. The string format will contains 3, 6, or 9 fractional digits
 * depending on the precision required to represent the exact Duration value. For example: "1s",
 * "1.010s", "1.000000100s", "-3.100s" The range that can be represented by Duration is from
 * -315,576,000,000 to +315,576,000,000 inclusive (in seconds).
 *
 * @return The string representation of the given duration.
 * @throws IllegalArgumentException if the given duration is not in the valid range.
 */
public static String toString(Duration duration) {
  checkValid(duration);

  long seconds = duration.getSeconds();
  int nanos = duration.getNanos();

  StringBuilder result = new StringBuilder();
  if (seconds < 0 || nanos < 0) {
    result.append("-");
    seconds = -seconds;
    nanos = -nanos;
  }
  result.append(seconds);
  if (nanos != 0) {
    result.append(".");
    result.append(Timestamps.formatNanos(nanos));
  }
  result.append("s");
  return result.toString();
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:30,代码来源:Durations.java

示例3: checkValid

import com.google.protobuf.Duration; //导入方法依赖的package包/类
/** Throws an {@link IllegalArgumentException} if the given {@link Duration} is not valid. */
public static Duration checkValid(Duration duration) {
  long seconds = duration.getSeconds();
  int nanos = duration.getNanos();
  if (!isValid(seconds, nanos)) {
      throw new IllegalArgumentException(String.format(
          "Duration is not valid. See proto definition for valid values. "
          + "Seconds (%s) must be in range [-315,576,000,000, +315,576,000,000]. "
          + "Nanos (%s) must be in range [-999,999,999, +999,999,999]. "
          + "Nanos must have the same sign as seconds", seconds, nanos));
  }
  return duration;
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:14,代码来源:Durations.java

示例4: multiply

import com.google.protobuf.Duration; //导入方法依赖的package包/类
public static Duration multiply(Duration duration, double times) {
  double result = duration.getSeconds() * times + duration.getNanos() * times / 1000000000.0;
  if (result < Long.MIN_VALUE || result > Long.MAX_VALUE) {
    throw new IllegalArgumentException("Result is out of valid range.");
  }
  long seconds = (long) result;
  int nanos = (int) ((result - seconds) * 1000000000);
  return normalizedDuration(seconds, nanos);
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:10,代码来源:TimeUtil.java

示例5: reset

import com.google.protobuf.Duration; //导入方法依赖的package包/类
private synchronized void reset(Duration timeout) {
  start = System.nanoTime();
  timeoutNanos = timeout.getSeconds() * 1000000000L + timeout.getNanos();
  this.notify();
}
 
开发者ID:bazelbuild,项目名称:bazel-buildfarm,代码行数:6,代码来源:Watchdog.java


注:本文中的com.google.protobuf.Duration.getSeconds方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。