litesoft
@ 898
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 180 181 182 |
package org.litesoft.core.simpletypes.temporal; import org.litesoft.core.typeutils.*; public abstract class AbstractTimestampHMS<T extends AbstractTimestampHMS, M extends AbstractTimestampHMS.Mutable> extends AbstractTimestampHM<T, M> implements TimestampAccessorHMS { private static final long serialVersionUID = 1L; protected AbstractTimestampHMS( int pOriginalZuluOffsetMins, long pUTC ) { super( pOriginalZuluOffsetMins, pUTC ); } protected AbstractTimestampHMS( int pOriginalZuluOffsetMins, UtilDateAdaptor pDateAdaptor ) { super( pOriginalZuluOffsetMins, pDateAdaptor ); } protected AbstractTimestampHMS( UtilDateAdaptor pDateAdaptor ) { super( pDateAdaptor ); } @Override public final int getSec() { return getWall().getSec(); } /** * Return a T with the Sec set to the parameter. */ public final T sec( int pSec ) { validateSec( pSec ); return (getSec() == pSec) ? us() : LLsetSec( pSec ); } /** * Return T with the parameter pSec added. */ public final T addSecs( int pSecs ) { return (pSecs == 0) ? us() : LLsetSec( getSec() + pSecs ); } /** * Return T with the parameter pSec subtracted. */ public final T minusSecs( int pSecs ) { return (pSecs == 0) ? us() : LLsetSec( getSec() - pSecs ); } // vvvvvvvvvvvvvvvvvv Support methods vvvvvvvvvvvvvvvvv protected static final int parseSec( String pStringForm, String... pParts ) { return parseInt( pParts[5], "Sec", pStringForm ); } protected static final StringBuilder formatSQLvalueYMDHMS( TimestampAccessorHMS pAccessor, boolean pAddTail, StringBuilder pSB ) { formatSQLvalueYMDHM( pAccessor, false, pSB ).append( ':' ); formatSec( pAccessor, pSB ); return tailSQLvalue( pAccessor, pAddTail, pSB ); } protected static final StringBuilder formatSortableDisplayFormYMDHMS( TimestampAccessorHMS pAccessor, StringBuilder pSB ) { formatSortableDisplayFormYMDHM( pAccessor, pSB ).append( ':' ); return formatSec( pAccessor, pSB ); } protected static final StringBuilder formatSec( TimestampAccessorHMS pAccessor, StringBuilder pSB ) { pSB.append( Integers.zeroPadIt( 2, pAccessor.getSec() ) ); return pSB; } protected static final int validateSec( int pSec ) throws IllegalArgumentException { if ( (pSec < 0) || (59 < pSec) ) { throw new IllegalArgumentException( "Invalid Sec provided: " + pSec ); } return pSec; } protected int LL_hashCode() { return hashCodeEm( super.hashCode(), getSec() ); } /** * 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.getSec() == them.getSec(); } protected Compare LL_compareNonNullLoose( Object them ) { Compare zCompare = super.LL_compareNonNullLoose( them ); if ( (zCompare.result() == EQUAL) && (them instanceof TimestampAccessorHMS) ) { zCompare = zCompare.then( this.getSec(), ((TimestampAccessorHMS) them).getSec() ); } return zCompare; } /** * @param pNewSec != current */ protected final T LLsetSec( int pNewSec ) { M zMutable = createMutable( getYear(), getMonth(), getDay(), getHour(), getMin(), pNewSec ); zMutable.normalize(); return createTypeFrom( zMutable ); } protected abstract M createMutable( int pYear, int pMonth, int pDay, int pHour, int pMin, int pNewSec ); protected static class Mutable extends AbstractTimestampHM.Mutable { protected int mSec; public Mutable( int pYear, int pMonth, int pDay, boolean pDayConstrained, int pHour, int pMin, int pSec ) { super( pYear, pMonth, pDay, pDayConstrained, pHour, pMin ); mSec = pSec; } public final int getSec() { return mSec; } public void normalize() { super.normalize(); while ( mSec < 0 ) { tooSmallSec(); } while ( 59 < mSec ) { tooLargeSec(); } } protected final void decrementSec() { if ( --mSec < 0 ) { tooSmallSec(); } } protected final void incrementSec() { if ( 59 < ++mSec ) { tooLargeSec(); } } private void tooSmallSec() { decrementMin(); mSec += 60; } private void tooLargeSec() { mSec -= 60; incrementMin(); } } } |
Commits for litesoft/trunk/Java/core/Anywhere/src/org/litesoft/core/simpletypes/temporal/AbstractTimestampHMS.java
Revision | Author | Commited | Message |
---|---|---|---|
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 |