Skip to content
Snippets Groups Projects
Commit 0f28daa7 authored by Christian Wulf's avatar Christian Wulf
Browse files

added type for ports

parent 58dac733
No related branches found
No related tags found
No related merge requests found
...@@ -26,7 +26,12 @@ public abstract class AbstractPort<T> { ...@@ -26,7 +26,12 @@ public abstract class AbstractPort<T> {
* <i>Used to validate the connection between two ports at runtime.</i> * <i>Used to validate the connection between two ports at runtime.</i>
* </p> * </p>
*/ */
protected Class<T> type; protected final Class<T> type;
public AbstractPort(final Class<T> type) {
super();
this.type = type;
}
public IPipe getPipe() { public IPipe getPipe() {
return this.pipe; return this.pipe;
...@@ -39,8 +44,4 @@ public abstract class AbstractPort<T> { ...@@ -39,8 +44,4 @@ public abstract class AbstractPort<T> {
public Class<T> getType() { public Class<T> getType() {
return this.type; return this.type;
} }
public void setType(final Class<T> type) {
this.type = type;
}
} }
...@@ -139,10 +139,23 @@ public abstract class AbstractStage extends Stage { ...@@ -139,10 +139,23 @@ public abstract class AbstractStage extends Stage {
* Creates and adds an InputPort to the stage * Creates and adds an InputPort to the stage
* *
* @return Newly added InputPort * @return Newly added InputPort
*
*/ */
// * @deprecated Since 1.1. Use {@link #createInputPort(Class)} instead.
@SuppressWarnings("unchecked")
// @Deprecated
protected <T> InputPort<T> createInputPort() { protected <T> InputPort<T> createInputPort() {
final InputPort<T> inputPort = new InputPort<T>(this); return (InputPort<T>) createInputPort(null);
// inputPort.setType(portType); }
/**
* 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); this.inputPortList.add(inputPort);
return inputPort; return inputPort;
} }
...@@ -151,10 +164,23 @@ public abstract class AbstractStage extends Stage { ...@@ -151,10 +164,23 @@ public abstract class AbstractStage extends Stage {
* Creates and adds an OutputPort to the stage * Creates and adds an OutputPort to the stage
* *
* @return Newly added OutputPort * @return Newly added OutputPort
*
*/ */
// * @deprecated Since 1.1. Use {@link #createOutputPort(Class)} instead.
@SuppressWarnings("unchecked")
// @Deprecated
protected <T> OutputPort<T> createOutputPort() { protected <T> OutputPort<T> createOutputPort() {
final OutputPort<T> outputPort = new OutputPort<T>(); return (OutputPort<T>) createOutputPort(null);
// outputPort.setType(portType); }
/**
* 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); this.outputPortList.add(outputPort);
return outputPort; return outputPort;
} }
......
...@@ -19,8 +19,8 @@ public final class InputPort<T> extends AbstractPort<T> { ...@@ -19,8 +19,8 @@ public final class InputPort<T> extends AbstractPort<T> {
private final Stage owningStage; private final Stage owningStage;
InputPort(final Stage owningStage) { InputPort(final Class<T> type, final Stage owningStage) {
super(); super(type);
this.owningStage = owningStage; this.owningStage = owningStage;
} }
......
...@@ -29,8 +29,8 @@ import teetime.framework.signal.TerminatingSignal; ...@@ -29,8 +29,8 @@ import teetime.framework.signal.TerminatingSignal;
*/ */
public final class OutputPort<T> extends AbstractPort<T> { public final class OutputPort<T> extends AbstractPort<T> {
OutputPort() { OutputPort(final Class<T> type) {
super(); super(type);
} }
/** /**
......
/**
* 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);
}
}
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
*/ */
package teetime.runtime.typeCheck; package teetime.runtime.typeCheck;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
...@@ -28,7 +27,6 @@ import teetime.framework.pipe.PipeFactoryRegistry; ...@@ -28,7 +27,6 @@ import teetime.framework.pipe.PipeFactoryRegistry;
import teetime.framework.pipe.PipeFactoryRegistry.PipeOrdering; import teetime.framework.pipe.PipeFactoryRegistry.PipeOrdering;
import teetime.framework.pipe.PipeFactoryRegistry.ThreadCommunication; import teetime.framework.pipe.PipeFactoryRegistry.ThreadCommunication;
import teetime.stage.ObjectProducer; import teetime.stage.ObjectProducer;
import teetime.stage.PortTypeConfiguration;
import teetime.stage.StartTimestampFilter; import teetime.stage.StartTimestampFilter;
import teetime.stage.StopTimestampFilter; import teetime.stage.StopTimestampFilter;
import teetime.stage.basic.Sink; import teetime.stage.basic.Sink;
...@@ -93,12 +91,12 @@ public class ConnectionTypeTest { ...@@ -93,12 +91,12 @@ public class ConnectionTypeTest {
// } // }
assertNull(objectProducer.getOutputPort().getType()); assertNull(objectProducer.getOutputPort().getType());
PortTypeConfiguration.setPortTypes(objectProducer, Class.forName(TimestampObject.class.getName())); // PortTypeConfiguration.setPortTypes(objectProducer, Class.forName(TimestampObject.class.getName()));
assertEquals(TimestampObject.class, objectProducer.getOutputPort().getType()); // assertEquals(TimestampObject.class, objectProducer.getOutputPort().getType());
assertNull(startTimestampFilter.getOutputPort().getType()); assertNull(startTimestampFilter.getOutputPort().getType());
PortTypeConfiguration.setPortTypes(startTimestampFilter); // PortTypeConfiguration.setPortTypes(startTimestampFilter);
assertEquals(TimestampObject.class, startTimestampFilter.getInputPort().getType()); // assertEquals(TimestampObject.class, startTimestampFilter.getInputPort().getType());
assertEquals(TimestampObject.class, startTimestampFilter.getOutputPort().getType()); // assertEquals(TimestampObject.class, startTimestampFilter.getOutputPort().getType());
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment