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