Java 类java.time.Period 实例源码

项目:morpheus-core    文件:RangeBasicTests.java   
@Test(dataProvider = "localDateRanges")
public void testRangeOfLocalDates(LocalDate start, LocalDate end, Period step, boolean parallel) {
    final Range<LocalDate> range = Range.of(start, end, step);
    final Array<LocalDate> array = range.toArray(parallel);
    final boolean ascend = start.isBefore(end);
    final int expectedLength = (int)Math.ceil(Math.abs((double)ChronoUnit.DAYS.between(start, end)) / (double)step.getDays());
    Assert.assertEquals(array.length(), expectedLength);
    Assert.assertEquals(array.typeCode(), ArrayType.LOCAL_DATE);
    Assert.assertTrue(!array.style().isSparse());
    Assert.assertEquals(range.start(), start, "The range start");
    Assert.assertEquals(range.end(), end, "The range end");
    LocalDate expected = null;
    for (int i=0; i<array.length(); ++i) {
        final LocalDate actual = array.getValue(i);
        expected = expected == null ? start : ascend ? expected.plus(step) : expected.minus(step);
        Assert.assertEquals(actual, expected, "Value matches at " + i);
        Assert.assertTrue(ascend ? actual.compareTo(start) >=0 && actual.isBefore(end) : actual.compareTo(start) <= 0 && actual.isAfter(end), "Value in bounds at " + i);
    }
}
项目:swblocks-decisiontree    文件:RuleChangeTest.java   
@Test
public void testConstruction() {
    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 change = new RuleChange(Type.ORIGINAL, rule);
    setBean(change);

    this.injectedValues.put("type", Type.ORIGINAL);
    this.injectedValues.put("rule", rule);

    JblTestClassUtils.assertGetterCorrectForConstructorInjection(this.injectedValues, getBean());
}
项目:openjdk-jdk10    文件:TCKDateTimeParseResolver.java   
@Test(dataProvider="resolveMinuteOfDay")
public void test_resolveMinuteOfDay(ResolverStyle style, long value, Integer expectedMinute, int expectedDays) {
    String str = Long.toString(value);
    DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(MINUTE_OF_DAY).toFormatter();

    if (expectedMinute != null) {
        TemporalAccessor accessor = f.withResolverStyle(style).parse(str);
        assertEquals(accessor.query(TemporalQueries.localDate()), null);
        assertEquals(accessor.query(TemporalQueries.localTime()), LocalTime.ofSecondOfDay(expectedMinute * 60));
        assertEquals(accessor.query(DateTimeFormatter.parsedExcessDays()), Period.ofDays(expectedDays));
    } else {
        try {
            f.withResolverStyle(style).parse(str);
            fail();
        } catch (DateTimeParseException ex) {
            // expected
        }
    }
}
项目:swblocks-decisiontree    文件:ValueGroupChangeTest.java   
@Test
public void testEquals() {
    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);

    assertTrue(change.equals(change));
    assertFalse(change.equals(null));
    assertFalse(change.equals(Boolean.TRUE));

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

    final ValueGroup otherValueGroup = new ValueGroup(id, "VG:TestOtherValueGroup", drivers, range);
    other = new ValueGroupChange(Type.NEW, otherValueGroup);
    assertFalse(change.equals(other));

    other = new ValueGroupChange(Type.ORIGINAL, otherValueGroup);
    assertFalse(change.equals(other));
}
项目:blog-examples    文件:TransformerImpl.java   
@Override
public IDestinationRecord transform(ISourceRecord source) {
    if(source == null){
        return null;
    }
    int age = Period.between(source.date(), mAsAt).getYears();
    return new IDestinationRecord() {

        @Override
        public String name() {
            return source.name();
        }

        @Override
        public int age() {
            return age;
        }
    };
}
项目:swblocks-decisiontree    文件:RuleChangeTest.java   
@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());
}
项目:morpheus-core    文件:PrinterOfObject.java   
/**
 * Constructor
 * @param nullValue the null value supplier
 */
