Example usage for java.util Locale ROOT

List of usage examples for java.util Locale ROOT

Introduction

In this page you can find the example usage for java.util Locale ROOT.

Prototype

Locale ROOT

To view the source code for java.util Locale ROOT.

Click Source Link

Document

Useful constant for the root locale.

Usage

From source file:org.openremote.server.inventory.DiscoveryService.java

protected RouteDefinition createDiscoveryRoute(Adapter adapter, String discoveryEndpointUri) {
    String routeId = "discovery-" + discoveryEndpointUri.hashCode();
    return new RouteDefinition(discoveryEndpointUri).id(routeId).autoStartup(false).process(exchange -> {

        Object discoveryResult = exchange.getIn().getBody();
        if (discoveryResult instanceof List) {
            List resultList = (List) discoveryResult;
            if (resultList.size() == 0)
                return;

            LOG.debug("Processing discovered device list: " + resultList.size());
            List<Device> devices = new ArrayList<>();

            // TODO Ugly hack to support v2 and v3 device model
            Object firstResult = resultList.get(0);
            if (firstResult instanceof DiscoveredDeviceDTO) {
                // V2
                List<DiscoveredDeviceDTO> discoveredDeviceDTOs = exchange.getIn().getBody(List.class);

                for (DiscoveredDeviceDTO deviceDTO : discoveredDeviceDTOs) {
                    List<DiscoveredDeviceAttrDTO> attributes = deviceDTO.getDeviceAttrs();

                    String discoveryCommand = null;
                    for (DiscoveredDeviceAttrDTO attribute : attributes) {
                        if (attribute.getName().equals(ATTR_NAME_DEVICE_DISCOVERY_COMMAND)) {
                            discoveryCommand = attribute.getValue();
                            break;
                        }/*from w  w w.  j  av a  2  s  .c  om*/
                    }

                    if (discoveryCommand == null) {
                        LOG.warn("Missing discovery command attribute, skipping discovered: " + deviceDTO);
                        continue;
                    }

                    Device converted = convertV2Device(adapter, deviceDTO, discoveryEndpointUri);

                    if (ATTR_VALUE_DEVICE_DISCOVERY_COMMAND_ADD
                            .equals(discoveryCommand.toLowerCase(Locale.ROOT))) {
                        devices.add(converted);
                    } else if (ATTR_VALUE_DEVICE_DISCOVERY_COMMAND_DELETE
                            .equals(discoveryCommand.toLowerCase(Locale.ROOT))) {
                        deviceService.setDeviceOffline(converted.getId());
                    } else {
                        LOG.warn("Unsupported discovery command attribute, skipping discovered: " + deviceDTO);
                    }
                }

            } else if (firstResult instanceof Device) {
                // V3
                devices = (List<Device>) exchange.getIn().getBody(List.class);
            }

            Device[] initializedDevices = deviceLibraryService.initializeDevices(adapter, devices);
            deviceService.addDevices(initializedDevices);

            EventService eventService = context.hasService(EventService.class);
            if (eventService != null)
                eventService.sendEvent(new InventoryDevicesUpdatedEvent());
        }
    });
}

From source file:de.ks.text.AsciiDocEditor.java

protected void searchForText() {
    String searchKey = searchField.textProperty().getValueSafe().toLowerCase(Locale.ROOT);
    String editorContent = editor.textProperty().getValueSafe().toLowerCase(Locale.ROOT);
    searchField.setDisable(true);/*from  w w  w. ja v  a2  s . com*/
    CompletableFuture<Integer> search = CompletableFuture.supplyAsync(() -> {
        if (lastSearch != null && lastSearch.matches(searchKey, editorContent)) {
            int startPoint = lastSearch.getPosition() + searchKey.length();
            int newPosition;
            if (startPoint >= editorContent.length()) {
                newPosition = -1;
            } else {
                newPosition = editorContent.substring(startPoint).indexOf(searchKey);
                if (newPosition >= 0) {
                    newPosition += lastSearch.getPosition() + searchKey.length();
                }
            }

            if (newPosition == -1) {
                newPosition = editorContent.indexOf(searchKey);
            }
            lastSearch.setPosition(newPosition);
            return newPosition;
        } else {
            int newPosition = editorContent.indexOf(searchKey);
            lastSearch = new LastSearch(searchKey, editorContent).setPosition(newPosition);
            return newPosition;
        }
    }, controller.getExecutorService());

    search.thenAcceptAsync(index -> {
        searchField.setDisable(false);
        if (index >= 0) {
            editor.positionCaret(index);
            editor.requestFocus();
        }
    }, controller.getJavaFXExecutor());
}

