/*
 * Copyright 2002-2015 The Jamocha Team
 * 
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 * 
 * http://www.jamocha.org/
 * 
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */
package org.jamocha.filter;

import static java.util.stream.Collectors.toList;

import org.jamocha.filter.PathFilterList.PathExistentialList;
import org.jamocha.filter.PathFilterSet.PathExistentialSet;

/**
 * @author Fabian Ohler <fabian.ohler1@rwth-aachen.de>
 *
 */
public class TrivialPathSetToPathListConverter implements PathFilterSetVisitor {

	PathFilterList result;

	public static PathFilterList convert(final PathFilterSet filter) {
		return filter.accept(new TrivialPathSetToPathListConverter()).result;
	}

	@Override
	public void visit(final PathExistentialSet set) {
		this.result = new PathExistentialList(set.getInitialPath(),
				new PathFilterList.PathSharedListWrapper().newSharedElement(
						set.getPurePart().stream().map(TrivialPathSetToPathListConverter::convert).collect(toList())),
				PathNodeFilterSet.newExistentialPathNodeFilterSet(set.isPositive(), set.getExistentialPaths(),
						set.getExistentialClosure()));
	}

	@Override
	public void visit(final PathFilter filter) {
		this.result = PathNodeFilterSet.newRegularPathNodeFilterSet(filter);
	}

}

@@ -656,16 +656,65 @@
 oList;%0A%0A
+import java.util.HashSet;%0Aimport java.util.Set;%0A%0A
 import o
@@ -826,16 +826,297 @@
 tialSet;
+%0Aimport org.jamocha.function.fwa.GenericWithArgumentsComposite;%0Aimport org.jamocha.function.fwa.PathLeaf;%0Aimport org.jamocha.function.fwa.PredicateWithArgumentsComposite;%0Aimport org.jamocha.function.impls.predicates.And;%0Aimport org.jamocha.function.impls.predicates.DummyPredicate;
 %0A%0A/**%0A *
@@ -1490,30 +1490,627 @@
 et) %7B%0A%09%09
-this.result = 
+PathFilter existentialClosure = set.getExistentialClosure();%0A%09%09final HashSet%3CPath%3E mixedPaths = PathCollector.newHashSet().collectAllInSets(existentialClosure).getPaths();%0A%09%09final Set%3CPath%3E existentialPaths = set.getExistentialPaths();%0A%09%09mixedPaths.removeAll(existentialPaths);%0A%09%09if (mixedPaths.isEmpty()) %7B%0A%09%09%09existentialClosure =%0A%09%09%09%09%09new PathFilter(GenericWithArgumentsComposite.newPredicateInstance(And.inClips,%0A%09%09%09%09%09%09%09set.existentialClosure.getFunction(), new PredicateWithArgumentsComposite%3CPathLeaf%3E(%0A%09%09%09%09%09%09%09%09%09DummyPredicate.instance, new PathLeaf(set.getInitialPath(), null))));%0A%09%09%7D%0A%09%09this.result =%0A%09%09%09%09
 new Path
@@ -2143,24 +2143,26 @@
 tialPath(),%0A
+%09%09
 %09%09%09%09new Path
@@ -2213,23 +2213,16 @@
 Element(
-%0A%09%09%09%09%09%09
 set.getP
@@ -2239,16 +2239,25 @@
 stream()
+%0A%09%09%09%09%09%09%09%09
 .map(Tri
@@ -2321,16 +2321,18 @@
 )),%0A%09%09%09%09
+%09%09
 PathNode
@@ -2391,24 +2391,17 @@
 tive(), 
-set.getE
+e
 xistenti
@@ -2407,26 +2407,24 @@
 ialPaths
-()
 ,%0A%09%09%09%09%09%09
 set.getE
@@ -2415,24 +2415,19 @@
 ,%0A%09%09%09%09%09%09
-set.getE
+%09%09e
 xistenti
@@ -2435,18 +2435,16 @@
 lClosure
-()
 ));%0A%09%7D%0A%0A

make sure the existential closure of the PathList hierarchy is joined with initial-fact if it doesn't contain any paths from the outer scope