/** * A recusrive function that builds the genotype string. * * @param g The current node. * @param b The string builder. */ private void buildStorageString(Genotype g, StringBuilder b) { if (g == null) { b.append(";"); return; } b.append( String.format("%02d", TokenMap.get(g.token.getToken())) + String.format("%02d", g.token.getAmount())); buildStorageString(g.left, b); buildStorageString(g.right, b); }
/** * Returns the genotype encoded as a string. * * @return The genotype encoded as a string. */ public String getStorageString() { StringBuilder b = new StringBuilder(); buildStorageString(this, b); return b.toString(); }