<commit_before>package edu.ucla.cens.awserver.validator;

import org.json.JSONObject;

import edu.ucla.cens.awserver.datatransfer.AwRequest;
import edu.ucla.cens.awserver.util.DateUtils;
import edu.ucla.cens.awserver.util.JsonUtils;

/**
 * Validates the timezone element from an AW JSON message.
 * 
 * @author selsky
 */
public class JsonMsgTimezoneValidator extends AbstractAnnotatingJsonObjectValidator {
	private String _key = "timezone";
		
	/**
     * @throws IllegalArgumentException if the provded AwRequestAnnotator is null
	 */
	public JsonMsgTimezoneValidator(AwRequestAnnotator awRequestAnnotator) {
		super(awRequestAnnotator);
	}
	
	/**
	 * @return true if the value returned from the AwRequest for the key "timezone" exists and is a valid timezone.
	 * @return false otherwise
	 */
	public boolean validate(AwRequest request, JSONObject jsonObject) {		 
		String tz = JsonUtils.getStringFromJson(jsonObject, _key);
		
		if(null == tz) {
			getAnnotator().annotate(request, "timezone in message is null");
			return false;
		}
		
		if(! DateUtils.isValidTimezone(tz)) {
			getAnnotator().annotate(request, "invalid timezone: " + tz);
			return false;
		}
		<commit_msg>fixed comments<commit_after>package edu.ucla.cens.awserver.validator;

import org.json.JSONObject;

import edu.ucla.cens.awserver.datatransfer.AwRequest;
import edu.ucla.cens.awserver.util.DateUtils;
import edu.ucla.cens.awserver.util.JsonUtils;

/**
 * Validates the timezone element from an AW JSON message.
 * 
 * @author selsky
 */
public class JsonMsgTimezoneValidator extends AbstractAnnotatingJsonObjectValidator {
	private String _key = "timezone";
		
	/**
     * @throws IllegalArgumentException if the provded AwRequestAnnotator is null
	 */
	public JsonMsgTimezoneValidator(AwRequestAnnotator awRequestAnnotator) {
		super(awRequestAnnotator);
	}
	
	/**
	 * @return true if the value returned from the JSONObject for the key "timezone" exists and is a valid timezone.
	 * @return false otherwise
	 */
	public boolean validate(AwRequest request, JSONObject jsonObject) {		 
		String tz = JsonUtils.getStringFromJson(jsonObject, _key);
		
		if(null == tz) {
			getAnnotator().annotate(request, "timezone in message is null");
			return false;
		}
		
		if(! DateUtils.isValidTimezone(tz)) {
			getAnnotator().annotate(request, "invalid timezone: " + tz);
			return false;
		}
		
{'fraction_non_alphanumeric': 0.09789029535864979, 'fraction_numerical': 0.0, 'mean_word_length': 4.4380733944954125, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7391926', 'n_tokens_mistral': 816, 'n_tokens_neox': 724, 'n_words': 185}