package com.dev.swms.client.ui.validate;

import com.dev.energy.client.validate.AbstractValidator;

public class DataNumberCombinParser extends AbstractValidator{
	
	public String validate(com.dev.energy.client.ui.InputUI inputUI) {
		if (inputUI.isEmpty()) {
			return null;
		}
		String value = inputUI.getValue().toString();
		boolean b = withRegex(value);
		if (b) {
			return null;
		}
		return this.getHintMessage(inputUI);
	}
	
	private String getRegexByParen(String value) {
		String regex = "";
		
		if(value.indexOf("(") == -1) {
			regex = "(\\d+.?\\d+)(((\\,)(\\d+.?\\d+))?)*";//只有单值的正则表达式
		} else {
			regex = "((\\()(\\d+.?\\d+)?\\,(\\d+.?\\d+)?(\\)))((\\,)((\\()(\\d+.?\\d+)?\\,(\\d+.?\\d+)?(\\))))*";
		}
		
		return regex;
	}

	public boolean withRegex(String str) {
		return str.matches(getRegexByParen(str));
	}
	
}
