Java Code Examples for java.time.Instant.plus()

The following are Jave code examples for showing how to use plus() of the java.time.Instant class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: swblocks-decisiontree   File: DatedEvaluatorTest.java   Source Code and License Vote up 6 votes
@Test
public void testSixRules() {
    final Builder<RuleSetBuilder, DecisionTreeRuleSet> ruleSetBuilder = ruleSetBuilder();
    final Instant now = Instant.now();
    final Instant start = now.minus(Period.ofWeeks(1));
    final Instant finish = now.plus(Period.ofWeeks(4));
    CommisionRuleSetSupplier.addRule(ruleSetBuilder, "*", "CME", "*", "*", "INDEX", start, finish, 1L, "1.1");
    CommisionRuleSetSupplier.addRule(ruleSetBuilder, "*", "CME", "S&P", "*", "INDEX", start, finish, 2L, "1.2");
    CommisionRuleSetSupplier.addRule(ruleSetBuilder, "VOICE", "CME", "ED", "*", "RATE", start, finish, 3L, "1.4");
    CommisionRuleSetSupplier.addRule(ruleSetBuilder, "VOICE", "*", "*", "US", "*", start, finish, 4L, "1.5");
    CommisionRuleSetSupplier.addRule(ruleSetBuilder, "*", "*", "*", "US", "*", start, finish, 5L, "1.2");
    CommisionRuleSetSupplier.addRule(ruleSetBuilder, "*", "*", "*", "UK", "*", start, finish, 6L, "1.1");

    final DecisionTreeRuleSet ruleSet = ruleSetBuilder.build();
    final TreeNode node = constructTree(ruleSet);
    Assert.assertNotNull(node);

    checkMatch(inputA, now, node, 3L);
    checkMatch(inputB, now, node, 4L);
    checkMatch(inputC, now, node, 4L);
    checkMatch(inputD, now, node, 6L);
    checkMatch(inputE, now, node, 5L);
    checkMatch(inputF, now, node, 6L);
}
 
Example 2
Project: swblocks-decisiontree   File: DatedEvaluatorTest.java   Source Code and License Vote up 6 votes
@Test
public void testFiveRules() {
    final Builder<RuleSetBuilder, DecisionTreeRuleSet> ruleSetBuilder = ruleSetBuilder();
    final Instant now = Instant.now();
    final Instant start = now.minus(Period.ofWeeks(1));
    final Instant finish = now.plus(Period.ofWeeks(4));

    CommisionRuleSetSupplier.addRule(ruleSetBuilder, "*", "CME", "*", "*", "INDEX", start, finish, 1L, "1.1");
    CommisionRuleSetSupplier.addRule(ruleSetBuilder, "*", "CME", "S&P", "*", "INDEX", start, finish, 2L, "1.2");
    CommisionRuleSetSupplier.addRule(ruleSetBuilder, "VOICE", "CME", "ED", "*", "RATE", start, finish, 3L, "1.4");
    CommisionRuleSetSupplier.addRule(ruleSetBuilder, "VOICE", "*", "*", "US", "*", start, finish, 4L, "1.5");
    CommisionRuleSetSupplier.addRule(ruleSetBuilder, "*", "*", "*", "US", "*", start, finish, 5L, "1.2");

    final DecisionTreeRuleSet ruleSet = ruleSetBuilder.build();
    final TreeNode node = constructTree(ruleSet);
    Assert.assertNotNull(node);

    checkMatch(inputA, now, node, 3L);
    checkMatch(inputB, now, node, 4L);
    checkMatch(inputC, now, node, 4L);
    checkMatch(inputE, now, node, 5L);

    checkNoMatch(inputD, now, node);
    checkNoMatch(inputF, now, node);
}
 
