<commit_before>package cec.view;

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

import javax.swing.JOptionPane;

/**
 * Auxiliary Class used in the Presentation Layer that implements methods
 * to validate user's input on Email fields and Folder names.
 * */

public class Validator {
		
	Pattern pattern;
	Matcher matcher;
	
	
	/**
	 * Method to verify if the email addresses supplied by the user are valid.
	 * This takes into consideration that the user can supply both to and cc, or only to, or only cc
	 * 
	 * @param to the email address in the to field
	 * @param cc the email address in the cc field
	 * @return boolean returns true if the email address are valid 
	 */
	public boolean isValidSendees(String to, String cc) {
		if (to.isEmpty() && cc.isEmpty())
			return false;
		
		if (!to.isEmpty() && !cc.isEmpty())
			return isValidTo(to) && isValidCC(cc);
		
		if (!to.isEmpty())
			return isValidTo(to);
		
		if (!cc.isEmpty()) 
			return isValidCC(cc);
		
		return true;
	}

	private boolean isValidTo(String emailString) {
		String[] emails = emailString.split(";");
		
		pattern = Pattern.compile("(.+)@(.+)(\\.)(.+)"); 
		
		for (String email: emails ) {
			matcher = pattern.matcher(email);	
			if (matcher.find() == false)
				return false;
		}
		
		return true;
	}
	
	private boolean isValidCC(String emailString) {
		return isValidTo(emailString);
	}

	
	/**
	 * Verify that the user entered folder name does not contain any characters which 
	 * prevents it from being saved in the windows file system
	 * 
	 * @param folderName the name which was supplied by the user
	 * @return boolean returns true if the string does not contain any special characters
	 */
	public boolean isValidFolderName(String folderName) {
		pattern = Pattern.compile("^[a-zA-Z0-9_\\s]+$");  
		matcher = pattern.matcher(folderName);
		if (matcher.find() == false) {
			return false;
		}
		return true;
	}
	
	public boolean isValidSearched(String originalString) {
				
		String modifiedString=originalString.toUpperCase();
		
		String toRemove="[[^A-Z]&&[^0-9]&&[^@]]";
		pattern = Pattern.compile(toRemove);
		matcher = pattern.matcher(modifiedString);		
		
		if(matcher.find())		
			modifiedString=matcher.replaceAll(" ").trim();
		return modifiedString.length()>0;	
		
	}
	

}<commit_msg>Validator Javadoc<commit_after>package cec.view;

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

import javax.swing.JOptionPane;

/**
 * Auxiliary Class used in the Presentation Layer that implements methods
 * to validate user's input on Email fields and Folder names.
 * */

public class Validator {
		
	Pattern pattern;
	Matcher matcher;
	
	
	/**
	 * Method to verify if the email addresses supplied by the user are valid.
	 * This takes into consideration that the user can supply both to and cc, or only to, or only cc
	 * 
	 * @param to the email address in the to field
	 * @param cc the email address in the cc field
	 * @return boolean returns true if the email address are valid 
	 */
	public boolean isValidSendees(String to, String cc) {
		if (to.isEmpty() && cc.isEmpty())
			return false;
		
		if (!to.isEmpty() && !cc.isEmpty())
			return isValidTo(to) && isValidCC(cc);
		
		if (!to.isEmpty())
			return isValidTo(to);
		
		if (!cc.isEmpty()) 
			return isValidCC(cc);
		
		return true;
	}

	private boolean isValidTo(String emailString) {
		String[] emails = emailString.split(";");
		
		pattern = Pattern.compile("(.+)@(.+)(\\.)(.+)"); 
		
		for (String email: emails ) {
			matcher = pattern.matcher(email);	
			if (matcher.find() == false)
				return false;
		}
		
		return true;
	}
	
	private boolean isValidCC(String emailString) {
		return isValidTo(emailString);
	}

	
	/**
	 * Verify that the user entered folder name does not contain any characters which 
	 * prevents it from being saved in the windows file system
	 * 
	 * @param folderName the name which was supplied by the user
	 * @return boolean returns true if the string does not contain any special characters
	 */
	public boolean isValidFolderName(String folderName) {
		pattern = Pattern.compile("^[a-zA-Z0-9_\\s]+$");  
		matcher = pattern.matcher(folderName);
		if (matcher.find() == false) {
			return false;
		}
		return true;
	}
	
	/**
	 * Verify that what the user is searching for is not empty and does not contain any special 
	 * character except the symbol "@" 
	 *  
	 * @param folderName the name which was supplied by the user
	 * @return boolean returns true if the string does not contain any special characters
	 */
	public boolean isValidSearched(String stringToFind) {
				
		String modifiedString=stringToFind.toUpperCase();
		
		String toRemove="[[^A-Z]&&[^0-9]&&[^@]]";
		pattern = Pattern.compile(toRemove);
		matcher = pattern.matcher(modifiedString);		
		
		if(matcher.find())		
			modifiedString=matcher.replaceAll(" ").trim();
		return modifiedString.length()>0;	
		
	}
	

}
{'fraction_non_alphanumeric': 0.11533767290480065, 'fraction_numerical': 0.0020341741253051262, 'mean_word_length': 3.4822242479489516, 'pattern_counts': {'":': 0, '<': 3, '<?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': '234387', 'n_tokens_mistral': 1680, 'n_tokens_neox': 1434, 'n_words': 501}