From source file:business.security.control.OwmClient.java

/**
 * Find current city weather within a circle
 *
 * @param lat is the latitude of the geographic center of the circle
 * (North/South coordinate)// w  ww . j  a  v a2 s  .  c o m
 * @param lon is the longitude of the geographic center of the circle
 * (East/West coordinate)
 * @param radius is the radius of the circle (in kilometres)
 * @throws JSONException if the response from the OWM server can't be parsed
 * @throws IOException if there's some network error or the OWM server
 * replies with a error.
 */
public WeatherStatusResponse currentWeatherAtCityCircle(float lat, float lon, float radius)
        throws IOException, JSONException {
    String subUrl = String.format(Locale.ROOT, "find/city?lat=%f&lon=%f&radius=%f&cluster=yes",
            Float.valueOf(lat), Float.valueOf(lon), Float.valueOf(radius));
    JSONObject response = doQuery(subUrl);
    return new WeatherStatusResponse(response);
}

From source file:edu.ncsa.sstde.indexing.postgis.PostgisIndexerSettings.java

public String getTableName(String predicate, String lang) {
    if (partitionNames == null)
        validateAndInitPartitions();// w  w  w  .j av  a  2s .  c o  m
    Map<String, String> langParts = partitionNames.get(predicate);
    if (langParts == null)
        langParts = partitionNames.get(DEFAULT_LOOKUP);
    String result = langParts.get(lang.toLowerCase(Locale.ROOT));
    return result == null ? langParts.get(DEFAULT_LOOKUP) : result;
}

From source file:dhbw.clippinggorilla.userinterface.windows.NewSourceWindow.java

public void validateSecondStage(Source s, String id, String title, String url, String description,
        Category category, Locale language, Locale country, String imageUrl) {
    String errors = "";
    if (id == null || id.isEmpty()) {
        errors += "Empty Id<br>";
    }//from  w w  w . ja va2 s. c o  m
    if (title == null || title.isEmpty()) {
        errors += "Empty Name<br>";
    }
    if (!isURL(url)) {
        errors += "Empty or invalid URL<br>";
    }
    if (description == null || description.isEmpty()) {
        errors += "Empty Description<br>";
    }
    if (category == null) {
        errors += "Empty Category<br>";
    }
    if (language == null || language.equals(Locale.ROOT)) {
        errors += "Empty Language<br>";
    }
    if (country == null || country.equals(Locale.ROOT)) {
        errors += "Empty Country<br>";
    }
    if (!isURL(imageUrl)) {
        errors += "Empty or invalid ImageURL";
    }
    if (!errors.isEmpty()) {
        VaadinUtils.errorNotification("Errors during Source setup<br>" + errors);
    } else {
        s.setName(title);
        s.setUrl(url);
        s.setDescription(description);
        s.setCategory(category.name());//Ignore possible null pointer, cant happen
        s.setLanguageAndCountry(language.getLanguage(), country.getCountry());//Ignore possible null pointer, cant happen
        s.setLogo(imageUrl);
        setContent(getThirdStage(s));
        center();
    }

}

From source file:org.elasticsearch.xpack.ml.integration.MlJobIT.java

