| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package org.xwiki.logging; |
| 21 |
|
|
| 22 |
|
import java.io.Serializable; |
| 23 |
|
import java.util.Collections; |
| 24 |
|
import java.util.Iterator; |
| 25 |
|
import java.util.LinkedList; |
| 26 |
|
import java.util.List; |
| 27 |
|
import java.util.concurrent.ConcurrentLinkedQueue; |
| 28 |
|
|
| 29 |
|
import org.xwiki.logging.event.BeginLogEvent; |
| 30 |
|
import org.xwiki.logging.event.LogEvent; |
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
@version |
| 36 |
|
@since |
| 37 |
|
|
| |
|
| 51.7% |
Uncovered Elements: 28 (58) |
Complexity: 20 |
Complexity Density: 0.67 |
|
| 38 |
|
public class LogTreeNode extends BeginLogEvent implements Iterable<LogEvent>, Serializable |
| 39 |
|
{ |
| |
|
| 88.9% |
Uncovered Elements: 2 (18) |
Complexity: 7 |
Complexity Density: 0.7 |
|
| 40 |
|
private static class LogTreeNodeIterator implements Iterator<LogEvent> |
| 41 |
|
{ |
| 42 |
|
private final Iterator<LogEvent> rootIterator; |
| 43 |
|
|
| 44 |
|
private Iterator<LogEvent> currentIterator; |
| 45 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 46 |
6 |
LogTreeNodeIterator(Iterator<LogEvent> rootIterator)... |
| 47 |
|
{ |
| 48 |
6 |
this.rootIterator = rootIterator; |
| 49 |
6 |
this.currentIterator = this.rootIterator; |
| 50 |
|
} |
| 51 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 52 |
59 |
@Override... |
| 53 |
|
public boolean hasNext() |
| 54 |
|
{ |
| 55 |
59 |
return this.currentIterator.hasNext() || this.rootIterator.hasNext(); |
| 56 |
|
} |
| 57 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 4 |
Complexity Density: 0.67 |
|
| 58 |
115 |
@Override... |
| 59 |
|
public LogEvent next() |
| 60 |
|
{ |
| 61 |
115 |
if (!this.currentIterator.hasNext()) { |
| 62 |
4 |
this.currentIterator = this.rootIterator; |
| 63 |
|
} |
| 64 |
|
|
| 65 |
115 |
LogEvent logEvent = this.currentIterator.next(); |
| 66 |
|
|
| 67 |
115 |
if (this.currentIterator == this.rootIterator && logEvent instanceof LogTreeNode) { |
| 68 |
5 |
this.currentIterator = ((LogTreeNode) logEvent).iterator(true); |
| 69 |
|
} |
| 70 |
|
|
| 71 |
115 |
return logEvent; |
| 72 |
|
} |
| 73 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 74 |
0 |
@Override... |
| 75 |
|
public void remove() |
| 76 |
|
{ |
| 77 |
0 |
this.currentIterator.remove(); |
| 78 |
|
} |
| 79 |
|
} |
| 80 |
|
|
| 81 |
|
|
| 82 |
|
|
| 83 |
|
|
| 84 |
|
private static final long serialVersionUID = 1L; |
| 85 |
|
|
| 86 |
|
|
| 87 |
|
|
| 88 |
|
|
| 89 |
|
protected ConcurrentLinkedQueue<LogEvent> children; |
| 90 |
|
|
| 91 |
|
|
| 92 |
|
|
| |
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 93 |
3 |
LogTreeNode()... |
| 94 |
|
{ |
| 95 |
|
|
| 96 |
|
} |
| 97 |
|
|
| 98 |
|
|
| 99 |
|
@param |
| 100 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 101 |
9 |
public LogTreeNode(LogEvent logEvent)... |
| 102 |
|
{ |
| 103 |
9 |
super(logEvent); |
| 104 |
|
} |
| 105 |
|
|
| |
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
| 106 |
17 |
@Override... |
| 107 |
|
public Iterator<LogEvent> iterator() |
| 108 |
|
{ |
| 109 |
17 |
return this.children != null ? this.children.iterator() : Collections.<LogEvent>emptyList().iterator(); |
| 110 |
|
} |
| 111 |
|
|
| 112 |
|
|
| 113 |
|
@param |
| 114 |
|
@return |
| 115 |
|
|
| |
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 116 |
6 |
public Iterator<LogEvent> iterator(boolean recurse)... |
| 117 |
|
{ |
| 118 |
6 |
if (!recurse) { |
| 119 |
0 |
return iterator(); |
| 120 |
|
} |
| 121 |
|
|
| 122 |
6 |
return new LogTreeNodeIterator(iterator()); |
| 123 |
|
} |
| 124 |
|
|
| 125 |
|
|
| 126 |
|
|
| 127 |
|
|
| 128 |
|
@param |
| 129 |
|
@return |
| 130 |
|
|
| |
|
| 92.9% |
Uncovered Elements: 1 (14) |
Complexity: 4 |
Complexity Density: 0.5 |
|
| 131 |
13 |
public int size(boolean recurse)... |
| 132 |
|
{ |
| 133 |
13 |
if (!recurse) { |
| 134 |
4 |
return this.children != null ? this.children.size() : 0; |
| 135 |
|
} |
| 136 |
|
|
| 137 |
9 |
int size = 0; |
| 138 |
|
|
| 139 |
9 |
for (LogEvent logEvent : this) { |
| 140 |
25 |
++size; |
| 141 |
|
|
| 142 |
25 |
if (logEvent instanceof LogTreeNode) { |
| 143 |
5 |
size += ((LogTreeNode) logEvent).size(true); |
| 144 |
|
} |
| 145 |
|
} |
| 146 |
|
|
| 147 |
9 |
return size; |
| 148 |
|
} |
| 149 |
|
|
| 150 |
|
|
| 151 |
|
@param |
| 152 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 153 |
76 |
void add(LogEvent logEvent)... |
| 154 |
|
{ |
| 155 |
76 |
if (this.children == null) { |
| 156 |
12 |
this.children = new ConcurrentLinkedQueue<LogEvent>(); |
| 157 |
|
} |
| 158 |
|
|
| 159 |
76 |
this.children.add(logEvent); |
| 160 |
|
} |
| 161 |
|
|
| 162 |
|
|
| 163 |
|
|
| 164 |
|
|
| 165 |
|
@param |
| 166 |
|
@param@link |
| 167 |
|
@return |
| 168 |
|
|
| |
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 4 |
Complexity Density: 0.57 |
|
| 169 |
0 |
public List<LogEvent> getLogs(LogLevel level, boolean recurse)... |
| 170 |
|
{ |
| 171 |
0 |
List<LogEvent> levelLogs = new LinkedList<LogEvent>(); |
| 172 |
|
|
| 173 |
0 |
for (LogEvent log : this) { |
| 174 |
0 |
if (log.getLevel() == level) { |
| 175 |
0 |
levelLogs.add(log); |
| 176 |
|
} |
| 177 |
|
|
| 178 |
0 |
if (recurse && log instanceof LogTreeNode) { |
| 179 |
0 |
levelLogs.addAll(((LogTreeNode) log).getLogs(level, true)); |
| 180 |
|
} |
| 181 |
|
} |
| 182 |
|
|
| 183 |
0 |
return levelLogs; |
| 184 |
|
} |
| 185 |
|
|
| 186 |
|
|
| 187 |
|
|
| 188 |
|
|
| 189 |
|
@param |
| 190 |
|
@param@link |
| 191 |
|
@return |
| 192 |
|
|
| |
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 4 |
Complexity Density: 0.57 |
|
| 193 |
0 |
public List<LogEvent> getLogsFrom(LogLevel level, boolean recurse)... |
| 194 |
|
{ |
| 195 |
0 |
List<LogEvent> levelLogs = new LinkedList<LogEvent>(); |
| 196 |
|
|
| 197 |
0 |
for (LogEvent log : this) { |
| 198 |
0 |
if (log.getLevel().compareTo(level) <= 0) { |
| 199 |
0 |
levelLogs.add(log); |
| 200 |
|
} |
| 201 |
|
|
| 202 |
0 |
if (recurse && log instanceof LogTreeNode) { |
| 203 |
0 |
levelLogs.addAll(((LogTreeNode) log).getLogsFrom(level, true)); |
| 204 |
|
} |
| 205 |
|
} |
| 206 |
|
|
| 207 |
0 |
return levelLogs; |
| 208 |
|
} |
| 209 |
|
} |