當前位置: 首頁>>代碼示例>>Java>>正文


Java MonthDay類代碼示例

本文整理匯總了Java中java.time.MonthDay的典型用法代碼示例。如果您正苦於以下問題:Java MonthDay類的具體用法?Java MonthDay怎麽用?Java MonthDay使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MonthDay類屬於java.time包,在下文中一共展示了MonthDay類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: decode

import java.time.MonthDay; //導入依賴的package包/類
@Override
public MonthDay decode(
        BsonReader reader,
        DecoderContext decoderContext) {

    BigDecimal value = reader
            .readDecimal128()
            .bigDecimalValue();
    int month = value.intValue();
    return of(
            month,
            value.subtract(new BigDecimal(month))
                 .scaleByPowerOfTen(2)
                 .intValue()
    );
}
 
開發者ID:cbartosiak,項目名稱:bson-codecs-jsr310,代碼行數:17,代碼來源:MonthDayCodec.java

示例2: getEvents

import java.time.MonthDay; //導入依賴的package包/類
/**
 * Returns events that occurred on the day of month specified.
 *
 * @param monthDay an object that wraps the month of year and the day of
 *                 month
 * @return the list of objects that represent events that occurred on the
 *         day of month specified
 * @throws IOException if any I/O error occurs
 */
public List<Event> getEvents(MonthDay monthDay) throws IOException {
	String	url = getWikipediaURL(monthDay);
	logger.info("Retrieving web page from {}", url);
	Document	doc = Jsoup.connect(url).timeout(timeout).get();
	List<Event>	events = new ArrayList<Event>();
	Elements	elements = doc.select("h2:has(#Events) + ul > li");
	logger.info("Found {} event(s)", elements.size());
	for (Element element: elements) {
		logger.debug("Text to be parsed: {}", element.text());
		String[]	parts = element.text().split(" \u2013 ", 2);
		if (parts.length != 2) {
			logger.warn("Skipping a malformed event");
			continue;
		}
		parts[0] = parts[0].trim();
		parts[1] = parts[1].trim();
		int	year = Year.parse(parts[0], formatter).getValue();
		Event	event = new Event(monthDay.atYear(year), parts[1]);
		logger.debug("Event created: {}", event);
		events.add(event);
	}
	return events;
}
 
開發者ID:Chrams,項目名稱:wikipedia-event-query,代碼行數:33,代碼來源:EventExtractor.java

示例3: test2

import java.time.MonthDay; //導入依賴的package包/類
@Test
public void test2() throws NoSuchMethodException, SecurityException, SQLException {
	PropertyMapperManager mapper = new PropertyMapperManager();
	assertThat(mapper.getValue(JavaType.of(Year.class), newResultSet("getInt", 2000), 1), is(Year.of(2000)));
	assertThat(mapper.getValue(JavaType.of(YearMonth.class), newResultSet("getInt", 200004), 1), is(YearMonth.of(2000, 4)));
	assertThat(mapper.getValue(JavaType.of(MonthDay.class), newResultSet("getInt", 401), 1), is(MonthDay.of(4, 1)));
	assertThat(mapper.getValue(JavaType.of(Month.class), newResultSet("getInt", 4), 1), is(Month.APRIL));
	assertThat(mapper.getValue(JavaType.of(DayOfWeek.class), newResultSet("getInt", 4), 1), is(DayOfWeek.THURSDAY));

	assertThat(mapper.getValue(JavaType.of(Year.class), newResultSet("getInt", 0, "wasNull", true), 1), is(nullValue()));
	assertThat(mapper.getValue(JavaType.of(YearMonth.class), newResultSet("getInt", 0, "wasNull", true), 1), is(nullValue()));
	assertThat(mapper.getValue(JavaType.of(MonthDay.class), newResultSet("getInt", 0, "wasNull", true), 1), is(nullValue()));
	assertThat(mapper.getValue(JavaType.of(Month.class), newResultSet("getInt", 0, "wasNull", true), 1), is(nullValue()));
	assertThat(mapper.getValue(JavaType.of(DayOfWeek.class), newResultSet("getInt", 0, "wasNull", true), 1), is(nullValue()));

}
 
開發者ID:future-architect,項目名稱:uroborosql,代碼行數:17,代碼來源:DateTimeApiPropertyMapperTest.java

示例4: doTest_comparisons_MonthDay