public void testCreateJobsWithIndexNameOption() throws Exception {
    String jobTemplate = "{\n" + "  \"analysis_config\" : {\n"
            + "        \"detectors\" :[{\"function\":\"metric\",\"field_name\":\"responsetime\"}]\n"
            + "    },\n" + "  \"data_description\": {},\n" + "  \"results_index_name\" : \"%s\"}";

    String jobId1 = "create-jobs-with-index-name-option-job-1";
    String indexName = "non-default-index";
    String jobConfig = String.format(Locale.ROOT, jobTemplate, indexName);

    Response response = client().performRequest("put",
            MachineLearning.BASE_PATH + "anomaly_detectors/" + jobId1, Collections.emptyMap(),
            new StringEntity(jobConfig, ContentType.APPLICATION_JSON));
    assertEquals(200, response.getStatusLine().getStatusCode());

    String jobId2 = "create-jobs-with-index-name-option-job-2";
    response = client().performRequest("put", MachineLearning.BASE_PATH + "anomaly_detectors/" + jobId2,
            Collections.emptyMap(), new StringEntity(jobConfig, ContentType.APPLICATION_JSON));
    assertEquals(200, response.getStatusLine().getStatusCode());

    response = client().performRequest("get", "_aliases");
    assertEquals(200, response.getStatusLine().getStatusCode());
    String responseAsString = responseEntityToString(response);

    assertThat(responseAsString, containsString(
            "\"" + AnomalyDetectorsIndex.jobResultsAliasedName("custom-" + indexName) + "\":{\"aliases\":{"));
    assertThat(responseAsString, containsString("\"" + AnomalyDetectorsIndex.jobResultsAliasedName(jobId1)
            + "\":{\"filter\":{\"term\":{\"job_id\":{\"value\":\"" + jobId1 + "\",\"boost\":1.0}}}}"));
    assertThat(responseAsString,//from   w  w w .  java 2s.  c  o  m
            containsString("\"" + AnomalyDetectorsIndex.resultsWriteAlias(jobId1) + "\":{}"));
    assertThat(responseAsString, containsString("\"" + AnomalyDetectorsIndex.jobResultsAliasedName(jobId2)
            + "\":{\"filter\":{\"term\":{\"job_id\":{\"value\":\"" + jobId2 + "\",\"boost\":1.0}}}}"));
    assertThat(responseAsString,
            containsString("\"" + AnomalyDetectorsIndex.resultsWriteAlias(jobId2) + "\":{}"));

    response = client().performRequest("get", "_cat/indices");
    assertEquals(200, response.getStatusLine().getStatusCode());
    responseAsString = responseEntityToString(response);
    assertThat(responseAsString,
            containsString(AnomalyDetectorsIndexFields.RESULTS_INDEX_PREFIX + "custom-" + indexName));
    assertThat(responseAsString, not(containsString(AnomalyDetectorsIndex.jobResultsAliasedName(jobId1))));
    assertThat(responseAsString, not(containsString(AnomalyDetectorsIndex.jobResultsAliasedName(jobId2))));

    String bucketResult = String.format(Locale.ROOT,
            "{\"job_id\":\"%s\", \"timestamp\": \"%s\", \"result_type\":\"bucket\", \"bucket_span\": \"%s\"}",
            jobId1, "1234", 1);
    String id = String.format(Locale.ROOT, "%s_bucket_%s_%s", jobId1, "1234", 300);
    response = client().performRequest("put",
            AnomalyDetectorsIndex.jobResultsAliasedName(jobId1) + "/doc/" + id, Collections.emptyMap(),
            new StringEntity(bucketResult, ContentType.APPLICATION_JSON));
    assertEquals(201, response.getStatusLine().getStatusCode());

    bucketResult = String.format(Locale.ROOT,
            "{\"job_id\":\"%s\", \"timestamp\": \"%s\", \"result_type\":\"bucket\", \"bucket_span\": \"%s\"}",
            jobId1, "1236", 1);
    id = String.format(Locale.ROOT, "%s_bucket_%s_%s", jobId1, "1236", 300);
    response = client().performRequest("put",
            AnomalyDetectorsIndex.jobResultsAliasedName(jobId1) + "/doc/" + id, Collections.emptyMap(),
            new StringEntity(bucketResult, ContentType.APPLICATION_JSON));
    assertEquals(201, response.getStatusLine().getStatusCode());

    client().performRequest("post", "_refresh");

    response = client().performRequest("get",
            MachineLearning.BASE_PATH + "anomaly_detectors/" + jobId1 + "/results/buckets");
    assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
    responseAsString = responseEntityToString(response);
    assertThat(responseAsString, containsString("\"count\":2"));

    response = client().performRequest("get", AnomalyDetectorsIndex.jobResultsAliasedName(jobId1) + "/_search");
    assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
    responseAsString = responseEntityToString(response);
    assertThat(responseAsString, containsString("\"total\":2"));

    response = client().performRequest("delete", MachineLearning.BASE_PATH + "anomaly_detectors/" + jobId1);
    assertThat(response.getStatusLine().getStatusCode(), equalTo(200));

    // check that indices still exist, but are empty and aliases are gone
    response = client().performRequest("get", "_aliases");
    assertEquals(200, response.getStatusLine().getStatusCode());
    responseAsString = responseEntityToString(response);
    assertThat(responseAsString, not(containsString(AnomalyDetectorsIndex.jobResultsAliasedName(jobId1))));
    assertThat(responseAsString, containsString(AnomalyDetectorsIndex.jobResultsAliasedName(jobId2))); //job2 still exists

    response = client().performRequest("get", "_cat/indices");
    assertEquals(200, response.getStatusLine().getStatusCode());
    responseAsString = responseEntityToString(response);
    assertThat(responseAsString,
            containsString(AnomalyDetectorsIndexFields.RESULTS_INDEX_PREFIX + "custom-" + indexName));

    client().performRequest("post", "_refresh");

    response = client().performRequest("get",
            AnomalyDetectorsIndexFields.RESULTS_INDEX_PREFIX + "custom-" + indexName + "/_count");
    assertEquals(200, response.getStatusLine().getStatusCode());
    responseAsString = responseEntityToString(response);
    assertThat(responseAsString, containsString("\"count\":0"));
}

