@Test public void testToString() throws Exception { final Character prototype = new Character(); prototype.set(Stats.ARMOR, 1); prototype.set(Stats.AGILITY, 2); prototype.set(Stats.INTELLECT, 3); assertEquals("Stats:\n - AGILITY:2\n - ARMOR:1\n - INTELLECT:3\n", prototype.toString()); final Character stupid = new Character(Type.ROGUE, prototype); stupid.remove(Stats.INTELLECT); assertEquals("Character type: ROGUE\nStats:\n - AGILITY:2\n - ARMOR:1\n", stupid.toString()); final Character weak = new Character("weak", prototype); weak.remove(Stats.ARMOR); assertEquals("Player: weak\nStats:\n - AGILITY:2\n - INTELLECT:3\n", weak.toString()); }
@Override public String toString() { StringBuilder builder = new StringBuilder(); if (name != null) { builder.append("Player: ").append(name).append('\n'); } if (type != null) { builder.append("Character type: ").append(type.name()).append('\n'); } builder.append("Stats:\n"); for (Stats stat : Stats.values()) { Integer value = this.get(stat); if (value == null) { continue; } builder.append(" - ").append(stat.name()).append(':').append(value).append('\n'); } return builder.toString(); }
Character implements Prototype { @Override public String toString() { StringBuilder builder = new StringBuilder(); if (name != null) { builder.append("Player: ").append(name).append('\n'); } if (type != null) { builder.append("Character type: ").append(type.name()).append('\n'); } builder.append("Stats:\n"); for (Stats stat : Stats.values()) { Integer value = this.get(stat); if (value == null) { continue; } builder.append(" - ").append(stat.name()).append(':').append(value).append('\n'); } return builder.toString(); } }
Character implements Prototype { @Override public String toString() { StringBuilder builder = new StringBuilder(); if (name != null) { builder.append("Player: ").append(name).append('\n'); } if (type != null) { builder.append("Character type: ").append(type.name()).append('\n'); } builder.append("Stats:\n"); for (Stats stat : Stats.values()) { Integer value = this.get(stat); if (value == null) { continue; } builder.append(" - ").append(stat.name()).append(':').append(value).append('\n'); } return builder.toString(); } Character();  Character(Type type, Prototype prototype);  Character(String name, Character prototype); }
Character implements Prototype { @Override public String toString() { StringBuilder builder = new StringBuilder(); if (name != null) { builder.append("Player: ").append(name).append('\n'); } if (type != null) { builder.append("Character type: ").append(type.name()).append('\n'); } builder.append("Stats:\n"); for (Stats stat : Stats.values()) { Integer value = this.get(stat); if (value == null) { continue; } builder.append(" - ").append(stat.name()).append(':').append(value).append('\n'); } return builder.toString(); } Character();  Character(Type type, Prototype prototype);  Character(String name, Character prototype); String name(); Type type(); @Override Integer get(Stats stat); @Override boolean has(Stats stat); @Override void set(Stats stat, Integer val); @Override void remove(Stats stat); @Override String toString(); }
Character implements Prototype { @Override public String toString() { StringBuilder builder = new StringBuilder(); if (name != null) { builder.append("Player: ").append(name).append('\n'); } if (type != null) { builder.append("Character type: ").append(type.name()).append('\n'); } builder.append("Stats:\n"); for (Stats stat : Stats.values()) { Integer value = this.get(stat); if (value == null) { continue; } builder.append(" - ").append(stat.name()).append(':').append(value).append('\n'); } return builder.toString(); } Character();  Character(Type type, Prototype prototype);  Character(String name, Character prototype); String name(); Type type(); @Override Integer get(Stats stat); @Override boolean has(Stats stat); @Override void set(Stats stat, Integer val); @Override void remove(Stats stat); @Override String toString();  }