/**
 * Copyright (c) 2017-2018, the Alpha Team.
 * All rights reserved.
 * 
 * Additional changes made by Siemens.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * 
 * 1) Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 * 
 * 2) Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package at.ac.tuwien.kr.alpha.common.atoms;

import at.ac.tuwien.kr.alpha.common.Predicate;
import at.ac.tuwien.kr.alpha.common.fixedinterpretations.PredicateInterpretation;
import at.ac.tuwien.kr.alpha.common.terms.Term;
import at.ac.tuwien.kr.alpha.grounder.Substitution;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

import static at.ac.tuwien.kr.alpha.Util.join;

public class ExternalAtom implements Atom {
	private final List<Term> input;
	private final List<Term> output;

	protected Predicate predicate;
	protected final PredicateInterpretation interpretation;

	public ExternalAtom(Predicate predicate, PredicateInterpretation interpretation, List<Term> input, List<Term> output) {
		this.predicate = predicate;
		this.interpretation = interpretation;
		this.input = input;
		this.output = output;
	}

	public boolean hasOutput() {
		return !output.isEmpty();
	}

	@Override
	public Predicate getPredicate() {
		return predicate;
	}

	public PredicateInterpretation getInterpretation() {
		return interpretation;
	}
	
	List<Term> getInput() {
		return Collections.unmodifiableList(input);
	}
	
	List<Term> getOutput() {
		return Collections.unmodifiableList(output);
	}

	@Override
	public List<Term> getTerms() {
		return input;
	}

	@Override
	public boolean isGround() {
		return false;
	}

	@Override
	public ExternalAtom substitute(Substitution substitution) {
		return new ExternalAtom(
			predicate,
			interpretation,
			input
				.stream()
				.map(t -> t.substitute(substitution))
				.collect(Collectors.toList()),
			output
		);
	}

	@Override
	public ExternalLiteral toLiteral(boolean positive) {
		return new ExternalLiteral(this, positive);
	}

	@Override
	public String toString() {
		String result = "&" + predicate.getName();
		if (!output.isEmpty()) {
			result += join("[", output, "]");
		}
		if (!input.isEmpty()) {
			result += join("(", input, ")");
		}
		return result;
	}
}

@@ -3011,16 +3011,106 @@
 %09output%0A
+%09%09%09%09.stream()%0A%09%09%09%09.map(t -%3E t.substitute(substitution))%0A%09%09%09%09.collect(Collectors.toList())%0A
 %09%09);%0A%09%7D%0A
@@ -3316,19 +3316,18 @@
 %0A%09%09if (!
-out
+in
 put.isEm
@@ -3358,19 +3358,18 @@
 in(%22%5B%22, 
-out
+in
 put, %22%5D%22
@@ -3374,34 +3374,35 @@
 %5D%22);%0A%09%09%7D%0A%09%09if (!
-in
+out
 put.isEmpty()) %7B
@@ -3425,18 +3425,19 @@
 in(%22(%22, 
-in
+out
 put, %22)%22

Fix toString and substitute methods of ExternalAtom.