Example 3
Project: swblocks-decisiontree   File: ChangeTest.java   Source Code and License Vote up 6 votes
@Test
public void hashCodeCorrect() {
    final Set<RuleChange> ruleChanges = null;
    final Set<ValueGroupChange> valueGroupChanges = null;

    final Instant initiatorTime = NOW;
    final Instant authoriserTime = initiatorTime.plus(Period.ofWeeks(1));

    final Audit audit = new Audit("USER1", initiatorTime, "USER2", authoriserTime);
    final Change change = new Change(new UUID(0, 2), "TEST-RULESET", NOW, CHANGE_RANGE, audit, ruleChanges,
            valueGroupChanges);

    final Audit otherAudit = new Audit("USER1", initiatorTime, "USER2", authoriserTime);
    final Change otherChange = new Change(new UUID(0, 2), "TEST-RULESET", NOW, CHANGE_RANGE, otherAudit,
            ruleChanges, valueGroupChanges);

    assertEquals(change.hashCode(), otherChange.hashCode());
}
 
Example 4
Project: swblocks-jbl   File: LruCacheTest.java   Source Code and License Vote up 6 votes
@Test
public void removesOldestEntry() {
    final Instant now = Instant.now();

    final Range<Instant> rangeOne = new Range<>(now, now.plus(Period.ofWeeks(1)));
    this.cache.putIfAbsent(rangeOne, rangeOne);
    assertTrue(this.cache.containsKey(rangeOne));

    final Range<Instant> rangeTwo = new Range<>(now.plus(Period.ofWeeks(1)), now.plus(Period.ofWeeks(2)));
    this.cache.putIfAbsent(rangeTwo, rangeTwo);
    assertTrue(this.cache.containsKey(rangeOne));
    assertTrue(this.cache.containsKey(rangeTwo));

    this.cache.get(rangeTwo);

    final Range<Instant> rangeThree = new Range<>(now.plus(Period.ofWeeks(2)), now.plus(Period.ofWeeks(3)));
    this.cache.putIfAbsent(rangeThree, rangeThree);

    assertFalse(this.cache.containsKey(rangeOne));
    assertTrue(this.cache.containsKey(rangeTwo));
    assertTrue(this.cache.containsKey(rangeThree));
}
 
Example 5
Project: swblocks-decisiontree   File: DatedEvaluatorTest.java   Source Code and License Vote up 6 votes
@Test
public void testFourRules() {
    final Builder<RuleSetBuilder, DecisionTreeRuleSet> ruleSetBuilder = ruleSetBuilder();
    final Instant now = Instant.now();
    final Instant start = now.minus(Period.ofWeeks(1));
    final Instant finish = now.plus(Period.ofWeeks(4));

    CommisionRuleSetSupplier.addRule(ruleSetBuilder, "*", "CME", "*", "*", "INDEX", start, finish, 1L, "1.1");
    CommisionRuleSetSupplier.addRule(ruleSetBuilder, "*", "CME", "S&P", "*", "INDEX", start, finish, 2L, "1.2");
    CommisionRuleSetSupplier.addRule(ruleSetBuilder, "VOICE", "CME", "ED", "*", "RATE", start, finish, 3L, "1.4");
    CommisionRuleSetSupplier.addRule(ruleSetBuilder, "VOICE", "*", "*", "US", "*", start, finish, 4L, "1.5");

    final DecisionTreeRuleSet ruleSet = ruleSetBuilder.build();
    final TreeNode node = constructTree(ruleSet);
    Assert.assertNotNull(node);

    checkMatch(inputA, now, node, 3L);
    checkMatch(inputB, now, node, 4L);
    checkMatch(inputC, now, node, 4L);

    checkNoMatch(inputD, now, node);
    checkNoMatch(inputE, now, node);
    checkNoMatch(inputF, now, node);
}
 
