From d5d5fc27b2e14f18910b9a084d90303d7d8010ae Mon Sep 17 00:00:00 2001 From: Nelson Tavares de Sousa <stu103017@mail.uni-kiel.de> Date: Mon, 1 Feb 2016 14:26:31 +0100 Subject: [PATCH] some pmd fixes --- .../A2InvalidThreadAssignmentCheck.java | 12 +- .../framework/AbstractCompositeStage.java | 6 +- .../java/teetime/framework/AbstractPort.java | 2 +- .../framework/ConfigurationContext.java | 8 +- .../teetime/framework/ExecutionException.java | 9 +- .../framework/ExecutionInstantiation.java | 108 ------------------ .../framework/IntraStageCollector.java | 2 +- .../teetime/framework/MonitoringThread.java | 8 +- .../java/teetime/framework/OutputPort.java | 3 +- .../java/teetime/framework/ThreadService.java | 2 - 10 files changed, 24 insertions(+), 136 deletions(-) delete mode 100644 src/main/java/teetime/framework/ExecutionInstantiation.java diff --git a/src/main/java/teetime/framework/A2InvalidThreadAssignmentCheck.java b/src/main/java/teetime/framework/A2InvalidThreadAssignmentCheck.java index 60e33dae..a592b39a 100644 --- a/src/main/java/teetime/framework/A2InvalidThreadAssignmentCheck.java +++ b/src/main/java/teetime/framework/A2InvalidThreadAssignmentCheck.java @@ -40,12 +40,13 @@ public class A2InvalidThreadAssignmentCheck { public void check() { int color = DEFAULT_COLOR; ObjectIntMap<AbstractStage> colors = new ObjectIntHashMap<AbstractStage>(); + ThreadPainter threadPainter = new ThreadPainter(); for (AbstractStage threadableStage : threadableStages) { color++; colors.put(threadableStage, color); - ThreadPainter threadPainter = new ThreadPainter(colors, color, threadableStages); + threadPainter.reset(colors, color, threadableStages); Traverser traverser = new Traverser(threadPainter); traverser.traverse(threadableStage); } @@ -53,12 +54,11 @@ public class A2InvalidThreadAssignmentCheck { private static class ThreadPainter implements ITraverserVisitor { - private final ObjectIntMap<AbstractStage> colors; - private final int color; - private final Set<AbstractStage> threadableStages; + private ObjectIntMap<AbstractStage> colors; + private int color; + private Set<AbstractStage> threadableStages; - public ThreadPainter(final ObjectIntMap<AbstractStage> colors, final int color, final Set<AbstractStage> threadableStages) { - super(); + public void reset(final ObjectIntMap<AbstractStage> colors, final int color, final Set<AbstractStage> threadableStages) { this.colors = colors; this.color = color; this.threadableStages = threadableStages; diff --git a/src/main/java/teetime/framework/AbstractCompositeStage.java b/src/main/java/teetime/framework/AbstractCompositeStage.java index db4fa8f5..3b421195 100644 --- a/src/main/java/teetime/framework/AbstractCompositeStage.java +++ b/src/main/java/teetime/framework/AbstractCompositeStage.java @@ -66,10 +66,8 @@ public abstract class AbstractCompositeStage { throw new IllegalArgumentException("1003 - targetPort may not be null"); } - if (sourcePort.getOwningStage().getInputPorts().size() == 0) { - if (sourcePort.getOwningStage().getOwningThread() == null) { - sourcePort.getOwningStage().declareActive(); - } + if (sourcePort.getOwningStage().getInputPorts().size() == 0 && sourcePort.getOwningStage().getOwningThread() == null) { + sourcePort.getOwningStage().declareActive(); } new InstantiationPipe<T>(sourcePort, targetPort, capacity); diff --git a/src/main/java/teetime/framework/AbstractPort.java b/src/main/java/teetime/framework/AbstractPort.java index 0f86d2b2..d85f8388 100644 --- a/src/main/java/teetime/framework/AbstractPort.java +++ b/src/main/java/teetime/framework/AbstractPort.java @@ -17,7 +17,7 @@ package teetime.framework; import teetime.framework.pipe.IPipe; -public abstract class AbstractPort<T> { +public class AbstractPort<T> { protected IPipe<?> pipe; /** diff --git a/src/main/java/teetime/framework/ConfigurationContext.java b/src/main/java/teetime/framework/ConfigurationContext.java index 0b358f7d..71e168ef 100644 --- a/src/main/java/teetime/framework/ConfigurationContext.java +++ b/src/main/java/teetime/framework/ConfigurationContext.java @@ -18,19 +18,13 @@ package teetime.framework; import java.util.Set; /** - * Represents a context that is used by a configuration and composite stages to connect ports, for example. + * Represents a context that is used by a configuration and composite stages to connect ports,for example. * Stages can be added by executing {@link #declareActive(AbstractStage)}. * * @since 2.0 */ final class ConfigurationContext { - // static final ConfigurationContext EMPTY_CONTEXT = new ConfigurationContext(null); - - // private static final Logger LOGGER = LoggerFactory.getLogger(ConfigurationContext.class); - - // private final Set<ConfigurationContext> children = new HashSet<ConfigurationContext>(); // parent-child-tree - private ThreadService threadService; ConfigurationContext(final Configuration configuration) { diff --git a/src/main/java/teetime/framework/ExecutionException.java b/src/main/java/teetime/framework/ExecutionException.java index 71dd418c..2a758e68 100644 --- a/src/main/java/teetime/framework/ExecutionException.java +++ b/src/main/java/teetime/framework/ExecutionException.java @@ -19,8 +19,10 @@ import java.util.List; import java.util.Map; /** - * Represents a exception, which is thrown by an analysis, if any problems occured within its execution. - * A collection of thrown exceptions within the analysis can be retrieved with {@link #getThrownExceptions()}. + * Represents a exception, which is thrown by an analysis, + * if any problems occured within its execution. + * A collection of thrown exceptions within the analysis + * can be retrieved with {@link #getThrownExceptions()}. * * @since 2.0 */ @@ -37,7 +39,8 @@ public class ExecutionException extends RuntimeException { /** * Returns all exceptions thrown within the execution. - * These are passed on as pairs of threads and throwables, to indicate a exception's context. + * These are passed on as pairs of threads and throwables, + * to indicate a exception's context. * * @return a thread-exceptionlist-map */ diff --git a/src/main/java/teetime/framework/ExecutionInstantiation.java b/src/main/java/teetime/framework/ExecutionInstantiation.java deleted file mode 100644 index 90a1473c..00000000 --- a/src/main/java/teetime/framework/ExecutionInstantiation.java +++ /dev/null @@ -1,108 +0,0 @@ -/** - * Copyright (C) 2015 Christian Wulf, Nelson Tavares de Sousa (http://teetime-framework.github.io) - * - * 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.framework; - -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - -import teetime.framework.pipe.InstantiationPipe; -import teetime.framework.pipe.UnsynchedPipe; -import teetime.framework.pipe.BoundedSynchedPipe; -import teetime.framework.pipe.UnboundedSynchedPipe; - -class ExecutionInstantiation { - - private static final int DEFAULT_COLOR = 0; - - private final ConfigurationContext context; - - private ExecutionInstantiation(final ConfigurationContext context) { - this.context = context; - } - - void instantiatePipes() { - int color = DEFAULT_COLOR; - Map<AbstractStage, Integer> colors = new HashMap<AbstractStage, Integer>(); - Set<AbstractStage> threadableStages = context.getThreadableStages(); - for (AbstractStage threadableStage : threadableStages) { - color++; - colors.put(threadableStage, color); - - ThreadPainter threadPainter = new ThreadPainter(colors, color, threadableStages); - threadPainter.colorAndConnectStages(threadableStage); - } - } - - private static class ThreadPainter { - - private final Map<AbstractStage, Integer> colors; - private final int color; - private final Set<AbstractStage> threadableStages; - - public ThreadPainter(final Map<AbstractStage, Integer> colors, final int color, final Set<AbstractStage> threadableStages) { - super(); - this.colors = colors; - this.color = color; - this.threadableStages = threadableStages; - } - - public int colorAndConnectStages(final AbstractStage stage) { - int createdConnections = 0; - - for (OutputPort<?> outputPort : stage.getOutputPorts()) { - if (outputPort.pipe != null && outputPort.pipe instanceof InstantiationPipe) { - InstantiationPipe<?> pipe = (InstantiationPipe<?>) outputPort.pipe; - createdConnections += processPipe(outputPort, pipe); - createdConnections++; - } - } - - return createdConnections; - } - - @SuppressWarnings({ "rawtypes", "unchecked" }) - private int processPipe(final OutputPort outputPort, final InstantiationPipe pipe) { - int numCreatedConnections; - - AbstractStage targetStage = pipe.getTargetPort().getOwningStage(); - int targetColor = colors.containsKey(targetStage) ? colors.get(targetStage) : DEFAULT_COLOR; - - if (threadableStages.contains(targetStage) && targetColor != color) { - if (pipe.capacity() != 0) { - new BoundedSynchedPipe(outputPort, pipe.getTargetPort(), pipe.capacity()); - } else { - new UnboundedSynchedPipe(outputPort, pipe.getTargetPort()); - } - numCreatedConnections = 0; - } else { - if (colors.containsKey(targetStage)) { - if (!colors.get(targetStage).equals(color)) { - throw new IllegalStateException("1001 - Crossing threads in " + targetStage.getId()); // One stage is connected to a stage of another thread - // (but not its "headstage") - } - } - new UnsynchedPipe(outputPort, pipe.getTargetPort()); - colors.put(targetStage, color); - numCreatedConnections = colorAndConnectStages(targetStage); - } - - return numCreatedConnections; - } - - } - -} diff --git a/src/main/java/teetime/framework/IntraStageCollector.java b/src/main/java/teetime/framework/IntraStageCollector.java index 7ece0d14..2b8680b6 100644 --- a/src/main/java/teetime/framework/IntraStageCollector.java +++ b/src/main/java/teetime/framework/IntraStageCollector.java @@ -29,7 +29,7 @@ public class IntraStageCollector implements ITraverserVisitor { @Override public VisitorBehavior visit(final AbstractStage stage) { - if (stage == startStage || stage.getOwningThread() == null /* before execution */ + if (stage.equals(startStage) || stage.getOwningThread() == null /* before execution */ || stage.getOwningThread() == startStage.getOwningThread() /* while execution */) { return VisitorBehavior.CONTINUE; } diff --git a/src/main/java/teetime/framework/MonitoringThread.java b/src/main/java/teetime/framework/MonitoringThread.java index c517db8c..85246bed 100644 --- a/src/main/java/teetime/framework/MonitoringThread.java +++ b/src/main/java/teetime/framework/MonitoringThread.java @@ -42,9 +42,11 @@ public class MonitoringThread extends Thread { final long pullThroughput = pipe.getPullThroughput(); final double ratio = (double) pushThroughput / pullThroughput; - LOGGER.info("pipe: " + "size=" + pipe.size() + ", " + "ratio: " + String.format("%.1f", ratio)); - LOGGER.info("pushes: " + pushThroughput); - LOGGER.info("pulls: " + pullThroughput); + if (LOGGER.isInfoEnabled()) { + LOGGER.info("pipe: " + "size=" + pipe.size() + ", " + "ratio: " + String.format("%.1f", ratio)); + LOGGER.info("pushes: " + pushThroughput); + LOGGER.info("pulls: " + pullThroughput); + } } LOGGER.info("------------------------------------"); diff --git a/src/main/java/teetime/framework/OutputPort.java b/src/main/java/teetime/framework/OutputPort.java index 366604f3..e8df8e84 100644 --- a/src/main/java/teetime/framework/OutputPort.java +++ b/src/main/java/teetime/framework/OutputPort.java @@ -59,7 +59,8 @@ public class OutputPort<T> extends AbstractPort<T> { * @param element * to be sent; May not be <code>null</code>. * - * @return <code>true</code> iff the <code>element</code> was sent; <code>false</code> otherwise. + * @return <code>true</code> iff the <code>element</code> was sent; + * <code>false</code> otherwise. * * @since 1.1 */ diff --git a/src/main/java/teetime/framework/ThreadService.java b/src/main/java/teetime/framework/ThreadService.java index 2df4b165..02189899 100644 --- a/src/main/java/teetime/framework/ThreadService.java +++ b/src/main/java/teetime/framework/ThreadService.java @@ -75,8 +75,6 @@ class ThreadService extends AbstractService<ThreadService> { throw new IllegalStateException("The start stage may not be null."); } - // TODO use decorator pattern to combine all analyzes so that only one traverser pass is necessary - A1ThreadableStageCollector stageCollector = new A1ThreadableStageCollector(); Traverser traversor = new Traverser(stageCollector, Direction.BOTH); traversor.traverse(startStage); -- GitLab