All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jd.httpservice.agent.PathParamResolvers Maven / Gradle / Ivy

There is a newer version: 2.1.4.RELEASE
Show newest version
package com.jd.httpservice.agent;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

class PathParamResolvers {

	/**
	 * 空路径参数解析器;
	 */
	public static final PathParamResolver NONE_PATH_PARAM_RESOLVER = new NonePathParamResolver();

	/**
	 * 根据指定的路径参数定义创建路径参数解析器;
	 * 
	 * @param paramDefinitions
	 * @return
	 */
	public static PathParamResolver createResolver(List> paramDefinitions) {
		return new ArgArrayPathParamResolver(paramDefinitions);
	}

	private static class ArgArrayPathParamResolver implements PathParamResolver {

		private List> paramDefinitions;

		public ArgArrayPathParamResolver(List> paramDefinitions) {
			this.paramDefinitions = paramDefinitions;
		}

		@Override
		public Map resolve(Object[] args) {
			Map pathParams = new HashMap();
			String name;
			String value;
			for (ArgDefEntry paramDef : paramDefinitions) {
				name = paramDef.getDefinition().getName();
				value = paramDef.getDefinition().getConverter().toString(args[paramDef.getIndex()]);
				pathParams.put(name, value);
			}
			return pathParams;
		}
	}

	private static class NonePathParamResolver implements PathParamResolver {

		@SuppressWarnings("unchecked")
		@Override
		public Map resolve(Object[] args) {
			return Collections.EMPTY_MAP;
		}

	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy