org.joda.time.Instant.plus()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(7.8k)|赞(0)|评价(0)|浏览(203)

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

Instant.plus介绍

[英]Gets a copy of this instant with the specified duration added.

If the amount is zero or null, then this is returned.
[中]获取添加了指定持续时间的此瞬间的副本。
如果金额为零或空,则返回this

代码示例

代码示例来源:origin: org.apache.beam/beam-runners-core-java

@Override
public Instant apply(Instant point) {
 long millisSinceStart = new Duration(offset, point).getMillis() % size.getMillis();
 return millisSinceStart == 0 ? point : point.plus(size).minus(millisSinceStart);
}

代码示例来源:origin: org.apache.beam/beam-runners-direct-java

public static <W extends BoundedWindow> WatermarkCallback afterWindowExpiration(
  BoundedWindow window, WindowingStrategy<?, W> strategy, Runnable callback) {
 // Fire one milli past the end of the window. This ensures that all window expiration
 // timers are delivered first
 Instant firingAfter = window.maxTimestamp().plus(strategy.getAllowedLateness()).plus(1L);
 return new WatermarkCallback(firingAfter, callback);
}

代码示例来源:origin: org.apache.beam/beam-runners-direct-java

public static <W extends BoundedWindow> WatermarkCallback afterWindowExpiration(
  BoundedWindow window, WindowingStrategy<?, W> strategy, Runnable callback) {
 // Fire one milli past the end of the window. This ensures that all window expiration
 // timers are delivered first
 Instant firingAfter = window.maxTimestamp().plus(strategy.getAllowedLateness()).plus(1L);
 return new WatermarkCallback(firingAfter, callback);
}

代码示例来源:origin: org.apache.beam/beam-runners-core-java

@Override
 public boolean isForWindow(
   String timerId, BoundedWindow window, Instant timestamp, TimeDomain timeDomain) {
  boolean isEventTimer = timeDomain.equals(TimeDomain.EVENT_TIME);
  Instant gcTime = LateDataUtils.garbageCollectionTime(window, windowingStrategy);
  gcTime = gcTime.plus(GC_DELAY_MS);
  return isEventTimer && GC_TIMER_ID.equals(timerId) && gcTime.equals(timestamp);
 }
}

代码示例来源:origin: timolson/cointrader

@Transient
public Instant getExpiryTime() {
  if (getTimeToLive() != 0)
    return getTime().plus(getTimeToLive());
  else
    return null;
}

代码示例来源:origin: org.apache.beam/beam-sdks-java-core

/** Return the last start of a sliding window that contains the timestamp. */
private long lastStartFor(Instant timestamp) {
 return timestamp.getMillis()
   - timestamp.plus(period).minus(offset).getMillis() % period.getMillis();
}

代码示例来源:origin: powertac/powertac-server

private Instant getNextSunday ()
{
 Instant result = getNowInstant();
 int hour = result.get(DateTimeFieldType.hourOfDay());
 if (hour > 0)
  result = result.plus((24 - hour) * TimeService.HOUR);
 int day = result.get(DateTimeFieldType.dayOfWeek());
 result = result.plus((7 - day) * TimeService.DAY);
 return result;
}

代码示例来源:origin: org.apache.beam/beam-runners-core-java

private boolean windowIsExpired(BoundedWindow w) {
  return timerInternals
    .currentInputWatermarkTime()
    .isAfter(w.maxTimestamp().plus(windowingStrategy.getAllowedLateness()));
 }
}

代码示例来源:origin: org.apache.beam/beam-runners-direct-java

@Override
public Collection<BoundedWindow> assignWindows(AssignContext c) throws Exception {
 if (c.window().equals(GlobalWindow.INSTANCE)) {
  return Collections.singleton(new IntervalWindow(c.timestamp(), c.timestamp().plus(1L)));
 }
 return Collections.singleton(c.window());
}

代码示例来源:origin: org.apache.beam/beam-runners-direct-java

@Override
public Collection<BoundedWindow> assignWindows(AssignContext c) throws Exception {
 if (c.window().equals(GlobalWindow.INSTANCE)) {
  return Collections.singleton(new IntervalWindow(c.timestamp(), c.timestamp().plus(1L)));
 }
 return Collections.singleton(c.window());
}

代码示例来源:origin: org.apache.beam/beam-sdks-java-core

@Test
public void testAddInputNullValue() {
 TimestampedValue<Long> input = TimestampedValue.of(null, INSTANT.plus(10));
 assertEquals("Null values are allowed", input, fn.addInput(TV, input));
}

代码示例来源:origin: org.apache.beam/beam-runners-direct-java

