|
@@ -2,7 +2,8 @@ |
2 |
2 |
|
|
3 |
3 |
|
import org.litesoft.core.typeutils.*; |
4 |
4 |
|
|
5 |
|
- |
public abstract class AbstractCalendarYM<T extends AbstractCalendarYM> extends AbstractCalendarY<T> implements CalendarAccessorYM |
|
5 |
+ |
public abstract class AbstractCalendarYM<T extends AbstractCalendarYM, M extends AbstractCalendarYM.Mutable> extends AbstractCalendarY<T, M> |
|
6 |
+ |
implements CalendarAccessorYM |
6 |
7 |
|
{ |
7 |
8 |
|
private static final long serialVersionUID = 1L; |
8 |
9 |
|
|
|
@@ -45,17 +46,29 @@ |
45 |
46 |
|
return (pMonths == 0) ? us() : LLsetMonth( mMonth - pMonths ); |
46 |
47 |
|
} |
47 |
48 |
|
|
48 |
|
- |
@Override |
49 |
|
- |
public String toSQLvalue() |
|
49 |
+ |
// vvvvvvvvvvvvvvvvvv Support methods vvvvvvvvvvvvvvvvv |
|
50 |
+ |
|
|
51 |
+ |
protected static final int parseMonth(String pStringForm, String... pParts) |
50 |
52 |
|
{ |
51 |
|
- |
return super.toSQLvalue() + "-" + formatMonth2(); |
|
53 |
+ |
return parseInt( pParts[1], "Month", pStringForm ); |
52 |
54 |
|
} |
53 |
55 |
|
|
54 |
|
- |
// vvvvvvvvvvvvvvvvvv Support methods vvvvvvvvvvvvvvvvv |
|
56 |
+ |
protected static final StringBuilder formatSQLvalueYM( CalendarAccessorYM pAccessor, StringBuilder pSB ) |
|
57 |
+ |
{ |
|
58 |
+ |
formatSQLvalueY( pAccessor, pSB ).append( '-' ); |
|
59 |
+ |
return formatMonth( pAccessor, pSB ); |
|
60 |
+ |
} |
55 |
61 |
|
|
56 |
|
- |
protected final String formatMonth2() |
|
62 |
+ |
protected static final StringBuilder formatSortableDisplayFormYM( CalendarAccessorYM pAccessor, StringBuilder pSB ) |
57 |
63 |
|
{ |
58 |
|
- |
return Integers.zeroPadIt( 2, mMonth ); |
|
64 |
+ |
formatSortableDisplayFormY( pAccessor, pSB ).append( '/' ); |
|
65 |
+ |
return formatMonth( pAccessor, pSB ); |
|
66 |
+ |
} |
|
67 |
+ |
|
|
68 |
+ |
protected static final StringBuilder formatMonth( CalendarAccessorYM pAccessor, StringBuilder pSB ) |
|
69 |
+ |
{ |
|
70 |
+ |
MM_Chunk.appendMonthTo( pAccessor, pSB ); |
|
71 |
+ |
return pSB; |
59 |
72 |
|
} |
60 |
73 |
|
|
61 |
74 |
|
protected static final int validateMonth( int pYear, int pMonth ) |
|
@@ -94,30 +107,37 @@ |
94 |
107 |
|
/** |
95 |
108 |
|
* @param pNewMonth != current |
96 |
109 |
|
*/ |
97 |
|
- |
abstract protected T LLsetMonth( int pNewMonth ); |
|
110 |
+ |
protected final T LLsetMonth( int pNewMonth ) |
|
111 |
+ |
throws IllegalArgumentException |
|
112 |
+ |
{ |
|
113 |
+ |
M zMutable = createMutable( getYear(), pNewMonth ); |
|
114 |
+ |
zMutable.normalize(); |
|
115 |
+ |
return createTypeFrom( zMutable ); |
|
116 |
+ |
} |
|
117 |
+ |
|
|
118 |
+ |
protected abstract M createMutable( int pYear, int pNewMonth ); |
|
119 |
+ |
|
|
120 |
+ |
protected abstract M createMutable( int pNewYear ); |
|
121 |
+ |
|
|
122 |
+ |
protected abstract T createTypeFrom( M pMutable ); |
98 |
123 |
|
|
99 |
|
- |
protected static class Mutable |
|
124 |
+ |
protected static class Mutable extends AbstractCalendarY.Mutable implements CalendarAccessorYM |
100 |
125 |
|
{ |
101 |
|
- |
private int mYear; |
102 |
126 |
|
private int mMonth; |
103 |
127 |
|
|
104 |
128 |
|
public Mutable( int pYear, int pMonth ) |
105 |
129 |
|
{ |
106 |
|
- |
mYear = pYear; |
|
130 |
+ |
super( pYear ); |
107 |
131 |
|
mMonth = pMonth; |
108 |
132 |
|
} |
109 |
133 |
|
|
110 |
|
- |
public final int getYear() |
111 |
|
- |
{ |
112 |
|
- |
return mYear; |
113 |
|
- |
} |
114 |
|
- |
|
115 |
134 |
|
public final int getMonth() |
116 |
135 |
|
{ |
117 |
136 |
|
return mMonth; |
118 |
137 |
|
} |
119 |
138 |
|
|
120 |
|
- |
public void normalize() { |
|
139 |
+ |
public void normalize() |
|
140 |
+ |
{ |
121 |
141 |
|
while ( mMonth > 12 ) |
122 |
142 |
|
{ |
123 |
143 |
|
tooLargeMonth(); |
|
@@ -146,13 +166,13 @@ |
146 |
166 |
|
|
147 |
167 |
|
private void tooSmallMonth() |
148 |
168 |
|
{ |
149 |
|
- |
mYear--; |
|
169 |
+ |
decrementYear(); |
150 |
170 |
|
mMonth += 12; |
151 |
171 |
|
} |
152 |
172 |
|
|
153 |
173 |
|
private void tooLargeMonth() |
154 |
174 |
|
{ |
155 |
|
- |
mYear++; |
|
175 |
+ |
incrementYear(); |
156 |
176 |
|
mMonth -= 12; |
157 |
177 |
|
} |
158 |
178 |
|
} |