protected void _serializeAsArrayContents(YearMonth value, JsonGenerator g, SerializerProvider provider) throws IOException { g.writeNumber(value.getYear()); g.writeNumber(value.getMonthValue()); }
protected void _serializeAsArrayContents(YearMonth value, JsonGenerator g, SerializerProvider provider) throws IOException { g.writeNumber(value.getYear()); g.writeNumber(value.getMonthValue()); }
@Override public void writeObject(ObjectOutput output, YearMonth value) throws IOException { output.writeInt(value.getYear()); DefaultExternalizer.MONTH.cast(Month.class).writeObject(output, value.getMonth()); }
@Override public Integer convertToDatabaseColumn(YearMonth attribute) { return (attribute.getYear() * 100) + attribute.getMonth().getValue(); }
private void goToDayCell(DateCell dateCell, int offset, ChronoUnit unit, boolean focusDayCell) { YearMonth yearMonth = selectedYearMonth.get().plus(offset, unit); goToDate(dayCellDate(dateCell).plus(offset, unit).withYear(yearMonth.getYear()), focusDayCell); }
@Override protected ByteBuf writeValue(final YearMonth value, final ByteBufAllocator allocator, final GraphBinaryWriter context) throws SerializationException { return allocator.buffer(2).writeInt(value.getYear()).writeByte(value.getMonthValue()); } }
protected LocalDate toLocalDate(YearMonth yearMonth) { return LocalDate.of(yearMonth.getYear(), yearMonth.getMonth(), 1); }
@Override public YearMonth generate(SourceOfRandomness random, GenerationStatus status) { long generated = random.nextLong( min.getYear() * 12L + min.getMonthValue() - 1, max.getYear() * 12L + max.getMonthValue() - 1); return YearMonth.of( (int) (generated / 12), (int) Math.abs(generated % 12) + 1); } }
/** The license that we'd like enforced. */ private LicenseHeaderStep(String licenseHeader, String delimiter, String yearSeparator) { if (delimiter.contains("\n")) { throw new IllegalArgumentException("The delimiter must not contain any newlines."); } // sanitize the input license licenseHeader = LineEnding.toUnix(licenseHeader); if (!licenseHeader.endsWith("\n")) { licenseHeader = licenseHeader + "\n"; } this.licenseHeader = licenseHeader; this.delimiterPattern = Pattern.compile('^' + delimiter, Pattern.UNIX_LINES | Pattern.MULTILINE); this.hasYearToken = licenseHeader.contains("$YEAR"); if (this.hasYearToken) { int yearTokenIndex = licenseHeader.indexOf("$YEAR"); this.licenseHeaderBeforeYearToken = licenseHeader.substring(0, yearTokenIndex); this.licenseHeaderAfterYearToken = licenseHeader.substring(yearTokenIndex + 5, licenseHeader.length()); this.licenseHeaderWithYearTokenReplaced = licenseHeader.replace("$YEAR", String.valueOf(YearMonth.now().getYear())); this.yearMatcherPattern = Pattern.compile("[0-9]{4}(" + Pattern.quote(yearSeparator) + "[0-9]{4})?"); } }
@Override public <O extends OutputShim> void write(final KryoShim<?, O> kryo, final O output, final YearMonth monthDay) { output.writeInt(monthDay.getYear()); output.writeInt(monthDay.getMonthValue()); }
private String currentYear() { return String.valueOf(YearMonth.now().getYear()); }
@Override public ByteBuf writeValue(final YearMonth value, final ByteBufAllocator allocator, final GraphBinaryWriter context) throws SerializationException { return allocator.buffer(2).writeInt(value.getYear()).writeByte(value.getMonthValue()); } }
@Override public void actionPerformed(ActionEvent e) { drawCalendar(displayedYearMonth.getYear(), Month.of(localMonthZeroBasedIndex + 1)); } }));
public static void main(String[] args) { for (int i = 5; i >= 0; i--) { YearMonth date = YearMonth.now().minusMonths(i); String monthName = date.getMonth().getDisplayName(TextStyle.SHORT, Locale.ENGLISH); System.out.println(monthName + "(" + date.getYear() + ")"); } }
@Test public void testWithNonStandardYearSeparator() throws IOException { setFile("build.gradle").toLines( "plugins {", " id 'nebula.kotlin' version '1.0.6'", " id 'com.diffplug.gradle.spotless'", "}", "repositories { mavenCentral() }", "spotless {", " kotlin {", " licenseHeader('" + HEADER_WITH_YEAR + "').yearSeparator(', ')", " ktlint()", " }", "}"); setFile("src/main/kotlin/test.kt").toResource("kotlin/licenseheader/KotlinCodeWithMultiYearHeader.test"); setFile("src/main/kotlin/test2.kt").toResource("kotlin/licenseheader/KotlinCodeWithMultiYearHeader2.test"); gradleRunner().withArguments("spotlessApply").build(); assertFile("src/main/kotlin/test.kt").matches(matcher -> { matcher.startsWith("// License Header 2012, 2014"); }); assertFile("src/main/kotlin/test2.kt").matches(matcher -> { matcher.startsWith(HEADER_WITH_YEAR.replace("$YEAR", String.valueOf(YearMonth.now().getYear()))); }); } }
@Override public YearMonth generate(SourceOfRandomness random, GenerationStatus status) { long generated = random.nextLong( min.getYear() * 12L + min.getMonthValue() - 1, max.getYear() * 12L + max.getMonthValue() - 1); return YearMonth.of( (int) (generated / 12), (int) Math.abs(generated % 12) + 1); } }
@Override public void write(ByteWriter writer, YearMonth yearMonth) { Preconditions.checkArgument(yearMonth != null, "null yearMonth"); Preconditions.checkArgument(writer != null); LongEncoder.write(writer, yearMonth.getYear()); LongEncoder.write(writer, yearMonth.getMonthValue()); }
@Override public LocalDate convert(YearMonth in, Context context) throws Exception { if (in == null) return null; return LocalDate.fromYearMonthDay(in.getYear(), in.getMonthValue(), 1); } });
public Integer getAno() { if (isEmptyOfData()) { return null; } return getValue().getYear(); }
protected void _serializeAsArrayContents(YearMonth value, JsonGenerator g, SerializerProvider provider) throws IOException { g.writeNumber(value.getYear()); g.writeNumber(value.getMonthValue()); }