/*
 * NoContieneValorCampoDependiente.java
 *
 * Created on 21 de marzo de 2007, 01:38 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 Julian
 */
public class NoContieneValorCampoDependiente extends AbstractRule {

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

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

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

		if (registro[new Integer((String) getParams()[0]).intValue()]
				.equals(getParams()[1])) {

			return Arrays.binarySearch((String[]) getParams()[2], field) < 0;
		}
		return false;
	}
}
