+ final static String createAnnotationString( final SortedSet<Annotation> annotations ) {
+ final SortedMap<String, List<Annotation>> m = new TreeMap<String, List<Annotation>>();
+ for( final Annotation an : annotations ) {
+ final String ref_source = ForesterUtil.isEmpty( an.getRefSource() ) ? "?" : an.getRefSource();
+ if ( !m.containsKey( ref_source ) ) {
+ m.put( ref_source, new ArrayList<Annotation>() );
+ }
+ m.get( ref_source ).add( an );
+ }
+ final StringBuilder sb = new StringBuilder();
+ for( final Entry<String, List<Annotation>> e : m.entrySet() ) {
+ final String ref_source = e.getKey();
+ final List<Annotation> ans = e.getValue();
+ if ( m.size() > 1 ) {
+ sb.append( "[" );
+ }
+ if ( !ref_source.equals( "?" ) ) {
+ sb.append( ref_source );
+ sb.append( ": " );
+ }
+ for( int i = 0; i < ans.size(); ++i ) {
+ final Annotation an = ans.get( i );
+ if ( !ForesterUtil.isEmpty( an.getRefValue() ) ) {
+ sb.append( an.getRefValue() );
+ sb.append( " " );
+ }
+ if ( !ForesterUtil.isEmpty( an.getDesc() ) ) {
+ sb.append( an.getDesc() );
+ }
+ if ( sb.charAt( sb.length() - 1 ) == ' ' ) {
+ sb.deleteCharAt( sb.length() - 1 );
+ }
+ if ( i < ans.size() - 1 ) {
+ sb.append( ", " );
+ }
+ }
+ if ( m.size() > 1 ) {
+ sb.append( "] " );
+ }
+ }
+ return sb.toString();
+ }
+