com.magician.route.mvc.cache.MagicianRouteManager Maven / Gradle / Ivy
The newest version!
package com.magician.route.mvc.cache;
import com.magician.route.commons.util.PathUtil;
import com.magician.route.mvc.enums.ReqMethod;
import com.magician.route.mvc.route.MagicianRoute;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* Route Management
*
* For route storage, adding, querying
*/
public class MagicianRouteManager {
/**
* Route to the collection
*/
private static Map> magicianRouteMap = new ConcurrentHashMap<>();
public static void addRoute(String path, ReqMethod reqMethod, MagicianRoute magicianRoute) {
path = PathUtil.getPath(path);
Map routeMap = magicianRouteMap.get(path);
if (routeMap == null) {
routeMap = new HashMap<>();
}
routeMap.put(reqMethod, magicianRoute);
magicianRouteMap.put(path, routeMap);
}
public static MagicianRoute getRoute(String path, ReqMethod reqMethod) {
Map routeMap = magicianRouteMap.get(path);
if (routeMap == null || routeMap.size() == 0) {
return null;
}
return routeMap.get(reqMethod);
}
public static Map> getMagicianRouteMap() {
return magicianRouteMap;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy