Clover Coverage Report - Atlassian Core
Coverage timestamp: Sun Nov 30 2008 18:33:35 CST
14   105   14   2
4   59   1   7
7     2  
1    
 
 
  ObjectUtils       Line # 18 14 14 48% 0.48
 
  (2)
 
1    /*
2    * Created by IntelliJ IDEA.
3    * User: Scott Farquhar
4    * Date: 12/02/2002
5    * Time: 00:52:58
6    * To change template for new class use
7    * Code Style | Class Templates options (Tools | IDE Options).
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    * Some common methods used against {@link Object} objects
17    */
 
18    public class ObjectUtils
19    {
20    private static final Predicate NOT_EMPTY_PREDICATE = new Predicate()
21    {
 
22  0 toggle public boolean evaluate(Object o)
23    {
24  0 return isNotEmpty(o);
25    }
26    };
27   
28    protected static Method hibernateGetClassMethod = null;
29   
 
30  1 toggle static
31    {
32  1 try
33    {
34  1 Class hibernateClass = ClassLoaderUtils.loadClass("net.sf.hibernate.Hibernate", ObjectUtils.class);
35  1 hibernateGetClassMethod = hibernateClass.getMethod("getClass", new Class[]{Object.class});
36    }
37    catch (Exception e)
38    {
39    }
40    }
41   
42   
43    /**
44    * @return True if both are null or equal, otherwise returns false
45    */
 
46  6 toggle public static boolean isIdentical(Object a, Object b)
47    {
48  6 return !isDifferent(a, b);
49    }
50   
51    /**
52    * @return False if both are null or equal, otherwise returns true
53    */
 
54  12 toggle public static boolean isDifferent(Object a, Object b)
55    {
56  12 if ((a == null && b == null) || (a != null && a.equals(b)))
57    {
58  4 return false;
59    }
60   
61  8 return true;
62    }
63   
64    /**
65    * Similar to {@link org.apache.commons.lang.StringUtils#isNotEmpty} but accepts a Sttring. Type safe
66    * @param o
67    * @return true if the object is not null && != ""
68    */
 
69  0 toggle public static boolean isNotEmpty(Object o)
70    {
71  0 return o != null && !"".equals(o);
72    }
73   
74    /**
75    * Returns a predicate for {@link #isNotEmpty(Object)}
76    * @return Predicate
77    */
 
78  0 toggle public static Predicate getIsSetPredicate()
79    {
80  0 return NOT_EMPTY_PREDICATE;
81    }
82   
83    /**
84    * Gets the true class of an object, trying to use Hibernate's proxy unwrapping tools if available on the classpath.
85    * <p />
86    * Otherwise simply returns the class of the object passed in if Hibernate not on the classpath.
87    * @param o The object to examine
88    * @return The true class of the object (unwrapping Hibernate proxies etc)
89    */
 
90  0 toggle public static Class getTrueClass(Object o)
91    {
92  0 if (hibernateGetClassMethod != null)
93    {
94  0 try
95    {
96  0 return (Class)hibernateGetClassMethod.invoke(null, new Object[] {o});
97    }
98    catch (Exception e)
99    {
100    }
101    }
102   
103  0 return o.getClass();
104    }
105    }