litesoft
@ 942
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.commonfoundation.base.*; import org.litesoft.commonfoundation.typeutils.*; import org.litesoft.commonfoundation.typeutils.gregorian.*; public abstract class AbstractTimestampHMSM<T extends AbstractTimestampHMSM, M extends AbstractTimestampHMSM.Mutable> extends AbstractTimestampHMS<T, M> implements TimestampAccessorHMSM { private static final long serialVersionUID = 1L; private final int mMilliSec; protected AbstractTimestampHMSM( int pYear, int pMonth, int pDay, int pZuluOffsetMins, int pHour, int pMin, int pSec, int pMilliSec ) { super( pYear, pMonth, pDay, pZuluOffsetMins, pHour, pMin, pSec ); mMilliSec = validateMilliSec( pMilliSec ); } @Override public final int getMilliSec() { return mMilliSec; } /** * Return a T with the MilliSec set to the parameter. */ public final T milliSec( int pMilliSec ) { validateMilliSec( pMilliSec ); return (mMilliSec == pMilliSec) ? us() : LLsetMilliSec( pMilliSec ); } /** * Return T with the parameter pMilliSec added. */ public final T addMilliSecs( int pMilliSecs ) { return (pMilliSecs == 0) ? us() : LLsetMilliSec( mMilliSec + pMilliSecs ); } /** * Return T with the parameter pMilliSec subtracted. */ public final T minusMilliSecs( int pMilliSecs ) { return (pMilliSecs == 0) ? us() : LLsetMilliSec( mMilliSec - pMilliSecs ); } // vvvvvvvvvvvvvvvvvv Support methods vvvvvvvvvvvvvvvvv protected static final int parseMilliSec( String pStringForm, String... pParts ) { String zFraction = pParts[6]; return (int) (1000 * fractional( zFraction, parseInt( zFraction, "MilliSec", pStringForm ) )); } protected static final StringBuilder formatSQLvalueYMDHMSM( TimestampAccessorHMSM pAccessor, boolean pAddTail, StringBuilder pSB ) { formatSQLvalueYMDHM( pAccessor, false, pSB ).append( ':' ); formatMilliSec( pAccessor, pSB ); return tailSQLvalue( pAccessor, pAddTail, pSB ); } protected static final StringBuilder formatSortableDisplayFormYMDHMSM( TimestampAccessorHMSM pAccessor, StringBuilder pSB ) { formatSortableDisplayFormYMDHM( pAccessor, pSB ).append( ':' ); return formatMilliSec( pAccessor, pSB ); } protected static final StringBuilder formatMilliSec( TimestampAccessorHMSM pAccessor, StringBuilder pSB ) { pSB.append( Integers.zeroPadIt( 3, pAccessor.getMilliSec() ) ); return pSB; } protected static final int validateMilliSec( int pMilliSec ) throws IllegalArgumentException { if ( (pMilliSec < 0) || (999 < pMilliSec) ) { throw new IllegalArgumentException( "Invalid MilliSec provided: " + pMilliSec ); } return pMilliSec; } protected int LL_hashCode() { return hashCodeEm( super.hashCode(), mMilliSec ); } /** * 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.getMilliSec() == them.getMilliSec(); } protected Compare LL_compareNonNullLoose( Object them ) { Compare zCompare = super.LL_compareNonNullLoose( them ); if ( (zCompare.result() == EQUAL) && (them instanceof TimestampAccessorHMSM) ) { zCompare = zCompare.then( this.getMilliSec(), ((TimestampAccessorHMSM) them).getMilliSec() ); } return zCompare; } /** * @param pNewMonth != current */ protected final T LLsetMilliSec( int pNewMilliSec ) { M zMutable = createMutable( getYear(), getMonth(), getDay(), getHour(), getMin(), getSec(), pNewMilliSec ); zMutable.normalize(); return createTypeFrom( zMutable ); } protected abstract M createMutable( int pYear, int pMonth, int pDay, int pHour, int pMin, int pSec, int pNewMilliSec ); protected static class Mutable extends AbstractTimestampHMS.Mutable implements TimestampAccessorHMSM { protected int mMilliSec; public Mutable( int pYear, int pMonth, int pDay, boolean pDayConstrained, int pZuluOffsetMins, int pHour, int pMin, int pSec, int pMilliSec ) { super( pYear, pMonth, pDay, pDayConstrained, pZuluOffsetMins, pHour, pMin, pSec ); mMilliSec = pMilliSec; } public final int getMilliSec() { return mMilliSec; } public void normalize() { super.normalize(); while ( mMilliSec < 0 ) { tooSmallMilliSec(); } while ( 999 < mMilliSec ) { tooLargeMilliSec(); } } protected final void decrementMilliSec() { if ( --mMilliSec < 0 ) { tooSmallMilliSec(); } } protected final void incrementMilliSec() { if ( 999 < ++mMilliSec ) { tooLargeMilliSec(); } } private void tooSmallMilliSec() { decrementMin(); mMilliSec += 1000; } private void tooLargeMilliSec() { mMilliSec -= 1000; incrementMin(); } } } |
Commits for litesoft/trunk/Java/core/Anywhere/src/org/litesoft/core/simpletypes/temporal/AbstractTimestampHMSM.java
Revision | Author | Commited | Message |
---|---|---|---|
942 Diff | GeorgeS | Mon 02 Jun, 2014 23:41:46 +0000 | Extracting commonfoundation |
939 Diff | GeorgeS | Mon 02 Jun, 2014 21:30:31 +0000 | Extracting commonfoundation |
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!!! |
893 Diff | GeorgeS | Mon 14 Jan, 2013 01:18:30 +0000 | |
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... |
861 Diff | GeorgeS | Mon 05 Nov, 2012 13:55:32 +0000 | |
859 | GeorgeS | Mon 05 Nov, 2012 01:26:38 +0000 |