com.github.mkolisnyk.sirius.client.Context Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sirius-java-client Show documentation
Show all versions of sirius-java-client Show documentation
Common client library for automated GUI testing
The newest version!
package com.github.mkolisnyk.sirius.client;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
public final class Context {
private Context() {
}
private static ConcurrentHashMap> contextVariables
= new ConcurrentHashMap>();
private static String getThreadName() {
return Thread.currentThread().getName() + "-" + Thread.currentThread().getId();
}
public static void put(String name, Object value) {
Map dataMap = new HashMap();
String threadName = getThreadName();
if (contextVariables.containsKey(threadName)) {
dataMap = contextVariables.get(threadName);
}
dataMap.put(name, value);
contextVariables.put(threadName, dataMap);
}
public static Object get(String name) {
String threadName = getThreadName();
if (contextVariables.containsKey(threadName)) {
return contextVariables.get(threadName).get(name);
}
return null;
}
public static void clearCurrent() {
contextVariables.put(getThreadName(), new HashMap());
}
public static Set variables() {
return contextVariables.get(getThreadName()).keySet();
}
}