<commit_before>/*jslint devel: true es5: true */
/*global $: true, joynr: true, provisioning: true, RadioProvider: true, RadioStation: true, GeoPosition: true, domain: true, getBuildSignatureString: true, TrafficServiceBroadcastFilter : true, GeocastBroadcastFilter: true */

/*
 * #%L
 * %%
 * Copyright (C) 2011 - 2015 BMW Car IT GmbH
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

function logHtml(line, msg) {
    $("div#divLog").prepend(
            msg + " <span style=\"font-size:0.8em;color:grey\">" + line + "</span><br>").show();
}
function log(line, msg) {
    logHtml(line, msg);
    msg = new Date().toISOString() + ": [provider.js: " + line + "] " + msg;
    console.log(msg);
}

function showCurrentStationInHtml(radioStation) {
    $("input#txtCurrentStationName").val(radioStation.name);
    $("input#txtCurrentStationTrafficService").val(radioStation.trafficService);
    $("input#txtCurrentStationCountry").val(radioStation.country);
}

function showFavoriteStationsInHtml(radioStations) {
    var i;
    var stationsString = "";
    for (i = 0; i < radioStations.length; i++) {
        if (i !== 0) {
            stationsString += "\n";
        }
        stationsString += "Name: " + radioStations[i].name;
        stationsString += " | TrafficService: " + radioStations[i].trafficService;
        stationsString += " | Country: " + radioStations[i].country;
    }
    $("textarea#txtFavoriteStations").val(stationsString);
}

var joynr;
var currentStationValue = "default value for current station";
var providerQos = null;

var RadioProviderImpl =
        function RadioProviderImpl() {
            var self = this;

            var stationsList = [
                new RadioStation({
                    name : "<NAME>",
                    trafficService : true,
                    country : "AUSTRALIA"
                }),
                new RadioStation({
                    name : "<NAME>",
                    trafficService : false,
                    country : "ITALY"
                }),
                new RadioStation({
                    name : "JAZZ.FM91",
                    trafficService : false,
                    country : "CANADA"
                }),
                new RadioStation({
                    name : "Bayern 3",
                    trafficService : true,
                    country : "GERMANY"
                })
            ];

            var currentStationIndex = 0;

            Object.defineProperty(this, "currentStationIndex", {
                get : function() {
                    return currentStationIndex;
                }
            });

            Object.defineProperty(this, "stationsList", {
                get : function() {
                    return stationsList;
                }
            });

            this.currentStation = {
                get : function() {
                    log("radioProvider.currentStation.get", "called");
                    return stationsList[currentStationIndex];
                }
            };

            this.addFavoriteStation =
                    function(opArgs) {
                        log("radioProvider.addFavoriteStation", "called with args: "
                            + JSON.stringify(opArgs));

                        if (opArgs === undefined) {
                            log(
                                    "radioProvider.addFavoriteStation",
                                    "operation arguments is undefined!");
                            return;
                        }
                        if (opArgs.newFavoriteStation === undefined) {
                            log(
                                    "radioProvider.addFavoriteStation",
                                    "operation argument \"newFavoriteStation\" is undefined!");
                            return;
                        }

                        stationsList.push(opArgs.newFavoriteStation);

                        showFavoriteStationsInHtml(stationsList);
                        return true;
                    };

            this.shuffleStations =
                    function() {
                        log("radioProvider.shuffleStations", "called");

                        var oldStationIndex = currentStationIndex;

                        currentStationIndex++;
                        currentStationIndex = currentStationIndex % stationsList.length;
                        self.currentStation.valueChanged(stationsList[currentStationIndex]);
                        log("radioProvider.shuffleStations", JSON
                                .stringify(stationsList[oldStationIndex])
                            + " -> "
                            + JSON.stringify(stationsList[currentStationIndex]));

                        showCurrentStationInHtml(stationsList[currentStationIndex]);
                    };

            // Provide broadcast specific implementation stubs. Properties will
            // be added when joynr.providerBuilder.build() gets called.

            this.weakSignal = {};

            this.newStationDiscovered = {};

            // the button onclick handler
            this.fireWeakSignal = function() {
                log("radioProvider.fireWeakSignal", "called");

                var outputParameters;
                outputParameters = self.weakSignal.createBroadcastOutputParameters();
                outputParameters.setWeakSignalStation(stationsList[currentStationIndex]);
                self.weakSignal.fire(outputParameters);
            };

            // the button onclick handler
            this.fireNewStationDiscovered = function() {
                log("radioProvider.fireNewStationDiscovered", "called");
                var outputParameters;
                var geoPosition;

                // can later replace the station with current station
                // and take its position
                geoPosition = new GeoPosition();
                geoPosition.latitude = 48.55;
                geoPosition.longitude = 12.0;
                outputParameters = self.newStationDiscovered.createBroadcastOutputParameters();
                outputParameters.setGeoPosition(geoPosition);
                outputParameters.setDiscoveredStation(stationsList[currentStationIndex]);
                self.newStationDiscovered.fire(outputParameters);
            };

            this.getLocationOfCurrentStation =
                function() {
                    log("radioProvider.getLocationOfCurrentStation", "called");
                    return stationsList[currentStationIndex].country;
                };<commit_msg>[JS] Radio: Added country specific location map<commit_after>/*jslint devel: true es5: true */
/*global $: true, joynr: true, provisioning: true, RadioProvider: true, RadioStation: true, GeoPosition: true, domain: true, getBuildSignatureString: true, TrafficServiceBroadcastFilter : true, GeocastBroadcastFilter: true */

