Tidy serialization #28, ExportData.

This commit is contained in:
Mike Pope 2013-03-04 18:52:44 +10:30
parent 89e1fd31b1
commit 0035d58780
1 changed files with 44 additions and 87 deletions

View File

@ -30,151 +30,106 @@ import javax.xml.stream.XMLStreamWriter;
*/
public class ExportData extends FreeColObject {
/**
* Describe highLevel here.
*/
private int highLevel = 90;
private static final int HIGH_LEVEL_DEFAULT = 90;
private static final int LOW_LEVEL_DEFAULT = 10;
private static final int EXPORT_LEVEL_DEFAULT = 50;
/**
* Describe lowLevel here.
*/
private int lowLevel = 10;
/** The high water mark for the goods type. */
private int highLevel = HIGH_LEVEL_DEFAULT;
/**
* Describe exportLevel here.
*/
private int exportLevel = 50;
/** The low water mark for the goods type. */
private int lowLevel = LOW_LEVEL_DEFAULT;
/**
* Describe export here.
*/
/** The amount of goods to retain, goods beyond this amount are exported. */
private int exportLevel = EXPORT_LEVEL_DEFAULT;
/** Whether to export or not. */
private boolean exported = false;
/**
* Package constructor: This class is only supposed to be
* constructed by {@link Colony}.
*
*/
public ExportData() {}
/**
* Creates a new <code>ExportData</code> instance.
* Creates a new <code>ExportData</code> instance with default settings.
*
* @param goodsType a <code>GoodsType</code> value
* @param goodsType The <code>GoodsType</code> this data refers to.
*/
public ExportData(GoodsType goodsType) {
setId(goodsType.getId());
}
/**
* Creates a new <code>ExportData</code> instance.
*
* @param goodsType a <code>GoodsType</code> value
* @param exported a <code>boolean</code> value
* @param lowLevel an <code>int</code> value
* @param highLevel an <code>int</code> value
* @param exportLevel an <code>int</code> value
*/
public ExportData(GoodsType goodsType, boolean exported, int lowLevel, int highLevel, int exportLevel) {
setId(goodsType.getId());
this.exported = exported;
this.lowLevel = lowLevel;
this.highLevel = highLevel;
this.exportLevel = exportLevel;
}
/**
* Creates a new <code>ExportData</code> instance.
* Get the high water mark for this data.
*
* @param goodsType a <code>GoodsType</code> value
* @param exported a <code>boolean</code> value
* @param exportLevel an <code>int</code> value
*/
public ExportData(GoodsType goodsType, boolean exported, int exportLevel) {
this(goodsType, exported, 0, 100, exportLevel);
}
/**
* Creates a new <code>ExportData</code> instance.
*
* @param goodsType a <code>GoodsType</code> value
* @param template an <code>ExportData</code> value
*/
public ExportData(GoodsType goodsType, ExportData template) {
setId(goodsType.getId());
this.exported = template.exported;
this.lowLevel = template.lowLevel;
this.highLevel = template.highLevel;
this.exportLevel = template.exportLevel;
}
/**
* Get the <code>HighLevel</code> value.
*
* @return an <code>int</code> value
* @return The high water mark.
*/
public final int getHighLevel() {
return highLevel;
}
/**
* Set the <code>HighLevel</code> value.
* Set the high water mark for this data.
*
* @param newHighLevel The new HighLevel value.
* @param newHighLevel The new high water mark value.
*/
public final void setHighLevel(final int newHighLevel) {
this.highLevel = newHighLevel;
}
/**
* Get the <code>LowLevel</code> value.
* Get the low water mark for this data.
*
* @return an <code>int</code> value
* @return The low water mark.
*/
public final int getLowLevel() {
return lowLevel;
}
/**
* Set the <code>LowLevel</code> value.
* Set the low water mark for this data.
*
* @param newLowLevel The new LowLevel value.
* @param newLowLevel The new low water mark value.
*/
public final void setLowLevel(final int newLowLevel) {
this.lowLevel = newLowLevel;
}
/**
* Get the <code>ExportLevel</code> value.
* Get the export level.
*
* @return an <code>int</code> value
* @return The export level.
*/
public final int getExportLevel() {
return exportLevel;
}
/**
* Set the <code>ExportLevel</code> value.
* Set the export level.
*
* @param newExportLevel The new ExportLevel value.
* @param newExportLevel The new export level value.
*/
public final void setExportLevel(final int newExportLevel) {
this.exportLevel = newExportLevel;
}
/**
* Get the <code>Export</code> value.
* Is the goods type of this export data to be exported?
*
* @return a <code>boolean</code> value
* @return True if this goods type is to be exported.
*/
public final boolean isExported() {
return exported;
}
/**
* Set the <code>Export</code> value.
* Set the export value.
*
* @param newExport The new Export value.
* @param newExport The new export value.
*/
public final void setExported(final boolean newExport) {
this.exported = newExport;
@ -182,6 +137,11 @@ public class ExportData extends FreeColObject {
// Serialization
private static final String EXPORTED_TAG = "exported";
private static final String EXPORT_LEVEL_TAG = "exportLevel";
private static final String HIGH_LEVEL_TAG = "highLevel";
private static final String LOW_LEVEL_TAG = "lowLevel";
/**
* {@inheritDoc}
@ -198,32 +158,29 @@ public class ExportData extends FreeColObject {
protected void writeAttributes(XMLStreamWriter out) throws XMLStreamException {
super.writeAttributes(out);
out.writeAttribute("exported", Boolean.toString(exported));
writeAttribute(out, EXPORTED_TAG, exported);
out.writeAttribute("highLevel", Integer.toString(highLevel));
writeAttribute(out, HIGH_LEVEL_TAG, highLevel);
out.writeAttribute("lowLevel", Integer.toString(lowLevel));
writeAttribute(out, LOW_LEVEL_TAG, lowLevel);
out.writeAttribute("exportLevel", Integer.toString(exportLevel));
writeAttribute(out, EXPORT_LEVEL_TAG, exportLevel);
}
/**
* {@inheritDoc}
*/
@Override
public void readFromXML(XMLStreamReader in) throws XMLStreamException {
public void readAttributes(XMLStreamReader in) throws XMLStreamException {
super.readAttributes(in);
exported = Boolean.parseBoolean(in.getAttributeValue(null,
"exported"));
exported = getAttribute(in, EXPORTED_TAG, false);
highLevel = Integer.parseInt(in.getAttributeValue(null, "highLevel"));
highLevel = getAttribute(in, HIGH_LEVEL_TAG, HIGH_LEVEL_DEFAULT);
lowLevel = Integer.parseInt(in.getAttributeValue(null, "lowLevel"));
lowLevel = getAttribute(in, LOW_LEVEL_TAG, LOW_LEVEL_DEFAULT);
exportLevel = Integer.parseInt(in.getAttributeValue(null,
"exportLevel"));
in.nextTag();
exportLevel = getAttribute(in, EXPORT_LEVEL_TAG, EXPORT_LEVEL_DEFAULT);
}
/**