Example 6
Project: swblocks-decisiontree   File: RuleChangeTest.java   Source Code and License Vote up 6 votes
@Test
public void hashCodeCorrect() {
    final Instant start = Instant.now().minus(Period.ofWeeks(-1));
    final Instant end = start.plus(Period.ofWeeks(5));
    final InputDriver[] drivers = getInputDriverArray("Test1", "Test2", "Test3");
    final Map<String, String> outputs = Collections.singletonMap("outputDriver", "result");

    final DecisionTreeRule rule =
            new DecisionTreeRule(new UUID(0, 1), new UUID(0, 2), drivers, outputs, start, end);
    final RuleChange ruleChange = new RuleChange(Type.ORIGINAL, rule);

    final DecisionTreeRule otherRule =
            new DecisionTreeRule(new UUID(0, 1), new UUID(0, 2), drivers, outputs, start, end);
    final RuleChange otherRuleChange = new RuleChange(Type.ORIGINAL, otherRule);

    assertEquals(ruleChange.hashCode(), otherRuleChange.hashCode());
}
 
Example 7
Project: swblocks-decisiontree   File: ChangeTest.java   Source Code and License Vote up 5 votes
@Test
public void changeAuditInfo() {
    testConstruction();

    Instant initiatorTime = NOW;

    final Audit audit = getBean().getAudit();
    assertEquals("USER1", audit.getInitiator());
    assertEquals(initiatorTime, audit.getInitiatorTime());
    assertEquals("USER2", audit.getAuthoriser());

    Instant authoriserTime = initiatorTime.plus(Period.ofWeeks(1));
    assertEquals(authoriserTime, audit.getAuthoriserTime());

    initiatorTime = NOW.plus(Period.ofWeeks(5));
    authoriserTime = initiatorTime.plus(Period.ofWeeks(1));
    final Audit newAudit = new Audit("USER3", initiatorTime, "USER4", authoriserTime);
    getBean().setAudit(newAudit);

    this.injectedValues.clear();

    this.injectedValues.put("initiator", "USER3");
    this.injectedValues.put("initiatorTime", initiatorTime);
    this.injectedValues.put("authoriser", "USER4");
    this.injectedValues.put("authoriserTime", authoriserTime);

    JblTestClassUtils.assertGetterCorrectForConstructorInjection(this.injectedValues, getBean().getAudit());
}
 
Example 8
Project: spring-boot-actuator-dashboard   File: AccessTokenService.java   Source Code and License Vote up 5 votes
String generateToken() {
	Instant now = Instant.now();
	Instant exp = now.plus(1, ChronoUnit.DAYS);

	JWTClaimsSet claimsSet = new JWTClaimsSet.Builder()
			.issuer(props.getExternalUrl() + "/oauth/token") //
			.expirationTime(Date.from(exp)) //
			.issueTime(Date.from(now)) //
			.claim("scope", Collections.singletonList("actuator.read")) //
			.build();

	return this.jwtTokenConverter.sign(claimsSet).serialize();
}
 
Example 9
Project: swblocks-decisiontree   File: ValueGroupChangeTest.java   Source Code and License Vote up 5 votes
@Test
public void hashCodeCorrect() {
    final UUID id = new UUID(0, 1);
    final Instant start = Instant.now().minus(Period.ofWeeks(-1));
    final Instant end = start.plus(Period.ofWeeks(5));
    final DateRange range = new DateRange(start, end);
    final List<String> drivers = Arrays.asList("Test1", "Test2", "Test3");
    final ValueGroup valueGroup = new ValueGroup(id, "TestValueGroup", drivers, range);

    final ValueGroupChange change = new ValueGroupChange(Type.NEW, valueGroup);
    final ValueGroupChange other = new ValueGroupChange(Type.NEW, valueGroup);

    assertEquals(change.hashCode(), other.hashCode());
}
 
Example 10
Project: ProjectAres   File: TimeUtils.java   Source Code and License Vote up 5 votes
public static Instant plus(Instant instant, Duration add) {
    if(isInfFuture(instant)) {
        return INF_FUTURE;
    } else if(isInfPast(instant)) {
        return INF_PAST;
    } else if(isInfPositive(add)) {
        return INF_FUTURE;
    } else if(isInfNegative(add)) {
        return INF_PAST;
    } else {
        return instant.plus(add);
    }
}
 
