MCPcopy Create free account
hub / github.com/MenoData/Time4J / Rule

Class Rule

base/src/main/java/net/time4j/CalendarUnit.java:627–789  ·  view source on GitHub ↗

Realisiert die Zeitarithmetik für eine kalendarische Zeiteinheit. @param generic type of calendrical context

Source from the content-addressed store, hash-verified

625 * @param <T> generic type of calendrical context
626 */
627 static class Rule<T extends ChronoEntity<T>>
628 implements UnitRule<T> {
629
630 //~ Instanzvariablen ----------------------------------------------
631
632 private final CalendarUnit unit;
633 private final int policy;
634
635 //~ Konstruktoren -------------------------------------------------
636
637 /**
638 * <p>Constructs a new rule for a calendar unit using the policy
639 * {@code OverflowUnit.POLICY_PREVIOUS_VALID_DATE}. </p>
640 *
641 * @param unit calendar unit
642 */
643 Rule(CalendarUnit unit) {
644 this(unit, OverflowUnit.POLICY_PREVIOUS_VALID_DATE);
645
646 }
647
648 /**
649 * <p>Constructs a new rule for a calendar unit using the given
650 * policy. </p>
651 *
652 * @param unit calendar unit as delegate
653 * @param policy strategy for handling day overflow
654 */
655 Rule(
656 CalendarUnit unit,
657 int policy
658 ) {
659 super();
660
661 this.unit = unit;
662 this.policy = policy;
663
664 }
665
666 //~ Methoden ------------------------------------------------------
667
668 @Override
669 public T addTo(
670 T context,
671 long amount
672 ) {
673
674 PlainDate date = context.get(PlainDate.CALENDAR_DATE);
675 date = PlainDate.doAdd(this.unit, date, amount, this.policy);
676 return context.with(PlainDate.CALENDAR_DATE, date);
677
678 }
679
680 @Override
681 public long between(T start, T end) {
682
683 PlainDate d1 = start.get(PlainDate.CALENDAR_DATE);
684 PlainDate d2 = end.get(PlainDate.CALENDAR_DATE);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected