/*
 * NoCoincideLongitudoTipoCampoCaracterNumericoObligatorioDependienteDep.java
 *
 * Created on 24 de junio de 2005, 12:51 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
package com.fidufosyga.rules;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 
 * @author Julian
 */
public class NoCoincideLongitudoTipoCampoCaracterNumericoObligatorioDependienteDep
		extends AbstractRule {

	private Pattern pattern;

	public NoCoincideLongitudoTipoCampoCaracterNumericoObligatorioDependienteDep() {
		String patternStr = "[^A-Z/\\s@Ñ]";
		pattern = Pattern.compile(patternStr);

	}

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

		if (registro[new Integer((String) getParams()[0]).intValue()]
				.equals(getParams()[1])) {
			if (field.trim().length() != field.length())
				return true;

			if (field.length() < new Integer((String) getParams()[2])
					.intValue()
					|| field.length() > new Integer((String) getParams()[3])
							.intValue())
				return true;
			Matcher matcher = pattern.matcher(field);
			return matcher.find();

		}

		return false;
	}

}
