<commit_before>/**
 * @fileoverview
 * Data objects and classes for the http logger
 *
 */


/**
 * @class
 * Data class for http logger
 */
window.HTTPLoggerData = new function()
{
    this.requestList = [];
    this.requestMap = {};
    this.selectedRequestId = null;
    var lastModifiedRequestId = null;


    this._views = ["request_list",
                   "request_info_raw",
                   "response_info_raw",
                   "request_info_headers",
                   "response_info_headers",
                   "request_overview",
                   "response_info_body"
                   ];

    /**
     * Get the log as a list
     */
    this.getLog = function()
    {
        return this.requestList;
    }
    
    /**
     * Get a specific request
     * @argument {string} id the id of the request
     * @returns {object} data object for the request or null if not found
     */
    this.getRequestById = function(id)
    {
        if (id in this.requestMap) { return this.requestMap[id] }
        else { return null }
    }
    
    /**
     * Clear the log data
     *
     */
    this.clearLog = function()
    {
        this.requestList = [];
        this.requestMap = {};
        this.selectedRequestId = null;
        this._updateViews();
    }

    /**
     * Add a request to the log
     */
    this.addRequest = function(request)
    {
        var r = { id:request["request-id"],
                  "request": request,
                  response:null
                }

        this.requestList.push(r);
        this.requestMap[r.id] = r;
        lastModifiedRequestId = r.id;
        this._updateViews();
    }
    
    /**
     * Add a response object to an existing request
     * fixme: now we silently ignore repsonses to non-exstant requests
     */
    this.addResponse = function(response)
    {
        var r = this.requestMap[response["request-id"]];
        if (r) {
            r.response = response;
            lastModifiedRequestId = r.id;
            this._updateViews();
        }
    }
    
    /**
     * Set the currently selected request, that is, the request that is being
     * inspected
     */
    this.setSelectedRequestId = function(id)
    {
        this.selectedRequestId = id;
        this._updateViews();
    }
    
    /**
     * Clear the selected request
     */
    this.clearSelectedRequest = function()
    {
        this.selectedRequestId = null;
        this._updateViews();
    }
    
    /**
     * Get the selected request
     */
    this.getSelectedRequest = function()
    {
        if (this.selectedRequestId && this.selectedRequestId in this.requestMap)
        {
            return this.requestMap[this.selectedRequestId];
        }
        else
        {
            return null;
        }
    }    

    /**
     * Get the ID of the selected request
     */
    this.getSelectedRequestId = function()
    {
        return this.selectedRequestId;
    }
    
    this.getLastModifiedRequestId = function()
    {
        return lastModifiedRequestId;
    }
    
    /**
     * Update all views that use this as a data source
     */
    this._updateViews = function()
    {
        for (var n=0, e; e=this._views[n]; n++)
        {
            if (e in window.views) { window.views[e].update() }
        }
    }
<commit_msg>Made all the innards of the class private<commit_after>/**
 * @fileoverview
 * Data objects and classes for the http logger
 *
 */


/**
 * @class
 * Data class for http logger
 */
window.HTTPLoggerData = new function()
{
    requestList = [];
    requestMap = {};
    selectedRequestId = null;
    var lastModifiedRequestId = null;


    _views = ["request_list",
                   "request_info_raw",
                   "response_info_raw",
                   "request_info_headers",
                   "response_info_headers",
                   "request_overview",
                   "response_info_body"
                   ];

    /**
     * Get the log as a list
     */
    this.getLog = function()
    {
        return requestList;
    }
    
    /**
     * Get a specific request
     * @argument {string} id the id of the request
     * @returns {object} data object for the request or null if not found
     */
    this.getRequestById = function(id)
    {
        if (id in requestMap) { return requestMap[id] }
        else { return null }
    }
    
    /**
     * Clear the log data
     *
     */
    this.clearLog = function()
    {
        requestList = [];
        requestMap = {};
        selectedRequestId = null;
        _updateViews();
    }

    /**
     * Add a request to the log
     */
    this.addRequest = function(request)
    {
        var r = { id:request["request-id"],
                  "request": request,
                  response:null
                }

        requestList.push(r);
        requestMap[r.id] = r;
        lastModifiedRequestId = r.id;
        _updateViews();
    }
    
    /**
     * Add a response object to an existing request
     * fixme: now we silently ignore repsonses to non-exstant requests
     */
    this.addResponse = function(response)
    {
        var r = requestMap[response["request-id"]];
        if (r) {
            r.response = response;
            lastModifiedRequestId = r.id;
            _updateViews();
        }
    }
    
    /**
     * Set the currently selected request, that is, the request that is being
     * inspected
     */
    this.setSelectedRequestId = function(id)
    {
        selectedRequestId = id;
        _updateViews();
    }
    
    /**
     * Clear the selected request
     */
    this.clearSelectedRequest = function()
    {
        selectedRequestId = null;
        _updateViews();
    }
    
    /**
     * Get the selected request
     */
    this.getSelectedRequest = function()
    {
        if (selectedRequestId && selectedRequestId in requestMap)
        {
            return requestMap[selectedRequestId];
        }
        else
        {
            return null;
        }
    }    

    /**
     * Get the ID of the selected request
     */
    this.getSelectedRequestId = function()
    {
        return selectedRequestId;
    }
    
    this.getLastModifiedRequestId = function()
    {
        return lastModifiedRequestId;
    }
    
    /**
     * Update all views that use this as a data source
     */
    var _updateViews = function()
    {
        for (var n=0, e; e=_views[n]; n++)
        {
            if (e in window.views) { window.views[e].update() }
        }
    }

{'fraction_non_alphanumeric': 0.1035012285012285, 'fraction_numerical': 0.0003071253071253071, 'mean_word_length': 1.5571260306242638, 'pattern_counts': {'":': 2, '<': 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': '2251567', 'n_tokens_mistral': 1846, 'n_tokens_neox': 1809, 'n_words': 448}