package org.bench4q.recorder.httpcapture;

import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class Param {
	public String name;
	public String value;

	public static Param createParam(String name, String value) {
		Param param = new Param();
		param.name = name;
		param.value = value;
		return param;
	}

	public static class ParamParser {
		public static List<Param> parse(String paramString) {
			List<String> paramStrings = getNVField(paramString);
			List<Param> params = new ArrayList<Param>();
			for (String paramSource : paramStrings) {
				int index = paramSource.indexOf("=");
				params.add(createParam(paramSource.substring(0, index).trim(),
						paramSource.substring(index + 1)));
			}
			return params;
		}

		static public List<String> getNVField(String value) {
			StringTokenizer st = new StringTokenizer(value, ";", false);
			List<String> result = new ArrayList<String>();
			while (st.hasMoreTokens()) {
				String token = st.nextToken();
				result.add(token.trim());
			}
			return result;
		}
	}
}
