package ee.stacc.productivity.edsl.string.samplegen;

import java.util.ArrayList;
import java.util.List;

import ee.stacc.productivity.edsl.string.IAbstractString;
import ee.stacc.productivity.edsl.string.StringChoice;
import ee.stacc.productivity.edsl.string.StringConstant;
import ee.stacc.productivity.edsl.string.StringRandomInteger;
import ee.stacc.productivity.edsl.string.StringSequence;

public class SampleGenerator {
	public static List<String> getConcreteStrings(IAbstractString aStr) {
		List<String> result = new ArrayList<String>();
		
		if (aStr instanceof StringConstant) {
			result.add(((StringConstant)aStr).getConstant());
		}
		else if (aStr instanceof StringChoice) {
			for (IAbstractString item: ((StringChoice)aStr).getItems()) {
				result.addAll(getConcreteStrings(item));
			}
		}
		else if (aStr instanceof StringSequence) {
			
			for (IAbstractString item: ((StringSequence)aStr).getItems()) {
				if (result.isEmpty()) { // first piece
					result.addAll(getConcreteStrings(item));
				}
				else { // later parts should be multiplied by existing strings
					List<String> options = getConcreteStrings(item);
					List<String> tempList = new ArrayList<String>();
					for (String resultItem: result) {
						for (String option: options) {
							tempList.add(resultItem + option);
						}
					}
					result = tempList;
				}
			}
		}
		else if (aStr instanceof StringRandomInteger) {
			result.add(((StringRandomInteger)aStr).getExample());
		}
		else {
			throw new UnsupportedOperationException("getConcreteStrings, class="
					+ aStr.getClass());
		}
		return result;
	}
}

@@ -99,73 +99,211 @@
 til.
-List;%0D%0A%0D%0Aimport ee.stacc.productivity.edsl.string.IAbstractString
+Arrays;%0D%0Aimport java.util.HashSet;%0D%0Aimport java.util.List;%0D%0Aimport java.util.Set;%0D%0A%0D%0Aimport ee.stacc.productivity.edsl.string.IAbstractString;%0D%0Aimport ee.stacc.productivity.edsl.string.StringCharacterSet
 ;%0D%0Ai
@@ -570,16 +570,157 @@
 ator %7B%0D%0A
+%09private static Set%3CCharacter%3E intCharset = %0D%0A%09%09new HashSet%3CCharacter%3E(Arrays.asList('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'));%0D%0A%09%0D%0A
 %09public 
@@ -1790,24 +1790,470 @@
 e());%0D%0A%09%09%7D%0D%0A
+%09%09else if (aStr instanceof StringCharacterSet) %7B%0D%0A%09%09%09// FIXME incorrect shortcut solution%0D%0A%09%09%09%0D%0A%09%09%09result.add(%22555%22);%0D%0A%09%09%09%0D%0A%09%09%09%0D%0A//%09%09%09StringCharacterSet cs = (StringCharacterSet)aStr;%0D%0A//%09%09%09if (cs.getContents().containsAll(intCharset) // gives NullPointerException%0D%0A//%09%09%09%09%09&& intCharset.containsAll(cs.getContents())) %7B%0D%0A//%09%09%09%09result.add(%22666%22);%0D%0A//%09%09%09%7D%0D%0A//%09%09%09else %7B%0D%0A//%09%09%09%09// creates nonvalid SQL%0D%0A//%09%09%09%09result.add(cs.toString());%0D%0A//%09%09%09%7D%0D%0A%09%09%7D%0D%0A
 %09%09else %7B%0D%0A%09%09

support charset