001    /**
002     * Copyright 2004-2013 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.hr.lm.accrual;
017    
018    import java.util.ArrayList;
019    import java.util.Date;
020    import java.util.List;
021    import java.util.Map;
022    
023    import org.kuali.hr.time.calendar.CalendarEntries;
024    
025    public class RateRangeAggregate {
026            private List<RateRange> rateRanges = new ArrayList<RateRange>();
027            private RateRange currentRate;
028            private boolean rateRangeChanged;
029            private Map<String, List<CalendarEntries>> calEntryMap;
030            
031            public RateRange getRate(Date date) {           
032                    rateRangeChanged = false;
033                    if (currentRate == null) {
034                            currentRate = rateRanges.get(0);
035                    }
036                    
037                    if (currentRate.getRange().contains(date.getTime())) {
038                            for (RateRange rateRange : rateRanges) {
039                                    if (rateRange.getRange().contains(date.getTime())) {
040                                            rateRangeChanged = rateRange.getAccrualRatePercentageModifier() != currentRate.getAccrualRatePercentageModifier();
041                                            currentRate = rateRange;
042                                            break;
043                                    }
044                            }
045                    }
046                    return currentRate;
047            }
048            
049            public List<RateRange> getRateRanges() {
050                    return rateRanges;
051            }
052            public void setRateRanges(List<RateRange> rateRanges) {
053                    this.rateRanges = rateRanges;
054            }
055            public RateRange getCurrentRate() {
056                    return currentRate;
057            }
058            public void setCurrentRate(RateRange currentRate) {
059                    this.currentRate = currentRate;
060            }
061            public boolean isRateRangeChanged() {
062                    return rateRangeChanged;
063            }
064            public void setRateRangeChanged(boolean rateRangeChanged) {
065                    this.rateRangeChanged = rateRangeChanged;
066            }
067            
068            // return the rateRange on the given day
069            public RateRange getRateOnDate(Date date) {
070                    for (RateRange rateRange : rateRanges) {
071                            if (rateRange.getRange().contains(date.getTime())) {
072                                    return rateRange;
073                            }
074                    }
075                    return null;
076            }
077    
078            public Map<String, List<CalendarEntries>> getCalEntryMap() {
079                    return calEntryMap;
080            }
081    
082            public void setCalEntryMap(Map<String, List<CalendarEntries>> calEntryMap) {
083                    this.calEntryMap = calEntryMap;
084            }
085            
086    
087    }