Subversion Repository Public Repository

litesoft

Diff Revisions 862 vs 864 for /trunk/Java/core/Anywhere/src/org/litesoft/core/simpletypes/temporal/CalendarYMD.java

Diff revisions: vs.
  @@ -7,13 +7,12 @@
7 7 import org.litesoft.core.typeutils.gregorian.*;
8 8
9 9 /**
10 - * A date that acts as a sort of proxy for a java.util.Date (burying the deprecated method use) providing
11 - * varying levels of resolution based on the DateRes.
10 + * A Calendar "date" (e.g. Year, Month, & Day) ("Wall" relative).
12 11 * <p/>
13 12 * Note: This class supports Gregorian dates only and has no concept of time or TimeZones. As such when working with
14 13 * Java Util Date(s) (or it's descendants) the local (or "Wall") date is all that is considered!
15 14 */
16 - public final class CalendarYMD extends AbstractCalendarYMD<CalendarYMD> implements SQLdateable
15 + public final class CalendarYMD extends AbstractCalendarYMD<CalendarYMD, AbstractCalendarYMD.Mutable> implements SQLdateable
17 16 {
18 17 private static final long serialVersionUID = 1L;
19 18
  @@ -51,25 +50,19 @@
51 50 return YearMonthDayFormatAccessor.get().format( this );
52 51 }
53 52
54 - public static String toString( CalendarYMD pDate )
53 + public static String toString( CalendarYMD pCalendar )
55 54 {
56 - return (pDate != null) ? pDate.toString() : null;
55 + return (pCalendar != null) ? pCalendar.toString() : null;
57 56 }
58 57
59 - public static String toYMD( CalendarYMD pFromYMD )
58 + public static String toYMD( CalendarYMD pCalendar )
60 59 {
61 - return (pFromYMD != null) ? pFromYMD.toYMD() : null;
60 + return (pCalendar != null) ? pCalendar.toYMD() : null;
62 61 }
63 62
64 63 public String toYMD()
65 64 {
66 - StringBuilder sb = new StringBuilder();
67 - yyyy_Chunk.appendTo( sb, this );
68 - sb.append( '/' );
69 - MM_Chunk.appendTo( sb, this );
70 - sb.append( '/' );
71 - dd_Chunk.appendTo( sb, this );
72 - return sb.toString();
65 + return formatSortableDisplayFormYMD( this, new StringBuilder() ).toString();
73 66 }
74 67
75 68 public static CalendarYMD fromYMD( String pToYMD )
  @@ -78,6 +71,11 @@
78 71 return fromStringForm( pToYMD, "//" );
79 72 }
80 73
74 + public final String toSQLvalue()
75 + {
76 + return formatSQLvalueYMD( this, new StringBuilder() ).toString();
77 + }
78 +
81 79 public static CalendarYMD fromSQLvalue( String pToSQLvalue )
82 80 {
83 81 return fromStringForm( pToSQLvalue, "--" );
  @@ -85,19 +83,17 @@
85 83
86 84 private static CalendarYMD fromStringForm( String pStringForm, String pSequentialSeperators )
87 85 {
88 - if ( pStringForm == null )
89 - {
90 - return null;
91 - }
92 - String[] parts = SimpleParser.parse( pStringForm, pSequentialSeperators, 3 );
93 - return new CalendarYMD( parseInt( parts[0], "Year", pStringForm ), //
94 - parseInt( parts[1], "Month", pStringForm ),
95 - parseInt( parts[2], "Day", pStringForm ) );
86 + String[] parts = parseSimple( pStringForm, pSequentialSeperators );
87 + return (parts == null) ? null : //
88 + new CalendarYMD( parseYear( pStringForm, parts ), //
89 + parseMonth( pStringForm, parts ),
90 + parseDay( pStringForm, parts ) );
96 91 }
97 92
93 + @Override
98 94 public UtilDateAdaptor toUtilDateAdaptor()
99 95 {
100 - return new UtilDateAdaptor( getYear(), getMonth(), getDay() );
96 + return UtilDateAdaptor.currentWall( getYear(), getMonth(), getDay() );
101 97 }
102 98
103 99 // vvvvvvvvvvvvvvvvvv Non-common Public methods vvvvvvvvvvvvvvvvv
  @@ -163,44 +159,33 @@
163 159 {
164 160 return 0;
165 161 }
166 - return ( result == LESSER ) ? new DaysDiff( this ).till( pThem ): -new DaysDiff( pThem ).till( this );
162 + return (result == LESSER) ? new DaysDiff( this ).till( pThem ) : -new DaysDiff( pThem ).till( this );
167 163 }
168 164
169 165 // vvvvvvvvvvvvvvvvvv Support methods vvvvvvvvvvvvvvvvv
170 166
171 - /**
172 - * @param pNewYear != current
173 - */
174 167 @Override
175 - protected CalendarYMD LLsetYear( int pNewYear )
168 + protected CalendarYMD createTypeFrom( Mutable pMutable )
176 169 {
177 - Mutable zMutable = new Mutable( pNewYear, getMonth(), getDay(), true );
178 - zMutable.normalize();
179 - return new CalendarYMD( zMutable.getYear(), zMutable.getMonth(), zMutable.getDay() );
170 + return new CalendarYMD( pMutable.getYear(), pMutable.getMonth(), pMutable.getDay() );
180 171 }
181 172
182 - /**
183 - * @param pNewMonth != current
184 - */
185 173 @Override
186 - protected CalendarYMD LLsetMonth( int pNewMonth )
187 - throws IllegalArgumentException
174 + protected Mutable createMutable( int pNewYear )
188 175 {
189 - Mutable zMutable = new Mutable( getYear(), pNewMonth, getDay(), true );
190 - zMutable.normalize();
191 - return new CalendarYMD( zMutable.getYear(), zMutable.getMonth(), zMutable.getDay() );
176 + return new Mutable( pNewYear, getMonth(), getDay(), true );
192 177 }
193 178
194 - /**
195 - * @param pNewDay != current
196 - */
197 179 @Override
198 - protected CalendarYMD LLsetDay( int pNewDay )
199 - throws IllegalArgumentException
180 + protected Mutable createMutable( int pYear, int pNewMonth )
181 + {
182 + return new Mutable( pYear, pNewMonth, getDay(), true );
183 + }
184 +
185 + @Override
186 + protected Mutable createMutable( int pYear, int pMonth, int pNewDay )
200 187 {
201 - Mutable zMutable = new Mutable( getYear(), getMonth(), pNewDay, false );
202 - zMutable.normalize();
203 - return new CalendarYMD( zMutable.getYear(), zMutable.getMonth(), zMutable.getDay() );
188 + return new Mutable( pYear, pMonth, pNewDay, false );
204 189 }
205 190
206 191 private static class DaysDiff