package background.systemVariables;

import java.util.ArrayList;

import background.VariableManager;

public class ArrayVariable {
	private ArrayList<SimpleVariable> innerVariables;
	public String name;
	public Boolean vizualize;
	public int size;
	private String type;
	public int posun = 0;
	
	public ArrayVariable(int p, int s, String t, VariableManager vm) {				
		posun = p;
		size = s-posun;
		
		type = t;
		innerVariables = new ArrayList<SimpleVariable>();
		for (int i=1; i<=size; i++) {		
			innerVariables.add(vm.getNewVariableOfType(type, vm.getDefaultValueForType(type)));
		}
	}

	
	public ArrayVariable(int s, String t, VariableManager vm) {
		size = s;
		type = t;
		innerVariables = new ArrayList<SimpleVariable>();
		for (int i=1; i<=size; i++) {		
			innerVariables.add(vm.getNewVariableOfType(type, vm.getDefaultValueForType(type)));
		}
	}

	public ArrayVariable(int s, String t) {
		size = s;
		type = t;
		innerVariables = new ArrayList<SimpleVariable>();
		for (int i=1; i<=size; i++) {		
			innerVariables.add(new SimpleVariable());
		}
	}

	
	public String getType() {
		return type;
	}
	
	public void setVizualize(Boolean b) {
		vizualize = b;
	}

	public SimpleVariable getNth(int i) {
		SimpleVariable result = innerVariables.get(i-posun);
		return result;
	}

	public void updateNth(int i, SimpleVariable val) {
		if (val.getType().equals(type)) {			
			innerVariables.get(i-posun).initialized = true;
			innerVariables.get(i-posun).setValue(val.getValue("string"));
		}
	}

	
	
}
