|
@@ -1,9 +1,7 @@ |
1 |
1 |
|
package com.temp.shared.utils; |
2 |
2 |
|
|
3 |
|
- |
import java.io.PrintStream; |
4 |
|
- |
import java.util.Arrays; |
5 |
|
- |
import java.util.HashMap; |
6 |
|
- |
import java.util.Map; |
|
3 |
+ |
import java.io.*; |
|
4 |
+ |
import java.util.*; |
7 |
5 |
|
|
8 |
6 |
|
/** |
9 |
7 |
|
* Collect all the Issues/Throwables for all the "Context(s)" from a particular |
|
@@ -15,19 +13,19 @@ |
15 |
13 |
|
private final String source; |
16 |
14 |
|
private final Map<String, ContextThrowables> contextThrowablesByContext = new HashMap<String, ContextThrowables>(); |
17 |
15 |
|
|
18 |
|
- |
public SourceIssues(String source, String context, Throwable... throwables) { |
19 |
|
- |
this.source = Assert.noEmpty("source", source); |
20 |
|
- |
add(context, throwables); |
|
16 |
+ |
public SourceIssues( String source, String context, Throwable... throwables ) { |
|
17 |
+ |
this.source = Assert.noEmpty( "source", source ); |
|
18 |
+ |
add( context, throwables ); |
21 |
19 |
|
} |
22 |
20 |
|
|
23 |
|
- |
public void add(String context, Throwable... throwables) { |
24 |
|
- |
context = StringUtils.deNull(context).trim(); |
25 |
|
- |
ContextThrowables contextThrowables = contextThrowablesByContext.get(context); |
26 |
|
- |
if (contextThrowables != null) { |
27 |
|
- |
contextThrowables.add(throwables); |
|
21 |
+ |
public void add( String context, Throwable... throwables ) { |
|
22 |
+ |
context = StringUtils.deNull( context ).trim(); |
|
23 |
+ |
ContextThrowables contextThrowables = contextThrowablesByContext.get( context ); |
|
24 |
+ |
if ( contextThrowables != null ) { |
|
25 |
+ |
contextThrowables.add( throwables ); |
28 |
26 |
|
} else { |
29 |
|
- |
contextThrowables = new ContextThrowables(context, throwables); // Validates that there is at least one Throwable! |
30 |
|
- |
contextThrowablesByContext.put(context, contextThrowables); |
|
27 |
+ |
contextThrowables = new ContextThrowables( context, throwables ); // Validates that there is at least one Throwable! |
|
28 |
+ |
contextThrowablesByContext.put( context, contextThrowables ); |
31 |
29 |
|
} |
32 |
30 |
|
} |
33 |
31 |
|
|
|
@@ -40,20 +38,20 @@ |
40 |
38 |
|
} |
41 |
39 |
|
|
42 |
40 |
|
public ContextThrowables[] getContextThrowables() { |
43 |
|
- |
ContextThrowables[] throwables = contextThrowablesByContext.values().toArray(new ContextThrowables[contextThrowablesByContext.size()]); |
44 |
|
- |
Arrays.sort(throwables); |
|
41 |
+ |
ContextThrowables[] throwables = contextThrowablesByContext.values().toArray( new ContextThrowables[contextThrowablesByContext.size()] ); |
|
42 |
+ |
Arrays.sort( throwables ); |
45 |
43 |
|
return throwables; |
46 |
44 |
|
} |
47 |
45 |
|
|
48 |
46 |
|
@Override |
49 |
47 |
|
public String toString() { |
50 |
|
- |
return appendTo(new StringBuilder()).toString(); |
|
48 |
+ |
return appendTo( new StringBuilder() ).toString(); |
51 |
49 |
|
} |
52 |
50 |
|
|
53 |
|
- |
public StringBuilder appendTo(StringBuilder sb) { |
54 |
|
- |
sb.append("Issues from Source '").append(source).append("':\n"); |
55 |
|
- |
for (ContextThrowables contextThrowables : getContextThrowables()) { |
56 |
|
- |
contextThrowables.appendTo(sb, 1); |
|
51 |
+ |
public StringBuilder appendTo( StringBuilder sb ) { |
|
52 |
+ |
sb.append( "Issues from Source '" ).append( source ).append( "':\n" ); |
|
53 |
+ |
for ( ContextThrowables contextThrowables : getContextThrowables() ) { |
|
54 |
+ |
contextThrowables.appendTo( sb, 1 ); |
57 |
55 |
|
} |
58 |
56 |
|
return sb; |
59 |
57 |
|
} |
|
@@ -61,14 +59,14 @@ |
61 |
59 |
|
/** |
62 |
60 |
|
* @param stream - note in GWT only println Object & String are implemented |
63 |
61 |
|
*/ |
64 |
|
- |
public void dumpToAsHTML(PrintStream stream, boolean fullStackTrace) { |
65 |
|
- |
stream.println("<pre>"); |
66 |
|
- |
stream.println("Issues from Source '" + source + "':"); |
67 |
|
- |
for (ContextThrowables contextThrowables : getContextThrowables()) { |
68 |
|
- |
stream.println("<ul>"); |
69 |
|
- |
contextThrowables.dumpToAsHTML(stream, fullStackTrace); |
70 |
|
- |
stream.println("</ul>"); |
|
62 |
+ |
public void dumpToAsHTML( PrintStream stream, boolean fullStackTrace ) { |
|
63 |
+ |
stream.println( "<pre>" ); |
|
64 |
+ |
stream.println( "Issues from Source '" + source + "':" ); |
|
65 |
+ |
for ( ContextThrowables contextThrowables : getContextThrowables() ) { |
|
66 |
+ |
stream.println( "<ul>" ); |
|
67 |
+ |
contextThrowables.dumpToAsHTML( stream, fullStackTrace ); |
|
68 |
+ |
stream.println( "</ul>" ); |
71 |
69 |
|
} |
72 |
|
- |
stream.println("</pre>"); |
|
70 |
+ |
stream.println( "</pre>" ); |
73 |
71 |
|
} |
74 |
72 |
|
} |