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

com.jd.httpservice.NamedParamMap Maven / Gradle / Ivy

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

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public class NamedParamMap {

	private Map> params = new LinkedHashMap<>();

	public NamedParam[] getParams() {
		List allParams = new ArrayList<>();
		for (List namedParams : params.values()) {
			allParams.addAll(namedParams);
		}
		return allParams.toArray(new NamedParam[allParams.size()]);
	}

	public NamedParam addParam(String name, String value) {
		List values = params.get(name);
		if (values == null) {
			values = new ArrayList<>();
			params.put(name, values);
		}
		NamedParam p = new NamedParam(name, value);
		values.add(p);
		return p;
	}

	public boolean isEmpty() {
		return params.isEmpty();
	}
	
	/**
	 * 合并;
	 * @param extParams
	 * @param prefix 附加的新参数的前缀;
	 */
	public void merge(NamedParamMap extParams) {
		merge(extParams, null);
	}

	/**
	 * 合并;
	 * @param extParams
	 * @param prefix 附加的新参数的前缀;
	 */
	public void merge(NamedParamMap extParams, String prefix) {
		if (prefix == null || prefix.length() == 0) {
			NamedParam[] paramArr = extParams.getParams();
			for (NamedParam np : paramArr) {
				addParam(np.getName(), np.getValue());
			}
		} else {
			NamedParam[] paramArr = extParams.getParams();
			for (NamedParam np : paramArr) {
				addParam(prefix + np.getName(), np.getValue());
			}
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy