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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package org.litesoft.core.simpletypes.temporal;

import java.util.*;

import org.litesoft.core.typeutils.*;

public abstract class AbstractCalendarY<T extends AbstractCalendarY, M extends AbstractCalendarY.Mutable> extends AbstractTemporal<T> implements CalendarAccessorY
{
    private static final long serialVersionUID = 1L;

    private /* final */ int mYear;

    protected AbstractCalendarY( int pYear )
    {
        mYear = pYear;
    }

    @Override
    public final int getYear()
    {
        return mYear;
    }

    /**
     * Return a T with the Year set to the parameter, if it was a LeapDay and can not be a LeapDay it will be 28Feb.
     */
    public final T year( int pYear )
    {
        return (mYear == pYear) ? us() : LLsetYear( pYear );
    }

    /**
     * if after add pYears AND it was a LeapDay and can not be a LeapDay it will be 28Feb.
     */
    public final T addYears( int pYears )
    {
        return (pYears == 0) ? us() : LLsetYear( mYear + pYears );
    }

    /**
     * if after minus pYears AND it was a LeapDay and can not be a LeapDay it will be 28Feb.
     */
    public final T minusYears( int pYears )
    {
        return (pYears == 0) ? us() : LLsetYear( mYear - pYears );
    }

    /**
     * True if this is 'before' or Equal to them.
     * <p/>
     * Note: Uses the lesser resolution of them and this.
     *
     * @param them !null
     *
     * @throws IllegalArgumentException if them is null
     */
    public final boolean beforeOrEqual( CalendarAccessorY them )
            throws IllegalArgumentException
    {
        undefinedResultIfNull( "before", them );
        return (this == them) || (GREATER != LL_compareNonNullLoose( them ).result());
    }

    /**
     * True if this is 'after' or Equal to them.
     * <p/>
     * Note: Uses the lesser resolution of them and this.
     *
     * @param them !null
     *
     * @throws IllegalArgumentException if them is null
     */
    public final boolean afterOrEqual( CalendarAccessorY them )
            throws IllegalArgumentException
    {
        undefinedResultIfNull( "after", them );
        return (this == them) || (LESSER != LL_compareNonNullLoose( them ).result());
    }

    public Date toUtilDate()
    {
        return toUtilDateAdaptor().getWallDate();
    }

    abstract public UtilDateAdaptor toUtilDateAdaptor();

    // vvvvvvvvvvvvvvvvvv Support methods vvvvvvvvvvvvvvvvv

    protected static final int parseYear(String pStringForm, String... pParts)
    {
        return parseInt( pParts[0], "Year", pStringForm );
    }

    protected static final StringBuilder formatSQLvalueY( CalendarAccessorY pAccessor, StringBuilder pSB )
    {
        return formatYear( pAccessor, pSB );
    }

    protected static final StringBuilder formatSortableDisplayFormY( CalendarAccessorY pAccessor, StringBuilder pSB )
    {
        return formatYear( pAccessor, pSB );
    }

    protected static final StringBuilder formatYear( CalendarAccessorY pAccessor, StringBuilder pSB )
    {
        yyyy_Chunk.appendYearTo( pAccessor, pSB );
        return pSB;
    }

    @Override
    protected int LL_hashCode()
    {
        return mYear;
    }

    /**
     * T is non-null and of the same class, so should check everything!
     */
    @Override
    protected boolean LL_equalsNonNullStrict( T them )
    {
        return this.getYear() == them.getYear();
    }

    @Override
    protected Compare LL_compareNonNullLoose( Object them )
    {
        if ( them instanceof CalendarAccessorY )
        {
            return Compare.first( this.getYear(), ((CalendarAccessorY) them).getYear() );
        }
        throw incompatible( them );
    }

    /**
     * @param pNewYear != current
     */
    protected final T LLsetYear( int pNewYear )
    {
        M zMutable = createMutable( pNewYear );
        zMutable.normalize();
        return createTypeFrom( zMutable );
    }

    protected abstract M createMutable( int pNewYear );

    protected abstract T createTypeFrom( M pMutable );

    protected static class Mutable implements CalendarAccessorY
    {
        private int mYear;

        public Mutable( int pYear )
        {
            mYear = pYear;
        }

        public final int getYear()
        {
            return mYear;
        }

        public void normalize()
        {
        }

        protected final void decrementYear()
        {
            mYear--;
        }

        protected final void incrementYear()
        {
            mYear++;
        }
    }
}

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

Diff revisions: vs.
Revision Author Commited Message
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!!!

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...

859 GeorgeS picture GeorgeS Mon 05 Nov, 2012 01:26:38 +0000