View Javadoc

1   /**
2    * Copyright 2004-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.kpme.tklm.leave.accrual;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  import java.util.Map;
21  
22  import org.joda.time.DateTime;
23  import org.kuali.kpme.core.calendar.entry.CalendarEntry;
24  import org.kuali.kpme.tklm.api.leave.accrual.RateRangeAggregateContract;
25  
26  public class RateRangeAggregate implements RateRangeAggregateContract {
27  	private List<RateRange> rateRanges = new ArrayList<RateRange>();
28  	private RateRange currentRate;
29  	private boolean rateRangeChanged;
30  	private Map<String, List<CalendarEntry>> calEntryMap;
31  	
32  	public RateRange getRate(DateTime date) {		
33  		rateRangeChanged = false;
34  		if (currentRate == null) {
35  			currentRate = rateRanges.get(0);
36  		}
37  		
38  		if (currentRate.getRange().contains(date)) {
39  			for (RateRange rateRange : rateRanges) {
40  				if (rateRange.getRange().contains(date)) {
41  					rateRangeChanged = rateRange.getAccrualRatePercentageModifier() != currentRate.getAccrualRatePercentageModifier();
42  					currentRate = rateRange;
43  					break;
44  				}
45  			}
46  		}
47  		return currentRate;
48  	}
49  	
50  	public List<RateRange> getRateRanges() {
51  		return rateRanges;
52  	}
53  	public void setRateRanges(List<RateRange> rateRanges) {
54  		this.rateRanges = rateRanges;
55  	}
56  	public RateRange getCurrentRate() {
57  		return currentRate;
58  	}
59  	public void setCurrentRate(RateRange currentRate) {
60  		this.currentRate = currentRate;
61  	}
62  	public boolean isRateRangeChanged() {
63  		return rateRangeChanged;
64  	}
65  	public void setRateRangeChanged(boolean rateRangeChanged) {
66  		this.rateRangeChanged = rateRangeChanged;
67  	}
68  	
69  	// return the rateRange on the given day
70  	public RateRange getRateOnDate(DateTime date) {
71  		for (RateRange rateRange : rateRanges) {
72  			if (rateRange.getRange().contains(date)) {
73  				return rateRange;
74  			}
75  		}
76  		return null;
77  	}
78  
79  	public Map<String, List<CalendarEntry>> getCalEntryMap() {
80  		return calEntryMap;
81  	}
82  
83  	public void setCalEntryMap(Map<String, List<CalendarEntry>> calEntryMap) {
84  		this.calEntryMap = calEntryMap;
85  	}
86  	
87  
88  }