/*
 * NoContieneValorCampoDependienteDependiente.java
 *
 * Created on 23 de marzo de 2007, 09:03 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 NoContieneValorCampoDependienteDependiente extends AbstractRule {

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

	public void setParams(Object[] params) {
		String valores = (String) params[4];
		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[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])) {
			if (registro[new Integer((String) getParams()[2]).intValue()]
					.equals(getParams()[3])) {
				return Arrays.binarySearch((String[]) getParams()[4], field) < 0;
			}
			return false;
		}
		return false;
	}
}
