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

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

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

public class UniqueValidation implements Validation {
	private List<Set<String>> uniqueArray;

	public boolean validate(int rowIndex, Integer[] index, String[] value,
			StringBuffer message) throws ValidationException {
		if (this.uniqueArray == null) {
			this.uniqueArray = new ArrayList<Set<String>>();
			for (int i = 0; i < value.length; i++) {
				this.uniqueArray.add(new HashSet());
			}
		}
		boolean result = true;
		for (int i = 0; i < value.length; i++) {
			if ((value[i].length() != 0)
					&& (!((Set<String>) this.uniqueArray.get(i)).add(value[i]))) {
				message.append("第" + (rowIndex + 1) + "行第"
						+ (index[i].intValue() + 1) + "列数据出现重复！");
				result = false;
			}
		}
		return result;
	}
}