From source file:com.stratelia.webactiv.util.DBUtil.java

private static int updateMaxFromTable(Connection connection, String tableName) throws SQLException {
    String table = tableName.toLowerCase(Locale.ROOT);
    int max = 0;/*from   w w w. j  a  v  a  2s .  com*/
    PreparedStatement prepStmt = null;
    int count = 0;
    try {
        prepStmt = connection.prepareStatement("UPDATE UniqueId SET maxId = maxId + 1 WHERE tableName = ?");
        prepStmt.setString(1, table);
        count = prepStmt.executeUpdate();
        connection.commit();
    } catch (SQLException sqlex) {
        rollback(connection);
        throw sqlex;
    } finally {
        close(prepStmt);
    }

    if (count == 1) {
        PreparedStatement selectStmt = null;
        ResultSet rs = null;
        try {
            // l'update c'est bien passe, on recupere la valeur
            selectStmt = connection.prepareStatement("SELECT maxId FROM UniqueId WHERE tableName = ?");
            selectStmt.setString(1, table);
            rs = selectStmt.executeQuery();
            if (!rs.next()) {
                SilverTrace.error("util", "DBUtil.getNextId", "util.MSG_NO_RECORD_FOUND");
                throw new RuntimeException("Erreur Interne DBUtil.getNextId()");
            }
            max = rs.getInt(1);
        } finally {
            close(rs, selectStmt);
        }
        return max;
    }
    throw new SQLException("Update impossible : Ligne non existante");
}

From source file:gmjonker.util.Stopwatch.java

public String nanosToString(long nanos) {
    TimeUnit unit = chooseUnit(nanos);
    double value = (double) nanos / NANOSECONDS.convert(1, unit);

    // Too bad this functionality is not exposed as a regular method call
    //        return Platform.formatCompact4Digits(value) + " " + abbreviate(unit);
    return String.format(Locale.ROOT, "%.4g", value) + " " + abbreviate(unit);
}

From source file:com.esri.arcgisruntime.sample.readsymbolsmobilestylefile.MainActivity.java

