1 /***
2 * Copyright 2003-2010 Terracotta, Inc.
3 *
4 * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
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 net.sf.ehcache.hibernate.domain;
17
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 import java.text.DateFormat;
22 import java.text.ParseException;
23 import java.text.SimpleDateFormat;
24 import java.util.Date;
25 import java.util.HashMap;
26 import java.util.Map;
27
28 public class HolidayCalendar {
29
30 private static final Logger LOG = LoggerFactory.getLogger(HolidayCalendar.class);
31
32 private Long id;
33
34 private Map holidays = new HashMap();
35
36 public HolidayCalendar init() {
37 DateFormat df = new SimpleDateFormat("yyyy.MM.dd");
38 try {
39 holidays.clear();
40 holidays.put(df.parse("2009.01.01"), "New Year's Day");
41 holidays.put(df.parse("2009.02.14"), "Valentine's Day");
42 holidays.put(df.parse("2009.11.11"), "Armistice Day");
43 } catch (ParseException e) {
44 LOG.info("Error parsing date string");
45 throw new RuntimeException(e);
46 }
47 return this;
48 }
49
50 public Map getHolidays() {
51 return holidays;
52 }
53
54 protected void setHolidays(Map holidays) {
55 this.holidays = holidays;
56 }
57
58 public void addHoliday(Date d, String name) {
59 holidays.put(d, name);
60 }
61
62 public String getHoliday(Date d) {
63 return (String) holidays.get(d);
64 }
65
66 public boolean isHoliday(Date d) {
67 return holidays.containsKey(d);
68 }
69
70 protected Long getId() {
71 return id;
72 }
73
74 protected void setId(Long id) {
75 this.id = id;
76 }
77 }
78