/*
 * ValidarVacioSegunRango.java
 *
 * Created on 29 de mayo de 2007, 09:25 AM
 *
 * 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 JSolano
 */
public class ValidarVacioSegunRango extends AbstractRule {
	// (COL?1 IN(?2) AND LEN(@campo)=0)
	/** Creates a new instance of CampoVacio */
	public ValidarVacioSegunRango() {
	}

	public void setParams(Object[] params) {
		String valores = (String) params[1];
		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[1] = array;

		super.setParams(params);
	}

	public boolean performValidation(String field, String registro[],
			String nombreArchivo) {

		String campo = registro[new Integer((String) getParams()[0]).intValue()];

		if (Arrays.binarySearch((String[]) getParams()[1], campo) >= 0
				&& field.length() == 0) {
			return true;
		}

		return false;

	}

}