/**
 * Loads the stylx file and searches for all symbols contained within. Put the resulting symbols into recycler views
 * based on their category (eyes, mouth, hat, face).
 *///from w w w  . j  a  v  a  2 s .  c  o m
private void loadSymbolsFromStyleFile() {
    // read permission accepted, enable UI elements
    mColorSpinner.setEnabled(true);
    mSizeSeekBar.setEnabled(true);
    createMapViewOnTouchListener();

    // create a SymbolStyle by passing the location of the .stylx file in the constructor
    mEmojiStyle = new SymbolStyle(
            Environment.getExternalStorageDirectory() + getString(R.string.mobile_style_file_path));
    // add a listener to run when the SymbolStyle has loaded
    mEmojiStyle.addDoneLoadingListener(() -> {
        if (mEmojiStyle.getLoadStatus() == LoadStatus.FAILED_TO_LOAD) {
            logErrorToUser(this,
                    getString(R.string.error_mobile_style_file_failed_load, mEmojiStyle.getLoadError()));
            return;
        }
        // get future to load default search parameters
        ListenableFuture<SymbolStyleSearchParameters> defaultSearchParametersFuture = mEmojiStyle
                .getDefaultSearchParametersAsync();
        defaultSearchParametersFuture.addDoneListener(() -> {
            try {
                SymbolStyleSearchParameters defaultSearchParameters = defaultSearchParametersFuture.get();
                // get future search symbols using the default search parameters
                ListenableFuture<List<SymbolStyleSearchResult>> symbolStyleSearchResultFuture = mEmojiStyle
                        .searchSymbolsAsync(defaultSearchParameters);
                symbolStyleSearchResultFuture.addDoneListener(() -> {
                    try {
                        List<SymbolStyleSearchResult> symbolStyleSearchResults = symbolStyleSearchResultFuture
                                .get();
                        for (SymbolStyleSearchResult symbolStyleSearchResult : symbolStyleSearchResults) {
                            // these categories are specific to this SymbolStyle
                            switch (symbolStyleSearchResult.getCategory().toLowerCase(Locale.ROOT)) {
                            case "eyes":
                                mEyesAdapter.addSymbol(symbolStyleSearchResult);
                                break;
                            case "mouth":
                                mMouthAdapter.addSymbol(symbolStyleSearchResult);
                                break;
                            case "hat":
                                mHatAdapter.addSymbol(symbolStyleSearchResult);
                                break;
                            case "face":
                                mFaceSymbolKey = symbolStyleSearchResult.getKey();
                                break;
                            }
                            animateRecyclerViews();
                        }
                    } catch (InterruptedException | ExecutionException e) {
                        logErrorToUser(this,
                                getString(R.string.error_searching_for_symbols_failed, e.getMessage()));
                    }
                });
            } catch (InterruptedException | ExecutionException e) {
                logErrorToUser(this,
                        getString(R.string.error_default_search_parameters_load_failed, e.getMessage()));
            }
        });
    });
    // load the SymbolStyle
    mEmojiStyle.loadAsync();
}

From source file:com.gargoylesoftware.htmlunit.WebClient2Test.java

/**
 * Regression test for bug 2812769./*from ww w.j a va2s. com*/
 * @throws Exception if an error occurs
 */
@Test
public void acceptLanguage() throws Exception {
    final String html = "<html><body></body></html>";
    final HtmlPage p = loadPageWithAlerts(html);
    // browsers are using different casing, but this is not relevant for this test
    assertEquals("en-us",
            getMockWebConnection().getLastAdditionalHeaders().get("Accept-Language").toLowerCase(Locale.ROOT));

    final WebClient client = p.getWebClient();
    final String lang = client.getBrowserVersion().getBrowserLanguage();
    try {
        client.getBrowserVersion().setBrowserLanguage("fr");
        client.getPage(getDefaultUrl());
        assertEquals("fr", getMockWebConnection().getLastAdditionalHeaders().get("Accept-Language"));
    } finally {
        // Restore original language.
        client.getBrowserVersion().setBrowserLanguage(lang);
    }
}