/*
 * SegunValorDeUnaListaNoContieneValorDeOtraListaDependiente.java
 *
 * Created on 28 de marzo de 2007, 07:39 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,A#B,2#3#4#5#6#7
/**
 * 
 * @author Julian
 */
public class SegunValorDeUnaListaNoContieneValorDeOtraListaDependiente extends
		AbstractRule {

	public SegunValorDeUnaListaNoContieneValorDeOtraListaDependiente() {
	}

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

		valores = (String) params[4];
		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[4] = array;
		super.setParams(params);
	}

	public boolean performValidation(String field, String[] registro,
			String nombreArchivo) {
		String codigoNovedad = registro[new Integer((String) getParams()[0])
				.intValue()];
		if (codigoNovedad.equals((String) getParams()[1])) {

			String otroCampo = registro[new Integer((String) getParams()[2])
					.intValue()];
			if (Arrays.binarySearch((String[]) getParams()[3], otroCampo) >= 0) {
				return Arrays.binarySearch((String[]) getParams()[4], field) < 0;
			}
		}
		return false;
	}
}