<commit_before>package ro.pub.cs.vmchecker.client.service;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Date;

import com.google.gwt.i18n.shared.DateTimeFormat;

import ro.pub.cs.vmchecker.client.event.AuthenticationEvent;
import ro.pub.cs.vmchecker.client.event.ServerTimeUpdateEvent;
import ro.pub.cs.vmchecker.client.event.ErrorDisplayEvent;
import ro.pub.cs.vmchecker.client.model.ErrorResponse;
import ro.pub.cs.vmchecker.client.service.ServiceError;
import ro.pub.cs.vmchecker.client.service.json.ErrorResponseDecoder;
import ro.pub.cs.vmchecker.client.service.json.JSONDecoder;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestBuilder;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.RequestException;
import com.google.gwt.http.client.Response;
import com.google.gwt.http.client.Header;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.http.client.URL;
import com.google.gwt.i18n.client.LocaleInfo;

public class Delegate<T> {

	public static final int requestTimeoutMillis = 10000; /* 10 seconds */

	private EventBus eventBus;
	private RequestBuilder rb;
	private boolean isGet, attachLocale;
	private String url;
	private HashMap<String, Request> ongoingRequests;

	public Delegate(EventBus eventBus, String url, boolean isGet, boolean attachLocale,
			HashMap<String, Request> ongoingRequests) {
		this.eventBus = eventBus;
		this.isGet = isGet;
		this.attachLocale = attachLocale;
		this.url = url;
		this.ongoingRequests = ongoingRequests;
		/**
		 * We reconstruct the entire RequestBuilder for GET requests when
		 * we call sendRequest(), so don't create a new instance for it
		 * here.
		 */
		if (!isGet) {
			rb = new RequestBuilder(RequestBuilder.POST, url);
			rb.setHeader("Content-Type", "application/x-www-form-urlencoded");
			rb.setTimeoutMillis(requestTimeoutMillis);
		}

		Request ongoing = ongoingRequests.get(url);
		if (ongoing != null) ongoing.cancel();

	}

	private Date parseDateFromResponse(Response response) {
		Header[] headers = response.getHeaders();
		for (Header header : headers) {
			if (header.getName() == "Date") {
				DateTimeFormat dtf = DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.RFC_2822);
				return dtf.parse(header.getValue());
			}
		}
		return new Date(0);<commit_msg>gwt: Use proper string comparator when extracting server Date.<commit_after>package ro.pub.cs.vmchecker.client.service;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Date;

import com.google.gwt.i18n.shared.DateTimeFormat;

import ro.pub.cs.vmchecker.client.event.AuthenticationEvent;
import ro.pub.cs.vmchecker.client.event.ServerTimeUpdateEvent;
import ro.pub.cs.vmchecker.client.event.ErrorDisplayEvent;
import ro.pub.cs.vmchecker.client.model.ErrorResponse;
import ro.pub.cs.vmchecker.client.service.ServiceError;
import ro.pub.cs.vmchecker.client.service.json.ErrorResponseDecoder;
import ro.pub.cs.vmchecker.client.service.json.JSONDecoder;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestBuilder;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.RequestException;
import com.google.gwt.http.client.Response;
import com.google.gwt.http.client.Header;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.http.client.URL;
import com.google.gwt.i18n.client.LocaleInfo;

public class Delegate<T> {

	public static final int requestTimeoutMillis = 10000; /* 10 seconds */

	private EventBus eventBus;
	private RequestBuilder rb;
	private boolean isGet, attachLocale;
	private String url;
	private HashMap<String, Request> ongoingRequests;

	public Delegate(EventBus eventBus, String url, boolean isGet, boolean attachLocale,
			HashMap<String, Request> ongoingRequests) {
		this.eventBus = eventBus;
		this.isGet = isGet;
		this.attachLocale = attachLocale;
		this.url = url;
		this.ongoingRequests = ongoingRequests;
		/**
		 * We reconstruct the entire RequestBuilder for GET requests when
		 * we call sendRequest(), so don't create a new instance for it
		 * here.
		 */
		if (!isGet) {
			rb = new RequestBuilder(RequestBuilder.POST, url);
			rb.setHeader("Content-Type", "application/x-www-form-urlencoded");
			rb.setTimeoutMillis(requestTimeoutMillis);
		}

		Request ongoing = ongoingRequests.get(url);
		if (ongoing != null) ongoing.cancel();

	}

	private Date parseDateFromResponse(Response response) {
		Header[] headers = response.getHeaders();
		for (Header header : headers) {
			if (header.getName().equals("Date")) {
				DateTimeFormat dtf = DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.RFC_2822);
				return dtf.parse(header.getValue());
			}
		}
		return new Date(0);
{'fraction_non_alphanumeric': 0.1152138821630347, 'fraction_numerical': 0.00645682001614205, 'mean_word_length': 4.936526946107785, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1919627', 'n_tokens_mistral': 1661, 'n_tokens_neox': 1556, 'n_words': 316}