package background.systemVariables;

import background.VariableManager;

public class StringVariable extends SimpleVariable {
	private String value;	
	private ArrayVariable arrayRepresentation;
	private VariableManager vm;

	/* ============================================= */
	
	public StringVariable(String xValue, VariableManager vm) {
		this.vm = vm;
		this.setValue(xValue);
		this.setVizualize(false);
		
	}
	
	public StringVariable(String xValue, Boolean viz, VariableManager vm) {
		this.vm = vm;
		this.setValue(xValue);
		this.setVizualize(viz);
	}

	/* ============================================= */
	
	
	private void makeArray() {
		arrayRepresentation = new ArrayVariable(value.length(), "char", vm);
		arrayRepresentation.name = this.name;		
		for (int i=0; i<value.length(); i++) {			
			CharacterVariable var = new CharacterVariable(value.charAt(i));	
			arrayRepresentation.updateNth(i, var);
		}			
	}
	
	public SimpleVariable getCharAt(int i) {
		return arrayRepresentation.getNth(i);
	}
	
	public void setValue(String xValue) {
		value = xValue;
		makeArray();
	}
	
	@Override
	public String getType() {
		return "string";
	}
	
	@Override
	public String getValue(String s) {
		return value;
	}	
}
