From 0f28daa751b107122e80ebff09239a226214c985 Mon Sep 17 00:00:00 2001 From: Christian Wulf <chw@informatik.uni-kiel.de> Date: Sat, 18 Apr 2015 00:48:37 +0200 Subject: [PATCH] added type for ports --- .../java/teetime/framework/AbstractPort.java | 11 +++--- .../java/teetime/framework/AbstractStage.java | 34 ++++++++++++++++--- .../java/teetime/framework/InputPort.java | 4 +-- .../java/teetime/framework/OutputPort.java | 4 +-- .../teetime/stage/PortTypeConfiguration.java | 34 ------------------- .../runtime/typeCheck/ConnectionTypeTest.java | 12 +++---- 6 files changed, 45 insertions(+), 54 deletions(-) delete mode 100644 src/main/java/teetime/stage/PortTypeConfiguration.java diff --git a/src/main/java/teetime/framework/AbstractPort.java b/src/main/java/teetime/framework/AbstractPort.java index 0425b51d..0eaeffb3 100644 --- a/src/main/java/teetime/framework/AbstractPort.java +++ b/src/main/java/teetime/framework/AbstractPort.java @@ -26,7 +26,12 @@ public abstract class AbstractPort<T> { * <i>Used to validate the connection between two ports at runtime.</i> * </p> */ - protected Class<T> type; + protected final Class<T> type; + + public AbstractPort(final Class<T> type) { + super(); + this.type = type; + } public IPipe getPipe() { return this.pipe; @@ -39,8 +44,4 @@ public abstract class AbstractPort<T> { public Class<T> getType() { return this.type; } - - public void setType(final Class<T> type) { - this.type = type; - } } diff --git a/src/main/java/teetime/framework/AbstractStage.java b/src/main/java/teetime/framework/AbstractStage.java index af656894..2e69cff7 100644 --- a/src/main/java/teetime/framework/AbstractStage.java +++ b/src/main/java/teetime/framework/AbstractStage.java @@ -139,10 +139,23 @@ public abstract class AbstractStage extends Stage { * Creates and adds an InputPort to the stage * * @return Newly added InputPort + * */ + // * @deprecated Since 1.1. Use {@link #createInputPort(Class)} instead. + @SuppressWarnings("unchecked") + // @Deprecated protected <T> InputPort<T> createInputPort() { - final InputPort<T> inputPort = new InputPort<T>(this); - // inputPort.setType(portType); + return (InputPort<T>) createInputPort(null); + } + + /** + * Creates and adds an InputPort to the stage + * + * @param type + * @return Newly added InputPort + */ + protected <T> InputPort<T> createInputPort(final Class<T> type) { + final InputPort<T> inputPort = new InputPort<T>(type, this); this.inputPortList.add(inputPort); return inputPort; } @@ -151,10 +164,23 @@ public abstract class AbstractStage extends Stage { * Creates and adds an OutputPort to the stage * * @return Newly added OutputPort + * */ + // * @deprecated Since 1.1. Use {@link #createOutputPort(Class)} instead. + @SuppressWarnings("unchecked") + // @Deprecated protected <T> OutputPort<T> createOutputPort() { - final OutputPort<T> outputPort = new OutputPort<T>(); - // outputPort.setType(portType); + return (OutputPort<T>) createOutputPort(null); + } + + /** + * Creates and adds an OutputPort to the stage + * + * @param type + * @return Newly added OutputPort + */ + protected <T> OutputPort<T> createOutputPort(final Class<T> type) { + final OutputPort<T> outputPort = new OutputPort<T>(type); this.outputPortList.add(outputPort); return outputPort; } diff --git a/src/main/java/teetime/framework/InputPort.java b/src/main/java/teetime/framework/InputPort.java index d19f2500..6de51627 100644 --- a/src/main/java/teetime/framework/InputPort.java +++ b/src/main/java/teetime/framework/InputPort.java @@ -19,8 +19,8 @@ public final class InputPort<T> extends AbstractPort<T> { private final Stage owningStage; - InputPort(final Stage owningStage) { - super(); + InputPort(final Class<T> type, final Stage owningStage) { + super(type); this.owningStage = owningStage; } diff --git a/src/main/java/teetime/framework/OutputPort.java b/src/main/java/teetime/framework/OutputPort.java index bbc69cf4..db50ef1c 100644 --- a/src/main/java/teetime/framework/OutputPort.java +++ b/src/main/java/teetime/framework/OutputPort.java @@ -29,8 +29,8 @@ import teetime.framework.signal.TerminatingSignal; */ public final class OutputPort<T> extends AbstractPort<T> { - OutputPort() { - super(); + OutputPort(final Class<T> type) { + super(type); } /** diff --git a/src/main/java/teetime/stage/PortTypeConfiguration.java b/src/main/java/teetime/stage/PortTypeConfiguration.java deleted file mode 100644 index 39f67c6c..00000000 --- a/src/main/java/teetime/stage/PortTypeConfiguration.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Copyright (C) 2015 TeeTime (http://teetime.sourceforge.net) - * - * 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.apache.org/licenses/LICENSE-2.0 - * - * 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 teetime.stage; - -import teetime.util.TimestampObject; - -public class PortTypeConfiguration { - - public static <T> void setPortTypes(final ObjectProducer<T> stage, final Class<T> clazz) { - stage.getOutputPort().setType(clazz); - } - - public static <T> void setPortTypes(final CollectorSink<T> stage, final Class<T> clazz) { - stage.getInputPort().setType(clazz); - } - - public static <T> void setPortTypes(final StartTimestampFilter stage) { - stage.getInputPort().setType(TimestampObject.class); - stage.getOutputPort().setType(TimestampObject.class); - } -} diff --git a/src/performancetest/java/teetime/runtime/typeCheck/ConnectionTypeTest.java b/src/performancetest/java/teetime/runtime/typeCheck/ConnectionTypeTest.java index 42d99c48..6996eefa 100644 --- a/src/performancetest/java/teetime/runtime/typeCheck/ConnectionTypeTest.java +++ b/src/performancetest/java/teetime/runtime/typeCheck/ConnectionTypeTest.java @@ -15,7 +15,6 @@ */ package teetime.runtime.typeCheck; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import java.lang.reflect.Constructor; @@ -28,7 +27,6 @@ import teetime.framework.pipe.PipeFactoryRegistry; import teetime.framework.pipe.PipeFactoryRegistry.PipeOrdering; import teetime.framework.pipe.PipeFactoryRegistry.ThreadCommunication; import teetime.stage.ObjectProducer; -import teetime.stage.PortTypeConfiguration; import teetime.stage.StartTimestampFilter; import teetime.stage.StopTimestampFilter; import teetime.stage.basic.Sink; @@ -93,12 +91,12 @@ public class ConnectionTypeTest { // } assertNull(objectProducer.getOutputPort().getType()); - PortTypeConfiguration.setPortTypes(objectProducer, Class.forName(TimestampObject.class.getName())); - assertEquals(TimestampObject.class, objectProducer.getOutputPort().getType()); + // PortTypeConfiguration.setPortTypes(objectProducer, Class.forName(TimestampObject.class.getName())); + // assertEquals(TimestampObject.class, objectProducer.getOutputPort().getType()); assertNull(startTimestampFilter.getOutputPort().getType()); - PortTypeConfiguration.setPortTypes(startTimestampFilter); - assertEquals(TimestampObject.class, startTimestampFilter.getInputPort().getType()); - assertEquals(TimestampObject.class, startTimestampFilter.getOutputPort().getType()); + // PortTypeConfiguration.setPortTypes(startTimestampFilter); + // assertEquals(TimestampObject.class, startTimestampFilter.getInputPort().getType()); + // assertEquals(TimestampObject.class, startTimestampFilter.getOutputPort().getType()); } } -- GitLab