本文整理匯總了Java中org.joda.time.Instant.plus方法的典型用法代碼示例。如果您正苦於以下問題:Java Instant.plus方法的具體用法?Java Instant.plus怎麽用?Java Instant.plus使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.joda.time.Instant
的用法示例。
在下文中一共展示了Instant.plus方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: forBid
import org.joda.time.Instant; //導入方法依賴的package包/類
/**
* Return a bid window for {@code bid}. It should later be merged into
* the corresponding auction window. However, it is possible this bid is for an already
* expired auction, or for an auction which the system has not yet seen. So we
* give the bid a bit of wiggle room in its interval.
*/
public static AuctionOrBidWindow forBid(
long expectedAuctionDurationMs, Instant timestamp, Bid bid) {
// At this point we don't know which auctions are still valid, and the bid may
// be for an auction which won't start until some unknown time in the future
// (due to Generator.AUCTION_ID_LEAD in Generator.nextBid).
// A real system would atomically reconcile bids and auctions by a separate mechanism.
// If we give bids an unbounded window it is possible a bid for an auction which
// has already expired would cause the system watermark to stall, since that window
// would never be retired.
// Instead, we will just give the bid a finite window which expires at
// the upper bound of auctions assuming the auction starts at the same time as the bid,
// and assuming the system is running at its lowest event rate (as per interEventDelayUs).
return new AuctionOrBidWindow(
timestamp, timestamp.plus(expectedAuctionDurationMs * 2), bid.auction, false);
}
示例2: assignWindow
import org.joda.time.Instant; //導入方法依賴的package包/類
@Override
public IntervalWindow assignWindow(Instant timestamp) {
Instant start =
new Instant(
timestamp.getMillis()
- timestamp.plus(size).minus(offset).getMillis() % size.getMillis());
// The global window is inclusive of max timestamp, while interval window excludes its
// upper bound
Instant endOfGlobalWindow = GlobalWindow.INSTANCE.maxTimestamp().plus(1);
// The end of the window is either start + size if that is within the allowable range, otherwise
// the end of the global window. Truncating the window drives many other
// areas of this system in the appropriate way automatically.
//
// Though it is curious that the very last representable fixed window is shorter than the rest,
// when we are processing data in the year 294247, we'll probably have technology that can
// account for this.
Instant end =
start.isAfter(endOfGlobalWindow.minus(size)) ? endOfGlobalWindow : start.plus(size);
return new IntervalWindow(start, end);
}
示例3: testSupportsWindowParameter
import org.joda.time.Instant; //導入方法依賴的package包/類
@Test
public void testSupportsWindowParameter() throws Exception {
Instant now = Instant.now();
try (DoFnTester<Integer, KV<Integer, BoundedWindow>> tester =
DoFnTester.of(new DoFnWithWindowParameter())) {
BoundedWindow firstWindow = new IntervalWindow(now, now.plus(Duration.standardMinutes(1)));
tester.processWindowedElement(1, now, firstWindow);
tester.processWindowedElement(2, now, firstWindow);
BoundedWindow secondWindow = new IntervalWindow(now, now.plus(Duration.standardMinutes(4)));
tester.processWindowedElement(3, now, secondWindow);
tester.finishBundle();
assertThat(
tester.peekOutputElementsInWindow(firstWindow),
containsInAnyOrder(
TimestampedValue.of(KV.of(1, firstWindow), now),
TimestampedValue.of(KV.of(2, firstWindow), now)));
assertThat(
tester.peekOutputElementsInWindow(secondWindow),
containsInAnyOrder(
TimestampedValue.of(KV.of(3, secondWindow), now)));
}
}
示例4: testExplodeWindowsManyWindowsMultipleWindowedValues
import org.joda.time.Instant; //導入方法依賴的package包/類
@Test
public void testExplodeWindowsManyWindowsMultipleWindowedValues() {
Instant now = Instant.now();
BoundedWindow centerWindow = new IntervalWindow(now.minus(1000L), now.plus(1000L));
BoundedWindow pastWindow = new IntervalWindow(now.minus(1500L), now.plus(500L));
BoundedWindow futureWindow = new IntervalWindow(now.minus(500L), now.plus(1500L));
BoundedWindow futureFutureWindow = new IntervalWindow(now, now.plus(2000L));
PaneInfo pane = PaneInfo.createPane(false, false, Timing.ON_TIME, 3L, 0L);
WindowedValue<String> value =
WindowedValue.of(
"foo",
now,
ImmutableList.of(pastWindow, centerWindow, futureWindow, futureFutureWindow),
pane);
assertThat(
value.explodeWindows(),
containsInAnyOrder(
WindowedValue.of("foo", now, futureFutureWindow, pane),
WindowedValue.of("foo", now, futureWindow, pane),
WindowedValue.of("foo", now, centerWindow, pane),
WindowedValue.of("foo", now, pastWindow, pane)));
}
示例5: generateSequentialList
import org.joda.time.Instant; //導入方法依賴的package包/類
public static void generateSequentialList(List<KV<String, TSProto>> ts, Instant time, String key,
double value, double change) {
Instant tsTime = new Instant(time);
for (int i = 0; i < 5; i++) {
ts.add(KV.of(key, TSProto.newBuilder().setAskPrice(value).setBidPrice(value).setKey(key)
.setIsLive(true).setTime(tsTime.getMillis()).build()));
tsTime = tsTime.plus(Duration.standardMinutes(1));
value += change;
}
value -= change;
for (int i = 5; i < 10; i++) {
ts.add(KV.of(key, TSProto.newBuilder().setAskPrice(value).setBidPrice(value).setKey(key)
.setIsLive(true).setTime(tsTime.getMillis()).build()));
tsTime = tsTime.plus(Duration.standardMinutes(1));
value -= change;
}
}
示例6: main
import org.joda.time.Instant; //導入方法依賴的package包/類
public static void main(String[] args) throws NoSuchAlgorithmException {
SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");
for (int i=1; i<=1440; i++) {
System.out.println("maps.put(\"20141109-"+i+"\", \""+sr.nextInt(10)+" "+sr.nextInt(10)+" "+sr.nextInt(10)+" "+sr.nextInt(10)+" "+sr.nextInt(10)+"\");");
}
System.out.println(LocalDate.now());
Instant in = new Instant(1414508801016L);
DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
formatter=formatter.withZone(DateTimeZone.forTimeZone(TimeZone.getTimeZone("GMT+8")));
in = in.plus(100);
System.out.println(in.get(DateTimeFieldType.millisOfSecond()));
System.out.println(in.toDate());
System.out.println(formatter.print(in));
System.out.println(in.getMillis());
Pattern pattern = Pattern.compile("\"phase\":\"20141018023\"(.*)\"data\":\\[\"(\\d)\",\"(\\d)\",\"(\\d)\",\"(\\d)\",\"(\\d)\"\\]\\}\\]\\}");
Matcher matcher = pattern.matcher("{\"code\":0,\"message\":\"\",\"data\":[{\"phasetype\":200,\"phase\":\"20141018023\",\"create_at\":\"2014-01-21 14:41:05\",\"time_startsale\":\"2014-10-18 01:50:00\",\"time_endsale\":\"2014-10-18 01:55:00\",\"time_endticket\":\"2014-10-18 01:55:00\",\"time_draw\":\"2014-10-18 01:56:00\",\"status\":5,\"forsale\":0,\"is_current\":0,\"result\":{\"result\":[{\"key\":\"ball\",\"data\":[\"1\",\"5\",\"0\",\"5\",\"9\"]}]},\"result_detail\":{\"resultDetail\":[{\"key\":\"prize1\",\"bet\":\"0\",\"prize\":100000},{\"key\":\"prize2\",\"bet\":\"0\",\"prize\":20000},{\"key\":\"prize3\",\"bet\":\"0\",\"prize\":200},{\"key\":\"prize4\",\"bet\":\"0\",\"prize\":20},{\"key\":\"prize5\",\"bet\":\"0\",\"prize\":1000},{\"key\":\"prize6\",\"bet\":\"0\",\"prize\":320},{\"key\":\"prize7\",\"bet\":\"0\",\"prize\":160},{\"key\":\"prize8\",\"bet\":\"0\",\"prize\":100},{\"key\":\"prize9\",\"bet\":\"0\",\"prize\":50},{\"key\":\"prize10\",\"bet\":\"0\",\"prize\":10},{\"key\":\"prize11\",\"bet\":\"0\",\"prize\":4}]},\"pool_amount\":\"\",\"sale_amount\":\"\",\"ext\":\"\",\"fc3d_sjh\":null,\"terminal_status\":2,\"fordraw\":0,\"time_startsale_fixed\":\"2014-10-18 01:47:40\",\"time_endsale_fixed\":\"2014-10-18 01:52:40\",\"time_endsale_syndicate_fixed\":\"2014-10-18 01:55:00\",\"time_endsale_upload_fixed\":\"2014-10-18 01:55:00\",\"time_draw_fixed\":\"2014-10-18 01:56:00\",\"time_startsale_correction\":140,\"time_endsale_correction\":140,\"time_endsale_syndicate_correction\":0,\"time_endsale_upload_correction\":0,\"time_draw_correction\":0,\"time_exchange\":\"2014-12-16 01:56:00\"},{\"phasetype\":\"200\",\"phase\":\"20141018024\",\"create_at\":\"2014-01-21 14:41:05\",\"time_startsale\":\"2014-10-18 01:55:00\",\"time_endsale\":\"2014-10-18 10:00:00\",\"time_endticket\":\"2014-10-18 10:00:00\",\"time_draw\":\"2014-10-18 10:01:00\",\"status\":\"2\",\"forsale\":\"1\",\"is_current\":\"1\",\"result\":null,\"result_detail\":null,\"pool_amount\":\"\",\"sale_amount\":\"\",\"ext\":\"\",\"fc3d_sjh\":null,\"terminal_status\":\"1\",\"fordraw\":\"0\",\"time_startsale_fixed\":\"2014-10-18 01:52:40\",\"time_endsale_fixed\":\"2014-10-18 09:57:40\",\"time_endsale_syndicate_fixed\":\"2014-10-18 10:00:00\",\"time_endsale_upload_fixed\":\"2014-10-18 10:00:00\",\"time_draw_fixed\":\"2014-10-18 10:01:00\",\"time_startsale_correction\":140,\"time_endsale_correction\":140,\"time_endsale_syndicate_correction\":0,\"time_endsale_upload_correction\":0,\"time_draw_correction\":0,\"time_exchange\":\"2014-12-16 10:01:00\"}],\"redirect\":\"\",\"datetime\":\"2014-10-18 04:08:45\",\"timestamp\":1413576525}");
//Pattern pattern = Pattern.compile("(.*)message(\\d\\d)(\\d)(\\d)(\\d)");
//Matcher matcher = pattern.matcher("23fawef_message12345");
//Pattern pattern = Pattern.compile("\"number\":\"(\\d) (\\d) (\\d) (\\d) (\\d)\",\"period\":\"20141017083");
//Matcher matcher = pattern.matcher("{\"latestPeriods\":[{\"number\":\"6 0 2 2 1\",\"period\":\"20141017084\"},{\"number\":\"0 8 9 1 9\",\"period\":\"20141017083\"},{\"number\":\"4 0 4 4 6\",\"period\":\"20141017082\"},{\"number\":\"4 5 8 7 7\",\"period\":\"20141017081\"},{\"number\":\"7 2 8 5 3\",\"period\":\"20141017080\"},{\"number\":\"9 7 3 8 0\",\"period\":\"20141017079\"},{\"number\":\"3 7 6 0 1\",\"period\":\"20141017078\"},{\"number\":\"9 6 4 8 5\",\"period\":\"20141017077\"},{\"number\":\"6 4 1 8 1\",\"period\":\"20141017076\"},{\"number\":\"9 5 2 8 7\",\"period\":\"20141017075\"}],\"successful\":\"true\",\"statusDesc\":\"獲取數據成功\"}");
matcher.find();
for (int i=1; i<=matcher.groupCount(); i++) {
System.out.println(matcher.group(i));
}
}
示例7: testClearedTrade
import org.joda.time.Instant; //導入方法依賴的package包/類
/**
* Here we only verify function calls -
* each of the called functions is tested
* separately
*/
@Test
public void testClearedTrade ()
{
// prepare spy
marketManagerService.initialize(brokerContext);
MarketMgrThatDoesntSend spyMktMgr = spy(marketManagerService);
// prepare some trade data
ClearedTrade trade;
double executionMWh = 2;
double executionPrice = 3;
Instant now = new Instant(null);
Instant tradeCreationTime = now.plus(TimeService.HOUR); // this probably doesn't work but what we care about is the next line
when(timeslotRepo.getTimeslotIndex(tradeCreationTime)).thenReturn(1);
// record trade twice: with and without useMtx
trade = new ClearedTrade(4, executionMWh, executionPrice, tradeCreationTime);
ReflectionTestUtils.setField(configuratorFactoryService, "useMtx", false);
spyMktMgr.handleMessage(trade);
ReflectionTestUtils.setField(configuratorFactoryService, "useMtx", true);
spyMktMgr.handleMessage(trade);
// verify calls: updateMarketTracking only called if useMtx == false
//verify(mockMktMgr, times(2)).handleMessage(trade);
verify(spyMktMgr, times(1)).updateMarketTracking(4, executionMWh, executionPrice);
verify(spyMktMgr, times(2)).updateLowHighTradePrices(executionPrice);
verify(spyMktMgr, times(2)).recordTradeResult(timeslotRepo.getTimeslotIndex(tradeCreationTime), 4, executionPrice, executionMWh);
}
示例8: testMarketTransaction
import org.joda.time.Instant; //導入方法依賴的package包/類
/**
* Here we only verify function calls -
* called function(s) is tested separately
*/
@Test
public void testMarketTransaction ()
{
// prepare spy
marketManagerService.initialize(brokerContext);
MarketMgrThatDoesntSend spyMktMgr = spy(marketManagerService);
// prepare a market transaction
double executionMWh = 2;
double executionPrice = 3;
Instant now = new Instant(null);
Instant tradeCreationTime = now.plus(TimeService.HOUR); // this probably doesn't work but what we care about is the next line
when(timeslotRepo.getTimeslotIndex(tradeCreationTime)).thenReturn(1);
// record trade twice: with and without useMtx
MarketTransaction mtx = new MarketTransaction(thebroker, 1, 4,
executionMWh, executionPrice);
ReflectionTestUtils.setField(configuratorFactoryService, "useMtx", false);
spyMktMgr.handleMessage(mtx);
ReflectionTestUtils.setField(configuratorFactoryService, "useMtx", true);
spyMktMgr.handleMessage(mtx);
// verify calls: updateMarketTracking only called if useMtx == true
verify(spyMktMgr, times(1)).updateMarketTracking(4, executionMWh, executionPrice);
}
示例9: test_canRunDP
import org.joda.time.Instant; //導入方法依賴的package包/類
/**
* correctess of whether we can run DP
* this tests assumes that cleared trades
* are handled correctly: this should be taken
* care of in a test above
*
* Test
*/
@Test
public void test_canRunDP() {
// make sure all fields are in place
marketManagerService.initialize(brokerContext);
ClearedTrade trade;
BalancingTransaction balanceTx;
Instant now = new Instant(null);
Instant tradeCreationTime = now.plus(364 * TimeService.HOUR); // this probably doesn't work but what we care about is the next line
when(timeslotRepo.getTimeslotIndex(tradeCreationTime)).thenReturn(364);
// add the 'enabled timeslots from setUp(), eventhough
// they are not contiguous
trade = new ClearedTrade(364, 0, 0, tradeCreationTime);
marketManagerService.handleMessage(trade);
trade = new ClearedTrade(365, 0, 0, tradeCreationTime);
marketManagerService.handleMessage(trade);
balanceTx = new BalancingTransaction(thebroker, 1, -1234, -1.234);
marketManagerService.handleMessage(balanceTx);
int backup = (Integer)
ReflectionTestUtils.getField(configuratorFactoryService.CONSTANTS,
"LARGE_ENOUGH_SAMPLE_FOR_MARKET_TRADES");
ReflectionTestUtils.setField(configuratorFactoryService.CONSTANTS,
"LARGE_ENOUGH_SAMPLE_FOR_MARKET_TRADES", 1); assertEquals("canRunDP()",
true, marketManagerService.canRunDP(currentTimeslot.getSerialNumber(), enabledTimeslots));
ReflectionTestUtils.setField(configuratorFactoryService.CONSTANTS,
"LARGE_ENOUGH_SAMPLE_FOR_MARKET_TRADES", 2); assertEquals("canRunDP()",
false, marketManagerService.canRunDP(currentTimeslot.getSerialNumber(), enabledTimeslots));
// restore value
ReflectionTestUtils.setField(configuratorFactoryService.CONSTANTS,
"LARGE_ENOUGH_SAMPLE_FOR_MARKET_TRADES", backup);
}
示例10: getOutputTime
import org.joda.time.Instant; //導入方法依賴的package包/類
/**
* Ensures that later sliding windows have an output time that is past the end of earlier windows.
*
* <p>If this is the earliest sliding window containing {@code inputTimestamp}, that's fine.
* Otherwise, we pick the earliest time that doesn't overlap with earlier windows.
*/
@Experimental(Kind.OUTPUT_TIME)
@Override
public Instant getOutputTime(Instant inputTimestamp, IntervalWindow window) {
Instant startOfLastSegment = window.maxTimestamp().minus(period);
return startOfLastSegment.isBefore(inputTimestamp)
? inputTimestamp
: startOfLastSegment.plus(1);
}
示例11: testExplodeWindowsInOneWindowEquals
import org.joda.time.Instant; //導入方法依賴的package包/類
@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));
}
示例12: setForWindow
import org.joda.time.Instant; //導入方法依賴的package包/類
@Override
public void setForWindow(BoundedWindow window) {
Instant gcTime = LateDataUtils.garbageCollectionTime(window, windowingStrategy);
// make sure this fires after any window.maxTimestamp() timers
gcTime = gcTime.plus(GC_DELAY_MS);
timerInternals.setTimer(StateNamespaces.window(windowCoder, window),
GC_TIMER_ID, gcTime, TimeDomain.EVENT_TIME);
}
示例13: isForWindow
import org.joda.time.Instant; //導入方法依賴的package包/類
@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);
}
示例14: setRelative
import org.joda.time.Instant; //導入方法依賴的package包/類
@Override
public void setRelative() {
Instant target;
Instant now = getCurrentTime();
if (period.equals(Duration.ZERO)) {
target = now.plus(offset);
} else {
long millisSinceStart = now.plus(offset).getMillis() % period.getMillis();
target = millisSinceStart == 0 ? now : now.plus(period).minus(millisSinceStart);
}
target = minTargetAndGcTime(target);
setUnderlyingTimer(target);
}
示例15: testTrivialProcessFnPropagatesOutputWindowAndTimestamp
import org.joda.time.Instant; //導入方法依賴的package包/類
@Test
public void testTrivialProcessFnPropagatesOutputWindowAndTimestamp() throws Exception {
// Tests that ProcessFn correctly propagates the window and timestamp of the element
// inside the KeyedWorkItem.
// The underlying DoFn is actually monolithic, so this doesn't test splitting.
DoFn<Integer, String> fn = new ToStringFn();
Instant base = Instant.now();
IntervalWindow w =
new IntervalWindow(
base.minus(Duration.standardMinutes(1)), base.plus(Duration.standardMinutes(1)));
ProcessFnTester<Integer, String, SomeRestriction, SomeRestrictionTracker> tester =
new ProcessFnTester<>(
base,
fn,
BigEndianIntegerCoder.of(),
SerializableCoder.of(SomeRestriction.class),
MAX_OUTPUTS_PER_BUNDLE,
MAX_BUNDLE_DURATION);
tester.startElement(
WindowedValue.of(
KV.of(42, new SomeRestriction()),
base,
Collections.singletonList(w),
PaneInfo.ON_TIME_AND_ONLY_FIRING));
assertEquals(
Arrays.asList(
TimestampedValue.of("42a", base),
TimestampedValue.of("42b", base),
TimestampedValue.of("42c", base)),
tester.peekOutputElementsInWindow(w));
}