|
@@ -3,7 +3,8 @@ |
3 |
3 |
|
import org.litesoft.core.typeutils.*; |
4 |
4 |
|
import org.litesoft.core.typeutils.gregorian.*; |
5 |
5 |
|
|
6 |
|
- |
public abstract class AbstractCalendarYMD<T extends AbstractCalendarYMD> extends AbstractCalendarYM<T> implements CalendarAccessorYMD |
|
6 |
+ |
public abstract class AbstractCalendarYMD<T extends AbstractCalendarYMD, M extends AbstractCalendarYMD.Mutable> extends AbstractCalendarYM<T, M> |
|
7 |
+ |
implements CalendarAccessorYMD |
7 |
8 |
|
{ |
8 |
9 |
|
private static final long serialVersionUID = 1L; |
9 |
10 |
|
|
|
@@ -12,7 +13,7 @@ |
12 |
13 |
|
protected AbstractCalendarYMD( int pYear, int pMonth, int pDay ) |
13 |
14 |
|
{ |
14 |
15 |
|
super( pYear, pMonth ); |
15 |
|
- |
mDay = validate( getYear(), getMonth(), pDay ); |
|
16 |
+ |
mDay = validateDay( getYear(), getMonth(), pDay ); |
16 |
17 |
|
} |
17 |
18 |
|
|
18 |
19 |
|
@Override |
|
@@ -26,7 +27,7 @@ |
26 |
27 |
|
*/ |
27 |
28 |
|
public final T day( int pDay ) |
28 |
29 |
|
{ |
29 |
|
- |
validate( getYear(), getMonth(), pDay ); |
|
30 |
+ |
validateDay( getYear(), getMonth(), pDay ); |
30 |
31 |
|
return (mDay == pDay) ? us() : LLsetDay( pDay ); |
31 |
32 |
|
} |
32 |
33 |
|
|
|
@@ -46,20 +47,32 @@ |
46 |
47 |
|
return (pDays == 0) ? us() : LLsetDay( mDay - pDays ); |
47 |
48 |
|
} |
48 |
49 |
|
|
49 |
|
- |
@Override |
50 |
|
- |
public String toSQLvalue() |
|
50 |
+ |
// vvvvvvvvvvvvvvvvvv Support methods vvvvvvvvvvvvvvvvv |
|
51 |
+ |
|
|
52 |
+ |
protected static final int parseDay(String pStringForm, String... pParts) |
51 |
53 |
|
{ |
52 |
|
- |
return super.toSQLvalue() + "-" + formatDay2(); |
|
54 |
+ |
return parseInt( pParts[2], "Day", pStringForm ); |
53 |
55 |
|
} |
54 |
56 |
|
|
55 |
|
- |
// vvvvvvvvvvvvvvvvvv Support methods vvvvvvvvvvvvvvvvv |
|
57 |
+ |
protected static final StringBuilder formatSQLvalueYMD( CalendarAccessorYMD pAccessor, StringBuilder pSB ) |
|
58 |
+ |
{ |
|
59 |
+ |
formatSQLvalueYM( pAccessor, pSB ).append( '-' ); |
|
60 |
+ |
return formatDay( pAccessor, pSB ); |
|
61 |
+ |
} |
56 |
62 |
|
|
57 |
|
- |
protected final String formatDay2() |
|
63 |
+ |
protected static final StringBuilder formatSortableDisplayFormYMD( CalendarAccessorYMD pAccessor, StringBuilder pSB ) |
58 |
64 |
|
{ |
59 |
|
- |
return Integers.zeroPadIt( 2, mDay ); |
|
65 |
+ |
formatSortableDisplayFormYM( pAccessor, pSB ).append( '/' ); |
|
66 |
+ |
return formatMonth( pAccessor, pSB ); |
60 |
67 |
|
} |
61 |
68 |
|
|
62 |
|
- |
protected static final int validate( int pYear, int pMonth, int pDay ) |
|
69 |
+ |
protected static final StringBuilder formatDay( CalendarAccessorYMD pAccessor, StringBuilder pSB ) |
|
70 |
+ |
{ |
|
71 |
+ |
dd_Chunk.appendTo( pSB, pAccessor ); |
|
72 |
+ |
return pSB; |
|
73 |
+ |
} |
|
74 |
+ |
|
|
75 |
+ |
protected static final int validateDay( int pYear, int pMonth, int pDay ) |
63 |
76 |
|
throws IllegalArgumentException |
64 |
77 |
|
{ |
65 |
78 |
|
if ( (pDay < 1) || (Month.daysIn( pYear, pMonth ) < pDay) ) |
|
@@ -95,9 +108,16 @@ |
95 |
108 |
|
/** |
96 |
109 |
|
* @param pNewDay != current |
97 |
110 |
|
*/ |
98 |
|
- |
abstract protected T LLsetDay( int pNewDay ); |
|
111 |
+ |
protected final T LLsetDay( int pNewDay ) |
|
112 |
+ |
{ |
|
113 |
+ |
M zMutable = createMutable( getYear(), getMonth(), pNewDay ); |
|
114 |
+ |
zMutable.normalize(); |
|
115 |
+ |
return createTypeFrom( zMutable ); |
|
116 |
+ |
} |
|
117 |
+ |
|
|
118 |
+ |
protected abstract M createMutable( int pYear, int pMonth, int pNewDay ); |
99 |
119 |
|
|
100 |
|
- |
protected static class Mutable extends AbstractCalendarYM.Mutable |
|
120 |
+ |
protected static class Mutable extends AbstractCalendarYM.Mutable implements CalendarAccessorYMD |
101 |
121 |
|
{ |
102 |
122 |
|
private int mDay; |
103 |
123 |
|
private boolean mDayConstrained; |