// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
//
// Contact: phylosoft @ gmail . com
-// WWW: www.phylosoft.org/forester
+// WWW: https://sites.google.com/site/cmzmasek/home/software/forester
package org.forester.evoinference.matrix.distance;
import org.forester.util.ForesterUtil;
import org.forester.util.IllegalFormatUseException;
-public class BasicSymmetricalDistanceMatrix implements DistanceMatrix {
+public final class BasicSymmetricalDistanceMatrix implements DistanceMatrix {
- NumberFormat nf1 = NumberFormat.getInstance();
+ // NumberFormat nf1 = NumberFormat.getInstance();
private final static NumberFormat PHYLIP_FORMATTER = new DecimalFormat( "0.000000" );
final double[][] _values;
final String[] _identifiers;
_identifiers = new String[ size ];
}
+ public final double[][] getValues() {
+ return _values;
+ }
+
@Override
- public String getIdentifier( final int i ) {
+ public final String getIdentifier( final int i ) {
return _identifiers[ i ];
}
@Override
- public int getIndex( final String identifier ) {
+ public final int getIndex( final String identifier ) {
for( int i = 0; i < _identifiers.length; i++ ) {
if ( getIdentifier( i ).equals( identifier ) ) {
return i;
}
@Override
- public int getSize() {
+ public final int getSize() {
return _values.length;
}
@Override
- public double getValue( final int col, final int row ) {
+ public final double getValue( final int col, final int row ) {
if ( col == row ) {
- if ( col >= getSize() ) {
+ if ( col >= _values.length ) {
throw new IndexOutOfBoundsException( "" );
}
return 0.0;
return _values[ col ][ row ];
}
- public void randomize( final long seed ) {
+ public final void randomize( final long seed ) {
final java.util.Random r = new java.util.Random( seed );
for( int j = 0; j < getSize(); ++j ) {
for( int i = 0; i < j; ++i ) {
}
@Override
- public void setIdentifier( final int i, final String identifier ) {
+ public final void setIdentifier( final int i, final String identifier ) {
_identifiers[ i ] = identifier;
}
- public void setRow( final String s, final int row ) {
+ public final void setRow( final String s, final int row ) {
final StringTokenizer tk = new StringTokenizer( s );
int i = 0;
while ( tk.hasMoreElements() ) {
}
@Override
- public void setValue( final int col, final int row, final double d ) {
+ public final void setValue( final int col, final int row, final double d ) {
+ if ( d < 0 ) {
+ throw new IllegalArgumentException( "negative distance value" );
+ }
if ( ( col == row ) && ( d != 0.0 ) ) {
throw new IllegalArgumentException( "attempt to set a non-zero value on the diagonal of a symmetrical distance matrix" );
}
_values[ col ][ row ] = d;
}
- public void write( final Writer w ) throws IOException {
+ public final void write( final Writer w ) throws IOException {
w.write( " " );
w.write( getSize() + "" );
w.write( ForesterUtil.LINE_SEPARATOR );
}
for( int col = 0; col < getSize(); ++col ) {
w.write( PHYLIP_FORMATTER.format( getValue( col, row ) ) );
- if ( col < getSize() - 1 ) {
+ if ( col < ( getSize() - 1 ) ) {
w.write( ' ' );
w.write( ' ' );
}
}
- if ( row < getSize() - 1 ) {
+ if ( row < ( getSize() - 1 ) ) {
w.write( ForesterUtil.LINE_SEPARATOR );
}
}
}
- private StringBuffer toPhylip() {
+ private final StringBuffer toPhylip() {
final StringBuffer sb = new StringBuffer();
sb.append( ' ' );
sb.append( ' ' );
//sb.append( "" );
for( int col = 0; col < getSize(); ++col ) {
sb.append( PHYLIP_FORMATTER.format( getValue( col, row ) ) );
- if ( col < getSize() - 1 ) {
+ if ( col < ( getSize() - 1 ) ) {
sb.append( ' ' );
sb.append( ' ' );
}
}
- if ( row < getSize() - 1 ) {
+ if ( row < ( getSize() - 1 ) ) {
sb.append( ForesterUtil.LINE_SEPARATOR );
}
}
}
@Override
- public String toString() {
+ public final String toString() {
return toPhylip().toString();
}
@Override
- public StringBuffer toStringBuffer( final Format format ) {
+ public final StringBuffer toStringBuffer( final Format format ) {
switch ( format ) {
case PHYLIP:
return toPhylip();