import java.time.MonthDay; //導入依賴的package包/類
void doTest_comparisons_MonthDay(MonthDay... localDates) {
    for (int i = 0; i < localDates.length; i++) {
        MonthDay a = localDates[i];
        for (int j = 0; j < localDates.length; j++) {
            MonthDay b = localDates[j];
            if (i < j) {
                assertTrue(a.compareTo(b) < 0, a + " <=> " + b);
                assertEquals(a.isBefore(b), true, a + " <=> " + b);
                assertEquals(a.isAfter(b), false, a + " <=> " + b);
                assertEquals(a.equals(b), false, a + " <=> " + b);
            } else if (i > j) {
                assertTrue(a.compareTo(b) > 0, a + " <=> " + b);
                assertEquals(a.isBefore(b), false, a + " <=> " + b);
                assertEquals(a.isAfter(b), true, a + " <=> " + b);
                assertEquals(a.equals(b), false, a + " <=> " + b);
            } else {
                assertEquals(a.compareTo(b), 0, a + " <=> " + b);
                assertEquals(a.isBefore(b), false, a + " <=> " + b);
                assertEquals(a.isAfter(b), false, a + " <=> " + b);
                assertEquals(a.equals(b), true, a + " <=> " + b);
            }
        }
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:25,代碼來源:TCKMonthDay.java

示例5: encode

import java.time.MonthDay; //導入依賴的package包/類
@Override
public void encode(
        BsonWriter writer,
        MonthDay value,
        EncoderContext encoderContext) {

    writer.writeDecimal128(parse(format(
            "%d.%02d",
            value.getMonthValue(),
            value.getDayOfMonth()
    )));
}
 
開發者ID:cbartosiak,項目名稱:bson-codecs-jsr310,代碼行數:13,代碼來源:MonthDayCodec.java

示例6: data_isValidMonthDay

import java.time.MonthDay; //導入依賴的package包/類
@DataProvider(name="isValidMonthDay")
Object[][] data_isValidMonthDay() {
    return new Object[][] {
            {Year.of(2007), MonthDay.of(6, 30), true},
            {Year.of(2008), MonthDay.of(2, 28), true},
            {Year.of(2008), MonthDay.of(2, 29), true},
            {Year.of(2009), MonthDay.of(2, 28), true},
            {Year.of(2009), MonthDay.of(2, 29), false},
            {Year.of(2009), null, false},
    };
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:12,代碼來源:TCKYear.java

示例7: data_atMonthDay

import java.time.MonthDay; //導入依賴的package包/類
@DataProvider(name="atMonthDay")
Object[][] data_atMonthDay() {
    return new Object[][] {
            {Year.of(2008), MonthDay.of(6, 30), LocalDate.of(2008, 6, 30)},
            {Year.of(2008), MonthDay.of(2, 29), LocalDate.of(2008, 2, 29)},
            {Year.of(2009), MonthDay.of(2, 29), LocalDate.of(2009, 2, 28)},
    };
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:9,代碼來源:TCKYear.java

示例8: test_serialization_format

import java.time.MonthDay; //導入依賴的package包/類
@Test
public void test_serialization_format() throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try (DataOutputStream dos = new DataOutputStream(baos) ) {
        dos.writeByte(13);       // java.time.temporal.Ser.MONTH_DAY_TYPE
        dos.writeByte(9);
        dos.writeByte(16);
    }
    byte[] bytes = baos.toByteArray();
    assertSerializedBySer(MonthDay.of(9, 16), bytes);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:12,代碼來源:TCKMonthDaySerialization.java

示例9: test_WBY_isSupportedBy

import java.time.MonthDay; //導入依賴的package包/類
@Test(dataProvider = "fields")
public void test_WBY_isSupportedBy(TemporalField weekField, TemporalField yearField) {
    assertEquals(yearField.isSupportedBy(LocalTime.NOON), false);
    assertEquals(yearField.isSupportedBy(MonthDay.of(2, 1)), false);
    assertEquals(yearField.isSupportedBy(LocalDate.MIN), true);
    assertEquals(yearField.isSupportedBy(OffsetDateTime.MAX), true);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:8,代碼來源:TestIsoWeekFields.java

示例10: now

import java.time.MonthDay; //導入依賴的package包/類
@Test
public void now() {
    MonthDay expected = MonthDay.now(Clock.systemDefaultZone());
    MonthDay test = MonthDay.now();
    for (int i = 0; i < 100; i++) {
        if (expected.equals(test)) {
            return;
        }
        expected = MonthDay.now(Clock.systemDefaultZone());
        test = MonthDay.now();
    }
    assertEquals(test, expected);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:14,代碼來源:TCKMonthDay.java

示例11: now_Clock

import java.time.MonthDay; //導入依賴的package包/類
@Test
public void now_Clock() {
    Instant instant = LocalDateTime.of(2010, 12, 31, 0, 0).toInstant(ZoneOffset.UTC);
    Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
    MonthDay test = MonthDay.now(clock);
    assertEquals(test.getMonth(), Month.DECEMBER);
    assertEquals(test.getDayOfMonth(), 31);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:9,代碼來源:TCKMonthDay.java

示例12: test_WOWBY_isSupportedBy

import java.time.MonthDay; //導入依賴的package包/類
@Test(dataProvider = "fields")
public void test_WOWBY_isSupportedBy(TemporalField weekField, TemporalField yearField) {
    assertEquals(weekField.isSupportedBy(LocalTime.NOON), false);
    assertEquals(weekField.isSupportedBy(MonthDay.of(2, 1)), false);
    assertEquals(weekField.isSupportedBy(LocalDate.MIN), true);
    assertEquals(weekField.isSupportedBy(OffsetDateTime.MAX), true);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:8,代碼來源:TestIsoWeekFields.java

示例13: test_hashCode_unique

import java.time.MonthDay; //導入依賴的package包/類
@Test
public void test_hashCode_unique() {
    int leapYear = 2008;
    Set<Integer> uniques = new HashSet<Integer>(366);
    for (int i = 1; i <= 12; i++) {
        for (int j = 1; j <= 31; j++) {
            if (YearMonth.of(leapYear, i).isValidDay(j)) {
                assertTrue(uniques.add(MonthDay.of(i, j).hashCode()));
            }
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:13,代碼來源:TCKMonthDay.java

示例14: test_atYear_int_invalidYear

import java.time.MonthDay; //導入依賴的package包/類
@Test(expectedExceptions=DateTimeException.class)
public void test_atYear_int_invalidYear() {
    MonthDay test = MonthDay.of(6, 30);
    test.atYear(Integer.MIN_VALUE);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:6,代碼來源:TCKMonthDay.java

示例15: test_comparisons

import java.time.MonthDay; //導入依賴的package包/類
@Test
public void test_comparisons() {
    doTest_comparisons_MonthDay(
        MonthDay.of(1, 1),
        MonthDay.of(1, 31),
        MonthDay.of(2, 1),
        MonthDay.of(2, 29),
        MonthDay.of(3, 1),
        MonthDay.of(12, 31)
    );
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:12,代碼來源:TCKMonthDay.java


注:本文中的java.time.MonthDay類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。