1
2
3
4
5
6
7
8
9 package com.atlassian.core.util;
10
11 import org.apache.commons.collections.Predicate;
12
13 import java.lang.reflect.Method;
14
15
16
17
18 public class ObjectUtils
19 {
20 private static final Predicate NOT_EMPTY_PREDICATE = new Predicate()
21 {
22 public boolean evaluate(Object o)
23 {
24 return isNotEmpty(o);
25 }
26 };
27
28 protected static Method hibernateGetClassMethod = null;
29
30 static
31 {
32 try
33 {
34 Class hibernateClass = ClassLoaderUtils.loadClass("net.sf.hibernate.Hibernate", ObjectUtils.class);
35 hibernateGetClassMethod = hibernateClass.getMethod("getClass", new Class[]{Object.class});
36 }
37 catch (Exception e)
38 {
39 }
40 }
41
42
43
44
45
46 public static boolean isIdentical(Object a, Object b)
47 {
48 return !isDifferent(a, b);
49 }
50
51
52
53
54 public static boolean isDifferent(Object a, Object b)
55 {
56 if ((a == null && b == null) || (a != null && a.equals(b)))
57 {
58 return false;
59 }
60
61 return true;
62 }
63
64
65
66
67
68
69 public static boolean isNotEmpty(Object o)
70 {
71 return o != null && !"".equals(o);
72 }
73
74
75
76
77
78 public static Predicate getIsSetPredicate()
79 {
80 return NOT_EMPTY_PREDICATE;
81 }
82
83
84
85
86
87
88
89
90 public static Class getTrueClass(Object o)
91 {
92 if (hibernateGetClassMethod != null)
93 {
94 try
95 {
96 return (Class)hibernateGetClassMethod.invoke(null, new Object[] {o});
97 }
98 catch (Exception e)
99 {
100 }
101 }
102
103 return o.getClass();
104 }
105 }