~mortenoh/+junk/dhis2-detailed-import-export

« back to all changes in this revision

Viewing changes to dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/RelativePeriods.java

  • Committer: larshelge at gmail
  • Date: 2009-03-03 16:46:36 UTC
  • Revision ID: larshelge@gmail.com-20090303164636-2sjlrquo7ib1gf7r
Initial check-in

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.hisp.dhis.reporttable;
 
2
 
 
3
/*
 
4
 * Copyright (c) 2004-2007, University of Oslo
 
5
 * All rights reserved.
 
6
 *
 
7
 * Redistribution and use in source and binary forms, with or without
 
8
 * modification, are permitted provided that the following conditions are met:
 
9
 * * Redistributions of source code must retain the above copyright notice, this
 
10
 *   list of conditions and the following disclaimer.
 
11
 * * Redistributions in binary form must reproduce the above copyright notice,
 
12
 *   this list of conditions and the following disclaimer in the documentation
 
13
 *   and/or other materials provided with the distribution.
 
14
 * * Neither the name of the HISP project nor the names of its contributors may
 
15
 *   be used to endorse or promote products derived from this software without
 
16
 *   specific prior written permission.
 
17
 *
 
18
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 
19
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 
20
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 
21
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 
22
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 
23
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 
24
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 
25
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
26
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 
27
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
28
 */
 
29
 
 
30
import java.io.Serializable;
 
31
 
 
32
/**
 
33
 * @author Lars Helge Overland
 
34
 * @version $Id$
 
35
 */
 
36
public class RelativePeriods
 
37
    implements Serializable
 
