From f8cb90526a5eb450eee64cb988d68d80b6375bf4 Mon Sep 17 00:00:00 2001 From: Nelson Tavares de Sousa <stu103017@mail.uni-kiel.de> Date: Tue, 23 Jun 2015 14:04:54 +0200 Subject: [PATCH] #165 added methods to give ports a name; tests missing --- .../java/teetime/framework/AbstractPort.java | 14 +++- .../java/teetime/framework/AbstractStage.java | 80 ++++++++++++++++++- .../java/teetime/framework/InputPort.java | 4 +- .../java/teetime/framework/OutputPort.java | 4 +- 4 files changed, 93 insertions(+), 9 deletions(-) diff --git a/src/main/java/teetime/framework/AbstractPort.java b/src/main/java/teetime/framework/AbstractPort.java index 0725cbe8..0544c479 100644 --- a/src/main/java/teetime/framework/AbstractPort.java +++ b/src/main/java/teetime/framework/AbstractPort.java @@ -19,6 +19,8 @@ import teetime.framework.pipe.IPipe; public abstract class AbstractPort<T> { + private final String portName; + protected IPipe pipe; /** * The type of this port. @@ -29,8 +31,9 @@ public abstract class AbstractPort<T> { protected final Class<T> type; private final Stage owningStage; - public AbstractPort(final Class<T> type, final Stage owningStage) { + public AbstractPort(final Class<T> type, final Stage owningStage, final String portName) { super(); + this.portName = portName; this.type = type; this.owningStage = owningStage; } @@ -50,4 +53,13 @@ public abstract class AbstractPort<T> { public final Stage getOwningStage() { return owningStage; } + + @Override + public final String toString() { + if (portName == null) { + return super.toString(); + } else { + return portName; + } + } } diff --git a/src/main/java/teetime/framework/AbstractStage.java b/src/main/java/teetime/framework/AbstractStage.java index a880c185..7d3c023f 100644 --- a/src/main/java/teetime/framework/AbstractStage.java +++ b/src/main/java/teetime/framework/AbstractStage.java @@ -141,7 +141,7 @@ public abstract class AbstractStage extends Stage { @SuppressWarnings("unchecked") // @Deprecated protected <T> InputPort<T> createInputPort() { - return (InputPort<T>) createInputPort(null); + return (InputPort<T>) createInputPort(null, null); } /** @@ -156,7 +156,41 @@ public abstract class AbstractStage extends Stage { * @return Newly added InputPort */ protected <T> InputPort<T> createInputPort(final Class<T> type) { - final InputPort<T> inputPort = new InputPort<T>(type, this); + return createInputPort(type, null); + } + + /** + * Creates and adds an InputPort to the stage + * + * @param name + * a specific name for the new port + * @param <T> + * the type of elements to be received + * + * @return Newly added InputPort + * + */ + // * @deprecated Since 1.1. Use {@link #createInputPort(Class)} instead. + @SuppressWarnings("unchecked") + // @Deprecated + protected <T> InputPort<T> createInputPort(final String name) { + return (InputPort<T>) createInputPort(null, name); + } + + /** + * Creates and adds an InputPort to the stage + * + * @param type + * class of elements to be received + * @param name + * a specific name for the new port + * @param <T> + * the type of elements to be received + * + * @return Newly added InputPort + */ + protected <T> InputPort<T> createInputPort(final Class<T> type, final String name) { + final InputPort<T> inputPort = new InputPort<T>(type, this, name); inputPorts = addElementToArray(inputPort, inputPorts); return inputPort; } @@ -174,7 +208,7 @@ public abstract class AbstractStage extends Stage { @SuppressWarnings("unchecked") // @Deprecated protected <T> OutputPort<T> createOutputPort() { - return (OutputPort<T>) createOutputPort(null); + return (OutputPort<T>) createOutputPort(null, null); } /** @@ -189,7 +223,45 @@ public abstract class AbstractStage extends Stage { * @return Newly added OutputPort */ protected <T> OutputPort<T> createOutputPort(final Class<T> type) { - final OutputPort<T> outputPort = new OutputPort<T>(type, this); + final OutputPort<T> outputPort = new OutputPort<T>(type, this, null); + outputPorts = addElementToArray(outputPort, outputPorts); + return outputPort; + } + + /** + * Creates and adds an OutputPort to the stage + * + * @param name + * a specific name for the new port + * + * @param <T> + * the type of elements to be sent + * + * @return Newly added OutputPort + * + */ + // * @deprecated Since 1.1. Use {@link #createOutputPort(Class)} instead. + @SuppressWarnings("unchecked") + // @Deprecated + protected <T> OutputPort<T> createOutputPort(final String name) { + return (OutputPort<T>) createOutputPort(null, name); + } + + /** + * Creates and adds an OutputPort to the stage + * + * @param name + * a specific name for the new port + * @param type + * class of elements to be sent + * + * @param <T> + * the type of elements to be sent + * + * @return Newly added OutputPort + */ + protected <T> OutputPort<T> createOutputPort(final Class<T> type, final String name) { + final OutputPort<T> outputPort = new OutputPort<T>(type, this, name); outputPorts = addElementToArray(outputPort, outputPorts); return outputPort; } diff --git a/src/main/java/teetime/framework/InputPort.java b/src/main/java/teetime/framework/InputPort.java index d2ffc259..bc71a2eb 100644 --- a/src/main/java/teetime/framework/InputPort.java +++ b/src/main/java/teetime/framework/InputPort.java @@ -26,8 +26,8 @@ package teetime.framework; */ public final class InputPort<T> extends AbstractPort<T> { - InputPort(final Class<T> type, final Stage owningStage) { - super(type, owningStage); + InputPort(final Class<T> type, final Stage owningStage, final String portName) { + super(type, owningStage, portName); } /** diff --git a/src/main/java/teetime/framework/OutputPort.java b/src/main/java/teetime/framework/OutputPort.java index 4d23baaa..103402d2 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(final Class<T> type, final Stage owningStage) { - super(type, owningStage); + OutputPort(final Class<T> type, final Stage owningStage, final String portName) { + super(type, owningStage, portName); } /** -- GitLab