From df626573d49735586d0d0016a23b4fcc54ebb80c Mon Sep 17 00:00:00 2001
From: Nelson Tavares de Sousa <ntd@informatik.uni-kiel.de>
Date: Tue, 17 Feb 2015 15:17:23 +0100
Subject: [PATCH] added static fiel to compositestage containing the registry
 (less memory consumption); added CountingMapMerger, see JavaDoc

---
 .../teetime/framework/CompositeStage.java     |  3 ++
 ...gmapMerger.java => CountingMapMerger.java} | 35 +++++++++++++------
 .../teetime/stage/DistributedMapCounter.java  | 18 +++++++++-
 .../teetime/stage/string/ToLowerCase.java     | 15 ++++++++
 .../java/teetime/stage/util/CountingMap.java  | 15 ++++++++
 5 files changed, 74 insertions(+), 12 deletions(-)
 rename src/main/java/teetime/stage/{CountingmapMerger.java => CountingMapMerger.java} (52%)

diff --git a/src/main/java/teetime/framework/CompositeStage.java b/src/main/java/teetime/framework/CompositeStage.java
index 556f6fd7..672ab25c 100644
--- a/src/main/java/teetime/framework/CompositeStage.java
+++ b/src/main/java/teetime/framework/CompositeStage.java
@@ -18,6 +18,7 @@ package teetime.framework;
 import java.util.Collection;
 import java.util.List;
 
+import teetime.framework.pipe.PipeFactoryRegistry;
 import teetime.framework.signal.ISignal;
 import teetime.framework.validation.InvalidPortConnection;
 
@@ -31,6 +32,8 @@ import teetime.framework.validation.InvalidPortConnection;
 @SuppressWarnings("PMD.AbstractNaming")
 public abstract class CompositeStage extends Stage {
 
+	private static PipeFactoryRegistry PIPEFACTORY_REGISTRY = PipeFactoryRegistry.INSTANCE;
+
 	protected abstract Stage getFirstStage();
 
 	protected abstract Collection<? extends Stage> getLastStages();
diff --git a/src/main/java/teetime/stage/CountingmapMerger.java b/src/main/java/teetime/stage/CountingMapMerger.java
similarity index 52%
rename from src/main/java/teetime/stage/CountingmapMerger.java
rename to src/main/java/teetime/stage/CountingMapMerger.java
index 1a4d2fc5..99225cfb 100644
--- a/src/main/java/teetime/stage/CountingmapMerger.java
+++ b/src/main/java/teetime/stage/CountingMapMerger.java
@@ -1,3 +1,18 @@
+/**
+ * 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 java.util.Map;
@@ -17,14 +32,16 @@ import teetime.stage.util.CountingMap;
  * @param <T>
  *            Key type of the map to be sent
  */
-public class CountingmapMerger<T> extends AbstractConsumerStage<CountingMap<T>> {
+public class CountingMapMerger<T> extends AbstractConsumerStage<CountingMap<T>> {
 
 	private final CountingMap<T> result = new CountingMap<T>();
 	private final OutputPort<Map<T, Integer>> port = createOutputPort();
 
+	@SuppressWarnings("unused")
+	// May be needed to identify, if all stages before this one terminated
 	private final int numberOfInputPorts;
 
-	public CountingmapMerger(final int numberOfInputPorts) {
+	public CountingMapMerger(final int numberOfInputPorts) {
 		for (int i = 1; i < numberOfInputPorts; i++) {
 			createInputPort();
 		}
@@ -35,15 +52,7 @@ public class CountingmapMerger<T> extends AbstractConsumerStage<CountingMap<T>>
 	protected void execute(final CountingMap<T> element) {
 		Set<Map.Entry<T, Integer>> entries = element.entrySet();
 		for (Entry<T, Integer> entry : entries) {
-			Integer resultValue = result.get(entry.getKey());
-			if (resultValue == null) {
-				result.put(entry.getKey(), entry.getValue());
-			}
-			else {
-				Integer temp = result.get(entry.getKey());
-				temp += entry.getValue();
-				result.put(entry.getKey(), temp);
-			}
+			result.add(entry.getKey(), entry.getValue());
 		}
 	}
 
@@ -53,4 +62,8 @@ public class CountingmapMerger<T> extends AbstractConsumerStage<CountingMap<T>>
 		super.onTerminating();
 	}
 
+	public CountingMap<T> getResult() {
+		return result;
+	}
+
 }
diff --git a/src/main/java/teetime/stage/DistributedMapCounter.java b/src/main/java/teetime/stage/DistributedMapCounter.java
index de7b7b7f..ebb3c0c3 100644
--- a/src/main/java/teetime/stage/DistributedMapCounter.java
+++ b/src/main/java/teetime/stage/DistributedMapCounter.java
@@ -1,3 +1,18 @@
+/**
+ * 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.framework.AbstractConsumerStage;
@@ -6,11 +21,12 @@ import teetime.stage.util.CountingMap;
 
 /**
  * This counts how many of different elements are sent to this stage. Nothing is forwarded.
- * On termination a Map of T's and counter value is sent to its outputport.
+ * On termination a CountingMap is sent to its outputport.
  *
  * @author Nelson Tavares de Sousa
  *
  * @param <T>
+ *            Type to be count
  */
 public class DistributedMapCounter<T> extends AbstractConsumerStage<T> {
 
diff --git a/src/main/java/teetime/stage/string/ToLowerCase.java b/src/main/java/teetime/stage/string/ToLowerCase.java
index fb0edfe5..5f5bc840 100644
--- a/src/main/java/teetime/stage/string/ToLowerCase.java
+++ b/src/main/java/teetime/stage/string/ToLowerCase.java
@@ -1,3 +1,18 @@
+/**
+ * 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.string;
 
 import teetime.framework.AbstractConsumerStage;
diff --git a/src/main/java/teetime/stage/util/CountingMap.java b/src/main/java/teetime/stage/util/CountingMap.java
index 0e6ae4ef..fcd0ed66 100644
--- a/src/main/java/teetime/stage/util/CountingMap.java
+++ b/src/main/java/teetime/stage/util/CountingMap.java
@@ -1,3 +1,18 @@
+/**
+ * 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.util;
 
 import java.util.HashMap;
-- 
GitLab