Coverage Report - de.jollyday.Holiday
 
Classes in this File Line Coverage Branch Coverage Complexity
Holiday
88%
24/27
92%
13/14
1,889
 
 1  
 /**
 2  
  * Copyright 2010 Sven Diedrichsen 
 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 
 12  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 
 13  
  * express or implied. See the License for the specific language 
 14  
  * governing permissions and limitations under the License. 
 15  
  */
 16  
 package de.jollyday;
 17  
 
 18  
 import java.time.LocalDate;
 19  
 import java.util.Locale;
 20  
 
 21  
 import de.jollyday.util.ResourceUtil;
 22  
 
 23  
 /**
 24  
  * Represents the holiday and contains the actual date and an localized
 25  
  * description.
 26  
  * 
 27  
  * @author Sven Diedrichsen
 28  
  * @version $Id: $
 29  
  */
 30  
 public final class Holiday {
 31  
         /**
 32  
          * The calculated hashcode cached for performance.
 33  
          */
 34  2831
         private int hashCode = 0;
 35  
         /**
 36  
          * The date the holiday occurs.
 37  
          */
 38  
         private final LocalDate date;
 39  
         /**
 40  
          * The properties key to retrieve the description with.
 41  
          */
 42  
         private final String propertiesKey;
 43  
 
 44  
         /**
 45  
          * The type of holiday. e.g. official holiday or not.
 46  
          * */
 47  
         private final HolidayType type;
 48  
         /**
 49  
          * Utility for accessing resources.
 50  
          */
 51  2831
         private ResourceUtil resourceUtil = new ResourceUtil();
 52  
 
 53  
         /**
 54  
          * Constructs a holiday for a date using the provided properties key to
 55  
          * retrieve the description with.
 56  
          * 
 57  
          * @param date
 58  
          *            a {@link LocalDate} object.
 59  
          * @param propertiesKey
 60  
          *            a {@link java.lang.String} object.
 61  
          * @param type
 62  
          *            a {@link de.jollyday.HolidayType} object.
 63  
          */
 64  
         public Holiday(LocalDate date, String propertiesKey, HolidayType type) {
 65  2831
                 super();
 66  2831
                 this.type = type;
 67  2831
                 this.date = date;
 68  2831
                 this.propertiesKey = propertiesKey == null ? "" : propertiesKey;
 69  2831
         }
 70  
 
 71  
         /**
 72  
          * <p>
 73  
          * Getter for the field <code>date</code>.
 74  
          * </p>
 75  
          * 
 76  
          * @return the holiday date
 77  
          */
 78  
         public LocalDate getDate() {
 79  19893
                 return date;
 80  
         }
 81  
 
 82  
         /**
 83  
          * <p>
 84  
          * Getter for the field <code>propertiesKey</code>.
 85  
          * </p>
 86  
          * 
 87  
          * @return the holidays properties key
 88  
          */
 89  
         public String getPropertiesKey() {
 90  1293
                 return propertiesKey;
 91  
         }
 92  
 
 93  
         /**
 94  
          * The description read with the default locale.
 95  
          * 
 96  
          * @return Description for this holiday
 97  
          */
 98  
         public String getDescription() {
 99  1290
                 return resourceUtil.getHolidayDescription(Locale.getDefault(), getPropertiesKey());
 100  
         }
 101  
 
 102  
         /**
 103  
          * The description read with the provided locale.
 104  
          * 
 105  
          * @param locale
 106  
          *            a {@link java.util.Locale} object.
 107  
          * @return Description for this holiday
 108  
          */
 109  
         public String getDescription(Locale locale) {
 110  3
                 return resourceUtil.getHolidayDescription(locale, getPropertiesKey());
 111  
         }
 112  
 
 113  
         @Override
 114  
         public boolean equals(Object obj) {
 115  5
                 if (obj == this) {
 116  1
                         return true;
 117  
                 }
 118  4
                 if (obj instanceof Holiday) {
 119  4
                         Holiday other = (Holiday) obj;
 120  4
                         return other.date.equals(this.date) && other.propertiesKey.equals(this.propertiesKey)
 121  2
                                         && type.equals(other.type);
 122  
                 }
 123  0
                 return false;
 124  
         }
 125  
 
 126  
         @Override
 127  
         public int hashCode() {
 128  2830
                 if (hashCode == 0) {
 129  2825
                         int hash = 1;
 130  2825
                         hash = hash * 31 + date.hashCode();
 131  2825
                         hash = hash * 31 + propertiesKey.hashCode();
 132  2825
                         hash = hash * 31 + type.hashCode();
 133  2825
                         hashCode = hash;
 134  
                 }
 135  2830
                 return hashCode;
 136  
         }
 137  
 
 138  
         @Override
 139  
         public String toString() {
 140  0
                 return date.toString() + " (" + getDescription() + ")";
 141  
         }
 142  
 
 143  
         /**
 144  
          * Gets the type holiday.
 145  
          * 
 146  
          * @return the type holiday
 147  
          */
 148  
         public HolidayType getType() {
 149  0
                 return type;
 150  
         }
 151  
 }