Example 11
Project: swblocks-decisiontree   File: ChangeTest.java   Source Code and License Vote up 5 votes
@Test
public void removeValueGroup() {
    testConstruction();
    final Instant start = NOW.minus(Period.ofWeeks(-1));
    final Instant end = start.plus(Period.ofWeeks(5));
    final DateRange range = new DateRange(start, end);
    final List<String> drivers = Arrays.asList("Test5", "Test6", "Test7");
    final ValueGroup valueGroup = new ValueGroup(ADDED_ID, "TestValueGroup", drivers, range);
    final ValueGroupChange valueGroupChange = new ValueGroupChange(Type.NEW, valueGroup);

    getBean().addValueGroupChange(valueGroupChange);

    ValueGroup valueGroupForTest = new ValueGroup(UNKNOWN_ID, "TestValueGroup", drivers, range);
    ValueGroupChange valueGroupChangeForTest = new ValueGroupChange(Type.NEW, valueGroupForTest);
    getBean().removeValueGroupChange(valueGroupChangeForTest);
    assertThat(getBean().getValueGroupChanges(), hasSize(2));
    assertThat(getBean().getRuleChanges(), hasSize(1));

    valueGroupForTest = new ValueGroup(UNKNOWN_ID, "TestValueGroup", drivers, range);
    valueGroupChangeForTest = new ValueGroupChange(Type.ORIGINAL, valueGroupForTest);
    getBean().removeValueGroupChange(valueGroupChangeForTest);
    assertThat(getBean().getValueGroupChanges(), hasSize(2));
    assertThat(getBean().getRuleChanges(), hasSize(1));

    valueGroupForTest = new ValueGroup(ADDED_ID, "TestValueGroup", drivers, range);
    valueGroupChangeForTest = new ValueGroupChange(Type.ORIGINAL, valueGroupForTest);
    getBean().removeValueGroupChange(valueGroupChangeForTest);
    assertThat(getBean().getValueGroupChanges(), hasSize(2));
    assertThat(getBean().getRuleChanges(), hasSize(1));

    valueGroupForTest = new ValueGroup(ADDED_ID, "TestValueGroup", drivers, range);
    valueGroupChangeForTest = new ValueGroupChange(Type.NEW, valueGroupForTest);
    getBean().removeValueGroupChange(valueGroupChangeForTest);
    assertThat(getBean().getValueGroupChanges(), hasSize(1));
    assertThat(getBean().getRuleChanges(), hasSize(1));
}
 
Example 12
Project: cryptotrader   File: TraderImplTest.java   Source Code and License Vote up 5 votes
@Test
public void testCalculateInterval() throws Exception {

    Duration interval = Duration.ofMillis(10);
    Instant t1 = Instant.now();
    Instant t2 = t1.plus(interval);
    when(module.getMock(PropertyManager.class).getNow()).thenReturn(t1);

    assertEquals(target.calculateInterval(t2), interval);
    assertEquals(target.calculateInterval(t1), ZERO);
    assertEquals(target.calculateInterval(t1.minus(interval)), ZERO);
    assertEquals(target.calculateInterval(null), ZERO);

}
 
Example 13
Project: swblocks-decisiontree   File: DecisionTreeRuleTest.java   Source Code and License Vote up 5 votes
@Test
public void testDateRange() {
    final Instant startInstance = Instant.now().minus(1, ChronoUnit.DAYS);
    final Instant endInstance = startInstance.plus(2, ChronoUnit.DAYS);
    final DecisionTreeRule decisionTreeRule =
            new DecisionTreeRule(new UUID(0, 1), UUID.randomUUID(),
                    getInputDriverArray("DRIVER_ONE", "DRIVER_TWO"),
                    this.outputDriver, startInstance, endInstance);

    assertEquals(startInstance, decisionTreeRule.getRange().getStart());
    assertEquals(endInstance, decisionTreeRule.getRange().getFinish());
}
 