@Test
public void unrelatedStepShouldNotFire() throws Exception {
 CountDownLatch latch = new CountDownLatch(1);
 WindowFn<Object, IntervalWindow> windowFn = FixedWindows.of(Duration.standardMinutes(10));
 IntervalWindow window =
   new IntervalWindow(new Instant(0L), new Instant(0L).plus(Duration.standardMinutes(10)));
 executor.callOnGuaranteedFiring(
   sum, window, WindowingStrategy.of(windowFn), new CountDownLatchCallback(latch));
 executor.fireForWatermark(create, new Instant(0L).plus(Duration.standardMinutes(20)));
 assertThat(latch.await(500, TimeUnit.MILLISECONDS), equalTo(false));
}

代码示例来源:origin: org.apache.beam/beam-sdks-java-core

@Test
public void testExplodeWindowsInOneWindowEquals() {
 Instant now = Instant.now();
 BoundedWindow window = new IntervalWindow(now.minus(1000L), now.plus(1000L));
 WindowedValue<String> value =
   WindowedValue.of("foo", now, window, PaneInfo.ON_TIME_AND_ONLY_FIRING);
 assertThat(Iterables.getOnlyElement(value.explodeWindows()), equalTo(value));
}

代码示例来源:origin: org.apache.beam/beam-runners-direct-java

@Test
public void getProcessingTimeIsClockNow() {
 assertThat(internals.currentProcessingTime(), equalTo(clock.now()));
 Instant oldProcessingTime = internals.currentProcessingTime();
 clock.advance(Duration.standardHours(12));
 assertThat(internals.currentProcessingTime(), equalTo(clock.now()));
 assertThat(
   internals.currentProcessingTime(),
   equalTo(oldProcessingTime.plus(Duration.standardHours(12))));
}

代码示例来源:origin: org.apache.beam/beam-runners-direct-java

@Test
public void getProcessingTimeIsClockNow() {
 assertThat(internals.currentProcessingTime(), equalTo(clock.now()));
 Instant oldProcessingTime = internals.currentProcessingTime();
 clock.advance(Duration.standardHours(12));
 assertThat(internals.currentProcessingTime(), equalTo(clock.now()));
 assertThat(
   internals.currentProcessingTime(),
   equalTo(oldProcessingTime.plus(Duration.standardHours(12))));
}

代码示例来源:origin: org.apache.beam/beam-runners-direct-java

@Test
public void multipleCallbacksShouldFireFires() throws Exception {
 CountDownLatch latch = new CountDownLatch(2);
 WindowFn<Object, IntervalWindow> windowFn = FixedWindows.of(Duration.standardMinutes(10));
 IntervalWindow window =
   new IntervalWindow(new Instant(0L), new Instant(0L).plus(Duration.standardMinutes(10)));
 executor.callOnGuaranteedFiring(
   create, window, WindowingStrategy.of(windowFn), new CountDownLatchCallback(latch));
 executor.callOnGuaranteedFiring(
   create, window, WindowingStrategy.of(windowFn), new CountDownLatchCallback(latch));
 executor.fireForWatermark(create, new Instant(0L).plus(Duration.standardMinutes(10)));
 assertThat(latch.await(500, TimeUnit.MILLISECONDS), equalTo(true));
}

代码示例来源:origin: org.apache.beam/beam-sdks-java-core

@ProcessElement
 public void processElement(ProcessContext c) throws Exception {
  assertThat(
    c.timestamp(),
    equalTo(
      new IntervalWindow(
          new Instant(0),
          new Instant(0).plus(Duration.standardMinutes(10)))
        .maxTimestamp()));
 }
}));

代码示例来源:origin: org.apache.beam/beam-sdks-java-core

@Test
public void testTerminationConditionsAfterTotalOf() {
 Instant now = Instant.now();
 Watch.Growth.AfterTotalOf<Object> c = Growth.afterTotalOf(standardSeconds(5));
 KV<Instant, ReadableDuration> state = c.forNewInput(now, null);
 assertFalse(c.canStopPolling(now, state));
 assertFalse(c.canStopPolling(now.plus(standardSeconds(3)), state));
 assertTrue(c.canStopPolling(now.plus(standardSeconds(6)), state));
}

代码示例来源:origin: org.apache.beam/beam-runners-direct-java

@ProcessElement
 public void process(@Element Integer e, MultiOutputReceiver r) {
  for (int i = 0; i < e; i++) {
   r.get(food)
     .outputWithTimestamp(
       KV.of("foo", e),
       new Instant(0).plus(Duration.standardHours(i)));
  }
  r.get(originals).output(e);
 }
})

代码示例来源:origin: org.apache.beam/beam-runners-core-java

@Test
 public void falseAfterEndOfWindow() throws Exception {
  triggerTester.injectElements(TimestampedValue.of(1, new Instant(1)));
  IntervalWindow window =
    new IntervalWindow(new Instant(0), new Instant(0).plus(Duration.standardMinutes(5)));
  assertThat(triggerTester.shouldFire(window), is(false));
  triggerTester.advanceInputWatermark(BoundedWindow.TIMESTAMP_MAX_VALUE);
  assertThat(triggerTester.shouldFire(window), is(false));
 }
}

相关文章