You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by mb...@apache.org on 2017/10/12 22:07:59 UTC

svn commit: r1812057 - /ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/calendar/

Author: mbrohl
Date: Thu Oct 12 22:07:59 2017
New Revision: 1812057

URL: http://svn.apache.org/viewvc?rev=1812057&view=rev
Log:
Improved: Fixing defects reported by FindBugs, package 
org.apache.ofbiz.service.calendar.
(OFBIZ-9691)

Thanks Dennis Balkir for reporting and providing the patch.

Modified:
    ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/calendar/ExpressionUiHelper.java
    ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/calendar/RecurrenceInfo.java
    ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/calendar/RecurrenceRule.java
    ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/calendar/TemporalExpression.java
    ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/calendar/TemporalExpressionWorker.java
    ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/calendar/TemporalExpressions.java

Modified: ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/calendar/ExpressionUiHelper.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/calendar/ExpressionUiHelper.java?rev=1812057&r1=1812056&r2=1812057&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/calendar/ExpressionUiHelper.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/calendar/ExpressionUiHelper.java Thu Oct 12 22:07:59 2017
@@ -39,7 +39,7 @@ import com.ibm.icu.util.Calendar;
 public class ExpressionUiHelper {
 
     /** An array of valid DayInMonth occurrence values. */
-    public static final int Occurrence[] = {1, 2, 3, 4, 5, -1, -2, -3, -4 -5};
+    private static final int Occurrence[] = {1, 2, 3, 4, 5, -1, -2, -3, -4 -5};
 
     /** Returns a List of valid DayInMonth occurrence int values.
      * @return returns a List of valid DayInMonth occurrence int values
@@ -57,7 +57,7 @@ public class ExpressionUiHelper {
         Calendar tempCal = Calendar.getInstance(locale);
         tempCal.set(Calendar.DAY_OF_WEEK, tempCal.getFirstDayOfWeek());
         SimpleDateFormat dateFormat = new SimpleDateFormat("EEEE", locale);
-        List<Map<String, Object>> result = new ArrayList<Map<String, Object>>(7);
+        List<Map<String, Object>> result = new ArrayList<>(7);
         for (int i = 0; i < 7; i++) {
             result.add(UtilMisc.toMap("description", (Object)dateFormat.format(tempCal.getTime()), "value", tempCal.get(Calendar.DAY_OF_WEEK)));
             tempCal.roll(Calendar.DAY_OF_WEEK, 1);
@@ -94,7 +94,7 @@ public class ExpressionUiHelper {
         Calendar tempCal = Calendar.getInstance(locale);
         tempCal.set(Calendar.MONTH, Calendar.JANUARY);
         SimpleDateFormat dateFormat = new SimpleDateFormat("MMMM", locale);
-        List<Map<String, Object>> result = new ArrayList<Map<String, Object>>(13);
+        List<Map<String, Object>> result = new ArrayList<>(13);
         for (int i = Calendar.JANUARY; i <= tempCal.getActualMaximum(Calendar.MONTH); i++) {
             result.add(UtilMisc.toMap("description", (Object)dateFormat.format(tempCal.getTime()), "value", i));
             tempCal.roll(Calendar.MONTH, 1);
@@ -108,7 +108,7 @@ public class ExpressionUiHelper {
      * <code>description</code> entry and a <code>value</code> entry.
      */
     public static List<Map<String, Object>> getFrequencyValueList(Map<String, Object> uiLabelMap) {
-        List<Map<String, Object>> result = new ArrayList<Map<String, Object>>(6);
+        List<Map<String, Object>> result = new ArrayList<>(6);
         result.add(UtilMisc.toMap("description", uiLabelMap.get("CommonSecond"), "value", Calendar.SECOND));
         result.add(UtilMisc.toMap("description", uiLabelMap.get("CommonMinute"), "value", Calendar.MINUTE));
         result.add(UtilMisc.toMap("description", uiLabelMap.get("CommonHour"), "value", Calendar.HOUR_OF_DAY));
@@ -125,7 +125,7 @@ public class ExpressionUiHelper {
      */
     public static List<Map<String, Object>> getExpressionTypeList(Map<String, Object> uiLabelMap) {
         int listSize = TemporalExpressionWorker.getExpressionTypeList().length;
-        List<Map<String, Object>> result = new ArrayList<Map<String, Object>>(listSize);
+        List<Map<String, Object>> result = new ArrayList<>(listSize);
         for (int i = 0; i < listSize; i++) {
             String exprType = TemporalExpressionWorker.getExpressionTypeList()[i];
             result.add(UtilMisc.toMap("description", uiLabelMap.get("TemporalExpression_" + exprType), "value", exprType));
@@ -145,13 +145,13 @@ public class ExpressionUiHelper {
                                                  .where("fromTempExprId", tempExprId)
                                                  .cache(true)
                                                  .queryList();
-        Set<String> excludedIds = new HashSet<String>();
+        Set<String> excludedIds = new HashSet<>();
         for (GenericValue value : findList) {
             excludedIds.add(value.getString("toTempExprId"));
         }
         excludedIds.add(tempExprId);
         findList = EntityQuery.use(delegator).from("TemporalExpression").cache(true).queryList();
-        Set<String> candidateIds = new HashSet<String>();
+        Set<String> candidateIds = new HashSet<>();
         for (GenericValue value : findList) {
             candidateIds.add(value.getString("tempExprId"));
         }

Modified: ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/calendar/RecurrenceInfo.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/calendar/RecurrenceInfo.java?rev=1812057&r1=1812056&r2=1812057&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/calendar/RecurrenceInfo.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/calendar/RecurrenceInfo.java Thu Oct 12 22:07:59 2017
@@ -75,7 +75,7 @@ public class RecurrenceInfo {
 
         // Get the recurrence rules objects
         try {
-            rRulesList = new ArrayList<RecurrenceRule>();
+            rRulesList = new ArrayList<>();
             for (GenericValue value: info.getRelated("RecurrenceRule", null, null, false)) {
                 rRulesList.add(new RecurrenceRule(value));
             }
@@ -87,7 +87,7 @@ public class RecurrenceInfo {
 
         // Get the exception rules objects
         try {
-            eRulesList = new ArrayList<RecurrenceRule>();
+            eRulesList = new ArrayList<>();
             for (GenericValue value: info.getRelated("ExceptionRecurrenceRule", null, null, false)) {
                 eRulesList.add(new RecurrenceRule(value));
             }
@@ -114,7 +114,7 @@ public class RecurrenceInfo {
 
     /** Returns the startDate Date object. */
     public Date getStartDate() {
-        return this.startDate;
+        return (Date) this.startDate.clone();
     }
 
     /** Returns the long value of the startDate. */
@@ -164,7 +164,7 @@ public class RecurrenceInfo {
 
     /** Removes the recurrence from persistant store. */
     public void remove() throws RecurrenceInfoException {
-        List<RecurrenceRule> rulesList = new ArrayList<RecurrenceRule>();
+        List<RecurrenceRule> rulesList = new ArrayList<>();
 
         rulesList.addAll(rRulesList);
         rulesList.addAll(eRulesList);

Modified: ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/calendar/RecurrenceRule.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/calendar/RecurrenceRule.java?rev=1812057&r1=1812056&r2=1812057&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/calendar/RecurrenceRule.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/calendar/RecurrenceRule.java Thu Oct 12 22:07:59 2017
@@ -22,6 +22,7 @@ import java.util.Arrays;
 import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Locale;
 
 import org.apache.ofbiz.base.util.Debug;
 import org.apache.ofbiz.base.util.StringUtil;
@@ -195,7 +196,7 @@ public class RecurrenceRule {
      *@return String The name of this frequency.
      */
     public String getFrequencyName() {
-        return rule.getString("frequency").toUpperCase();
+        return rule.getString("frequency").toUpperCase(Locale.getDefault());
     }
 
     /**
@@ -721,21 +722,23 @@ public class RecurrenceRule {
 
     // Returns the Calendar day of the rule day string
     private int getCalendarDay(String day) {
-        if (day != null) day = day.trim();
-        if (day.equalsIgnoreCase("MO"))
-            return Calendar.MONDAY;
-        if (day.equalsIgnoreCase("TU"))
-            return Calendar.TUESDAY;
-        if (day.equalsIgnoreCase("WE"))
-            return Calendar.WEDNESDAY;
-        if (day.equalsIgnoreCase("TH"))
-            return Calendar.THURSDAY;
-        if (day.equalsIgnoreCase("FR"))
-            return Calendar.FRIDAY;
-        if (day.equalsIgnoreCase("SA"))
-            return Calendar.SATURDAY;
-        if (day.equalsIgnoreCase("SU"))
-            return Calendar.SUNDAY;
+        if (day != null) {
+            day = day.trim();
+            if (day.equalsIgnoreCase("MO"))
+                return Calendar.MONDAY;
+            if (day.equalsIgnoreCase("TU"))
+                return Calendar.TUESDAY;
+            if (day.equalsIgnoreCase("WE"))
+                return Calendar.WEDNESDAY;
+            if (day.equalsIgnoreCase("TH"))
+                return Calendar.THURSDAY;
+            if (day.equalsIgnoreCase("FR"))
+                return Calendar.FRIDAY;
+            if (day.equalsIgnoreCase("SA"))
+                return Calendar.SATURDAY;
+            if (day.equalsIgnoreCase("SU"))
+                return Calendar.SUNDAY;
+        }
         return 0;
     }
 

Modified: ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/calendar/TemporalExpression.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/calendar/TemporalExpression.java?rev=1812057&r1=1812056&r2=1812057&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/calendar/TemporalExpression.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/calendar/TemporalExpression.java Thu Oct 12 22:07:59 2017
@@ -45,10 +45,38 @@ public abstract class TemporalExpression
     public abstract void accept(TemporalExpressionVisitor visitor);
 
     public int compareTo(TemporalExpression obj) {
-        if (this.equals(obj) || obj.sequence == this.sequence) {
+        if (this.equals(obj)) {
             return 0;
         }
-         return obj.sequence < this.sequence ? 1 : -1;
+        return Integer.compare(this.sequence, obj.sequence);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        TemporalExpression other = (TemporalExpression) obj;
+        if (id == null) {
+            if (other.id != null)
+                return false;
+        } else if (!id.equals(other.id))
+            return false;
+        if (sequence != other.sequence)
+            return false;
+        return true;
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((id == null) ? 0 : id.hashCode());
+        result = prime * result + sequence;
+        return result;
     }
 
     protected boolean containsExpression(TemporalExpression expression) {
@@ -78,8 +106,8 @@ public abstract class TemporalExpression
      * @return A Set of matching <code>Date</code> objects
      */
     public Set<Date> getRange(org.apache.ofbiz.base.util.DateRange range, Calendar cal) {
-        Set<Date> set = new TreeSet<Date>();
-        Date last = range.start();
+        Set<Date> set = new TreeSet<>();
+        Date last;
         Calendar next = first(cal);
         while (next != null && range.includesDate(next.getTime())) {
             last = next.getTime();

Modified: ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/calendar/TemporalExpressionWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/calendar/TemporalExpressionWorker.java?rev=1812057&r1=1812056&r2=1812057&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/calendar/TemporalExpressionWorker.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/calendar/TemporalExpressionWorker.java Thu Oct 12 22:07:59 2017
@@ -150,7 +150,7 @@ public final class TemporalExpressionWor
         if (UtilValidate.isEmpty(valueList)) {
             throw new IllegalArgumentException("tempExprId argument invalid - no child expressions found");
         }
-        Set<TemporalExpression> exprList = new TreeSet<TemporalExpression>();
+        Set<TemporalExpression> exprList = new TreeSet<>();
         for (GenericValue value : valueList) {
             exprList.add(makeTemporalExpression(delegator, value.getRelatedOne("ToTemporalExpression", false)));
         }
@@ -163,6 +163,6 @@ public final class TemporalExpressionWor
     }
 
     public static String[] getExpressionTypeList() {
-        return ExpressionTypeList;
+        return ExpressionTypeList.clone();
     }
 }

Modified: ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/calendar/TemporalExpressions.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/calendar/TemporalExpressions.java?rev=1812057&r1=1812056&r2=1812057&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/calendar/TemporalExpressions.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/calendar/TemporalExpressions.java Thu Oct 12 22:07:59 2017
@@ -78,13 +78,25 @@ public class TemporalExpressions impleme
         }
 
         @Override
+        public int hashCode() {
+            final int prime = 31;
+            int result = super.hashCode();
+            result = prime * result + ((range == null) ? 0 : range.hashCode());
+            return result;
+        }
+
+        @Override
         public boolean equals(Object obj) {
-            if (obj == this) {
-                return true;
+            if (obj != null) {
+                if (obj == this) {
+                    return true;
+                }
+                try {
+                    return this.range.equals(((DateRange) obj).range);
+                }
+                catch (ClassCastException e) {
+                }
             }
-            try {
-                return this.range.equals(((DateRange) obj).range);
-            } catch (ClassCastException e) {}
             return false;
         }
 
@@ -176,14 +188,27 @@ public class TemporalExpressions impleme
         }
 
         @Override
+        public int hashCode() {
+            final int prime = 31;
+            int result = super.hashCode();
+            result = prime * result + dayOfWeek;
+            result = prime * result + occurrence;
+            return result;
+        }
+
+        @Override
         public boolean equals(Object obj) {
-            if (obj == this) {
-                return true;
+            if (obj != null) {
+                if (obj == this) {
+                    return true;
+                }
+                try {
+                    DayInMonth that = (DayInMonth) obj;
+                    return this.dayOfWeek == that.dayOfWeek && this.occurrence == that.occurrence;
+                }
+                catch (ClassCastException e) {
+                }
             }
-            try {
-                DayInMonth that = (DayInMonth) obj;
-                return this.dayOfWeek == that.dayOfWeek && this.occurrence == that.occurrence;
-            } catch (ClassCastException e) {}
             return false;
         }
 
@@ -294,14 +319,27 @@ public class TemporalExpressions impleme
         }
 
         @Override
+        public int hashCode() {
+            final int prime = 31;
+            int result = super.hashCode();
+            result = prime * result + end;
+            result = prime * result + start;
+            return result;
+        }
+
+        @Override
         public boolean equals(Object obj) {
-            if (obj == this) {
-                return true;
+            if (obj != null) {
+                if (obj == this) {
+                    return true;
+                }
+                try {
+                    DayOfMonthRange that = (DayOfMonthRange) obj;
+                    return this.start == that.start && this.end == that.end;
+                }
+                catch (ClassCastException e) {
+                }
             }
-            try {
-                DayOfMonthRange that = (DayOfMonthRange) obj;
-                return this.start == that.start && this.end == that.end;
-            } catch (ClassCastException e) {}
             return false;
         }
 
@@ -399,14 +437,27 @@ public class TemporalExpressions impleme
         }
 
         @Override
+        public int hashCode() {
+            final int prime = 31;
+            int result = super.hashCode();
+            result = prime * result + end;
+            result = prime * result + start;
+            return result;
+        }
+
+        @Override
         public boolean equals(Object obj) {
-            if (obj == this) {
-                return true;
+            if (obj != null) {
+                if (obj == this) {
+                    return true;
+                }
+                try {
+                    DayOfWeekRange that = (DayOfWeekRange) obj;
+                    return this.start == that.start && this.end == that.end;
+                }
+                catch (ClassCastException e) {
+                }
             }
-            try {
-                DayOfWeekRange that = (DayOfWeekRange) obj;
-                return this.start == that.start && this.end == that.end;
-            } catch (ClassCastException e) {}
             return false;
         }
 
@@ -521,14 +572,27 @@ public class TemporalExpressions impleme
         }
 
         @Override
+        public int hashCode() {
+            final int prime = 31;
+            int result = super.hashCode();
+            result = prime * result + ((excluded == null) ? 0 : excluded.hashCode());
+            result = prime * result + ((included == null) ? 0 : included.hashCode());
+            return result;
+        }
+
+        @Override
         public boolean equals(Object obj) {
-            if (obj == this) {
-                return true;
+            if (obj != null) {
+                if (obj == this) {
+                    return true;
+                }
+                try {
+                    Difference that = (Difference) obj;
+                    return this.included.equals(that.included) && this.excluded.equals(that.excluded);
+                }
+                catch (ClassCastException e) {
+                }
             }
-            try {
-                Difference that = (Difference) obj;
-                return this.included.equals(that.included) && this.excluded.equals(that.excluded);
-            } catch (ClassCastException e) {}
             return false;
         }
 
@@ -603,7 +667,7 @@ public class TemporalExpressions impleme
                 throw new IllegalArgumentException("freqCount argument must be a positive integer");
             }
             if (start != null) {
-                this.start = start;
+                this.start = (Date) start.clone();
             } else {
                 this.start = new Date();
             }
@@ -621,14 +685,28 @@ public class TemporalExpressions impleme
         }
 
         @Override
+        public int hashCode() {
+            final int prime = 31;
+            int result = super.hashCode();
+            result = prime * result + freqCount;
+            result = prime * result + freqType;
+            result = prime * result + ((start == null) ? 0 : start.hashCode());
+            return result;
+        }
+
+        @Override
         public boolean equals(Object obj) {
-            if (obj == this) {
-                return true;
+            if (obj != null) {
+                if (obj == this) {
+                    return true;
+                }
+                try {
+                    Frequency that = (Frequency) obj;
+                    return this.start.equals(that.start) && this.freqType == that.freqType && this.freqCount == that.freqCount;
+                }
+                catch (ClassCastException e) {
+                }
             }
-            try {
-                Frequency that = (Frequency) obj;
-                return this.start.equals(that.start) && this.freqType == that.freqType && this.freqCount == that.freqCount;
-            } catch (ClassCastException e) {}
             return false;
         }
 
@@ -764,14 +842,27 @@ public class TemporalExpressions impleme
         }
 
         @Override
+        public int hashCode() {
+            final int prime = 31;
+            int result = super.hashCode();
+            result = prime * result + end;
+            result = prime * result + start;
+            return result;
+        }
+
+        @Override
         public boolean equals(Object obj) {
-            if (obj == this) {
-                return true;
+            if (obj != null) {
+                if (obj == this) {
+                    return true;
+                }
+                try {
+                    HourRange that = (HourRange) obj;
+                    return this.start == that.start && this.end == that.end;
+                }
+                catch (ClassCastException e) {
+                }
             }
-            try {
-                HourRange that = (HourRange) obj;
-                return this.start == that.start && this.end == that.end;
-            } catch (ClassCastException e) {}
             return false;
         }
 
@@ -792,7 +883,7 @@ public class TemporalExpressions impleme
         }
 
         public Set<Integer> getHourRangeAsSet() {
-            Set<Integer> rangeSet = new TreeSet<Integer>();
+            Set<Integer> rangeSet = new TreeSet<>();
             if (this.start == this.end) {
                 rangeSet.add(this.start);
             } else {
@@ -912,13 +1003,25 @@ public class TemporalExpressions impleme
         }
 
         @Override
+        public int hashCode() {
+            final int prime = 31;
+            int result = super.hashCode();
+            result = prime * result + ((expressionSet == null) ? 0 : expressionSet.hashCode());
+            return result;
+        }
+
+        @Override
         public boolean equals(Object obj) {
-            if (obj == this) {
-                return true;
+            if (obj != null) {
+                if (obj == this) {
+                    return true;
+                }
+                try {
+                    return this.expressionSet.equals(((Intersection) obj).expressionSet);
+                }
+                catch (ClassCastException e) {
+                }
             }
-            try {
-                return this.expressionSet.equals(((Intersection) obj).expressionSet);
-            } catch (ClassCastException e) {}
             return false;
         }
 
@@ -933,9 +1036,8 @@ public class TemporalExpressions impleme
             }
             if (includesDate(first)) {
                 return first;
-            } else {
-                return null;
             }
+            return null;
         }
 
         /** Returns the member expression <code>Set</code>. The
@@ -1021,14 +1123,27 @@ public class TemporalExpressions impleme
         }
 
         @Override
+        public int hashCode() {
+            final int prime = 31;
+            int result = super.hashCode();
+            result = prime * result + end;
+            result = prime * result + start;
+            return result;
+        }
+
+        @Override
         public boolean equals(Object obj) {
-            if (obj == this) {
-                return true;
+            if (obj != null) {
+                if (obj == this) {
+                    return true;
+                }
+                try {
+                    MinuteRange that = (MinuteRange) obj;
+                    return this.start == that.start && this.end == that.end;
+                }
+                catch (ClassCastException e) {
+                }
             }
-            try {
-                MinuteRange that = (MinuteRange) obj;
-                return this.start == that.start && this.end == that.end;
-            } catch (ClassCastException e) {}
             return false;
         }
 
@@ -1049,7 +1164,7 @@ public class TemporalExpressions impleme
         }
 
         public Set<Integer> getMinuteRangeAsSet() {
-            Set<Integer> rangeSet = new TreeSet<Integer>();
+            Set<Integer> rangeSet = new TreeSet<>();
             if (this.start == this.end) {
                 rangeSet.add(this.start);
             } else {
@@ -1157,14 +1272,27 @@ public class TemporalExpressions impleme
         }
 
         @Override
+        public int hashCode() {
+            final int prime = 31;
+            int result = super.hashCode();
+            result = prime * result + end;
+            result = prime * result + start;
+            return result;
+        }
+
+        @Override
         public boolean equals(Object obj) {
-            if (obj == this) {
-                return true;
+            if (obj != null) {
+                if (obj == this) {
+                    return true;
+                }
+                try {
+                    MonthRange that = (MonthRange) obj;
+                    return this.start == that.start && this.end == that.end;
+                }
+                catch (ClassCastException e) {
+                }
             }
-            try {
-                MonthRange that = (MonthRange) obj;
-                return this.start == that.start && this.end == that.end;
-            } catch (ClassCastException e) {}
             return false;
         }
 
@@ -1304,14 +1432,28 @@ public class TemporalExpressions impleme
         }
 
         @Override
+        public int hashCode() {
+            final int prime = 31;
+            int result = super.hashCode();
+            result = prime * result + ((excluded == null) ? 0 : excluded.hashCode());
+            result = prime * result + ((included == null) ? 0 : included.hashCode());
+            result = prime * result + ((substitute == null) ? 0 : substitute.hashCode());
+            return result;
+        }
+
+        @Override
         public boolean equals(Object obj) {
-            if (obj == this) {
-                return true;
+            if (obj != null) {
+                if (obj == this) {
+                    return true;
+                }
+                try {
+                    Substitution that = (Substitution) obj;
+                    return this.included.equals(that.included) && this.excluded.equals(that.excluded) && this.substitute.equals(that.substitute);
+                }
+                catch (ClassCastException e) {
+                }
             }
-            try {
-                Substitution that = (Substitution) obj;
-                return this.included.equals(that.included) && this.excluded.equals(that.excluded) && this.substitute.equals(that.substitute);
-            } catch (ClassCastException e) {}
             return false;
         }
 
@@ -1411,13 +1553,25 @@ public class TemporalExpressions impleme
         }
 
         @Override
+        public int hashCode() {
+            final int prime = 31;
+            int result = super.hashCode();
+            result = prime * result + ((expressionSet == null) ? 0 : expressionSet.hashCode());
+            return result;
+        }
+
+        @Override
         public boolean equals(Object obj) {
-            if (obj == this) {
-                return true;
+            if (obj != null) {
+                if (obj == this) {
+                    return true;
+                }
+                try {
+                    return this.expressionSet.equals(((Union) obj).expressionSet);
+                }
+                catch (ClassCastException e) {
+                }
             }
-            try {
-                return this.expressionSet.equals(((Union) obj).expressionSet);
-            } catch (ClassCastException e) {}
             return false;
         }