From bb54192a69ac002a2bfa85d736417de9b2b50ea4 Mon Sep 17 00:00:00 2001
From: Christian Wulf <chw@informatik.uni-kiel.de>
Date: Tue, 17 Mar 2015 12:05:53 +0100
Subject: [PATCH] improved InstanceOfFilter

---
 .../java/teetime/stage/InstanceOfFilter.java  | 29 +++++++++++++++----
 src/site/markdown/wiki                        |  2 +-
 .../teetime/stage/InstanceOfFilterTest.java   |  8 ++---
 3 files changed, 28 insertions(+), 11 deletions(-)

diff --git a/src/main/java/teetime/stage/InstanceOfFilter.java b/src/main/java/teetime/stage/InstanceOfFilter.java
index 76dab9b2..791b2da2 100644
--- a/src/main/java/teetime/stage/InstanceOfFilter.java
+++ b/src/main/java/teetime/stage/InstanceOfFilter.java
@@ -19,12 +19,13 @@ import teetime.framework.AbstractConsumerStage;
 import teetime.framework.OutputPort;
 
 /**
- * @author Jan Waller, Nils Christian Ehmke, Christian Wulf
+ * @author Jan Waller, Nils Christian Ehmke, Christian Wulf, Nelson Tavares de Sousa
  *
  */
-public final class InstanceOfFilter<I, O> extends AbstractConsumerStage<I> {
+public final class InstanceOfFilter<I, O extends I> extends AbstractConsumerStage<I> {
 
-	private final OutputPort<O> outputPort = this.createOutputPort();
+	private final OutputPort<O> matchedOutputPort = this.createOutputPort();
+	private final OutputPort<I> mismatchedOutputPort = this.createOutputPort();
 
 	private Class<O> type;
 
@@ -36,11 +37,12 @@ public final class InstanceOfFilter<I, O> extends AbstractConsumerStage<I> {
 	@Override
 	protected void execute(final I element) {
 		if (this.type.isInstance(element)) {
-			outputPort.send((O) element);
-		} else { // swallow up the element
+			matchedOutputPort.send((O) element);
+		} else {
 			if (this.logger.isDebugEnabled()) {
 				this.logger.debug("element is not an instance of " + this.type.getName() + ", but of " + element.getClass());
 			}
+			mismatchedOutputPort.send(element);
 		}
 	}
 
@@ -52,8 +54,23 @@ public final class InstanceOfFilter<I, O> extends AbstractConsumerStage<I> {
 		this.type = type;
 	}
 
+	/**
+	 *
+	 * @return the output port that outputs
+	 *
+	 * @deprecated 1.1. Use {@link #getMatchedOutputPort()} instead.
+	 */
+	@Deprecated
 	public OutputPort<O> getOutputPort() {
-		return this.outputPort;
+		return matchedOutputPort;
+	}
+
+	public OutputPort<O> getMatchedOutputPort() {
+		return matchedOutputPort;
+	}
+
+	public OutputPort<I> getMismatchedOutputPort() {
+		return mismatchedOutputPort;
 	}
 
 }
diff --git a/src/site/markdown/wiki b/src/site/markdown/wiki
index 63ccbbc8..0e447457 160000
--- a/src/site/markdown/wiki
+++ b/src/site/markdown/wiki
@@ -1 +1 @@
-Subproject commit 63ccbbc87bd2c0e6599ca91502149dba3cfb99de
+Subproject commit 0e4474577e1f49bc96e734c286b2d9e0363895e8
diff --git a/src/test/java/teetime/stage/InstanceOfFilterTest.java b/src/test/java/teetime/stage/InstanceOfFilterTest.java
index efbe1f4a..ea1e93b6 100644
--- a/src/test/java/teetime/stage/InstanceOfFilterTest.java
+++ b/src/test/java/teetime/stage/InstanceOfFilterTest.java
@@ -45,7 +45,7 @@ public class InstanceOfFilterTest {
 		final List<Clazz> results = new ArrayList<InstanceOfFilterTest.Clazz>();
 		final Object clazz = new Clazz();
 
-		test(filter).and().send(clazz).to(filter.getInputPort()).and().receive(results).from(filter.getOutputPort()).start();
+		test(filter).and().send(clazz).to(filter.getInputPort()).and().receive(results).from(filter.getMatchedOutputPort()).start();
 
 		assertThat(results, contains(clazz));
 	}
@@ -55,7 +55,7 @@ public class InstanceOfFilterTest {
 		final List<Clazz> results = new ArrayList<InstanceOfFilterTest.Clazz>();
 		final Object clazz = new SubClazz();
 
-		test(filter).and().send(clazz).to(filter.getInputPort()).and().receive(results).from(filter.getOutputPort()).start();
+		test(filter).and().send(clazz).to(filter.getInputPort()).and().receive(results).from(filter.getMatchedOutputPort()).start();
 
 		assertThat(results, contains(clazz));
 	}
@@ -65,7 +65,7 @@ public class InstanceOfFilterTest {
 		final List<Clazz> results = new ArrayList<InstanceOfFilterTest.Clazz>();
 		final Object object = new Object();
 
-		test(filter).and().send(object).to(filter.getInputPort()).and().receive(results).from(filter.getOutputPort()).start();
+		test(filter).and().send(object).to(filter.getInputPort()).and().receive(results).from(filter.getMatchedOutputPort()).start();
 
 		assertThat(results, is(empty()));
 	}
@@ -81,7 +81,7 @@ public class InstanceOfFilterTest {
 		input.add(new SubClazz());
 		input.add(new Object());
 
-		test(filter).and().send(input).to(filter.getInputPort()).and().receive(results).from(filter.getOutputPort()).start();
+		test(filter).and().send(input).to(filter.getInputPort()).and().receive(results).from(filter.getMatchedOutputPort()).start();
 
 		assertThat(results, hasSize(2));
 	}
-- 
GitLab