package org.bench4q.agent.scenario.dfa;

import java.util.List;

import org.bench4q.agent.scenario.dfa.ParamPart.ParamPartType;
import org.bench4q.agent.scenario.dfa.State.LiteralState;

public class DFA {
	/**
	 * 
	 * @param paramOriginValue
	 * @return If the @param is in the supported format then return the well
	 *         resolved parts; But if not, it'll return only one ParamPart with
	 *         ParamPartType.STRING as type and paramOriginValu as content
	 * 
	 */
	public static List<ParamPart> resolveMaltipleParamPart(
			String paramOriginValue) {
		State state = State.getLiteralState();
		try {
			for (char c : paramOriginValue.toCharArray()) {
				state = state.digest(c);
			}
			if (state instanceof LiteralState
					&& state.getBufferCommon().length() > 0) {
				state.addResult(new ParamPart(ParamPartType.STRING, state
						.getBufferCommon().toString(), null, null));
			}
		} catch (Exception e) {
			state.clearResult();
			state.addResult(new ParamPart(ParamPartType.STRING,
					paramOriginValue, null, null));
		}
		return state.getResult();
	}

}
