Subversion Repository Public Repository

litesoft

Diff Revisions 852 vs 853 for /trunk/Java/core/Anywhere/src/org/litesoft/core/simpletypes/temporal/DateRes.java

Diff revisions: vs.
  @@ -2,6 +2,8 @@
2 2 package org.litesoft.core.simpletypes.temporal;
3 3
4 4 import org.litesoft.core.simpletypes.temporal.nonpublic.*;
5 + import org.litesoft.core.typeutils.*;
6 + import org.litesoft.core.typeutils.gregorian.*;
5 7
6 8 /**
7 9 * A Date resolution from the Year thru the Day.
  @@ -15,9 +17,9 @@
15 17 public static final char INDICATOR_MONTH = 'M';
16 18 public static final char INDICATOR_DAY = 'd';
17 19
18 - public static final int YEARindex = 0;
19 - public static final int MONTHindex = 1;
20 - public static final int DAYindex = 2;
20 + private static final int YEARindex = 0;
21 + private static final int MONTHindex = 1;
22 + private static final int DAYindex = 2;
21 23
22 24 public static DateRes ToYEAR = new DateRes( "ToYEAR", "Year", YEARindex, INDICATOR_YEAR );
23 25 public static DateRes ToMONTH = new DateRes( "ToMONTH", "Month", MONTHindex, INDICATOR_MONTH );
  @@ -33,6 +35,20 @@
33 35 super( pName, pFriendlyName, pIndex, pIndicator );
34 36 }
35 37
38 + public DateFormat getDateFormat()
39 + {
40 + switch ( getIndex() )
41 + {
42 + default:
43 + case DAYindex:
44 + return YearMonthDayFormatAccessor.get();
45 + case MONTHindex:
46 + return YearMonthFormatAccessor.get();
47 + case YEARindex:
48 + return YearFormatAccessor.get();
49 + }
50 + }
51 +
36 52 private static AbstractRes[] OPTIONS = new AbstractRes[]{ToYEAR, ToMONTH, ToDAY,};
37 53
38 54 public static DateRes fromIndex( int pIndex )
  @@ -55,4 +71,49 @@
55 71 {
56 72 return DAYindex <= getIndex();
57 73 }
74 +
75 + public int validateMonth( Object pCaller, int pYear, int pMonth )
76 + throws IllegalArgumentException
77 + {
78 + validateToMonth( pCaller );
79 + if ( (pMonth < 1) || (12 < pMonth) )
80 + {
81 + throw new IllegalArgumentException( "Invalid Month provided (Year: " + pYear + "): " + pMonth );
82 + }
83 + return pMonth;
84 + }
85 +
86 + public int validateDay( Object pCaller, int pYear, int pMonth, int pDay )
87 + throws IllegalArgumentException
88 + {
89 + validateToDay( pCaller );
90 + if ( (pDay < 1) || (Month.daysIn( pYear, validateMonth( pCaller, pYear, pMonth ) ) < pDay) )
91 + {
92 + throw new IllegalArgumentException( "Invalid Day provided (Year: " + pYear + ", Month: " + pMonth + "): " + pDay );
93 + }
94 + return pDay;
95 + }
96 +
97 + public void validateToMonth( Object pCaller )
98 + throws IllegalArgumentException
99 + {
100 + if ( !isValidToMonth() )
101 + {
102 + throw doesNotContain( pCaller, DateRes.ToMONTH );
103 + }
104 + }
105 +
106 + public void validateToDay( Object pCaller )
107 + {
108 + if ( !isValidToDay() )
109 + {
110 + throw doesNotContain( pCaller, DateRes.ToDAY );
111 + }
112 + }
113 +
114 + private IllegalArgumentException doesNotContain( Object pCaller, DateRes pDateRes )
115 + {
116 + return new IllegalArgumentException( Objects.justClassNameOf( pCaller ) + "'s resolution is only to the '" + this.getFriendlyName() +
117 + "', but " + pDateRes.getFriendlyName() + " access or manipulation was attempted" );
118 + }
58 119 }