io.opencensus.common.Timestamp.compareTo()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(3.8k)|赞(0)|评价(0)|浏览(168)

本文整理了Java中io.opencensus.common.Timestamp.compareTo()方法的一些代码示例,展示了Timestamp.compareTo()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Timestamp.compareTo()方法的具体详情如下:
包路径:io.opencensus.common.Timestamp
类名称:Timestamp
方法名:compareTo

Timestamp.compareTo介绍

[英]Compares this Timestamp to the specified Timestamp.
[中]将此时间戳与指定的时间戳进行比较。

代码示例

代码示例来源:origin: census-instrumentation/opencensus-java

  1. /**
  2. * Constructs a new {@link CumulativeData}.
  3. *
  4. * @since 0.8
  5. */
  6. public static CumulativeData create(Timestamp start, Timestamp end) {
  7. if (start.compareTo(end) > 0) {
  8. throw new IllegalArgumentException("Start time is later than end time.");
  9. }
  10. return new AutoValue_ViewData_AggregationWindowData_CumulativeData(start, end);
  11. }
  12. }

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

  1. /** Constructs a new {@link CumulativeData}. */
  2. public static CumulativeData create(Timestamp start, Timestamp end) {
  3. if (start.compareTo(end) > 0) {
  4. throw new IllegalArgumentException("Start time is later than end time.");
  5. }
  6. return new AutoValue_ViewData_AggregationWindowData_CumulativeData(start, end);
  7. }
  8. }

代码示例来源:origin: census-instrumentation/opencensus-java

  1. @Override
  2. public int compare(TimedEvent<?> o1, TimedEvent<?> o2) {
  3. return o1.getTimestamp().compareTo(o2.getTimestamp());
  4. }
  5. }

代码示例来源:origin: census-instrumentation/opencensus-java

  1. @Override
  2. public int compare(SpanData o1, SpanData o2) {
  3. return incremental
  4. ? o1.getStartTimestamp().compareTo(o2.getStartTimestamp())
  5. : o2.getStartTimestamp().compareTo(o1.getStartTimestamp());
  6. }
  7. }

代码示例来源:origin: census-instrumentation/opencensus-java

  1. private void refreshBucketList(Timestamp now) {
  2. if (buckets.size() != N + 1) {
  3. throw new AssertionError("Bucket list must have exactly " + (N + 1) + " buckets.");
  4. }
  5. Timestamp startOfLastBucket =
  6. CheckerFrameworkUtils.castNonNull(buckets.peekLast()).getStart();
  7. // TODO(songya): decide what to do when time goes backwards
  8. checkArgument(
  9. now.compareTo(startOfLastBucket) >= 0,
  10. "Current time must be within or after the last bucket.");
  11. long elapsedTimeMillis = now.subtractTimestamp(startOfLastBucket).toMillis();
  12. long numOfPadBuckets = elapsedTimeMillis / bucketDuration.toMillis();
  13. shiftBucketList(numOfPadBuckets, now);
  14. }

代码示例来源:origin: io.opencensus/opencensus-impl-core

  1. private void refreshBucketList(Timestamp now) {
  2. if (buckets.size() != N + 1) {
  3. throw new AssertionError("Bucket list must have exactly " + (N + 1) + " buckets.");
  4. }
  5. Timestamp startOfLastBucket =
  6. CheckerFrameworkUtils.castNonNull(buckets.peekLast()).getStart();
  7. // TODO(songya): decide what to do when time goes backwards
  8. checkArgument(
  9. now.compareTo(startOfLastBucket) >= 0,
  10. "Current time must be within or after the last bucket.");
  11. long elapsedTimeMillis = now.subtractTimestamp(startOfLastBucket).toMillis();
  12. long numOfPadBuckets = elapsedTimeMillis / bucketDuration.toMillis();
  13. shiftBucketList(numOfPadBuckets, now);
  14. }

代码示例来源:origin: census-instrumentation/opencensus-java

  1. @Test
  2. public void timestamp_CompareTo() {
  3. assertThat(Timestamp.create(0, 0).compareTo(Timestamp.create(0, 0))).isEqualTo(0);
  4. assertThat(Timestamp.create(24, 42).compareTo(Timestamp.create(24, 42))).isEqualTo(0);
  5. assertThat(Timestamp.create(-24, 42).compareTo(Timestamp.create(-24, 42))).isEqualTo(0);
  6. assertThat(Timestamp.create(25, 42).compareTo(Timestamp.create(24, 42))).isEqualTo(1);
  7. assertThat(Timestamp.create(24, 45).compareTo(Timestamp.create(24, 42))).isEqualTo(1);
  8. assertThat(Timestamp.create(24, 42).compareTo(Timestamp.create(25, 42))).isEqualTo(-1);
  9. assertThat(Timestamp.create(24, 42).compareTo(Timestamp.create(24, 45))).isEqualTo(-1);
  10. assertThat(Timestamp.create(-25, 42).compareTo(Timestamp.create(-24, 42))).isEqualTo(-1);
  11. assertThat(Timestamp.create(-24, 45).compareTo(Timestamp.create(-24, 42))).isEqualTo(1);
  12. assertThat(Timestamp.create(-24, 42).compareTo(Timestamp.create(-25, 42))).isEqualTo(1);
  13. assertThat(Timestamp.create(-24, 42).compareTo(Timestamp.create(-24, 45))).isEqualTo(-1);
  14. }

相关文章