Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[JBRULES-3536] use a null safe comparator in TreeMaps

  • Loading branch information...
commit 0dce8029c1785e90db5063b8759cb1c8e793daa6 1 parent caf0d24
mariofusco authored
22  drools-verifier/src/main/java/org/drools/verifier/data/VerifierDataMaps.java
@@ -28,17 +28,17 @@
28 28
 
29 29
     private Map<VerifierComponentType, Map<String, VerifierComponent>> all = new TreeMap<VerifierComponentType, Map<String, VerifierComponent>>();
30 30
 
31  
-    private Map<String, RulePackage> packagesByName = new TreeMap<String, RulePackage>();
32  
-    private Map<String, ObjectType> objectTypesByFullName = new TreeMap<String, ObjectType>();
33  
-    private Map<String, Field> fieldsByObjectTypeAndFieldName = new TreeMap<String, Field>();
  31
+    private Map<String, RulePackage> packagesByName = new TreeMap<String, RulePackage>(STRING_NULL_SAFE_COMPARATOR);
  32
+    private Map<String, ObjectType> objectTypesByFullName = new TreeMap<String, ObjectType>(STRING_NULL_SAFE_COMPARATOR);
  33
+    private Map<String, Field> fieldsByObjectTypeAndFieldName = new TreeMap<String, Field>(STRING_NULL_SAFE_COMPARATOR);
34 34
     private Multimap<String, Field> fieldsByObjectTypeId = TreeMultimap.create();
35 35
     private Multimap<String, Pattern> patternsByObjectTypeId = TreeMultimap.create();
36 36
     private Multimap<String, Pattern> patternsByRuleName = TreeMultimap.create();
37 37
     private Multimap<String, Restriction> restrictionsByFieldId = TreeMultimap.create();
38  
-    private Map<String, Variable> variablesByRuleAndVariableName = new TreeMap<String, Variable>();
39  
-    private Map<String, EntryPoint> entryPointsByEntryId = new TreeMap<String, EntryPoint>();
40  
-    private Map<String, VerifierRule> rulesByName = new TreeMap<String, VerifierRule>();
41  
-    private Map<String, Import> importsByName = new TreeMap<String, Import>();
  38
+    private Map<String, Variable> variablesByRuleAndVariableName = new TreeMap<String, Variable>(STRING_NULL_SAFE_COMPARATOR);
  39
+    private Map<String, EntryPoint> entryPointsByEntryId = new TreeMap<String, EntryPoint>(STRING_NULL_SAFE_COMPARATOR);
  40
+    private Map<String, VerifierRule> rulesByName = new TreeMap<String, VerifierRule>(STRING_NULL_SAFE_COMPARATOR);
  41
+    private Map<String, Import> importsByName = new TreeMap<String, Import>(STRING_NULL_SAFE_COMPARATOR);
42 42
     private Multimap<String, VerifierRule> rulesByCategory = TreeMultimap.create();
43 43
 
44 44
     public Collection<ObjectType> getObjectTypesByRuleName(String ruleName) {
@@ -233,4 +233,12 @@ public ObjectType getObjectTypeByObjectTypeNameAndPackageName(String factTypeNam
233 233
 
234 234
         return null;
235 235
     }
  236
+
  237
+    private static final NullSafeComparator<String> STRING_NULL_SAFE_COMPARATOR = new NullSafeComparator<String>();
  238
+
  239
+    public static class NullSafeComparator<T extends Comparable<T>> implements Comparator<T> {
  240
+        public int compare(T o1, T o2) {
  241
+            return o1 == null ? (o2 == null ? 0 : -1) : (o2 == null ? 1 : o1.compareTo(o2));
  242
+        }
  243
+    }
236 244
 }

0 notes on commit 0dce802

Please sign in to comment.
Something went wrong with that request. Please try again.