Clover Coverage Report - Atlassian Core
Coverage timestamp: Sun Nov 30 2008 18:33:35 CST
57   151   32   14.25
46   118   0.56   4
4     8  
1    
 
 
  PropertyUtils       Line # 20 57 32 72.9% 0.72897196
 
  (10)
 
1    /*
2    * Created by IntelliJ IDEA.
3    * User: Administrator
4    * Date: 28/02/2002
5    * Time: 11:48:12
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 com.opensymphony.module.propertyset.PropertySet;
12    import org.apache.log4j.Category;
13    import org.apache.log4j.Logger;
14   
15    import java.util.Collection;
16    import java.util.Iterator;
17    import java.util.Properties;
18    import java.io.*;
19   
 
20    public class PropertyUtils
21    {
22    private static final Logger log = Logger.getLogger(PropertyUtils.class);
23   
 
24  0 toggle public static Properties getProperties(String resource, Class callingClass)
25    {
26  0 return getPropertiesFromStream(ClassLoaderUtils.getResourceAsStream(resource, callingClass));
27    }
28   
 
29  0 toggle public static Properties getPropertiesFromFile(File file)
30    {
31  0 try
32    {
33  0 return getPropertiesFromStream(new FileInputStream(file));
34    }
35    catch (FileNotFoundException e)
36    {
37  0 log.error("Error loading properties from file: " + file.getPath() + ". File does not exist.", e);
38  0 return null;
39    }
40    }
41   
 
42  0 toggle public static Properties getPropertiesFromStream(InputStream is)
43    {
44  0 if (is == null)
45  0 return null;
46   
47  0 Properties props = new Properties();
48  0 try
49    {
50  0 props.load(is);
51    }
52    catch (IOException e)
53    {
54  0 log.error("Error loading properties from stream.", e);
55    }
56    finally
57    {
58  0 FileUtils.shutdownStream(is);
59    }
60   
61  0 return props;
62    }
63   
64   
65    /**
66    * Check to see if the two propertySet contain the same values and types
67    * NOTE If both PropertySets are null then <i>true</i> is returned
68    * @param pThis First PropertySet
69    * @param pThat Second PropertySet
70    * @return Are the two PropertySets identical
71    */
 
72  20 toggle public static boolean identical(PropertySet pThis, PropertySet pThat)
73    {
74    //Check to see if both of the collections are null
75  20 if (pThis == null && pThat == null)
76  1 return true;
77   
78    //Check to see if either of the collections are null
79  19 if (pThis == null || pThat == null)
80  2 return false;
81   
82  17 Collection thisKeys = pThis.getKeys();
83  17 Collection thatKeys = pThat.getKeys();
84   
85  17 if (!thisKeys.containsAll(thatKeys) || !thatKeys.containsAll(thisKeys))
86  1 return false;
87   
88  16 Iterator thisKeysIterator = thisKeys.iterator();
89  16 String key;
90  16 int keyType;
91  36 while (thisKeysIterator.hasNext())
92    {
93  28 key = (String) thisKeysIterator.next();
94  28 keyType = pThis.getType(key);
95  28 if (PropertySet.BOOLEAN == keyType)
96    {
97  4 if (pThis.getBoolean(key) != pThat.getBoolean(key))
98  1 return false;
99    }
100  24 else if (PropertySet.DATA == keyType)
101    {
102  0 throw new IllegalArgumentException("DATA Comparision has not been implemented in PropertyUtil");
103    }
104  24 else if (PropertySet.DATE == keyType)
105    {
106  4 if (!pThis.getDate(key).equals(pThat.getDate(key)))
107  1 return false;
108    }
109  20 else if (PropertySet.DOUBLE == keyType)
110    {
111  4 if (pThis.getDouble(key) != pThat.getDouble(key))
112  1 return false;
113    }
114  16 else if (PropertySet.INT == keyType)
115    {
116  4 if (pThis.getInt(key) != pThat.getInt(key))
117  1 return false;
118    }
119  12 else if (PropertySet.OBJECT == keyType)
120    {
121  0 throw new IllegalArgumentException("OBJECT Comparision has not been implemented in PropertyUtil");
122    }
123  12 else if (PropertySet.PROPERTIES == keyType)
124    {
125  0 throw new IllegalArgumentException("PROPERTIES Comparision has not been implemented in PropertyUtil");
126    }
127  12 else if (PropertySet.LONG == keyType)
128    {
129  4 if (pThis.getLong(key) != pThat.getLong(key))
130  1 return false;
131    }
132  8 else if (PropertySet.STRING == keyType)
133    {
134  4 if (!pThis.getString(key).equals(pThat.getString(key)))
135  1 return false;
136    }
137  4 else if (PropertySet.TEXT == keyType)
138    {
139  4 if (!pThis.getText(key).equals(pThat.getText(key)))
140  2 return false;
141    }
142  0 else if (PropertySet.XML == keyType)
143    {
144  0 throw new IllegalArgumentException("XML Comparision has not been implemented in PropertyUtil");
145    }
146    }
147   
148  8 return true;
149    }
150   
151    }