/*
 * ListaDiferenteOtroCampoValorCampoInvalido.java
 *
 * Created on 2 de abril de 2007, 06:30 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;

/**
 * 
 * 4,'MS'#'AS','1'#'2'
 * 
 * ListaDiferenteOtroCampoValorCampoInvalido COL?1 NOT IN (?2) AND
 * 
 * @campo in (?3)
 * @author Julian
 */
public class ListaDiferenteOtroCampoValorCampoInvalido extends AbstractRule {

        @Override
	public void setParams(Object[] params) {
		String valores = (String) params[1];
		ArrayList<String> listaString = new ArrayList();
		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();
		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);
	}

        @Override
	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) {
			if (Arrays.binarySearch((String[]) getParams()[2], field) >= 0) {
				return true;
			}

		}
		return false;
	}

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

}