Example 14
Project: swblocks-decisiontree   File: ChangeTest.java   Source Code and License Vote up 5 votes
@Test
public void addValueGroupChange() {
    testConstruction();
    final Instant start = NOW.minus(Period.ofWeeks(-1));
    final Instant end = start.plus(Period.ofWeeks(5));
    final DateRange range = new DateRange(start, end);
    final List<String> drivers = Arrays.asList("Test5", "Test6", "Test7");
    final ValueGroup valueGroup = new ValueGroup(ADDED_ID, "TestValueGroup", drivers, range);
    final ValueGroupChange valueGroupChange = new ValueGroupChange(Type.NEW, valueGroup);

    final ValueGroup originalValueGroupChanged = new ValueGroup(BASE_ID, "TestValueGroup",
            Arrays.asList("Test2", "Test3"), range);
    final ValueGroupChange originalValueGroupChange = new ValueGroupChange(Type.NEW, originalValueGroupChanged);

    getBean().addValueGroupChange(valueGroupChange);
    getBean().addValueGroupChange(originalValueGroupChange);
    assertThat(getBean().getValueGroupChanges(), hasSize(3));
    assertThat(getBean().getValueGroupChanges(), hasItems(getBean().getValueGroupChanges().iterator().next(),
            valueGroupChange, originalValueGroupChange));
    assertThat(getBean().getRuleChanges(), hasSize(1));

    final Map<UUID, Optional<TreeValueGroup>> groups = getBean().getGroups();
    assertNotNull(groups);
    assertThat(groups.size(), is(2));
    assertThat(groups, allOf(
            hasEntry(BASE_ID, Optional.<TreeValueGroup>of(originalValueGroupChanged)),
            hasEntry(ADDED_ID, Optional.<TreeValueGroup>of(valueGroup))));

}
 
Example 15
Project: openjdk-jdk10   File: TCKInstant.java   Source Code and License Vote up 4 votes
@Test(expectedExceptions=DateTimeException.class)
public void plus_longTemporalUnit_overflowTooSmall() {
    Instant i = Instant.ofEpochSecond(MIN_SECOND);
    i.plus(999999999, NANOS);
    i.plus(-1, SECONDS);
}
 
Example 16
Project: swblocks-decisiontree   File: DatedEvaluatorTest.java   Source Code and License Vote up 4 votes
@Test
public void testAlternativePathsFailurePathsAndValueGroups() {
    final Instant now = Instant.now();
    final Instant start = now.minus(Period.ofWeeks(1));
    final Instant finish = now.plus(Period.ofWeeks(4));

    final Builder<RuleSetBuilder, DecisionTreeRuleSet> ruleSetBuilder = RuleSetBuilder.creator(Arrays.asList(
            "MARKUP_CODE", "CLIENT_ACCOUNT", "CLIENT_SPN", "ADVISOR_SPN", "EXECUTION_VENUE", "MEMBERSHIP",
            "SECURITY_TYPE", "CONTRACT", "FEE_GROUP", "PRODUCT_GROUP", "EXCHANGE", "REGION"));

    ruleSetBuilder.with(RuleSetBuilder::rule, RuleBuilder.creator()
            .with(RuleBuilder::input, Arrays.asList("CLM", "*", "VG:AdVG1589CLM:0152035:03227805:0521659",
                    "VG:VG1589CLM:0151488:4679563:7888805", "*", "*", "*", "*", "381", "Equity indices",
                    "VG:IFEU:IFLL", "ER"))
            .with(RuleBuilder::start, start)
            .with(RuleBuilder::end, finish)
            .with(RuleBuilder::setId, new UUID(0, 1L)));

    ruleSetBuilder.with(RuleSetBuilder::rule, RuleBuilder.creator()
            .with(RuleBuilder::input, Arrays.asList("CLM", "*", "VG:AdVG1589CLM:0152035:03227805:0521659",
                    "VG:VG1589CLM:0151488:4679563:7888805", "*", "*", "*", "*", "*", "*", "VG:IFEU:IFLL", "ER"))
            .with(RuleBuilder::start, start)
            .with(RuleBuilder::end, finish)
            .with(RuleBuilder::setId, new UUID(0, 2L)));

    ruleSetBuilder.with(RuleSetBuilder::rule, RuleBuilder.creator()
            .with(RuleBuilder::input, Arrays.asList("CLM", "*", "VG:AdVG1589CLM:0152035:03227805:0521659",
                    "VG:AdVG1589CLM:0151488:3679563:6888805", "*", "*", "*", "*", "*", "*", "VG:IFEU:IFLL", "ER"))
            .with(RuleBuilder::start, start)
            .with(RuleBuilder::end, finish)
            .with(RuleBuilder::setId, new UUID(0, 3L)));

    ruleSetBuilder.with(RuleSetBuilder::rule, RuleBuilder.creator()
            .with(RuleBuilder::input, Arrays.asList("CLM", "*", "VG:AdVG1589CLM:0152035:03227805:0521659",
                    "VG:VG1589CLM:0151488:4679563:7888805", "ELEC", "NMEM", "*", "*", "123", "Equity indices",
                    "VG:IFEU:IFLL", "ER"))
            .with(RuleBuilder::start, start)
            .with(RuleBuilder::end, finish)
            .with(RuleBuilder::setId, new UUID(0, 4L)));

    final DecisionTreeRuleSet ruleSet = ruleSetBuilder.build();
    final TreeNode node = constructTree(ruleSet);
    Assert.assertNotNull(node);

    final List<String> inputs = Arrays.asList("CLM", "A102059551", "0152035", "0151488",
            "ELEC", "NMEM", "FUTURE", "Y2", "381", "Equity indices", "IFLL", "ER");
    final Optional<UUID> result = Evaluator.singleEvaluate(inputs, now, node);
    assertTrue(result.isPresent());
    assertEquals(new UUID(0, 1L), result.get());
}
 
