<commit_before>package com.woopra.java.sdk;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Iterator;

import com.woopra.json.JSONException;
import com.woopra.sss.test.AsyncClient;

/**
 * Woopra Java SDK
 * This class enables back-end tracking in Java for Woopra.
 * Even though the getInstance is implemented for this class, note that the design of
 * this object is such that a new instance should be created for each new request.
 * @author <NAME>
 * @version 2013-09-30
 */
public class WoopraTracker {
	
	private static String SDK_ID = "java";
	protected static int defaultTimeout;
	private static HashMap<String, WoopraTracker> instances;
	private String domain;
	private int idleTimeout;

	
	static {
		WoopraTracker.defaultTimeout = 300000;
		WoopraTracker.instances = new HashMap<String, WoopraTracker>();
    }
	
	/**
	 * If an instance of WoopraTracker already exists, this method returns it.
	 * It creates a new instance otherwise.
	 * @return WoopraTracker
	 */
	public synchronized final static WoopraTracker getInstance(String domain) {
		WoopraTracker instance = WoopraTracker.instances.get(domain);
		if (instance != null) {
    		return instance;
    	} else {
    		instance = new WoopraTracker(domain);
    		WoopraTracker.instances.put(domain, instance);
    		return instance;
    	}
	}

	/**
	 * Public Constructor
	 */
	public WoopraTracker(String domain) {
		this.domain = domain;
		this.idleTimeout = WoopraTracker.defaultTimeout;
	}
	
	/**
	 * Tracks a custom event through the back-end.
	 * @param event	(WoopraEvent) the event to track
	 * @return WoopraTracker 
	 */
	public void track(WoopraVisitor visitor, WoopraEvent event) {
		if (visitor != null && event != null) {
			this.woopraHttpRequest(event, visitor);
		}
	}
	
	/**
	 * Pushes the identified user to Woopra through the back-end.
	 * Please note that the identified user is automatically pushed with any tracking event.
	 * Therefore, this method is useful if you need to identify a user without tracking any event.
	 */
	public void push(WoopraVisitor visitor) {
		if (visitor != null) {
			this.woopraHttpRequest(null, visitor);
		}
	}
	
	/**
	 * Get the value of the idle timeout (time in milliseconds after which the user is considered offline)
	 * @return idle timeout
	 */
	public int getIdle_timeout() {
		return idleTimeout;
	}

	/**
	 * Set the value of the idle timeout (time in milliseconds after which the user is considered offline)
	 * @param idle_timeout
	 */
	public void setIdleTimeout(int idleTimeout) {
		this.idleTimeout = idleTimeout;
	}

	private void woopraHttpRequest(WoopraEvent event, WoopraVisitor visitor) {
		try {
			String baseUrl = "http://www.woopra.com/track/";
			String configParams = "?host=".concat(URLEncoder.encode((String) this.domain, "UTF-8"));
			configParams = configParams.concat("&cookie=").concat(URLEncoder.encode(visitor.getCookieValue(), "UTF-8"));
			if (! visitor.getIpAddress().equals("")) {
				configParams = configParams.concat("&ip=").concat(URLEncoder.encode(visitor.getIpAddress(), "UTF-8"));
			}
			configParams = configParams.concat("&timeout=").concat(URLEncoder.encode(String.valueOf(this.idleTimeout), "UTF-8"));
			String userParams = "";<commit_msg>remove timeout getter (useless)<commit_after>package com.woopra.java.sdk;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Iterator;

import com.woopra.json.JSONException;
import com.woopra.sss.test.AsyncClient;

/**
 * Woopra Java SDK
 * This class enables back-end tracking in Java for Woopra.
 * Even though the getInstance is implemented for this class, note that the design of
 * this object is such that a new instance should be created for each new request.
 * @author <NAME>
 * @version 2013-09-30
 */
public class WoopraTracker {
	
	private static String SDK_ID = "java";
	protected static int defaultTimeout;
	private static HashMap<String, WoopraTracker> instances;
	private String domain;
	private int idleTimeout;

	
	static {
		WoopraTracker.defaultTimeout = 300000;
		WoopraTracker.instances = new HashMap<String, WoopraTracker>();
    }
	
	/**
	 * If an instance of WoopraTracker already exists, this method returns it.
	 * It creates a new instance otherwise.
	 * @return WoopraTracker
	 */
	public synchronized final static WoopraTracker getInstance(String domain) {
		WoopraTracker instance = WoopraTracker.instances.get(domain);
		if (instance != null) {
    		return instance;
    	} else {
    		instance = new WoopraTracker(domain);
    		WoopraTracker.instances.put(domain, instance);
    		return instance;
    	}
	}

	/**
	 * Public Constructor
	 */
	public WoopraTracker(String domain) {
		this.domain = domain;
		this.idleTimeout = WoopraTracker.defaultTimeout;
	}
	
	/**
	 * Tracks a custom event through the back-end.
	 * @param event	(WoopraEvent) the event to track
	 * @return WoopraTracker 
	 */
	public void track(WoopraVisitor visitor, WoopraEvent event) {
		if (visitor != null && event != null) {
			this.woopraHttpRequest(event, visitor);
		}
	}
	
	/**
	 * Pushes the identified user to Woopra through the back-end.
	 * Please note that the identified user is automatically pushed with any tracking event.
	 * Therefore, this method is useful if you need to identify a user without tracking any event.
	 */
	public void push(WoopraVisitor visitor) {
		if (visitor != null) {
			this.woopraHttpRequest(null, visitor);
		}
	}

	/**
	 * Set the value of the idle timeout (time in milliseconds after which the user is considered offline)
	 * @param idle_timeout
	 */
	public void setIdleTimeout(int idleTimeout) {
		this.idleTimeout = idleTimeout;
	}

	private void woopraHttpRequest(WoopraEvent event, WoopraVisitor visitor) {
		try {
			String baseUrl = "http://www.woopra.com/track/";
			String configParams = "?host=".concat(URLEncoder.encode((String) this.domain, "UTF-8"));
			configParams = configParams.concat("&cookie=").concat(URLEncoder.encode(visitor.getCookieValue(), "UTF-8"));
			if (! visitor.getIpAddress().equals("")) {
				configParams = configParams.concat("&ip=").concat(URLEncoder.encode(visitor.getIpAddress(), "UTF-8"));
			}
			configParams = configParams.concat("&timeout=").concat(URLEncoder.encode(String.valueOf(this.idleTimeout), "UTF-8"));
			String userParams = "";
{'fraction_non_alphanumeric': 0.10686668728734922, 'fraction_numerical': 0.005567584287039901, 'mean_word_length': 4.100157728706624, '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': '1198250', 'n_tokens_mistral': 2104, 'n_tokens_neox': 1942, 'n_words': 574}