<commit_before>package br.com.caelum.grails.stella.constraints

import org.codehaus.groovy.grails.validation.AbstractConstraint 
import org.springframework.validation.Errors 

import br.com.caelum.stella.validation.InvalidStateException 
import br.com.caelum.stella.validation.CPFValidator 

/** 
* @author <NAME>
* @author <NAME>
*/
class CPFConstraint extends AbstractConstraint { 

	public static final String CPF_CONSTRAINT = "cpf" 
	public static final String CPF_MESSAGE_CODE = "default.cpf.message" 
	public static final String CPF_NOT_MESSAGE_CODE = "default.invalid.cpf.message" 	

	Boolean formatted = false 
	Boolean cpf = true 

	void setParameter(Object constraintParameter) { 
		super.setParameter(constraintParameter) 
		if(constraintParameter instanceof Boolean) { 
			cpf = (Boolean)constraintParameter 
		} else if(constraintParameter instanceof Map) { 
			formatted = constraintParameter.get('formatted', false) 
			cpf = constraintParameter.get('cpf', true) 
		} 
	} 

	public void processValidate(Object target, Object propertyValue, Errors errors) { 

		if(!cpf) { 
			return; 
		} 
		println validateCpf(propertyValue)
		if(!validateCpf(propertyValue)) {
			def args = [constraintPropertyName, constraintOwningClass, propertyValue] 
			super.rejectValue( 
				target, 
				errors, 
				CPF_MESSAGE_CODE, 
				CPF_NOT_MESSAGE_CODE,
				args as Object[])
		} 

	} 

	public String getName() { CPF_CONSTRAINT } 

	boolean supports(Class type) { 
		return type != null && String.class.isAssignableFrom(type); 
	} 

	private validateCpf(cpf) { 
		def validator = new CPFValidator(formatted) 
		return validator.invalidMessagesFor(cpf).empty 
	} 

}<commit_msg>sanitize debug<commit_after>package br.com.caelum.grails.stella.constraints

import org.codehaus.groovy.grails.validation.AbstractConstraint 
import org.springframework.validation.Errors 

import br.com.caelum.stella.validation.InvalidStateException 
import br.com.caelum.stella.validation.CPFValidator 

/** 
* @author <NAME>
* @author <NAME>
*/
class CPFConstraint extends AbstractConstraint { 

	public static final String CPF_CONSTRAINT = "cpf" 
	public static final String CPF_MESSAGE_CODE = "default.cpf.message" 
	public static final String CPF_NOT_MESSAGE_CODE = "default.invalid.cpf.message" 	

	Boolean formatted = false 
	Boolean cpf = true 

	void setParameter(Object constraintParameter) { 
		super.setParameter(constraintParameter) 
		if(constraintParameter instanceof Boolean) { 
			cpf = (Boolean)constraintParameter 
		} else if(constraintParameter instanceof Map) { 
			formatted = constraintParameter.get('formatted', false) 
			cpf = constraintParameter.get('cpf', true) 
		} 
	} 

	public void processValidate(Object target, Object propertyValue, Errors errors) { 

		if(!cpf) { 
			return; 
		} 
		if(!validateCpf(propertyValue)) {
			def args = [constraintPropertyName, constraintOwningClass, propertyValue] 
			super.rejectValue( 
				target, 
				errors, 
				CPF_MESSAGE_CODE, 
				CPF_NOT_MESSAGE_CODE,
				args as Object[])
		} 

	} 

	public String getName() { CPF_CONSTRAINT } 

	boolean supports(Class type) { 
		return type != null && String.class.isAssignableFrom(type); 
	} 

	private validateCpf(cpf) { 
		def validator = new CPFValidator(formatted) 
		return validator.invalidMessagesFor(cpf).empty 
	} 

}
{'fraction_non_alphanumeric': 0.09096385542168675, 'fraction_numerical': 0.0, 'mean_word_length': 4.408794788273616, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '534687', 'n_tokens_mistral': 1162, 'n_tokens_neox': 1008, 'n_words': 211}