private static CalendarQuarter readCalendarQuarter(ObjectInput in) throws IOException { int year = in.readInt(); int quarter = in.readInt(); return CalendarQuarter.of(year, Quarter.valueOf(quarter)); }
/** * <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 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>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>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); }