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

modified stage naming

parent 3868f2c9
No related branches found
No related tags found
No related merge requests found
package teetime.framework;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -12,13 +12,15 @@ import teetime.framework.validation.InvalidPortConnection;
public abstract class Stage {
private final String id;
private static HashMap<String, Integer> instancesCounter = new HashMap<String, Integer>();
/**
* A unique logger instance per stage instance
*/
protected final Logger logger; // NOPMD
protected Stage() {
this.id = UUID.randomUUID().toString(); // the id should only be represented by a UUID, not additionally by the class name
this.id = this.nameInstance();
// this.id = UUID.randomUUID().toString(); // the id should only be represented by a UUID, not additionally by the class name
this.logger = LoggerFactory.getLogger(this.getClass().getName() + "(" + this.id + ")");
}
......@@ -31,6 +33,20 @@ public abstract class Stage {
return this.getClass().getName() + ": " + this.getId();
}
private String nameInstance() {
int instances = 0;
String id;
String simpleName = this.getClass().getSimpleName();
if (instancesCounter.containsKey(simpleName)) {
instances = instancesCounter.get(simpleName);
}
id = simpleName + "-" + instances;
instancesCounter.put(simpleName, ++instances);
return id;
}
// public abstract Stage getParentStage();
//
// public abstract void setParentStage(Stage parentStage, int index);
......
package teetime.framework;
import org.junit.Assert;
import org.junit.Test;
import teetime.stage.Cache;
import teetime.stage.Counter;
public class StageTest {
@Test
public void testId() {
Counter<Object> counter0 = new Counter<Object>();
Counter<Object> counter1 = new Counter<Object>();
Assert.assertEquals("Counter-0", counter0.getId());
Assert.assertEquals("Counter-1", counter1.getId());
for (int i = 0; i < 100; i++) {
Cache<Object> cache = new Cache<Object>();
Assert.assertEquals("Cache-" + i, cache.getId());
}
}
}
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