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
// This Source Code is in the Public Domain per: http://litesoft.org/License.txt
package org.litesoft.core.simpletypes.temporal;

import org.litesoft.commonfoundation.typeutils.*;
import org.litesoft.core.simpletypes.temporal.nonpublic.*;
import org.litesoft.commonfoundation.typeutils.gregorian.*;

/**
 * A Date resolution from the Year thru the Day.
 */
public final class DateRes extends AbstractRes
{
    private static final long serialVersionUID = 1L;

    // Formatting Indicators
    public static final char INDICATOR_YEAR = 'y';
    public static final char INDICATOR_MONTH = 'M';
    public static final char INDICATOR_DAY = 'd';

    private static final int YEARindex = 0;
    private static final int MONTHindex = 1;
    private static final int DAYindex = 2;

    public static DateRes ToYEAR = new DateRes( "ToYEAR", "Year", YEARindex, INDICATOR_YEAR );
    public static DateRes ToMONTH = new DateRes( "ToMONTH", "Month", MONTHindex, INDICATOR_MONTH );
    public static DateRes ToDAY = new DateRes( "ToDAY", "Day", DAYindex, INDICATOR_DAY );

    @SuppressWarnings({"deprecation", "UnusedDeclaration"}) @Deprecated /** for Serialization */
    protected DateRes()
    {
    }

    private DateRes( String pName, String pFriendlyName, int pIndex, char pIndicator )
    {
        super( pName, pFriendlyName, pIndex, pIndicator );
    }

    public DateFormat getDateFormat()
    {
        switch ( getIndex() )
        {
            default:
            case DAYindex:
                return YearMonthDayFormatAccessor.get();
            case MONTHindex:
                return YearMonthFormatAccessor.get();
            case YEARindex:
                return YearFormatAccessor.get();
        }
    }

    private static AbstractRes[] OPTIONS = new AbstractRes[]{ToYEAR, ToMONTH, ToDAY,};

    public static DateRes fromIndex( int pIndex )
    {
        return (DateRes) LLfromIndex( OPTIONS, pIndex );
    }

    public static DateRes rehydrate( String pDesiccated )
            throws IllegalArgumentException
    {
        return (DateRes) LLrehydrate( "DateRes", OPTIONS, pDesiccated );
    }

    public boolean isValidToMonth()
    {
        return MONTHindex <= getIndex();
    }

    public boolean isValidToDay()
    {
        return DAYindex <= getIndex();
    }

    public int validateMonth( Object pCaller, int pYear, int pMonth )
            throws IllegalArgumentException
    {
        validateToMonth( pCaller );
        if ( (pMonth < 1) || (12 < pMonth) )
        {
            throw new IllegalArgumentException( "Invalid Month provided (Year: " + pYear + "): " + pMonth );
        }
        return pMonth;
    }

    public int validateDay( Object pCaller, int pYear, int pMonth, int pDay )
            throws IllegalArgumentException
    {
        validateToDay( pCaller );
        if ( (pDay < 1) || (Month.daysIn( pYear, validateMonth( pCaller, pYear, pMonth ) ) < pDay) )
        {
            throw new IllegalArgumentException( "Invalid Day provided (Year: " + pYear + ", Month: " + pMonth + "): " + pDay );
        }
        return pDay;
    }

    public void validateToMonth( Object pCaller )
            throws IllegalArgumentException
    {
        if ( !isValidToMonth() )
        {
            throw doesNotContain( pCaller, DateRes.ToMONTH );
        }
    }

    public void validateToDay( Object pCaller )
    {
        if ( !isValidToDay() )
        {
            throw doesNotContain( pCaller, DateRes.ToDAY );
        }
    }

    private IllegalArgumentException doesNotContain( Object pCaller, DateRes pDateRes )
    {
        return new IllegalArgumentException( Objects.justClassNameOf( pCaller ) + "'s resolution is only to the '" + this.getFriendlyName() +
                                             "', but " + pDateRes.getFriendlyName() + " access or manipulation was attempted" );
    }
}

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

Diff revisions: vs.
Revision Author Commited Message
939 Diff Diff GeorgeS picture GeorgeS Mon 02 Jun, 2014 21:30:31 +0000

Extracting commonfoundation

853 Diff Diff GeorgeS picture GeorgeS Sun 04 Nov, 2012 15:18:21 +0000
849 Diff Diff GeorgeS picture GeorgeS Tue 11 Sep, 2012 17:11:59 +0000

Clean up serialization

151 Diff Diff GeorgeS picture GeorgeS Thu 17 Mar, 2011 04:16:22 +0000
49 Diff Diff GeorgeS picture GeorgeS Mon 12 Apr, 2010 02:59:10 +0000

License Text

2 GeorgeS picture GeorgeS Sun 07 Feb, 2010 12:50:58 +0000