diff --git a/src/main/java/teetime/framework/AbstractPort.java b/src/main/java/teetime/framework/AbstractPort.java index 0425b51d5f9e3c73a3dce2ea2107a8945140b497..0eaeffb3c6198ebdfeaaaf8b04a6ba48d7f1a7d5 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 af656894919486fc8f264f1fbd503bc4957b4ef5..2e69cff7d8fd68a8765e6fd84a615f3ef6f63be8 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 d19f2500d3c9aed63f1330e0804dc6244f3e38a2..6de51627c26915a33f072174742084dcbeb4458a 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 bbc69cf4e293f72caee80fa0250dab9e18f1ce73..db50ef1ccae890ae28a8a88e882052c9754ed892 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 39f67c6cee620b05b945a27941aa7189f77b2fc0..0000000000000000000000000000000000000000 --- 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 42d99c4813f1cdd6cf540ceacfaf42e871f2053a..6996eefa25a97869b936466edbc015ec89647877 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()); } }