Clover Coverage Report - Atlassian Core
Coverage timestamp: Sun Nov 30 2008 18:33:35 CST
18   83   13   1.64
4   62   0.72   11
11     1.18  
1    
 
 
  ThreadLocalErrorCollection       Line # 11 18 13 87.9% 0.8787879
 
  (6)
 
1    package com.atlassian.core.logging;
2   
3    import org.apache.log4j.spi.LoggingEvent;
4   
5    import java.util.List;
6    import java.util.LinkedList;
7   
8    /**
9    * A simple ThreadLocal stack to prevent circular content includes.
10    */
 
11    public class ThreadLocalErrorCollection
12    {
13    public static final int DEFAULT_LIMIT =100;
14    private static ThreadLocal threadLocalCollection = new ThreadLocal(){
 
15  1 toggle protected Object initialValue(){
16  1 return new LinkedList();
17    }
18    };
19   
20    private static ThreadLocal threadLocalEnabled = new ThreadLocal(){
 
21  0 toggle protected Object initialValue(){
22  0 return Boolean.FALSE;
23    }
24    };
25   
26    private static int limit = DEFAULT_LIMIT;
27   
 
28  211 toggle public static void add(long timeInMillis, LoggingEvent e)
29    {
30  211 if (!isEnabled())
31  2 return;
32   
33  209 List loggingEvents = getList();
34   
35  209 loggingEvents.add(new DatedLoggingEvent(timeInMillis, e));
36   
37  309 while (loggingEvents.size() > limit)
38  100 loggingEvents.remove(0);
39   
40    }
41   
 
42  6 toggle public static void clear()
43    {
44  6 getList().clear();
45    }
46   
 
47  222 toggle public static List getList()
48    {
49  222 List list = (List) threadLocalCollection.get();
50  222 return list;
51    }
52   
 
53  4 toggle public static boolean isEmpty()
54    {
55  4 return getList().isEmpty();
56    }
57   
 
58  0 toggle public static int getLimit()
59    {
60  0 return limit;
61    }
62   
 
63  1 toggle public static void setLimit(int limit)
64    {
65  1 ThreadLocalErrorCollection.limit = limit;
66    }
67   
 
68  211 toggle public static boolean isEnabled()
69    {
70  211 Boolean enabledState = (Boolean) threadLocalEnabled.get();
71  211 return Boolean.TRUE.equals(enabledState);
72    }
73   
 
74  7 toggle public static void enable()
75    {
76  7 threadLocalEnabled.set(Boolean.TRUE);
77    }
78   
 
79  8 toggle public static void disable()
80    {
81  8 threadLocalEnabled.set(Boolean.FALSE);
82    }
83    }