/** * <p>Rolls by given amount of quarters. </p> * * @param quarters count of quarters (maybe negative) * @return result of rolling operation */ /*[deutsch] * <p>Rollt um die angegebene Anzahl von Quartalen vor oder * zurück. </p> * * @param quarters count of quarters (maybe negative) * @return result of rolling operation */ public Quarter roll(int quarters) { return Quarter.valueOf( (this.ordinal() + (quarters % 4 + 4)) % 4 + 1); }
@Override public int compareTo(CalendarQuarter other) { if (this.year < other.year) { return -1; } else if (this.year > other.year) { return 1; } else { return this.quarter.compareTo(other.quarter); } }
/** * <p>Equivalent to the expression * {@code getDisplayName(locale, TextWidth.WIDE, OutputContext.FORMAT)}. * </p> * * @param locale language setting * @return descriptive text (long form, never {@code null}) * @see #getDisplayName(Locale, TextWidth, OutputContext) */ /*[deutsch] * <p>Entspricht dem Ausdruck * {@code getDisplayName(locale, TextWidth.WIDE, OutputContext.FORMAT)}. * </p> * * @param locale language setting * @return descriptive text (long form, never {@code null}) * @see #getDisplayName(Locale, TextWidth, OutputContext) */ public String getDisplayName(Locale locale) { return this.getDisplayName( locale, TextWidth.WIDE, OutputContext.FORMAT); }
/** * <p>Adds given quarter years to this quarter year. </p> * * @param quarters the count of quarter years to be added * @return result of addition */ /*[deutsch] * <p>Addiert die angegebenen Quartale zu diesem Kalenderquartal. </p> * * @param quarters the count of quarter years to be added * @return result of addition */ public CalendarQuarter plus(Quarters quarters) { if (quarters.isEmpty()) { return this; } long value = this.year * 4L + this.quarter.getValue() - 1 + quarters.getAmount(); int y = MathUtils.safeCast(MathUtils.floorDivide(value, 4)); Quarter q = Quarter.valueOf(MathUtils.floorModulo(value, 4) + 1); return CalendarQuarter.of(y, q); }
@Override public boolean test(GregorianDate context) { int month = context.getMonth(); return (this.getValue() == ((month - 1) / 3) + 1); }
private static CalendarQuarter readCalendarQuarter(ObjectInput in) throws IOException { int year = in.readInt(); int quarter = in.readInt(); return CalendarQuarter.of(year, Quarter.valueOf(quarter)); }
case OP_FIRST_DAY_OF_NEXT_QUARTER: Quarter q1 = Month.valueOf(month).getQuarterOfYear(); Quarter q2 = q1.next(); month = Month.atStartOfQuarterYear(q2).getValue(); if (q1 == Quarter.Q4) { case OP_LAST_DAY_OF_PREVIOUS_QUARTER: Quarter p1 = Month.valueOf(month).getQuarterOfYear(); Quarter p2 = p1.previous(); month = Month.atEndOfQuarterYear(p2).getValue(); if (p2 == Quarter.Q4) {
/** * <p>Rolls to the next quarter. </p> * * <p>The result is {@code Q1} if this method is applied on {@code Q4}. </p> * * @return next quarter rolling at last quarter */ /*[deutsch] * <p>Ermittelt das nächste Quartal. </p> * * <p>Auf {@code Q4} angewandt ist das Ergebnis {@code Q1}. </p> * * @return next quarter rolling at last quarter */ public Quarter next() { return this.roll(1); }
@Override public int hashCode() { return this.year ^ this.quarter.hashCode(); }
/** * <p>Gets the corresponding numerical value. </p> * * @return int (Q1 = 1, Q2 = 2, Q3 = 3, Q4 = 4) */ /*[deutsch] * <p>Liefert den korrespondierenden chronologischen Integer-Wert. </p> * * @return int (Q1 = 1, Q2 = 2, Q3 = 3, Q4 = 4) */ public int getValue() { return (this.ordinal() + 1); }
/** * <p>Subtracts given quarter years from this quarter year. </p> * * @param quarters the count of quarter years to be subtracted * @return result of subtraction */ /*[deutsch] * <p>Subtrahiert die angegebenen Quartale von diesem Kalenderquartal. </p> * * @param quarters the count of quarter years to be subtracted * @return result of subtraction */ public CalendarQuarter minus(Quarters quarters) { if (quarters.isEmpty()) { return this; } long value = this.year * 4L + this.quarter.getValue() - 1 - quarters.getAmount(); int y = MathUtils.safeCast(MathUtils.floorDivide(value, 4)); Quarter q = Quarter.valueOf(MathUtils.floorModulo(value, 4) + 1); return CalendarQuarter.of(y, q); }
/** * <p>Outputs this instance as a String in CLDR-format "uuuu-'Q'Q" (like "2016-Q1"). </p> * * @return String */ /*[deutsch] * <p>Gibt diese Instanz als String im CLDR-Format "uuuu-'Q'Q" (wie "2016-Q1") aus. </p> * * @return String */ @Override public String toString() { StringBuilder sb = new StringBuilder(); formatYear(sb, this.year); sb.append("-Q"); sb.append(this.quarter.getValue()); return sb.toString(); }
@Override public V getValue(PlainDate context) { Object ret; switch (this.index) { case EnumElement.MONTH: ret = Month.valueOf(context.month); break; case EnumElement.DAY_OF_WEEK: ret = context.getDayOfWeek(); break; case EnumElement.QUARTER_OF_YEAR: ret = Quarter.valueOf(((context.month - 1) / 3) + 1); break; default: throw new UnsupportedOperationException(this.name); } return this.type.cast(ret); }
/** * <p>Rolls to the previous quarter. </p> * * <p>The result is {@code Q4} if this method is applied on {@code Q1}. </p> * * @return previous quarter rolling at first quarter */ /*[deutsch] * <p>Ermittelt das vorherige Quartal. </p> * * <p>Auf {@code Q1} angewandt ist das Ergebnis {@code Q4}. </p> * * @return previous quarter rolling at first quarter */ public Quarter previous() { return this.roll(-1); }
@Override public PlainDate withValue( PlainDate context, V value, boolean lenient ) { if (value == null) { throw new IllegalArgumentException("Missing element value."); } switch (this.index) { case EnumElement.MONTH: return context.withMonth(Month.class.cast(value).getValue()); case EnumElement.DAY_OF_WEEK: return context.withDayOfWeek(Weekday.class.cast(value)); case EnumElement.QUARTER_OF_YEAR: int q1 = ((context.month - 1) / 3) + 1; int q2 = Quarter.class.cast(value).getValue(); return context.plus((q2 - q1), CalendarUnit.QUARTERS); default: throw new UnsupportedOperationException(this.name); } }
/** * <p>Determines the difference in years between given quarter years. </p> * * @param q1 first quarter year * @param q2 second quarter year * @return year difference */ /*[deutsch] * <p>Bestimmt die Jahresdifferenz zwischen den angegebenen Quartalen. </p> * * @param q1 first quarter year * @param q2 second quarter year * @return year difference */ public static Years<CalendarUnit> between(CalendarQuarter q1, CalendarQuarter q2) { int delta = q2.getYear() - q1.getYear(); if (delta > 0) { if (q2.getQuarter().compareTo(q1.getQuarter()) < 0) { delta--; } } else if (delta < 0) { if (q2.getQuarter().compareTo(q1.getQuarter()) > 0) { delta++; } } return Years.ofGregorian(delta); }
CalendarQuarter cq = (CalendarQuarter) this.obj; out.writeInt(cq.getYear()); out.writeInt(cq.getQuarter().getValue()); break; case MONTH_TYPE: