/** * Resolves singletons. * * @return the singleton instance */ private Object readResolve() { return Months.of(months); }
/** * Returns a new instance with the specified amount of time added. * * <p>This instance is immutable and unaffected by this method call. * * @param amount the amount of time to add, may be negative * @return the new amount plus the specified amount of time, not null * @throws ArithmeticException if the result overflows an {@code int} */ public Months plus(Months amount) { return plus(amount.getAmount()); }
/** * Returns a new instance with the specified amount of time subtracted. * * <p>This instance is immutable and unaffected by this method call. * * @param amount the amount of time to add, may be negative * @return the new amount minus the specified amount of time, not null * @throws ArithmeticException if the result overflows an {@code int} */ public Months minus(Months amount) { return minus(amount.getAmount()); }
/** * Returns a new instance of the subclass with a different number of months. * * @param amount the number of months to set in the new instance, may be negative * @return a new period element, not null */ @Override public Months withAmount(int amount) { return Months.of(amount); }