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

import java.util.*;

import org.litesoft.core.simpletypes.temporal.*;
import org.litesoft.core.typeutils.*;
import org.litesoft.core.util.*;

public class CreditsData implements Comparable
{
    private String mWho;
    private SimpleDate mStartDate, mEndDate = null;

    public CreditsData( String pStartDateYYYY_MM_DD, String pWho, String pEndDateYYYY_MM_DD )
    {
        mStartDate = SimpleDate.fromYMD( "yyyy/MM/dd", pStartDateYYYY_MM_DD );
        mWho = UtilsCommon.assertNotNullNotEmpty( "Who", pWho );
        if ( pEndDateYYYY_MM_DD != null )
        {
            mEndDate = SimpleDate.fromYMD( "yyyy/MM/dd", pEndDateYYYY_MM_DD );
        }
    }

    public CreditsData( String pStartDateYYYY_MM_DD, String pWho )
    {
        this( pStartDateYYYY_MM_DD, pWho, null );
    }

    public String getWho()
    {
        return mWho;
    }

    public SimpleDate getStartDate()
    {
        return mStartDate;
    }

    public SimpleDate getEndDate()
    {
        return (mEndDate != null) ? mEndDate : new SimpleDate( new Date() );
    }

    public boolean wasActiveDuring( int pYear, int pMonth, int pFromDay, int pThruDay )
    {
        SimpleDate fromDate = new SimpleDate( pYear, pMonth, pFromDay );
        SimpleDate thruDate = new SimpleDate( pYear, pMonth, pThruDay );
        return !mStartDate.after( thruDate ) && !fromDate.after( getEndDate() );
    }

    private Integer getActiveDuration()
    {
        int rv = getStartDate().daysTill( getEndDate() );
        return new Integer( rv );
    }

    public int compareTo( Object o )
    {
        return compareTo( (CreditsData) o );
    }

    public int compareTo( CreditsData them )
    {
        // Note Reverse Order
        int rv = them.getActiveDuration().compareTo( this.getActiveDuration() );
        return (rv != 0) ? rv : this.getWho().compareTo( them.getWho() );
    }

    public boolean equals( CreditsData them )
    {
        return (this == them) || ((them != null) && //
                                  this.mWho.equals( them.mWho ) && //
                                  this.mStartDate.equals( them.mStartDate ) && //
                                  Objects.areNonArraysEqual( this.mEndDate, them.mEndDate ));
    }

    public boolean equals( Object o )
    {
        return (this == o) || ((o instanceof CreditsData) && equals( (CreditsData) o ));
    }

    public int hashCode()
    {
        int result = (mEndDate == null) ? 0 : mEndDate.hashCode();
        result = 31 * result + mStartDate.hashCode();
        result = 31 * result + mWho.hashCode();
        return result;
    }

    public static class MonthYear
    {
        private int mY, mM;

        public MonthYear( int pY, int pM )
        {
            mY = pY;
            mM = pM;
        }

        public MonthYear( SimpleDate pSimpleDate )
        {
            mY = pSimpleDate.getYear();
            mM = pSimpleDate.getMonth();
        }

        public int getYear()
        {
            return mY;
        }

        public int getMonth()
        {
            return mM;
        }

        public MonthYear incMonth()
        {
            if ( 13 == ++mM )
            {
                mM = 1;
                mY++;
            }
            return this;
        }

        public String toString()
        {
            return twoDigits( mM ) + "/" + twoDigits( mY );
        }

        private String twoDigits( int i )
        {
            String s = Integer.toString( i + 100 );
            while ( s.length() > 2 )
            {
                s = s.substring( 1 );
            }
            return s;
        }

        public boolean isLessThan( SimpleDate them )
        {
            if ( this.mY == them.getYear() )
            {
                return (this.mM < them.getMonth());
            }
            return (this.mY < them.getYear());
        }

        public boolean isLessThanOrEqual( SimpleDate them )
        {
            if ( this.mY == them.getYear() )
            {
                return (this.mM <= them.getMonth());
            }
            return (this.mY < them.getYear());
        }
    }
}

Commits for litesoft/trunk/Java/core/jvm1.4/src/org/litesoft/ui/support/nonpublic/CreditsData.java

Diff revisions: vs.
Revision Author Commited Message
804 Diff Diff GeorgeS picture GeorgeS Wed 15 Aug, 2012 12:48:51 +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