litesoft
@ 912
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
package org.litesoft.core.simpletypes.temporal; import org.litesoft.core.typeutils.*; public abstract class AbstractCalendarYM<T extends AbstractCalendarYM, M extends AbstractCalendarYM.Mutable> extends AbstractCalendarY<T, M> implements CalendarAccessorYM { private static final long serialVersionUID = 1L; private /* final */ int mMonth; protected AbstractCalendarYM( int pYear, int pMonth ) { super( pYear ); mMonth = validateMonth( getYear(), pMonth ); } @Override public final int getMonth() { return mMonth; } /** * Return a T with the Month set to the parameter, if there are insufficient days in the new month, the date will be set to the last day of the target month. */ public final T month( int pMonth ) { validateMonth( getYear(), pMonth ); return (mMonth == pMonth) ? us() : LLsetMonth( pMonth ); } /** * if after add pMonth there are insufficient days in the new month, the date will be set to the last day of the target month. */ public final T addMonths( int pMonths ) { return (pMonths == 0) ? us() : LLsetMonth( mMonth + pMonths ); } /** * if after minus pMonths there are insufficient days in the new month, the date will be set to the last day of the target month. */ public final T minusMonths( int pMonths ) { return (pMonths == 0) ? us() : LLsetMonth( mMonth - pMonths ); } // vvvvvvvvvvvvvvvvvv Support methods vvvvvvvvvvvvvvvvv protected static final int parseMonth(String pStringForm, String... pParts) { return parseInt( pParts[1], "Month", pStringForm ); } protected static final StringBuilder formatSQLvalueYM( CalendarAccessorYM pAccessor, StringBuilder pSB ) { formatSQLvalueY( pAccessor, pSB ).append( '-' ); return formatMonth( pAccessor, pSB ); } protected static final StringBuilder formatSortableDisplayFormYM( CalendarAccessorYM pAccessor, StringBuilder pSB ) { formatSortableDisplayFormY( pAccessor, pSB ).append( '/' ); return formatMonth( pAccessor, pSB ); } protected static final StringBuilder formatMonth( CalendarAccessorYM pAccessor, StringBuilder pSB ) { MM_Chunk.appendMonthTo( pAccessor, pSB ); return pSB; } protected static final int validateMonth( int pYear, int pMonth ) throws IllegalArgumentException { if ( (pMonth < 1) || (12 < pMonth) ) { throw new IllegalArgumentException( "Invalid Month provided (Year: " + pYear + "): " + pMonth ); } return pMonth; } protected int LL_hashCode() { return hashCodeEm( super.hashCode(), mMonth ); } /** * T is non-null and of the same class, so should check everything! */ protected boolean LL_equalsNonNullStrict( T them ) { return super.LL_equalsNonNullStrict( them ) && this.getMonth() == them.getMonth(); } protected Compare LL_compareNonNullLoose( Object them ) { Compare zCompare = super.LL_compareNonNullLoose( them ); if ( (zCompare.result() == EQUAL) && (them instanceof CalendarAccessorYM) ) { zCompare = zCompare.then( this.getMonth(), ((CalendarAccessorYM) them).getMonth() ); } return zCompare; } /** * @param pNewMonth != current */ protected final T LLsetMonth( int pNewMonth ) throws IllegalArgumentException { M zMutable = createMutable( getYear(), pNewMonth ); zMutable.normalize(); return createTypeFrom( zMutable ); } protected abstract M createMutable( int pYear, int pNewMonth ); protected abstract M createMutable( int pNewYear ); protected abstract T createTypeFrom( M pMutable ); protected static class Mutable extends AbstractCalendarY.Mutable implements CalendarAccessorYM { private int mMonth; public Mutable( int pYear, int pMonth ) { super( pYear ); mMonth = pMonth; } public final int getMonth() { return mMonth; } public void normalize() { while ( mMonth > 12 ) { tooLargeMonth(); } while ( mMonth < 1 ) { tooSmallMonth(); } } protected final void decrementMonth() { if ( --mMonth < 1 ) { tooSmallMonth(); } } protected final void incrementMonth() { if ( 12 < ++mMonth ) { tooLargeMonth(); } } private void tooSmallMonth() { decrementYear(); mMonth += 12; } private void tooLargeMonth() { incrementYear(); mMonth -= 12; } } } |
Commits for litesoft/trunk/Java/core/Anywhere/src/org/litesoft/core/simpletypes/temporal/AbstractCalendarYM.java
Revision | Author | Commited | Message |
---|---|---|---|
912 Diff | GeorgeS | Fri 28 Jun, 2013 06:48:05 +0000 | Revert to mixed & Working (PEDS & Prioritizer) code! |
898 Diff | GeorgeS | Sun 17 Mar, 2013 21:46:33 +0000 | Temporal!!! |
864 Diff | GeorgeS | Mon 19 Nov, 2012 01:48:25 +0000 | |
862 Diff | GeorgeS | Thu 15 Nov, 2012 02:23:36 +0000 | On the Way... |
859 | GeorgeS | Mon 05 Nov, 2012 01:26:38 +0000 |