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

import java.util.HashSet;
import java.util.Set;

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

public class RowUniqueValidation implements Validation {
	private Set<String> uniqueSet;
	private String errorTip;

	public RowUniqueValidation(String errorTip) {
		this.errorTip = errorTip;
		this.uniqueSet = new HashSet();
	}

	public boolean validate(int rowIndex, Integer[] index, String[] value,
			StringBuffer message) throws ValidationException {
		boolean result = true;

		StringBuffer rowString = new StringBuffer();
		for (int i = 0; i < value.length; i++) {
			rowString.append(value[i].replace("#", "!"));
			rowString.append("#");
		}
		if ((rowString.length() != 0)
				&& (!this.uniqueSet.add(rowString.toString()))) {
			message.append("第" + (rowIndex + 1) + "行"
					+ (this.errorTip != null ? this.errorTip : ""));
			result = false;
		}
		return result;
	}
}
