/*
 * Copyright (c) 2012 Mateusz Parzonka, Eric Bodden
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * Mateusz Parzonka - initial API and implementation
 */
package prm4j.logic;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;

import prm4j.api.Parameter;
import prm4j.api.Symbol;
import prm4j.api.fsm.FSM;

public class StatefulSpecConverter {

    private final Map<Symbol, Set<Set<Symbol>>> propertyEnableSets;
    private final Map<Symbol, Set<Set<Parameter<?>>>> parameterEnableSets;
    private final Map<MonitorState<?>, Set<Set<Symbol>>> stateCoEnableSets;
    private final MonitorState<?> initialState;
    private final List<Symbol> symbols;

    public StatefulSpecConverter(StatefulSpec spec) {
	propertyEnableSets = spec.getPropertyEnableSet();
	parameterEnableSets = getParameterEnableSets(propertyEnableSets);
	stateCoEnableSets = spec.getStateCoEnableSet();
	initialState = spec.getInitialState();
	symbols = spec.getSymbols();
    }

    private static <A> Map<Symbol, Set<Set<Parameter<?>>>> getParameterEnableSets(
	    Map<Symbol, Set<Set<Symbol>>> symbol2setOfSetOfSymbol) {
	Map<Symbol, Set<Set<Parameter<?>>>> result = new HashMap<Symbol, Set<Set<Parameter<?>>>>();
	for (Entry<Symbol, Set<Set<Symbol>>> entry : symbol2setOfSetOfSymbol.entrySet()) {
	    result.put(entry.getKey(), toParameterSets(entry.getValue()));
	}
	return result;
    }

    private static Set<Set<Parameter<?>>> toParameterSets(Set<Set<Symbol>> propertyEnableSet) {
	Set<Set<Parameter<?>>> result = new HashSet<Set<Parameter<?>>>();
	for (Set<Symbol> set : propertyEnableSet) {
	    Set<Parameter<?>> parameterSet = new HashSet<Parameter<?>>();
	    for (Symbol symbol : set) {
		parameterSet.addAll(symbol.getParameters());
	    }
	    result.add(parameterSet);
	}
	return result;
    }

}

@@ -860,24 +860,123 @@
 bol%3E%3E%3E state
+PropertyCoEnableSets;%0A    private final Map%3CMonitorState%3C?%3E, Set%3CSet%3CParameter%3C?%3E%3E%3E%3E stateParameter
 CoEnableSets
@@ -1198,39 +1198,72 @@
 s = 
-getParameterEnableSets(p
+toMap2SetOfSetOfParameters(propertyEnableSets);%0A%09stateP
 roperty
+Co
 Enab
@@ -1272,45 +1272,109 @@
 Sets
-);%0A%09stateCoEnableSets = spec.getState
+ = spec.getStateCoEnableSet();%0A%09stateParameterCoEnableSets = toMap2SetOfSetOfParameters(stateProperty
 CoEn
@@ -1376,25 +1376,25 @@
 yCoEnableSet
-(
+s
 );%0A%09initialS
@@ -1485,21 +1485,16 @@
 ic %3C
-A
+T
 %3E Map%3C
-Symbol
+T
 , Se
@@ -1519,29 +1519,33 @@
 %3E%3E%3E 
-getParameterEnableSet
+toMap2SetOfSetOfParameter
 s(%0A%09
@@ -1548,30 +1548,25 @@
 s(%0A%09    Map%3C
-Symbol
+T
 , Set%3CSet%3CSy
@@ -1573,22 +1573,17 @@
 mbol%3E%3E%3E 
-symbol
+t
 2setOfSe
@@ -1596,30 +1596,25 @@
 bol) %7B%0A%09Map%3C
-Symbol
+T
 , Set%3CSet%3CPa
@@ -1644,30 +1644,25 @@
 new HashMap%3C
-Symbol
+T
 , Set%3CSet%3CPa
@@ -1690,22 +1690,17 @@
  (Entry%3C
-Symbol
+T
 , Set%3CSe
@@ -1719,22 +1719,17 @@
 entry : 
-symbol
+t
 2setOfSe

Make method more generic