PrinterOfObject(Supplier<String> nullValue) {
    super(FunctionStyle.OBJECT, nullValue);
    this.printerMap.put(boolean.class, Printer.ofBoolean());
    this.printerMap.put(Boolean.class, Printer.ofBoolean());
    this.printerMap.put(int.class, Printer.ofInt());
    this.printerMap.put(Integer.class, Printer.ofInt());
    this.printerMap.put(long.class, Printer.ofLong());
    this.printerMap.put(Long.class, Printer.ofLong());
    this.printerMap.put(double.class, Printer.ofDouble("0.000###;-0.000###"));
    this.printerMap.put(Double.class, Printer.ofDouble("0.000###;-0.000###"));
    this.printerMap.put(LocalDate.class, Printer.ofLocalDate(DateTimeFormatter.ISO_LOCAL_DATE));
    this.printerMap.put(LocalTime.class, Printer.ofLocalTime(DateTimeFormatter.ISO_LOCAL_TIME));
    this.printerMap.put(LocalDateTime.class, Printer.ofLocalDateTime(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
    this.printerMap.put(ZonedDateTime.class, Printer.ofZonedDateTime(DateTimeFormatter.ISO_ZONED_DATE_TIME));
    this.printerMap.put(Period.class, Printer.ofPeriod());
    this.printerMap.put(ZoneId.class, Printer.ofZoneId());
    this.printerMap.put(TimeZone.class, Printer.ofTimeZone());
    this.printerMap.put(java.util.Date.class, Printer.ofDate("yyyy-MM-dd"));
    this.printerMap.put(java.sql.Date.class, Printer.ofDate("yyyy-MM-dd"));
}
项目:device-bacnet    文件:ScheduleContext.java   
private ZonedDateTime initNextTime(ZonedDateTime start, ZonedDateTime now, Period p, Duration d) {
    // if the start time is in the future next will just be start
    ZonedDateTime next = start;
    // if the start time is in the past, increment until we find the next time to execute
    // cannot call isComplete() here as it depends on nextTime
    if(startTime.compareTo(now) <= 0 && !schedule.getRunOnce()) {
        // TODO: Look to optimize.  Consider a one-second timer, it would take too long
        // For example if only a single unit, e.g. only minutes, then can optimize relative to start 
        // if there are more than one unit, then the loop may be best as it will be difficult
        while(next.compareTo(now) <= 0) {
            next = next.plus(p);
            next = next.plus(d);
        }
    }
    return next;
}
项目:swblocks-decisiontree    文件:RuleRangeChangeBuilderTest.java   
@Test
public void amendsEndDateOfFirstSegmentToFinishBeforeSecondSegmentStarts() {
    createBuilder(new UUID(0, 1), new DateRange(null, NOW.plus(Period.ofWeeks(3))));
    final List<RuleChange> changes = this.builder.build();
    assertThat(changes, hasSize(2));

    final List<RuleChange> originals = getChangesByType(changes, Type.ORIGINAL);
    assertThat(originals, hasSize(1));

    assertRuleChange(originals.get(0), Type.ORIGINAL, new UUID(0, 1), new UUID(0, 2),
            new String[]{"VOICE", "CME", "ED", "US", "INDEX"}, Collections.singletonMap("Rate", "1.1"),
            NOW.plus(Period.ofWeeks(2)), NOW.plus(Period.ofWeeks(4)).minusMillis(1L));

    final List<RuleChange> newChanges = getChangesByType(changes, Type.NEW);
    assertThat(newChanges, hasSize(1));

    assertRuleChange(newChanges.get(0), Type.NEW, null, new UUID(0, 2),
            new String[]{"VOICE", "CME", "ED", "US", "INDEX"}, Collections.singletonMap("Rate", "1.1"),
            NOW.plus(Period.ofWeeks(2)), NOW.plus(Period.ofWeeks(3)));
}
项目:openjdk-jdk10    文件:TCKPeriod.java   
public void test_equals() {
    assertEquals(Period.of(1, 0, 0).equals(Period.ofYears(1)), true);
    assertEquals(Period.of(0, 1, 0).equals(Period.ofMonths(1)), true);
    assertEquals(Period.of(0, 0, 1).equals(Period.ofDays(1)), true);
    assertEquals(Period.of(1, 2, 3).equals(Period.of(1, 2, 3)), true);

    assertEquals(Period.ofYears(1).equals(Period.ofYears(1)), true);
    assertEquals(Period.ofYears(1).equals(Period.ofYears(2)), false);

    assertEquals(Period.ofMonths(1).equals(Period.ofMonths(1)), true);
    assertEquals(Period.ofMonths(1).equals(Period.ofMonths(2)), false);

    assertEquals(Period.ofDays(1).equals(Period.ofDays(1)), true);
    assertEquals(Period.ofDays(1).equals(Period.ofDays(2)), false);

    assertEquals(Period.of(1, 2, 3).equals(Period.of(0, 2, 3)), false);
    assertEquals(Period.of(1, 2, 3).equals(Period.of(1, 0, 3)), false);
    assertEquals(Period.of(1, 2, 3).equals(Period.of(1, 2, 0)), false);
}
项目:swblocks-decisiontree    文件:RuleGroupChangeBuilderTest.java   
private void assertOriginalSegmentsRemoved(final List<RuleChange> originals) {
    assertRuleChange(originals.get(0), Type.ORIGINAL, new UUID(0, 1), new UUID(0, 2),
            new String[]{"VOICE", GroupDriver.VG_PREFIX + GROUP_ID, "ED", "US", "INDEX"},
            Collections.singletonMap("Rate1", "1.1 "),
            NOW.plus(Period.ofWeeks(2)), NOW.plus(Period.ofWeeks(4)));

    assertRuleChange(originals.get(1), Type.ORIGINAL, new UUID(0, 2), new UUID(0, 2),
            new String[]{"EMAIL", GroupDriver.VG_PREFIX + GROUP_ID, "ED", "US", "INDEX"},
            Collections.singletonMap("Rate1", "1.2"),
            NOW.plus(Period.ofWeeks(4)), NOW.plus(Period.ofWeeks(6)));

    assertRuleChange(originals.get(2), Type.ORIGINAL, new UUID(0, 3), new UUID(0, 2),
            new String[]{"ELECTRONIC", GroupDriver.VG_PREFIX + GROUP_ID, "ED", "US", "INDEX"},
            Collections.singletonMap("Rate1", "1.3"),
            NOW.plus(Period.ofWeeks(6)), NOW.plus(Period.ofWeeks(8)));
}
项目:swblocks-decisiontree    文件:ValueGroupChangeTest.java   
@Test
public void testConstruction() {
    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);

    setBean(change);

    this.injectedValues.put("type", Type.NEW);
    this.injectedValues.put("valueGroup", valueGroup);

    JblTestClassUtils.assertGetterCorrectForConstructorInjection(this.injectedValues, getBean());
}
项目:swblocks-decisiontree    文件:DatedTreeNodeTest.java   
@Test
public void addNodeUpdatesDateRangeEnd() {
    final TreeNode root = createDatedTreeNode("Root", Instant.MIN, Instant.MAX);

    final Instant start = NOW.minus(Period.ofWeeks(5));
    final Instant end = NOW.plus(Period.ofWeeks(5));

    final TreeNode node = createDatedTreeNode("Test1", start, end);
    root.addNode(node);

    final TreeNode other = createDatedTreeNode("Test1", start, Instant.MAX);
    root.addNode(other);
    assertEquals(node, root.getExactNode(node).get());

    final Range<Instant> range = new Range<>(start, Instant.MAX);
    assertEquals(range, node.getDateRange());
}
项目:swblocks-decisiontree    文件:TimeSliceCacheConcurrencyTest.java   
@Test
@Concurrent(count = 20)
@Repeating(repetition = 200)
public void cacheAccess() {
    final Instant now = Instant.now();
    final int start = (int) (Math.random() * 100);
    final int end = start + (int) (Math.random() * 100);

    final Range<Instant> dateRange = new Range<>(now.plus(Period.ofWeeks(start)), now.plus(Period.ofWeeks(end)));
    final TreeNode node = NodeSupplier.createTreeNode(
            new StringDriver(UUID.randomUUID().toString()), NodeSupplier.ROOT_NODE_LEVEL).get();

    final Optional<TreeNode> treeNode = Optional.of(node);
    this.cache.put(dateRange, treeNode);

    for (final Range<Instant> dr : this.cache.keys()) {
        this.cache.get(Optional.of(dr));
    }

    this.cache.get(Optional.of(dateRange));
}
项目:openjdk-jdk10    文件:TCKDateTimeParseResolver.java   
@Test(dataProvider="resolveSecondOfDay")
public void test_resolveSecondOfDay(ResolverStyle style, long value, Integer expectedSecond, int expectedDays) {
    String str = Long.toString(value);
    DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(SECOND_OF_DAY).toFormatter();

    if (expectedSecond != null) {
        TemporalAccessor accessor = f.withResolverStyle(style).parse(str);
        assertEquals(accessor.query(TemporalQueries.localDate()), null);
        assertEquals(accessor.query(TemporalQueries.localTime()), LocalTime.ofSecondOfDay(expectedSecond));
        assertEquals(accessor.query(DateTimeFormatter.parsedExcessDays()), Period.ofDays(expectedDays));
    } else {
        try {
            f.withResolverStyle(style).parse(str);
            fail();
        } catch (DateTimeParseException ex) {
            // expected
        }
    }
}
项目:swblocks-decisiontree    文件:RuleChangeBuilderTest.java   
@Test
public void createsChangeUsingDefaultPeriod() {
    addChange(null, NOW.plus(Period.ofWeeks(1)), true, true);

    final List<RuleChange> ruleChanges = this.builder.build();
    assertThat(ruleChanges, hasSize(4));

    final List<RuleChange> originals = getChangesByType(ruleChanges, Type.ORIGINAL);
    assertThat(originals, hasSize(3));

    assertOriginalSegmentsRemoved(originals);

    final List<RuleChange> newChanges = getChangesByType(ruleChanges, Type.NEW);
    assertThat(newChanges, hasSize(1));

    assertRuleChange(newChanges.get(0), Type.NEW, null, new UUID(0, 2),
            new String[]{"VOICE", "CME", "ED", "UK", "INDEX"}, Collections.singletonMap("Rate", "2.0"),
            null, DecisionTreeRule.MAX);
}
项目:jdk8u-jdk    文件:TCKDateTimeParseResolver.java   
@Test(dataProvider="resolveFourToTime")
public void test_resolveThreeToTime(ResolverStyle style,
                                   long hour, long min, long sec, long nano, LocalTime expectedTime, Period excessPeriod) {
    DateTimeFormatter f = new DateTimeFormatterBuilder()
            .parseDefaulting(HOUR_OF_DAY, hour)
            .parseDefaulting(MINUTE_OF_HOUR, min)
            .parseDefaulting(SECOND_OF_MINUTE, sec).toFormatter();

    ResolverStyle[] styles = (style != null ? new ResolverStyle[] {style} : ResolverStyle.values());
    for (ResolverStyle s : styles) {
        if (expectedTime != null) {
            TemporalAccessor accessor = f.withResolverStyle(s).parse("");
            assertEquals(accessor.query(TemporalQueries.localDate()), null, "ResolverStyle: " + s);
            assertEquals(accessor.query(TemporalQueries.localTime()), expectedTime.minusNanos(nano), "ResolverStyle: " + s);
            assertEquals(accessor.query(DateTimeFormatter.parsedExcessDays()), excessPeriod, "ResolverStyle: " + s);
        } else {
            try {
                f.withResolverStyle(style).parse("");
                fail();
            } catch (DateTimeParseException ex) {
                // expected
            }
        }
    }
}
项目:swblocks-decisiontree    文件:RuleChangeBuilderTest.java   
@Test
public void changeAddedToSecondSegmentAtStartAndFinishesWithinSecondSegmentUsesExistingOutputs() {
    addChange(NOW.plus(Period.ofWeeks(4)), NOW.plus(Period.ofWeeks(5)), true, false);
    final List<RuleChange> ruleChanges = this.builder.build();
    assertThat(ruleChanges, hasSize(3));

    final List<RuleChange> originals = getChangesByType(ruleChanges, Type.ORIGINAL);
    assertThat(originals, hasSize(1));

    assertRuleChange(originals.get(0), Type.ORIGINAL, new UUID(0, 2), new UUID(0, 2),
            new String[]{"EMAIL", "CME", "ED", "US", "INDEX"}, Collections.singletonMap("Rate", "1.2"),
            NOW.plus(Period.ofWeeks(4)), NOW.plus(Period.ofWeeks(6)));

    final List<RuleChange> newChanges = getChangesByType(ruleChanges, Type.NEW);
    assertThat(newChanges, hasSize(2));

    assertRuleChange(newChanges.get(0), Type.NEW, null, new UUID(0, 2),
            new String[]{"VOICE", "CME", "ED", "UK", "INDEX"}, Collections.singletonMap("Rate", "1.2"),
            NOW.plus(Period.ofWeeks(4)), NOW.plus(Period.ofWeeks(5)));

    assertRuleChange(newChanges.get(1), Type.NEW, null, new UUID(0, 2),
            new String[]{"EMAIL", "CME", "ED", "US", "INDEX"}, Collections.singletonMap("Rate", "1.2"),
            NOW.plus(Period.ofWeeks(5)), NOW.plus(Period.ofWeeks(6)));
}
项目:swblocks-decisiontree    文件:RuleChangeBuilderTest.java   
@Test
public void changeAddedToSecondSegmentAfterStartAndFinishesAtSecondSegmentEnd() {
    addChange(NOW.plus(Period.ofWeeks(5)), NOW.plus(Period.ofWeeks(6)), true, true);
    final List<RuleChange> ruleChanges = this.builder.build();
    assertThat(ruleChanges, hasSize(3));

    final List<RuleChange> originals = getChangesByType(ruleChanges, Type.ORIGINAL);
    assertThat(originals, hasSize(1));

    assertRuleChange(originals.get(0), Type.ORIGINAL, new UUID(0, 2), new UUID(0, 2),
            new String[]{"EMAIL", "CME", "ED", "US", "INDEX"}, Collections.singletonMap("Rate", "1.2"),
            NOW.plus(Period.ofWeeks(4)), NOW.plus(Period.ofWeeks(6)));

    final List<RuleChange> newChanges = getChangesByType(ruleChanges, Type.NEW);
    assertThat(newChanges, hasSize(2));

    assertRuleChange(newChanges.get(0), Type.NEW, null, new UUID(0, 2),
            new String[]{"EMAIL", "CME", "ED", "US", "INDEX"}, Collections.singletonMap("Rate", "1.2"),
            NOW.plus(Period.ofWeeks(4)), NOW.plus(Period.ofWeeks(5)));

    assertRuleChange(newChanges.get(1), Type.NEW, null, new UUID(0, 2),
            new String[]{"VOICE", "CME", "ED", "UK", "INDEX"}, Collections.singletonMap("Rate", "2.0"),
            NOW.plus(Period.ofWeeks(5)), NOW.plus(Period.ofWeeks(6)));
}
项目:swblocks-decisiontree    文件:DatedEvaluatorTest.java   
@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);
}
项目:mot-public-api    文件:MotrReadServiceTest.java   
@Test
public void getLatestMotTestByRegistration_ValidRegistration_ReturnsVehicle_WithoutManufactureDate() {

    final String registration = "AA00AAA";
    final LocalDateTime expiryDateTime = LocalDateTime.now().plus(Period.ofMonths(6));
    final Date expiryDate = Date.from(expiryDateTime.atZone(ZoneId.systemDefault()).toInstant());
    final long motTestNumber = 5672823;
    final String make = "MADEBY";
    final String model = "ETERNIA";
    final String primaryColour = "BLUE";
    final String secondaryColour = "WHITE";

    final Vehicle backendVehicle = new Vehicle();
    backendVehicle.setRegistration(registration);
    backendVehicle.setMake(make);
    backendVehicle.setModel(model);
    backendVehicle.setPrimaryColour(primaryColour);
    backendVehicle.setSecondaryColour(secondaryColour);

    final MotTest backendTest = new MotTest();
    backendTest.setExpiryDate(expiryDate);
    backendTest.setNumber(motTestNumber);

    when(vehicleReadServiceMock.findByRegistration(registration)).thenReturn(Arrays.asList(backendVehicle));
    when(motTestReadServiceMock.getLatestMotTestPassByVehicle(backendVehicle)).thenReturn(backendTest);

    MotrResponse motrResponse = motrReadService.getLatestMotTestByRegistration(registration);

    assertNotNull("Returned vehicle is null", motrResponse);
    assertEquals("Registration is incorrect", registration, motrResponse.getRegistration());
    assertEquals("Make is incorrect", make, motrResponse.getMake());
    assertEquals("Model is incorrect", model, motrResponse.getModel());
    assertNull("Manufacturing year was made up", motrResponse.getManufactureYear());
    assertEquals("Test expiry date is incorrect", expiryDateTime.format(DateTimeFormatter.ISO_DATE),
            motrResponse.getMotTestExpiryDate());
    assertEquals("Test number is incorrect", Long.toString(motTestNumber), motrResponse.getMotTestNumber());
    assertEquals("Primary colour is incorrect", primaryColour, motrResponse.getPrimaryColour());
    assertEquals("Secondary colour is incorrect", secondaryColour, motrResponse.getSecondaryColour());

}
项目:bson-codecs-jsr310    文件:PeriodCodec.java   
@Override
public Period decode(
        BsonReader reader,
        DecoderContext decoderContext) {

    return parse(reader.readString());
}
项目:swblocks-decisiontree    文件:RuleGroupChangeBuilderTest.java   
private void createRuleMapWithSingleRuleAndValueGroup(final Set<ValueGroup> groups) {
    final Builder<RuleSetBuilder, DecisionTreeRuleSet> ruleSetBuilder = RuleSetBuilder.creator("commissions",
            Arrays.asList("EXMETHOD", "EXCHANGE", "PRODUCT", "REGION", "ASSET"));
    ruleSetBuilder.with(RuleSetBuilder::groups, groups);

    ruleSetBuilder.with(RuleSetBuilder::rule, RuleBuilder.creator()
            .with(RuleBuilder::setId, new UUID(0, 1))
            .with(RuleBuilder::setCode, RULE_CODE)
            .with(RuleBuilder::input, Arrays.asList("VOICE", GroupDriver.VG_PREFIX + GROUP_ID, "ED", "US", "INDEX"))
            .with(RuleBuilder::output, Collections.singletonMap("Rate1", "1.1 "))
            .with(RuleBuilder::start, NOW.plus(Period.ofWeeks(2)))
            .with(RuleBuilder::end, NOW.plus(Period.ofWeeks(4))));

    ruleSetBuilder.with(RuleSetBuilder::rule, RuleBuilder.creator()
            .with(RuleBuilder::setId, new UUID(0, 2))
            .with(RuleBuilder::setCode, RULE_CODE)
            .with(RuleBuilder::input, Arrays.asList("EMAIL", GroupDriver.VG_PREFIX + GROUP_ID, "ED", "US", "INDEX"))
            .with(RuleBuilder::output, Collections.singletonMap("Rate1", "1.2"))
            .with(RuleBuilder::start, NOW.plus(Period.ofWeeks(4)))
            .with(RuleBuilder::end, NOW.plus(Period.ofWeeks(6))));

    ruleSetBuilder.with(RuleSetBuilder::rule, RuleBuilder.creator()
            .with(RuleBuilder::setId, new UUID(0, 3))
            .with(RuleBuilder::setCode, RULE_CODE)
            .with(RuleBuilder::input,
                    Arrays.asList("ELECTRONIC", GroupDriver.VG_PREFIX + GROUP_ID, "ED", "US", "INDEX"))
            .with(RuleBuilder::output, Collections.singletonMap("Rate1", "1.3"))
            .with(RuleBuilder::start, NOW.plus(Period.ofWeeks(6)))
            .with(RuleBuilder::end, NOW.plus(Period.ofWeeks(8))));

    ruleSetBuilder.with(RuleSetBuilder::rule, RuleBuilder.creator()
            .with(RuleBuilder::setId, new UUID(0, 4))
            .with(RuleBuilder::setCode, new UUID(2, 2))
            .with(RuleBuilder::input, Arrays.asList("EMAIL", "CME", "ED", "US", "INDEX"))
            .with(RuleBuilder::output, Collections.singletonMap("Rate1", "1.3"))
            .with(RuleBuilder::start, NOW.plus(Period.ofWeeks(2)))
            .with(RuleBuilder::end, NOW.plus(Period.ofWeeks(8))));

    this.ruleSet = ruleSetBuilder.build();
}
项目:GitHub    文件:PeriodTest.java   
public void test_for_issue() throws Exception {
    VO vo = new VO();
    vo.setDate(Period.of(3, 2, 11));

    String text = JSON.toJSONString(vo);
    System.out.println(text);

    VO vo1 = JSON.parseObject(text, VO.class);

    Assert.assertEquals(vo.getDate(), vo1.getDate());
}
项目:swblocks-decisiontree    文件:ValueGroupRangeChangeBuilderTest.java   
@Test(expected = IllegalStateException.class)
public void triesToAmendStartAndEndDateOfValueGroupDatesNotInChronologicalOrder() {
    builder.with(ValueGroupChangeBuilder::changeRange, new DateRange(NOW.plus(Period.ofWeeks(4)),
            NOW.plus(Period.ofWeeks(2))));

    builder.build();
}
项目:openjdk-jdk10    文件:TCKPeriod.java   
@Test(dataProvider="between")
public void factory_between_LocalDate(int y1, int m1, int d1, int y2, int m2, int d2, int ye, int me, int de) {
    LocalDate start = LocalDate.of(y1, m1, d1);
    LocalDate end = LocalDate.of(y2, m2, d2);
    Period test = Period.between(start, end);
    assertPeriod(test, ye, me, de);
    //assertEquals(start.plus(test), end);
}
项目:openjdk-jdk10    文件:TCKChronoPeriod.java   
@Test(dataProvider="calendars", expectedExceptions=DateTimeException.class)
public void test_plus_wrongChrono(Chronology chrono) {
    ChronoPeriod period = chrono.period(1, 2, 3);
    ChronoPeriod isoPeriod = Period.of(2, 3, 4);
    ChronoPeriod thaiPeriod = ThaiBuddhistChronology.INSTANCE.period(2, 3, 4);
    // one of these two will fail
    period.plus(isoPeriod);
    period.plus(thaiPeriod);
}
项目:swblocks-decisiontree    文件:ChangeTest.java   
@Test
public void testConstruction() {
    final Set<RuleChange> ruleChanges = new HashSet<>(1);

    final Instant start = NOW.minus(Period.ofWeeks(-1));
    final Instant end = start.plus(Period.ofWeeks(5));
    final DateRange range = new DateRange(start, end);
    final InputDriver[] drivers = getInputDriverArray("Test1", "Test2", "Test3");
    final Map<String, String> outputs = Collections.singletonMap("outputDriver", "result");
    final DecisionTreeRule rule =
            new DecisionTreeRule(BASE_ID, new UUID(0, 2), drivers, outputs, start, end);
    final RuleChange ruleChange = new RuleChange(Type.ORIGINAL, rule);

    ruleChanges.add(ruleChange);

    final Set<ValueGroupChange> valueGroupChanges = new HashSet<>();

    final List<String> valueGroupDrivers = Arrays.asList("Test1", "Test2", "Test3");
    final ValueGroup valueGroup = new ValueGroup(BASE_ID, "TestValueGroup", valueGroupDrivers, range);
    final ValueGroupChange valueGroupChange = new ValueGroupChange(Type.ORIGINAL, valueGroup);

    valueGroupChanges.add(valueGroupChange);

    final UUID id = new UUID(0, 2);
    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(id, "TEST-RULESET", NOW, CHANGE_RANGE, audit, ruleChanges, valueGroupChanges);
    setBean(change);

    this.injectedValues.put("id", id);
    this.injectedValues.put("ruleSetName", "TEST-RULESET");
    this.injectedValues.put("ruleChanges", ruleChanges);
    this.injectedValues.put("valueGroupChanges", valueGroupChanges);
    this.injectedValues.put("activationTime", NOW);
    this.injectedValues.put("changeRange", CHANGE_RANGE);

    JblTestClassUtils.assertGetterCorrectForConstructorInjection(this.injectedValues, getBean());
}
项目:daelic    文件:GroupByV1Context.java   
GroupByV1Context(Integer timeout, Integer priority, String queryId, Boolean useCache, Boolean populateCache,
                 Boolean bySegment, Boolean finalize, Period chunkPeriod, Boolean groupByIsSingleThreaded,
                 Integer maxIntermediateRows, Integer maxResults, Boolean useOffHeap) {

    super(timeout, priority, queryId, useCache, populateCache, bySegment, finalize, chunkPeriod);

    this.groupByIsSingleThreaded = groupByIsSingleThreaded;
    this.maxIntermediateRows = maxIntermediateRows;
    this.maxResults = maxResults;
    this.useOffHeap = useOffHeap;
}
项目:sentry    文件:TimeMappingUtil.java   
public String periodToString(Period in) {
    if (in == null) {
        return "";
    } else {
        return in.toString();
    }
}
项目:openjdk-jdk10    文件:TCKLocalDate.java   
@Test(dataProvider="until")
public void test_periodUntil_LocalDate(int y1, int m1, int d1, int y2, int m2, int d2, int ye, int me, int de) {
    LocalDate start = LocalDate.of(y1, m1, d1);
    LocalDate end = LocalDate.of(y2, m2, d2);
    Period test = start.until(end);
    assertEquals(test.getYears(), ye);
    assertEquals(test.getMonths(), me);
    assertEquals(test.getDays(), de);
}
项目:openjdk-jdk10    文件:TCKPeriod.java   
@Test
public void factory_ofWeeks_int() {
    assertPeriod(Period.ofWeeks(0), 0, 0, 0);
    assertPeriod(Period.ofWeeks(1), 0, 0, 7);
    assertPeriod(Period.ofWeeks(234), 0, 0, 234 * 7);
    assertPeriod(Period.ofWeeks(-100), 0, 0, -100 * 7);
    assertPeriod(Period.ofWeeks(Integer.MAX_VALUE / 7), 0, 0, (Integer.MAX_VALUE / 7) * 7);
    assertPeriod(Period.ofWeeks(Integer.MIN_VALUE / 7), 0, 0, (Integer.MIN_VALUE / 7) * 7);
}
项目:openjdk-jdk10    文件:TCKPeriod.java   
@Test
public void test_plusMonths() {
    assertPeriod(Period.of(1, 2, 3).plusMonths(0), 1, 2, 3);
    assertPeriod(Period.of(1, 2, 3).plusMonths(10), 1, 12, 3);
    assertPeriod(Period.of(1, 2, 3).plusMonths(-10), 1, -8, 3);
    assertPeriod(Period.of(1, 2, 3).plusMonths(-2), 1, 0, 3);

    assertPeriod(Period.of(1, 2, 3).plus(Period.ofMonths(0)), 1, 2, 3);
    assertPeriod(Period.of(1, 2, 3).plus(Period.ofMonths(10)), 1, 12, 3);
    assertPeriod(Period.of(1, 2, 3).plus(Period.ofMonths(-10)), 1, -8, 3);
    assertPeriod(Period.of(1, 2, 3).plus(Period.ofMonths(-2)), 1, 0, 3);
}
项目:openjdk-jdk10    文件:TCKPeriod.java   
@Test
public void factory_of_ints() {
    assertPeriod(Period.of(1, 2, 3), 1, 2, 3);
    assertPeriod(Period.of(0, 2, 3), 0, 2, 3);
    assertPeriod(Period.of(1, 0, 0), 1, 0, 0);
    assertPeriod(Period.of(0, 0, 0), 0, 0, 0);
    assertPeriod(Period.of(-1, -2, -3), -1, -2, -3);
}
项目:openjdk-jdk10    文件:TCKPeriod.java   
@DataProvider(name="toStringAndParse")
Object[][] data_toString() {
    return new Object[][] {
            {Period.ZERO, "P0D"},
            {Period.ofDays(0), "P0D"},
            {Period.ofYears(1), "P1Y"},
            {Period.ofMonths(1), "P1M"},
            {Period.ofDays(1), "P1D"},
            {Period.of(1, 2, 0), "P1Y2M"},
            {Period.of(0, 2, 3), "P2M3D"},
            {Period.of(1, 2, 3), "P1Y2M3D"},
    };
}
项目:swblocks-decisiontree    文件:ChangeTest.java   
@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));
}
项目:OpenJSharp    文件:Parsed.java   
private void updateCheckConflict(LocalTime timeToSet, Period periodToSet) {
    if (time != null) {
        if (time.equals(timeToSet) == false) {
            throw new DateTimeException("Conflict found: Fields resolved to different times: " + time + " " + timeToSet);
        }
        if (excessDays.isZero() == false && periodToSet.isZero() == false && excessDays.equals(periodToSet) == false) {
            throw new DateTimeException("Conflict found: Fields resolved to different excess periods: " + excessDays + " " + periodToSet);
        } else {
            excessDays = periodToSet;
        }
    } else {
        time = timeToSet;
        excessDays = periodToSet;
    }
}
项目:jdk8u-jdk    文件:TCKChronoPeriod.java   
@Test(dataProvider="calendars", expectedExceptions=DateTimeException.class)
public void test_minus_wrongChrono(Chronology chrono) {
    ChronoPeriod period = chrono.period(1, 2, 3);
    ChronoPeriod isoPeriod = Period.of(2, 3, 4);
    ChronoPeriod thaiPeriod = ThaiBuddhistChronology.INSTANCE.period(2, 3, 4);
    // one of these two will fail
    period.minus(isoPeriod);
    period.minus(thaiPeriod);
}
项目:swblocks-decisiontree    文件:ChangeBuilderTest.java   
static DecisionTreeRuleSet getRuleSet(final Instant now) {
    final Builder<RuleSetBuilder, DecisionTreeRuleSet> ruleSetBuilder = RuleSetBuilder.creator("commissions",
            Arrays.asList("VOICE", "CME", "ED", "US", "Rate"));
    ruleSetBuilder.with(RuleSetBuilder::rule, RuleBuilder.creator()
            .with(RuleBuilder::setId, new UUID(0, 1))
            .with(RuleBuilder::setCode, new UUID(0, 2))
            .with(RuleBuilder::input, Arrays.asList("VOICE", "CME", "ED", "US", "INDEX"))
            .with(RuleBuilder::output, Collections.singletonMap("Rate", "1.1"))
            .with(RuleBuilder::start, now.plus(Period.ofWeeks(2)))
            .with(RuleBuilder::end, now.plus(Period.ofWeeks(4)).minusMillis(1L)));

    ruleSetBuilder.with(RuleSetBuilder::rule, RuleBuilder.creator()
            .with(RuleBuilder::setId, new UUID(0, 2))
            .with(RuleBuilder::setCode, new UUID(0, 2))
            .with(RuleBuilder::input, Arrays.asList("EMAIL", "CME", "ED", "US", "INDEX"))
            .with(RuleBuilder::output, Collections.singletonMap("Rate", "1.2"))
            .with(RuleBuilder::start, now.plus(Period.ofWeeks(4)))
            .with(RuleBuilder::end, now.plus(Period.ofWeeks(6)).minusMillis(1L)));

    ruleSetBuilder.with(RuleSetBuilder::rule, RuleBuilder.creator()
            .with(RuleBuilder::setId, new UUID(0, 3))
            .with(RuleBuilder::setCode, new UUID(0, 2))
            .with(RuleBuilder::input, Arrays.asList("ELECTRONIC", "CME", "ED", "US", "INDEX"))
            .with(RuleBuilder::output, Collections.singletonMap("Rate", "1.3"))
            .with(RuleBuilder::start, now.plus(Period.ofWeeks(6)))
            .with(RuleBuilder::end, now.plus(Period.ofWeeks(8))));

    return ruleSetBuilder.build();
}
项目:openjdk-jdk10    文件:TCKYear.java   
@DataProvider(name="plusInvalidUnit")
Object[][] data_plusInvalidUnit() {
    return new Object[][] {
            {Period.of(0, 1, 0)},
            {Period.of(0, 0, 1)},
            {Period.of(0, 1, 1)},
            {Period.of(1, 1, 1)},
            {Duration.ofDays(1)},
            {Duration.ofHours(1)},
            {Duration.ofMinutes(1)},
            {Duration.ofSeconds(1)},
    };
}