X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Fevoinference%2Fdistance%2FS.java;h=e1593f4ada902510517c4bb6e5f74abce8ded07d;hb=8dbc83f2fcaa7e9cb0ebc88fa9205c8c385a6e08;hp=6c84598fdf07f1aff9142fce8b632ba70d237f9d;hpb=3dc1b0bab30025b34753df4325b60cb47ee5bdff;p=jalview.git diff --git a/forester/java/src/org/forester/evoinference/distance/S.java b/forester/java/src/org/forester/evoinference/distance/S.java index 6c84598..e1593f4 100644 --- a/forester/java/src/org/forester/evoinference/distance/S.java +++ b/forester/java/src/org/forester/evoinference/distance/S.java @@ -1,6 +1,7 @@ package org.forester.evoinference.distance; +import java.text.DecimalFormat; import java.util.ArrayList; import java.util.List; import java.util.Map.Entry; @@ -20,8 +21,32 @@ public class S { _data = new ArrayList>>(); } + @Override + public String toString() { + final DecimalFormat df = new DecimalFormat( "0.00" ); + final StringBuilder sb = new StringBuilder(); + for( int j = 1; j < size(); ++j ) { + for( final Entry> entry : getSentrySet( j ) ) { + final double key = entry.getKey(); + final SortedSet values = entry.getValue(); + sb.append( df.format( key ) + "->" ); + boolean first = true; + for( final Integer v : values ) { + if ( !first ) { + sb.append( "," ); + } + first = false; + sb.append( v ); + } + sb.append( " " ); + } + sb.append( "\n" ); + } + return sb.toString(); + } + void addPairing( final double key, final int value, final int j ) { - final SortedMap> m = _data.get( j ); + final SortedMap> m = getS( j ); addPairing( key, value, m ); } @@ -30,7 +55,7 @@ public class S { } Set>> getSentrySet( final int j ) { - return _data.get( j ).entrySet(); + return getS( j ).entrySet(); } void initialize( final BasicSymmetricalDistanceMatrix d ) { @@ -41,6 +66,7 @@ public class S { addPairing( d.getValues()[ i ][ j ], i, map ); } } + System.out.println( toString() ); } void removePairing( final double key, final int value, final int j ) { @@ -49,7 +75,7 @@ public class S { if ( x.size() == 1 ) { if ( !x.contains( value ) ) { //TODO remove me later - throw new IllegalStateException( "!x.contains( value )" ); + throw new IllegalStateException( "pairing " + key + " -> " + value + " does not exist" ); } m.remove( key ); } @@ -57,7 +83,7 @@ public class S { final boolean removed = x.remove( value ); if ( !removed ) { //TODO remove me later - throw new IllegalStateException( value + " not found" ); + throw new IllegalStateException( "pairing " + key + " -> " + value + " does not exist/was not removed" ); } } else { @@ -66,6 +92,10 @@ public class S { } } + int size() { + return _data.size(); + } + private static void addPairing( final double key, final int value, final SortedMap> m ) { if ( !m.containsKey( key ) ) { final TreeSet x = new TreeSet();