SimpleSubstitutionMatrix implements SubstitutionMatrix<C> { @Override public String toString() { StringBuilder s = new StringBuilder(); StringTokenizer st = new StringTokenizer(description, "\n\r"); while (st.hasMoreTokens()) { String line = st.nextToken(); if (!line.startsWith(comment)) { s.append(comment); } s.append(String.format("%s%n", line)); } s.append(getMatrixAsString()); return s.toString(); } @SuppressWarnings("unchecked") // TODO proper generic type checking instead of possible ClassCastException  SimpleSubstitutionMatrix();  SimpleSubstitutionMatrix(CompoundSet<C> compoundSet, File fileInput);  SimpleSubstitutionMatrix(CompoundSet<C> compoundSet, Reader input, String name);  SimpleSubstitutionMatrix(CompoundSet<C> compoundSet, String matrixInput, String name);  SimpleSubstitutionMatrix(CompoundSet<C> compoundSet, short match, short replace); private  SimpleSubstitutionMatrix(CompoundSet<C> compoundSet, Scanner input, String name); @Override CompoundSet<C> getCompoundSet(); @Override String getDescription(); @Override short[][] getMatrix(); @Override String getMatrixAsString(); @Override short getMaxValue(); @Override short getMinValue(); @Override String getName(); @Override short getValue(C from, C to); @Override SubstitutionMatrix<C> normalizeMatrix(short scale); @Override void setDescription(String description); @Override void setName(String name); @Override String toString();  }
@Test public void testToString() { SubstitutionMatrix<NucleotideCompound> matrix = new SimpleSubstitutionMatrix<NucleotideCompound>( DNACompoundSet.getDNACompoundSet(), "# Test\nA C G T\nA 5 0 0 0\nC 0 5 0 0 \nG 0 0 5 0\n T 0 0 0 1\n", "DNAtest"); assertEquals(matrix.toString().substring(0,6), "# Test"); assertEquals(matrix.toString(), String.format("# Test%n A C G T%nA 5 0 0 0%nC 0 5 0 0%nG 0 0 5 0%nT 0 0 0 1%n")); }