Example 17
Project: openjdk-jdk10   File: TCKInstant.java   Source Code and License Vote up 4 votes
@Test(expectedExceptions=DateTimeException.class)
public void plus_longTemporalUnit_overflowTooBig() {
    Instant i = Instant.ofEpochSecond(MAX_SECOND, 999999999);
    i.plus(1, NANOS);
}
 
Example 18
Project: jdk8u-jdk   File: TCKInstant.java   Source Code and License Vote up 4 votes
@Test(expectedExceptions=DateTimeException.class)
public void plus_longTemporalUnit_overflowTooBig() {
    Instant i = Instant.ofEpochSecond(MAX_SECOND, 999999999);
    i.plus(1, NANOS);
}
 
Example 19
Project: jdk8u-jdk   File: TCKInstant.java   Source Code and License Vote up 4 votes
@Test(expectedExceptions=DateTimeException.class)
public void plus_longTemporalUnit_overflowTooSmall() {
    Instant i = Instant.ofEpochSecond(MIN_SECOND);
    i.plus(999999999, NANOS);
    i.plus(-1, SECONDS);
}
 
Example 20
Project: smarti   File: DateUtils.java   Source Code and License Vote up 3 votes
/**
 * Returns the earliest/latest {@link Date} based on the {@link DateValue#getDate()}
 * and {@link DateValue#getGrain()}.
 * @param dateValue the date value
 * @return the earliest possible start in {@link Pair#getLeft()} and the latest
 * possible end in {@link Pair#getRight()}. If the parsed {@link DateValue} does
 * not have a {@link DateValue#getGrain()} the left and right date will be the
 * value of {@link DateValue#getDate()}
 * @throws NullPointerException if the parsed {@link DateValue} or
 * {@link DateValue#getDate()} are <code>null</code>
 */
public static Pair<Date, Date> getDateRange(DateValue dateValue){
    if(dateValue.getGrain() == null){
        return new ImmutablePair<>(dateValue.getDate(), dateValue.getDate());
    } else {
        Instant inst = dateValue.getDate().toInstant();
        Instant startInst = inst.truncatedTo(dateValue.getGrain().getChronoUnit());
        Instant endInst = startInst.plus(1,dateValue.getGrain().getChronoUnit());
        return new ImmutablePair<>(Date.from(startInst), Date.from(endInst));
    }
}