Skip to content
Snippets Groups Projects
Commit f8cb9052 authored by Nelson Tavares de Sousa's avatar Nelson Tavares de Sousa
Browse files

#165 added methods to give ports a name; tests missing

parent 86dda433
Branches
Tags
No related merge requests found
...@@ -19,6 +19,8 @@ import teetime.framework.pipe.IPipe; ...@@ -19,6 +19,8 @@ import teetime.framework.pipe.IPipe;
public abstract class AbstractPort<T> { public abstract class AbstractPort<T> {
private final String portName;
protected IPipe pipe; protected IPipe pipe;
/** /**
* The type of this port. * The type of this port.
...@@ -29,8 +31,9 @@ public abstract class AbstractPort<T> { ...@@ -29,8 +31,9 @@ public abstract class AbstractPort<T> {
protected final Class<T> type; protected final Class<T> type;
private final Stage owningStage; 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(); super();
this.portName = portName;
this.type = type; this.type = type;
this.owningStage = owningStage; this.owningStage = owningStage;
} }
...@@ -50,4 +53,13 @@ public abstract class AbstractPort<T> { ...@@ -50,4 +53,13 @@ public abstract class AbstractPort<T> {
public final Stage getOwningStage() { public final Stage getOwningStage() {
return owningStage; return owningStage;
} }
@Override
public final String toString() {
if (portName == null) {
return super.toString();
} else {
return portName;
}
}
} }
...@@ -141,7 +141,7 @@ public abstract class AbstractStage extends Stage { ...@@ -141,7 +141,7 @@ public abstract class AbstractStage extends Stage {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
// @Deprecated // @Deprecated
protected <T> InputPort<T> createInputPort() { 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 { ...@@ -156,7 +156,41 @@ public abstract class AbstractStage extends Stage {
* @return Newly added InputPort * @return Newly added InputPort
*/ */
protected <T> InputPort<T> createInputPort(final Class<T> type) { 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); inputPorts = addElementToArray(inputPort, inputPorts);
return inputPort; return inputPort;
} }
...@@ -174,7 +208,7 @@ public abstract class AbstractStage extends Stage { ...@@ -174,7 +208,7 @@ public abstract class AbstractStage extends Stage {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
// @Deprecated // @Deprecated
protected <T> OutputPort<T> createOutputPort() { 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 { ...@@ -189,7 +223,45 @@ public abstract class AbstractStage extends Stage {
* @return Newly added OutputPort * @return Newly added OutputPort
*/ */
protected <T> OutputPort<T> createOutputPort(final Class<T> type) { 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); outputPorts = addElementToArray(outputPort, outputPorts);
return outputPort; return outputPort;
} }
......
...@@ -26,8 +26,8 @@ package teetime.framework; ...@@ -26,8 +26,8 @@ package teetime.framework;
*/ */
public final class InputPort<T> extends AbstractPort<T> { public final class InputPort<T> extends AbstractPort<T> {
InputPort(final Class<T> type, final Stage owningStage) { InputPort(final Class<T> type, final Stage owningStage, final String portName) {
super(type, owningStage); super(type, owningStage, portName);
} }
/** /**
......
...@@ -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(final Class<T> type, final Stage owningStage) { OutputPort(final Class<T> type, final Stage owningStage, final String portName) {
super(type, owningStage); super(type, owningStage, portName);
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment