/*
 * DeUnaListaDeValoresCamposNoVacios.java
 *
 * Created on 27 de marzo de 2007, 02:10 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;

// 12,C,20#21#22#23
/**
 * 
 * @author Julian
 */
public class DeUnaListaDeValoresCampoVacios extends AbstractRule {

	public DeUnaListaDeValoresCampoVacios() {
	}

	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;

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

	public boolean performValidation(String field, String[] registro,
			String nombreArchivo) {
		String otroCampo = registro[new Integer((String) getParams()[0])
				.intValue()];
		if (Arrays.binarySearch((String[]) getParams()[1], otroCampo) >= 0) {

			for (int i = 0; i < ((String[]) getParams()[2]).length; i++) {
				String campo = registro[new Integer(
						((String[]) getParams()[2])[i]).intValue()];
				if (campo.length() == 0) {
					return true;
				}
			}

		}
		return false;
	}
}
