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

Class IntegerElementRule

base/src/main/java/net/time4j/AnnualDate.java:945–1066  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

943 }
944
945 private static class IntegerElementRule
946 implements IntElementRule<AnnualDate> {
947
948 //~ Instanzvariablen ----------------------------------------------
949
950 private final boolean daywise;
951
952 //~ Konstruktoren -------------------------------------------------
953
954 IntegerElementRule(boolean daywise) {
955 super();
956
957 this.daywise = daywise;
958
959 }
960
961 //~ Methoden ------------------------------------------------------
962
963 @Override
964 public int getInt(AnnualDate context) {
965
966 return (this.daywise ? context.dayOfMonth : context.month);
967
968 }
969
970 @Override
971 public boolean isValid(
972 AnnualDate context,
973 int value
974 ) {
975
976 if (value < 1) {
977 return false;
978 } else if (this.daywise) {
979 return (value <= getMaxDay(context.month));
980 } else {
981 return (value <= 12);
982 }
983
984 }
985
986 @Override
987 public AnnualDate withValue(
988 AnnualDate context,
989 int value,
990 boolean lenient
991 ) {
992
993 if (this.daywise) {
994 return AnnualDate.of(context.month, value);
995 } else {
996 return AnnualDate.of(value, Math.min(context.dayOfMonth, getMaxDay(value)));
997 }
998
999 }
1000
1001 @Override
1002 public Integer getValue(AnnualDate context) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected