package com.ssm.util.sms.excel.validation.base;

import com.ssm.util.sms.excel.exception.ValidationException;
import com.ssm.util.sms.excel.validation.Validation;

public class StringLengthValidation implements Validation {
	private int minLength;
	private int maxLength;

	public StringLengthValidation(int minLength, int maxLength) {
		this.minLength = minLength;
		this.maxLength = maxLength;
	}

	public boolean validate(int rowIndex, Integer[] index, String[] value,
			StringBuffer message) throws ValidationException {
		boolean result = true;
		for (int i = 0; i < value.length; i++) {
			if ((value[i].length() < this.minLength)
					|| (value[i].length() > this.maxLength)) {
				message.append("第" + (rowIndex + 1) + "行第"
						+ (index[i].intValue() + 1) + "列数据长度不合法！");
				result = false;
			}
		}
		return result;
	}
}
