package eu.ydp.empiria.player.client.controller.variables.objects;

import java.util.Vector;

import com.google.gwt.json.client.JSONValue;

public abstract class Variable {
	
	public Variable(){
		values = new Vector<String>();
		identifier = "";
		cardinality = Cardinality.SINGLE;
		baseType = BaseType.STRING;
	}
	
	public String identifier;

	public Cardinality cardinality;
	
	public BaseType baseType;
	
	public Vector<String> values;
		
	public abstract void reset();
	
	public String getValuesShort(){
		
		String output = "";
		
		for (int i = 0 ; i < values.size() ; i ++ ){
			output += values.get(i);
			if (i < values.size()-1)
				output += ";";
		}
		
		return output;
	}
	
	public boolean compareValues(String[] testValues){
		Vector<String> vec = new Vector<String>();
		for (int i = 0 ; i < testValues.length ; i ++)
			vec.add(testValues[i]);
		return compareValues(vec);
		
	}
	public boolean compareValues(Vector<String> testValues){
		
		if (values.size() != testValues.size())
			return false;
		
		boolean contains;
		
		for (String ref : values){
			contains = false;
			for (String test : testValues){
				if (ref.compareTo(test) == 0){
					contains = true;
					break;
				}
			}	
			if (!contains)
				return false;
		}
		return true;
	}

	public abstract JSONValue toJSON();
	public abstract void fromJSON(JSONValue value);
}

@@ -621,16 +621,27 @@
 tput += 
+escapeCSV (
 values.g
@@ -645,16 +645,18 @@
 s.get(i)
+ )
 ;%0D%0A%09%09%09if
@@ -725,32 +725,228 @@
 output;%0D%0A%09%7D%0D%0A%09%0D%0A
+%09protected String escapeCSV(String value)%7B%0D%0A%09%09if (value.contains(%22'%22)  %7C%7C  value.contains(%22;%22))%7B%0D%0A%09%09%09value = value.replace(%22'%22, %22''%22);%0D%0A%09%09%09value = %22'%22 + value + %22'%22;%0D%0A%09%09%7D%0D%0A%09%09return value;%0D%0A%09%7D%0D%0A%09%0D%0A
 %09public boolean 

escape special characters in short format of the variables value