38
{
 
39
    public static final String REPORTING_MONTH = "reporting_month";    
 
40
    public static final String LAST_3_MONTHS = "last3_months";
 
41
    public static final String LAST_6_MONTHS = "last6_months";
 
42
    public static final String LAST_9_MONTHS = "last9_months";
 
43
    public static final String LAST_12_MONTHS = "last12_months";
 
44
    public static final String SO_FAR_THIS_YEAR = "so_far_this_year";
 
45
    public static final String SO_FAR_THIS_FINANCIAL_YEAR = "so_far_this_financial_year";    
 
46
    public static final String LAST_3_TO_6_MONTHS = "last3_6_months";
 
47
    public static final String LAST_6_TO_9_MONTHS = "last6_9_months";
 
48
    public static final String LAST_9_TO_12_MONTHS = "last9_12_months";
 
49
    
 
50
    public static final String[] PREVIOUS_MONTH_NAMES = { 
 
51
        "previous_month_1",
 
52
        "previous_month_2",
 
53
        "previous_month_3",
 
54
        "previous_month_4",
 
55
        "previous_month_5",
 
56
        "previous_month_6",
 
57
        "previous_month_7",
 
58
        "previous_month_8",
 
59
        "previous_month_9",
 
60
        "previous_month_10",
 
61
        "previous_month_11",
 
62
        "previous_month_12" };
 
63
    
 
64
    public static final String[] MONTHS_THIS_YEAR = {
 
65
        "january",
 
66
        "february",
 
67
        "march",
 
68
        "april",
 
69
        "may",
 
70
        "june",
 
71
        "july",
 
72
        "august",
 
73
        "september",
 
74
        "october",
 
75
        "november",
 
76
        "december" };
 
77
    
 
78
    public static final String[] QUARTERS_THIS_YEAR = {
 
79
        "quarter1",
 
80
        "quarter2",
 
81
        "quarter3",
 
82
        "quarter4" };
 
83
    
 
84
    private Boolean reportingMonth;
 
85
    
 
86
    private Boolean last3Months;
 
87
    
 
88
    private Boolean last6Months;
 
89
    
 
90
    private Boolean last9Months;
 
91
    
 
92
    private Boolean last12Months;
 
93
    
 
94
    private Boolean soFarThisYear;
 
95
    
 
96
    private Boolean soFarThisFinancialYear;
 
97
    
 
98
    private Boolean last3To6Months;
 
99
    
 
100
    private Boolean last6To9Months;
 
101
    
 
102
    private Boolean last9To12Months;
 
103
    
 
104
    private Boolean last12IndividualMonths;
 
105
    
 
106
    private Boolean individualMonthsThisYear;
 
107
    
 
108
    private Boolean individualQuartersThisYear;
 
109
    
 
110
    // -------------------------------------------------------------------------
 
111
    // Constructors
 
112
    // -------------------------------------------------------------------------
 
113
 
 
114
    public RelativePeriods()
 
115
    {   
 
116
    }
 
117
 
 
118
    public RelativePeriods( boolean reportingMonth, boolean last3Months,
 
119
        boolean last6Months, boolean last9Months, boolean last12Months, boolean soFarThisYear, boolean soFarThisFinancialYear,
 
120
        boolean last3To6Months, boolean last6To9Months, boolean last9To12Months,
 
121
        boolean last12IndividualMonths, boolean individualMonthsThisYear, boolean individualQuartersThisYear )
 
122
    {
 
123
        this.reportingMonth = reportingMonth;
 
124
        this.last3Months = last3Months;
 
125
        this.last6Months = last6Months;
 
126
        this.last9Months = last9Months;
 
127
        this.last12Months = last12Months;
 
128
        this.soFarThisYear = soFarThisYear;
 
129
        this.soFarThisFinancialYear = soFarThisFinancialYear;
 
130
        this.last3To6Months = last3To6Months;
 
131
        this.last6To9Months = last6To9Months;
 
132
        this.last9To12Months = last9To12Months;
 
133
        this.last12IndividualMonths = last12IndividualMonths;
 
134
        this.individualMonthsThisYear = individualMonthsThisYear;
 
135
        this.individualQuartersThisYear = individualQuartersThisYear;
 
136
    }
 
137
 
 
138
    // -------------------------------------------------------------------------
 
139
    // Logic
 
140
    // -------------------------------------------------------------------------
 
141
 
 
142
    public boolean isReportingMonth()
 
143
    {
 
144
        return reportingMonth != null && reportingMonth;
 
145
    }
 
146
    
 
147
    public boolean isLast3Months()
 
148
    {
 
149
        return last3Months != null && last3Months;
 
150
    }
 
151
    
 
152
    public boolean isLast6Months()
 
153
    {
 
154
        return last6Months != null && last6Months;
 
155
    }
 
156
    
 
157
    public boolean isLast9Months()
 
158
    {
 
159
        return last9Months != null && last9Months;
 
160
    }
 
161
    
 
162
    public boolean isLast12Months()
 
163
    {
 
164
        return last12Months != null && last12Months;
 
165
    }
 
166
    
 
167
    public boolean isSoFarThisYear()
 
168
    {
 
169
        return soFarThisYear != null && soFarThisYear;
 
170
    }
 
171
    
 
172
    public boolean isSoFarThisFinancialYear()
 
173
    {
 
174
        return soFarThisFinancialYear != null && soFarThisFinancialYear;
 
175
    }
 
176
    
 
177
    public boolean isLast3To6Months()
 
178
    {
 
179
        return last3To6Months != null && last3To6Months;
 
180
    }
 
181
    
 
182
    public boolean isLast6To9Months()
 
183
    {
 
184
        return last6To9Months != null && last6To9Months;
 
185
    }
 
186
    
 
187
    public boolean isLast9To12Months()
 
188
    {
 
189
        return last9To12Months != null && last9To12Months;
 
190
    }
 
191
    
 
192
    public boolean isLast12IndividualMonths()
 
193
    {
 
194
        return last12IndividualMonths != null && last12IndividualMonths;
 
195
    }
 
196
    
 
197
    public boolean isIndividualMonthsThisYear()
 
198
    {
 
199
        return individualMonthsThisYear != null && individualMonthsThisYear;
 
200
    }
 
201
    
 
202
    public boolean isIndividualQuartersThisYear()
 
203
    {
 
204
        return individualQuartersThisYear != null && individualQuartersThisYear;
 
205
    }
 
206
        
 
207
    // -------------------------------------------------------------------------
 
208
    // Getters & setters
 
209
    // -------------------------------------------------------------------------
 
210
 
 
211
    public Boolean getReportingMonth()
 
212
    {
 
213
        return reportingMonth;
 
214
    }
 
215
 
 
216
    public void setReportingMonth( Boolean reportingMonth )
 
217
    {
 
218
        this.reportingMonth = reportingMonth;
 
219
    }
 
220
    
 
221
    public Boolean getLast3Months()
 
222
    {
 
223
        return last3Months;
 
224
    }
 
225
 
 
226
    public void setLast3Months( Boolean last3Months )
 
227
    {
 
228
        this.last3Months = last3Months;
 
229
    }
 
230
 
 
231
    public Boolean getLast6Months()
 
232
    {
 
233
        return last6Months;
 
234
    }
 
235
 
 
236
    public void setLast6Months( Boolean last6Months )
 
237
    {
 
238
        this.last6Months = last6Months;
 
239
    }
 
240
 
 
241
    public Boolean getLast9Months()
 
242
    {
 
243
        return last9Months;
 
244
    }
 
245
 
 
246
    public void setLast9Months( Boolean last9Months )
 
247
    {
 
248
        this.last9Months = last9Months;
 
249
    }
 
250
 
 
251
    public Boolean getLast12Months()
 
252
    {
 
253
        return last12Months;
 
254
    }
 
255
 
 
256
    public void setLast12Months( Boolean last12Months )
 
257
    {
 
258
        this.last12Months = last12Months;
 
259
    }
 
260
 
 
261
    public Boolean getSoFarThisYear()
 
262
    {
 
263
        return soFarThisYear;
 
264
    }
 
265
 
 
266
    public void setSoFarThisYear( Boolean soFarThisYear )
 
267
    {
 
268
        this.soFarThisYear = soFarThisYear;
 
269
    }
 
270
 
 
271
    public Boolean getSoFarThisFinancialYear()
 
272
    {
 
273
        return soFarThisFinancialYear;
 
274
    }
 
275
 
 
276
    public void setSoFarThisFinancialYear( Boolean soFarThisFinancialYear )
 
277
    {
 
278
        this.soFarThisFinancialYear = soFarThisFinancialYear;
 
279
    }
 
280
 
 
281
    public Boolean getLast3To6Months()
 
282
    {
 
283
        return last3To6Months;
 
284
    }
 
285
 
 
286
    public void setLast3To6Months( Boolean last3To6Months )
 
287
    {
 
288
        this.last3To6Months = last3To6Months;
 
289
    }
 
290
 
 
291
    public Boolean getLast6To9Months()
 
292
    {
 
293
        return last6To9Months;
 
294
    }
 
295
 
 
296
    public void setLast6To9Months( Boolean last6To9Months )
 
297
    {
 
298
        this.last6To9Months = last6To9Months;
 
299
    }
 
300
 
 
301
    public Boolean getLast9To12Months()
 
302
    {
 
303
        return last9To12Months;
 
304
    }
 
305
 
 
306
    public void setLast9To12Months( Boolean last9To12Months )
 
307
    {
 
308
        this.last9To12Months = last9To12Months;
 
309
    }
 
310
 
 
311
    public Boolean getLast12IndividualMonths()
 
312
    {
 
313
        return last12IndividualMonths;
 
314
    }
 
315
 
 
316
    public void setLast12IndividualMonths( Boolean last12IndividualMonths )
 
317
    {
 
318
        this.last12IndividualMonths = last12IndividualMonths;
 
319
    }
 
320
 
 
321
    public Boolean getIndividualMonthsThisYear()
 
322
    {
 
323
        return individualMonthsThisYear;
 
324
    }
 
325
 
 
326
    public void setIndividualMonthsThisYear( Boolean individualMonthsThisYear )
 
327
    {
 
328
        this.individualMonthsThisYear = individualMonthsThisYear;
 
329
    }
 
330
 
 
331
    public Boolean getIndividualQuartersThisYear()
 
332
    {
 
333
        return individualQuartersThisYear;
 
334
    }
 
335
 
 
336
    public void setIndividualQuartersThisYear( Boolean individualQuartersThisYear )
 
337
    {
 
338
        this.individualQuartersThisYear = individualQuartersThisYear;
 
339
    }
 
340
 
 
341
    // -------------------------------------------------------------------------
 
342
    // Equals, hashCode, and toString
 
343
    // -------------------------------------------------------------------------
 
344
 
 
345
    @Override
 
346
    public String toString()
 
347
    {
 
348
        String toString = "[Reporting month: " + reportingMonth +
 
349
            ", Last 3 months: " + last3Months +
 
350
            ", Last 6 months: " + last6Months +
 
351
            ", Last 9 months: " + last9Months +
 
352
            ", Last 12 months: " + last12Months +
 
353
            ", So far this year: " + soFarThisYear + 
 
354
            ", So far this financial year: " + soFarThisFinancialYear +
 
355
            ", Last 3 to 6 months: " + last3To6Months +
 
356
            ", Last 6 to 9 months: " + last6To9Months +
 
357
            ", Last 9 to 12 months: " + last9To12Months + 
 
358
            ", Last 12 Individual months: " + last12IndividualMonths + 
 
359
            ", Individual months this year: " + individualMonthsThisYear +
 
360
            ", Individual quarters this year: " + individualQuartersThisYear + "]";
 
361
        
 
362
        return toString;
 
363
    }
 
364
 
 
365
    @Override
 
366
    public int hashCode()
 
367
    {
 
368
        final int prime = 31;
 
369
        
 
370
        int result = 1;
 
371
        
 
372
        result = prime * result + ( ( last12Months == null ) ? 0 : last12Months.hashCode() );
 
373
        result = prime * result + ( ( last3Months == null ) ? 0 : last3Months.hashCode() );
 
374
        result = prime * result + ( ( last3To6Months == null ) ? 0 : last3To6Months.hashCode() );
 
375
        result = prime * result + ( ( last6Months == null ) ? 0 : last6Months.hashCode() );
 
376
        result = prime * result + ( ( last6To9Months == null ) ? 0 : last6To9Months.hashCode() );
 
377
        result = prime * result + ( ( last9Months == null ) ? 0 : last9Months.hashCode() );
 
378
        result = prime * result + ( ( last9To12Months == null ) ? 0 : last9To12Months.hashCode() );
 
379
        result = prime * result + ( ( reportingMonth == null ) ? 0 : reportingMonth.hashCode() );
 
380
        result = prime * result + ( ( soFarThisYear == null ) ? 0 : soFarThisYear.hashCode() );
 
381
        result = prime * result + ( ( soFarThisFinancialYear == null ) ? 0 : soFarThisFinancialYear.hashCode() );
 
382
        result = prime * result + ( ( last12IndividualMonths == null ) ? 0 : last12IndividualMonths.hashCode() );
 
383
        result = prime * result + ( ( individualMonthsThisYear == null ) ? 0 : individualMonthsThisYear.hashCode() );
 
384
        result = prime * result + ( ( individualQuartersThisYear == null ) ? 0 : individualQuartersThisYear.hashCode() );
 
385
        
 
386
        return result;
 
387
    }
 
388
 
 
389
    @Override
 
390
    public boolean equals( Object object )
 
391
    {
 
392
        if ( this == object )
 
393
        {
 
394
            return true;
 
395
        }
 
396
        
 
397
        if ( object == null )
 
398
        {
 
399
            return false;
 
400
        }
 
401
        
 
402
        if ( getClass() != object.getClass() )
 
403
        {
 
404
            return false;
 
405
        }
 
406
        
 
407
        final RelativePeriods other = (RelativePeriods) object;
 
408
        
 
409
        if ( last12Months == null )
 
410
        {
 
411
            if ( other.last12Months != null )
 
412
            {
 
413
                return false;
 
414
            }
 
415
        }
 
416
        else if ( !last12Months.equals( other.last12Months ) )
 
417
        {
 
418
            return false;
 
419
        }
 
420
        
 
421
        if ( last3Months == null )
 
422
        {
 
423
            if ( other.last3Months != null )
 
424
            {
 
425
                return false;
 
426
            }
 
427
        }
 
428
        else if ( !last3Months.equals( other.last3Months ) )
 
429
        {
 
430
            return false;
 
431
        }
 
432
        
 
433
        if ( last3To6Months == null )
 
434
        {
 
435
            if ( other.last3To6Months != null )
 
436
            {
 
437
                return false;
 
438
            }
 
439
        }
 
440
        else if ( !last3To6Months.equals( other.last3To6Months ) )
 
441
        {
 
442
            return false;
 
443
        }
 
444
        
 
445
        if ( last6Months == null )
 
446
        {
 
447
            if ( other.last6Months != null )
 
448
            {
 
449
                return false;
 
450
            }
 
451
        }
 
452
        else if ( !last6Months.equals( other.last6Months ) )
 
453
        {
 
454
            return false;
 
455
        }
 
456
        
 
457
        if ( last6To9Months == null )
 
458
        {
 
459
            if ( other.last6To9Months != null )
 
460
            {
 
461
                return false;
 
462
            }
 
463
        }
 
464
        else if ( !last6To9Months.equals( other.last6To9Months ) )
 
465
        {
 
466
            return false;
 
467
        }
 
468
        
 
469
        if ( last9Months == null )
 
470
        {
 
471
            if ( other.last9Months != null )
 
472
            {
 
473
                return false;
 
474
            }
 
475
        }
 
476
        else if ( !last9Months.equals( other.last9Months ) )
 
477
        {
 
478
            return false;
 
479
        }
 
480
        
 
481
        if ( last9To12Months == null )
 
482
        {
 
483
            if ( other.last9To12Months != null )
 
484
            {
 
485
                return false;
 
486
            }
 
487
        }
 
488
        else if ( !last9To12Months.equals( other.last9To12Months ) )
 
489
        {
 
490
            return false;
 
491
        }
 
492
        
 
493
        if ( reportingMonth == null )
 
494
        {
 
495
            if ( other.reportingMonth != null )
 
496
            {
 
497
                return false;
 
498
            }
 
499
        }
 
500
        else if ( !reportingMonth.equals( other.reportingMonth ) )
 
501
        {
 
502
            return false;
 
503
        }
 
504
        
 
505
        if ( soFarThisYear == null )
 
506
        {
 
507
            if ( other.soFarThisYear != null )
 
508
            {
 
509
                return false;
 
510
            }
 
511
        }
 
512
        else if ( !soFarThisYear.equals( other.soFarThisYear ) )
 
513
        {
 
514
            return false;
 
515
        }
 
516
 
 
517
        if ( soFarThisFinancialYear == null )
 
518
        {
 
519
            if ( other.soFarThisFinancialYear != null )
 
520
            {
 
521
                return false;
 
522
            }
 
523
        }
 
524
        else if ( !soFarThisFinancialYear.equals( other.soFarThisFinancialYear ) )
 
525
        {
 
526
            return false;
 
527
        }
 
528
        
 
529
        if ( last12IndividualMonths == null )
 
530
        {
 
531
            if ( other.last12IndividualMonths != null )
 
532
            {
 
533
                return false;
 
534
            }
 
535
        }
 
536
        else if ( !last12IndividualMonths.equals( other.last12IndividualMonths ) )
 
537
        {
 
538
            return false;
 
539
        }
 
540
 
 
541
        if ( individualMonthsThisYear == null )
 
542
        {
 
543
            if ( other.individualMonthsThisYear != null )
 
544
            {
 
545
                return false;
 
546
            }
 
547
        }
 
548
        else if ( !individualMonthsThisYear.equals( other.individualMonthsThisYear ) )
 
549
        {
 
550
            return false;
 
551
        }
 
552
 
 
553
        if ( individualQuartersThisYear == null )
 
554
        {
 
555
            if ( other.individualQuartersThisYear != null )
 
556
            {
 
557
                return false;
 
558
            }
 
559
        }
 
560
        else if ( !individualQuartersThisYear.equals( other.individualQuartersThisYear ) )
 
561
        {
 
562
            return false;
 
563
        }
 
564
        
 
565
        return true;
 
566
    }
 
567
}