/*
 * #%L
 * %%
 * Copyright (C) 2011 - 2015 BMW Car IT GmbH
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

function logHtml(line, msg) {
    $("div#divLog").prepend(
            msg + " <span style=\"font-size:0.8em;color:grey\">" + line + "</span><br>").show();
}
function log(line, msg) {
    logHtml(line, msg);
    msg = new Date().toISOString() + ": [provider.js: " + line + "] " + msg;
    console.log(msg);
}

function showCurrentStationInHtml(radioStation) {
    $("input#txtCurrentStationName").val(radioStation.name);
    $("input#txtCurrentStationTrafficService").val(radioStation.trafficService);
    $("input#txtCurrentStationCountry").val(radioStation.country);
}

function showFavoriteStationsInHtml(radioStations) {
    var i;
    var stationsString = "";
    for (i = 0; i < radioStations.length; i++) {
        if (i !== 0) {
            stationsString += "\n";
        }
        stationsString += "Name: " + radioStations[i].name;
        stationsString += " | TrafficService: " + radioStations[i].trafficService;
        stationsString += " | Country: " + radioStations[i].country;
    }
    $("textarea#txtFavoriteStations").val(stationsString);
}

var joynr;
var currentStationValue = "default value for current station";
var providerQos = null;

var RadioProviderImpl =
        function RadioProviderImpl() {
            var self = this;

            var stationsList = [
                new RadioStation({
                    name : "<NAME>",
                    trafficService : true,
                    country : "AUSTRALIA"
                }),
                new RadioStation({
                    name : "Radio Popolare",
                    trafficService : false,
                    country : "ITALY"
                }),
                new RadioStation({
                    name : "JAZZ.FM91",
                    trafficService : false,
                    country : "CANADA"
                }),
                new RadioStation({
                    name : "Bayern 3",
                    trafficService : true,
                    country : "GERMANY"
                })
            ];

            var countryGeoPositionMap = {
                // Melbourne
                "AUSTRALIA": new GeoPosition({ latitude: -37.8141070, longitude: 144.9632800 }),
                // Bolzano
                "ITALY": new GeoPosition({ latitude: 46.4982950, longitude: 11.3547580 }),
                // Edmonton
                "CANADA": new GeoPosition({ latitude: 53.5443890, longitude: -113.4909270 }),
                // Munich
                "GERMANY": new GeoPosition({ latitude: 48.1351250, longitude: 11.5819810 })
            };

            var currentStationIndex = 0;

            Object.defineProperty(this, "currentStationIndex", {
                get : function() {
                    return currentStationIndex;
                }
            });

            Object.defineProperty(this, "stationsList", {
                get : function() {
                    return stationsList;
                }
            });

            this.currentStation = {
                get : function() {
                    log("radioProvider.currentStation.get", "called");
                    return stationsList[currentStationIndex];
                }
            };

            this.addFavoriteStation =
                    function(opArgs) {
                        log("radioProvider.addFavoriteStation", "called with args: "
                            + JSON.stringify(opArgs));

                        if (opArgs === undefined) {
                            log(
                                    "radioProvider.addFavoriteStation",
                                    "operation arguments is undefined!");
                            return;
                        }
                        if (opArgs.newFavoriteStation === undefined) {
                            log(
                                    "radioProvider.addFavoriteStation",
                                    "operation argument \"newFavoriteStation\" is undefined!");
                            return;
                        }

                        stationsList.push(opArgs.newFavoriteStation);

                        showFavoriteStationsInHtml(stationsList);
                        return true;
                    };

            this.shuffleStations =
                    function() {
                        log("radioProvider.shuffleStations", "called");

                        var oldStationIndex = currentStationIndex;

                        currentStationIndex++;
                        currentStationIndex = currentStationIndex % stationsList.length;
                        self.currentStation.valueChanged(stationsList[currentStationIndex]);
                        log("radioProvider.shuffleStations", JSON
                                .stringify(stationsList[oldStationIndex])
                            + " -> "
                            + JSON.stringify(stationsList[currentStationIndex]));

                        showCurrentStationInHtml(stationsList[currentStationIndex]);
                    };

            // Provide broadcast specific implementation stubs. Properties will
            // be added when joynr.providerBuilder.build() gets called.

            this.weakSignal = {};

            this.newStationDiscovered = {};

            // the button onclick handler
            this.fireWeakSignal = function() {
                log("radioProvider.fireWeakSignal", "called");

                var outputParameters;
                outputParameters = self.weakSignal.createBroadcastOutputParameters();
                outputParameters.setWeakSignalStation(stationsList[currentStationIndex]);
                self.weakSignal.fire(outputParameters);
            };

            // the button onclick handler
            this.fireNewStationDiscovered = function() {
                log("radioProvider.fireNewStationDiscovered", "called");
                var outputParameters;
                var geoPosition;

                geoPosition = countryGeoPositionMap[stationsList[currentStationIndex].country];
                outputParameters = self.newStationDiscovered.createBroadcastOutputParameters();
                outputParameters.setGeoPosition(geoPosition);
                outputParameters.setDiscoveredStation(stationsList[currentStationIndex]);
                self.newStationDiscovered.fire(outputParameters);
            };

            this.getLocationOfCurrentStation =
                function() {
                    log("radioProvider.getLocationOfCurrentStation", "called");
                    return stationsList[currentStationIndex].country;
                };
{'fraction_non_alphanumeric': 0.09514444595144446, 'fraction_numerical': 0.008341245083412451, 'mean_word_length': 1.5999647390691114, 'pattern_counts': {'":': 6, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4550178', 'n_tokens_mistral': 3607, 'n_tokens_neox': 3291, 'n_words': 748}