<commit_before>package com.pollistics.models.validators;

import com.pollistics.models.Poll;
import com.pollistics.models.User;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;


public class PollValidator implements Validator {
	public final static string[] FORBIDDEN_CHARS = ["?", ".", " ", "#", "/", ",", ":"];

	public static boolean containsItemFromArray(String inputString, String[] items) {
		// Convert the array of String items as a Stream
		// For each element of the Stream call inputString.contains(element)
		// If you have any match returns true, false otherwise
		return Arrays.stream(items).anyMatch(inputString::contains);
	}

	@Override
	public boolean supports(Class<?> clazz) {
		return clazz.isInstance(User.class);
	}

	@Override
	public void validate(Object target, Errors errors) {
		Poll poll = (Poll) target;

		if (containsItemFromArray(poll.getSlug(), FORBIDDEN_CHARS)) {
			errors.rejectValue("slug", "invalid.slug", "A slug can't contain '?', '-', ' ', '#', ':', ',' or '.'");
		}

		if(poll.getOptions().size() < 2) {
			errors.rejectValue("options", "invalid.options", "A poll has at least 2 options");
		}

		int nVotes = poll.getOptions().entrySet()
			.stream()
			.map(option -> option.getValue())
			.reduce(0, (total,votes) -> total + votes);

		if(nVotes != 0) {
			errors.rejectValue("options", "invalid.options", "Poll options can't have votes upon creation");
		}
	}
}
<commit_msg>I am really dumb in Java<commit_after>package com.pollistics.models.validators;

import com.pollistics.models.Poll;
import com.pollistics.models.User;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;


public class PollValidator implements Validator {
	public final static String[] FORBIDDEN_CHARS = {"?", ".", " ", "#", "/", ",", ":"};

	public static boolean containsItemFromArray(String inputString, String[] items) {
		// Convert the array of String items as a Stream
		// For each element of the Stream call inputString.contains(element)
		// If you have any match returns true, false otherwise
		return Arrays.stream(items).anyMatch(inputString::contains);
	}

	@Override
	public boolean supports(Class<?> clazz) {
		return clazz.isInstance(User.class);
	}

	@Override
	public void validate(Object target, Errors errors) {
		Poll poll = (Poll) target;

		if (containsItemFromArray(poll.getSlug(), FORBIDDEN_CHARS)) {
			errors.rejectValue("slug", "invalid.slug", "A slug can't contain '?', '-', ' ', '#', ':', ',' or '.'");
		}

		if(poll.getOptions().size() < 2) {
			errors.rejectValue("options", "invalid.options", "A poll has at least 2 options");
		}

		int nVotes = poll.getOptions().entrySet()
			.stream()
			.map(option -> option.getValue())
			.reduce(0, (total,votes) -> total + votes);

		if(nVotes != 0) {
			errors.rejectValue("options", "invalid.options", "Poll options can't have votes upon creation");
		}
	}
}

{'fraction_non_alphanumeric': 0.15462868769074262, 'fraction_numerical': 0.0027127839945744322, 'mean_word_length': 4.483271375464684, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 9, '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': '5217253', 'n_tokens_mistral': 984, 'n_tokens_neox': 902, 'n_words': 235}