Subversion Repository Public Repository

litesoft

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
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 AbstractTimestampHM<T extends AbstractTimestampHM, M extends AbstractTimestampHM.Mutable> extends AbstractTimestampH<T, M>
        implements TimestampAccessorHM {
    private static final long serialVersionUID = 1L;

    private final int mMin;

    protected AbstractTimestampHM( int pYear, int pMonth, int pDay, int pZuluOffsetMins, int pHour, int pMin ) {
        super( pYear, pMonth, pDay, pZuluOffsetMins, pHour );
        mMin = validateMin( pMin );
    }

    @Override
    public final int getMin() {
        return mMin;
    }

    /**
     * Return a T with the Min set to the parameter.
     */
    public final T min( int pMin ) {
        validateMin( pMin );
        return (mMin == pMin) ? us() : LLsetMin( pMin );
    }

    /**
     * Return T with the parameter pMin added.
     */
    public final T addMins( int pMins ) {
        return (pMins == 0) ? us() : LLsetMin( mMin + pMins );
    }

    /**
     * Return T with the parameter pMin subtracted.
     */
    public final T minusMins( int pMins ) {
        return (pMins == 0) ? us() : LLsetMin( mMin - pMins );
    }

    // vvvvvvvvvvvvvvvvvv Support methods vvvvvvvvvvvvvvvvv

    protected static final int parseMin( String pStringForm, String... pParts ) {
        return parseInt( pParts[4], "Min", pStringForm );
    }

    protected static final StringBuilder formatSQLvalueYMDHM( TimestampAccessorHM pAccessor, boolean pAddTail, StringBuilder pSB ) {
        formatSQLvalueYMDH( pAccessor, false, pSB ).append( ':' );
        formatMin( pAccessor, pSB );
        return tailSQLvalue( pAccessor, pAddTail, pSB );
    }

    protected static final StringBuilder formatSortableDisplayFormYMDHM( TimestampAccessorHM pAccessor, StringBuilder pSB ) {
        formatSortableDisplayFormYMDH( pAccessor, pSB ).append( ':' );
        return formatMin( pAccessor, pSB );
    }

    protected static final StringBuilder formatMin( TimestampAccessorHM pAccessor, StringBuilder pSB ) {
        pSB.append( Integers.zeroPadIt( 2, pAccessor.getMin() ) );
        return pSB;
    }

    protected static final int validateMin( int pMin )
            throws IllegalArgumentException {
        if ( (pMin < 0) || (59 < pMin) ) {
            throw new IllegalArgumentException( "Invalid Min provided: " + pMin );
        }
        return pMin;
    }

    protected int LL_hashCode() {
        return hashCodeEm( super.hashCode(), mMin );
    }

    /**
     * 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.getMin() == them.getMin();
    }

    protected Compare LL_compareNonNullLoose( Object them ) {
        Compare zCompare = super.LL_compareNonNullLoose( them );
        if ( (zCompare.result() == EQUAL) && (them instanceof TimestampAccessorHM) ) {
            zCompare = zCompare.then( this.getMin(), ((TimestampAccessorHM) them).getMin() );
        }
        return zCompare;
    }

    /**
     * @param pNewMonth != current
     */
    protected final T LLsetMin( int pNewMin ) {
        M zMutable = createMutable( getYear(), getMonth(), getDay(), getHour(), pNewMin );
        zMutable.normalize();
        return createTypeFrom( zMutable );
    }

    protected abstract M createMutable( int pYear, int pMonth, int pDay, int pHour, int pNewMin );

    protected static class Mutable extends AbstractTimestampH.Mutable implements TimestampAccessorHM {
        protected int mMin;

        public Mutable( int pYear, int pMonth, int pDay, boolean pDayConstrained, int pZuluOffsetMins, int pHour, int pMin ) {
            super( pYear, pMonth, pDay, pDayConstrained, pZuluOffsetMins, pHour );
            mMin = pMin;
        }

        public final int getMin() {
            return mMin;
        }

        public void normalize() {
            super.normalize();
            while ( mMin < 0 ) {
                tooSmallMin();
            }
            while ( 59 < mMin ) {
                tooLargeMin();
            }
        }

        protected final void decrementMin() {
            if ( --mMin < 0 ) {
                tooSmallMin();
            }
        }

        protected final void incrementMin() {
            if ( 59 < ++mMin ) {
                tooLargeMin();
            }
        }

        private void tooSmallMin() {
            decrementHour();
            mMin += 60;
        }

        private void tooLargeMin() {
            mMin -= 60;
            incrementHour();
        }

        @Override
        protected final void adjustMinutesTo( int pOffsetMinsAdjustment ) {
            if ( pOffsetMinsAdjustment != 0 ) {
                mMin += pOffsetMinsAdjustment;
                normalize();
            }
        }
    }
}

Commits for litesoft/trunk/Java/core/Anywhere/src/org/litesoft/core/simpletypes/temporal/AbstractTimestampHM.java

Diff revisions: vs.
Revision Author Commited Message
948 Diff Diff GeorgeS picture GeorgeS Sat 07 Jun, 2014 23:42:39 +0000

Jusefuls Formatter Updated to New Code Format

942 Diff Diff GeorgeS picture GeorgeS Mon 02 Jun, 2014 23:41:46 +0000

Extracting commonfoundation

939 Diff Diff GeorgeS picture GeorgeS Mon 02 Jun, 2014 21:30:31 +0000

Extracting commonfoundation

912 Diff Diff GeorgeS picture GeorgeS Fri 28 Jun, 2013 06:48:05 +0000

Revert to mixed & Working (PEDS & Prioritizer) code!

898 Diff Diff GeorgeS picture GeorgeS Sun 17 Mar, 2013 21:46:33 +0000

Temporal!!!

893 Diff Diff GeorgeS picture GeorgeS Mon 14 Jan, 2013 01:18:30 +0000
864 Diff Diff GeorgeS picture GeorgeS Mon 19 Nov, 2012 01:48:25 +0000
862 Diff Diff GeorgeS picture GeorgeS Thu 15 Nov, 2012 02:23:36 +0000

On the Way...

861 Diff Diff GeorgeS picture GeorgeS Mon 05 Nov, 2012 13:55:32 +0000
859 GeorgeS picture GeorgeS Mon 05 Nov, 2012 01:26:38 +0000