1 4 package org.infoglue.cms.util; 5 6 import java.util.Collection ; 7 import java.util.Iterator ; 8 import java.util.SortedSet ; 9 10 15 public final class DomainUtils 16 { 17 private DomainUtils() {} 18 19 25 public static boolean equals(Object o1, Object o2) 26 { 27 return (o1 == null) ? o1 == o2 : o1.equals(o2); 28 } 29 30 37 public static boolean equals(Collection c1, Collection c2) 38 { 39 if (c1 == null || c2 == null) 40 return c1 == c2; 41 42 if (c1.size() != c2.size()) 43 return false; 44 45 return (c1 instanceof SortedSet && c2 instanceof SortedSet ) 46 ? containsAll((SortedSet )c1, (SortedSet )c2) 47 : c1.containsAll(c2) && c2.containsAll(c1); 48 } 49 50 57 public static int compare(Comparable c1, Comparable c2) 58 { 59 if(c1 == null && c2 == null) 60 return 0; 61 62 if(c1 != null && c2 == null) 63 return -1; 64 65 if(c1 == null && c2 != null) 66 return 1; 67 68 return c1.compareTo(c2); 69 } 70 71 80 private static boolean containsAll(SortedSet s1, SortedSet s2) 81 { 82 Iterator i = s1.iterator(), j = s2.iterator(); 83 84 while (i.hasNext() && j.hasNext()) 85 if (!i.next().equals(j.next())) 86 return false; 87 88 return !i.hasNext() && !j.hasNext(); 89 } 90 91 96 public static int hashCode(Object s) 97 { 98 return (s == null) ? 0 : s.hashCode(); 99 } 100 } 101 | Popular Tags |