/** * @param meadow a meadow or field * @return the proper tag for it */ @SuppressWarnings("TypeMayBeWeakened") private static String getMeadowTag(final Meadow meadow) { if (meadow.isField()) { return "field"; } else { return "meadow"; } }
/** * Write an object to a stream. * * @param ostream The stream to write to. * @param obj The object to write. * @param indent The current indentation level. * @throws IOException on I/O error */ @Override public void write(final Appendable ostream, final HarvestableFixture obj, final int indent) throws IOException { if (obj instanceof CacheFixture) { writeTag(ostream, "cache", indent); final CacheFixture cache = (CacheFixture) obj; writeProperty(ostream, "kind", cache.getKind()); writeProperty(ostream, "contents", cache.getContents()); } else if (obj instanceof Meadow) { writeTag(ostream, getMeadowTag((Meadow) obj), indent); final Meadow meadow = (Meadow) obj; writeProperty(ostream, "kind", meadow.getKind()); writeProperty(ostream, "cultivated", Boolean.toString(meadow.isCultivated())); writeProperty(ostream, "status", meadow.getStatus().toString()); } else if (obj instanceof Grove) { writeTag(ostream, getGroveTag((Grove) obj), indent); final Grove grove = (Grove) obj; writeProperty(ostream, "cultivated", Boolean.toString(grove.isCultivated())); writeProperty(ostream, "kind", grove.getKind()); } else if (obj instanceof Mine) { writeTag(ostream, "mine", indent); final Mine mine = (Mine) obj; writeProperty(ostream, "kind", mine.getKind()); writeProperty(ostream, "status", mine.getStatus().toString()); } else if (obj instanceof MineralVein) { writeTag(ostream, "mineral", indent); final MineralVein mineral = (MineralVein) obj; writeProperty(ostream, "kind", mineral.getKind()); writeProperty(ostream, "exposed", Boolean.toString(mineral.isExposed())); writeProperty(ostream, "dc", Integer.toString(mineral.getDC())); } else if (obj instanceof Shrub) { writeTag(ostream, "shrub", indent); writeProperty(ostream, "kind", ((Shrub) obj).getKind()); } else if (obj instanceof StoneDeposit) { writeTag(ostream, "stone", indent); final StoneDeposit stone = (StoneDeposit) obj; writeProperty(ostream, "kind", stone.stone().toString()); writeProperty(ostream, "dc", Integer.toString(stone.getDC())); } else { throw new IllegalStateException("Unhandled HarvestableFixture subtype"); } writeProperty(ostream, "id", Integer.toString(obj.getID())); writeImageXML(ostream, obj); closeLeafTag(ostream); }