package caseStudy;

public class Row extends SaveAsXML {
    private SaveableField <String> instructions;
    private SaveableField <Integer> length;
    
    // XML Tags
    public static final String STARTCLASSTAG = "<Row>";
    public static final String ENDCLASSTAG = "</Row>";
    
    // Constructors
    public Row() {
        initializeFields();
        instructions.setValue("");;
        length.setValue(0);
    }
    public Row(Row r) {
        initializeFields();
        length.setValue(r.getLength());
        instructions.setValue(r.getInstructions());
    }
    public Row(String i, int l) {
        initializeFields();
        instructions.setValue(i);
        length.setValue(l);
    }
    public Row(String xml) {
        initializeFields();
        this.load(xml);
    }
    
    // Accessors
    public String getInstructions() {
        return instructions.getValue();
    }
    public int getLength() {
        return length.getValue();
    }
    public String toString() {
        return instructions.getValue() + " (" + length.getValue() + " sts)";
    }
    public String save() {
        return STARTCLASSTAG
                + instructions.save()
                + length.save()
                + ENDCLASSTAG;
    }
    public boolean equals(Row r) {
        if((instructions.getValue() == r.getInstructions()) 
                && (length.getValue() == r.getLength())) {
            return true;
        }
        return false;
    }
   
    // Modifiers
    public void setInstructions(String newInstructions) {
        instructions.setValue(newInstructions);
    }
    public void addToInstructions(String toAdd) {
        instructions.setValue(instructions.getValue().concat(toAdd));
    }
    public void setLength(int l) {
        length.setValue(l);
    }
    public void load(String xml) {
        length.setValue(Integer.parseInt(length.getStringDataFromXML(xml)));
        instructions.setValue(instructions.getStringDataFromXML(xml));
    }
    private void initializeFields() {
        instructions = new SaveableField <String> ("instructions");
        length = new SaveableField <Integer> ("length");
    }
}
