/*
 * NoContieneValorCampoOpcional.java
 *
 * Created on 22 de marzo de 2007, 10:42 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.fidufosyga.rules;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * 
 * @author Julian
 */
public class NoContieneValorCampoOpcional extends AbstractRule {

	/** Creates a new instance of NoContieneValorObligatorio */
	public NoContieneValorCampoOpcional() {
	}

	public void setParams(Object[] params) {
		String valores = (String) params[0];
		ArrayList<String> listaString = new ArrayList<String>();
		StringTokenizer st = new StringTokenizer(valores, ",");
		while (st.hasMoreTokens()) {
			listaString.add(st.nextToken());
		}
		String[] array = listaString.toArray(new String[listaString.size()]);
		Arrays.sort(array);
		params[0] = array;
		super.setParams(params);
	}

	public boolean performValidation(String field, String[] registro,
			String nombreArchivo) {
		if (field != null && field.length() > 0) {
			return Arrays.binarySearch((String[]) getParams()[0], field) < 0;
		}
		return false;
	}
}
