<commit_before>package org.xcolab.utils.validation;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder;

public class ValidScreenNameValidator implements
		ConstraintValidator<ValidScreenName, Object> {
	private String screenNameProperty;
	private long DEFAULT_COMPANY_ID = 10112L;

	@Override
	public void initialize(ValidScreenName constraintAnnotation) {
		screenNameProperty = constraintAnnotation.screenNameProperty();
	}

	@Override
	public boolean isValid(Object value, ConstraintValidatorContext context) {
		String screenName = ConstraintValidatorHelper.getPropertyValue(
				String.class, screenNameProperty, value);
		if (screenName == null) {
			// ignore in case of null. Another validator will care about this
			return true;
		}

		if (validateScreenName(screenName)) {
			return true;
		} else {
			boolean isDefaultMessage = "".equals(context
					.getDefaultConstraintMessageTemplate());
			/*
			 * if custom message was provided, don't touch it, otherwise build
			 * the default message
			 */
			if (isDefaultMessage) {
				StringBuilder sb = new StringBuilder();
				sb.append("Please provide a ");
				sb.append(screenNameProperty);
				sb.append(" containing only alphanumeric characters - no whitespaces or other special signs");
				context.disableDefaultConstraintViolation();
				ConstraintViolationBuilder violationBuilder = context
						.buildConstraintViolationWithTemplate(sb.toString());
				violationBuilder.addConstraintViolation();
			}

			return false;
		}
	}

	public boolean validateScreenName(String name) {
		return name != null && name.matches("^[a-zA-Z0-9]+$");
	}

    public String normalizeScreenName(String name) {
        if (name == null) {
            return null;
        }

        return name.replaceAll("[^a-zA-Z0-9]", "");
    }

}<commit_msg>refactoring<commit_after>package org.xcolab.utils.validation;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder;

public class ValidScreenNameValidator implements
		ConstraintValidator<ValidScreenName, Object> {
	private String screenNameProperty;
	private long DEFAULT_COMPANY_ID = 10112L;

	@Override
	public void initialize(ValidScreenName constraintAnnotation) {
		screenNameProperty = constraintAnnotation.screenNameProperty();
	}

	@Override
	public boolean isValid(Object value, ConstraintValidatorContext context) {
		String screenName = ConstraintValidatorHelper.getPropertyValue(
				String.class, screenNameProperty, value);
		if (screenName == null) {
			// ignore in case of null. Another validator will care about this
			return true;
		}

		if (validateScreenName(screenName)) {
			return true;
		} else {
			boolean isDefaultMessage = "".equals(context
					.getDefaultConstraintMessageTemplate());
			/*
			 * if custom message was provided, don't touch it, otherwise build
			 * the default message
			 */
			if (isDefaultMessage) {
				StringBuilder sb = new StringBuilder();
				sb.append("Please provide a ");
				sb.append(screenNameProperty);
				sb.append(" containing only alphanumeric characters - no whitespaces or other special signs");
				context.disableDefaultConstraintViolation();
				ConstraintViolationBuilder violationBuilder = context
						.buildConstraintViolationWithTemplate(sb.toString());
				violationBuilder.addConstraintViolation();
			}

			return false;
		}
	}

	public boolean validateScreenName(String name) {
		return name != null && name.matches("^[a-zA-Z0-9]+$");
	}
}
{'fraction_non_alphanumeric': 0.08930029948271168, 'fraction_numerical': 0.004356112169888375, 'mean_word_length': 4.6091603053435115, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3115701', 'n_tokens_mistral': 1091, 'n_tokens_neox': 944, 'n_words': 243}