List of usage examples for java.util Locale ROOT
Locale ROOT
To view the source code for java.util Locale ROOT.
Click Source Link
From source file:com.google.gwt.emultest.java.util.HashMapTest.java
public void testKeySet() { HashMap<String, String> hashMap = new HashMap<String, String>(); checkEmptyHashMapAssumptions(hashMap); Set<String> keySet = hashMap.keySet(); assertNotNull(keySet);/*w w w .j a v a 2s.co m*/ assertTrue(keySet.isEmpty()); assertTrue(keySet.size() == 0); hashMap.put(KEY_TEST_KEY_SET, VALUE_TEST_KEY_SET); assertTrue(keySet.size() == SIZE_ONE); assertTrue(keySet.contains(KEY_TEST_KEY_SET)); assertFalse(keySet.contains(VALUE_TEST_KEY_SET)); assertFalse(keySet.contains(KEY_TEST_KEY_SET.toUpperCase(Locale.ROOT))); }
From source file:com.netflix.discovery.shared.Applications.java
/** * Add the instance to the given map based if the vip address matches with * that of the instance. Note that an instance can be mapped to multiple vip * addresses./*from w ww .j a v a 2 s . com*/ * */ private void addInstanceToMap(InstanceInfo info, String vipAddresses, Map<String, AbstractQueue<InstanceInfo>> vipMap) { if (vipAddresses != null) { String[] vipAddressArray = vipAddresses.split(","); for (String vipAddress : vipAddressArray) { String vipName = vipAddress.toUpperCase(Locale.ROOT); AbstractQueue<InstanceInfo> instanceInfoList = vipMap.get(vipName); if (instanceInfoList == null) { instanceInfoList = new ConcurrentLinkedQueue<InstanceInfo>(); vipMap.put(vipName, instanceInfoList); } instanceInfoList.add(info); } } }
From source file:org.elasticsearch.xpack.ml.integration.MlJobIT.java
public void testCreateJob_WithClashingFieldMappingsFails() throws Exception { String jobTemplate = "{\n" + " \"analysis_config\" : {\n" + " \"detectors\" :[{\"function\":\"metric\",\"field_name\":\"metric\", \"by_field_name\":\"%s\"}]\n" + " },\n" + " \"data_description\": {}\n" + "}"; String jobId1 = "job-with-response-field"; String byFieldName1;// w ww . ja va 2s . c o m String jobId2 = "job-will-fail-with-mapping-error-on-response-field"; String byFieldName2; // we should get the friendly advice nomatter which way around the clashing fields are seen if (randomBoolean()) { byFieldName1 = "response"; byFieldName2 = "response.time"; } else { byFieldName1 = "response.time"; byFieldName2 = "response"; } String jobConfig = String.format(Locale.ROOT, jobTemplate, byFieldName1); Response response = client().performRequest("put", MachineLearning.BASE_PATH + "anomaly_detectors/" + jobId1, Collections.emptyMap(), new StringEntity(jobConfig, ContentType.APPLICATION_JSON)); assertEquals(200, response.getStatusLine().getStatusCode()); final String failingJobConfig = String.format(Locale.ROOT, jobTemplate, byFieldName2); ResponseException e = expectThrows(ResponseException.class, () -> client().performRequest("put", MachineLearning.BASE_PATH + "anomaly_detectors/" + jobId2, Collections.emptyMap(), new StringEntity(failingJobConfig, ContentType.APPLICATION_JSON))); assertThat(e.getMessage(), containsString("This job would cause a mapping clash with existing field [response] - " + "avoid the clash by assigning a dedicated results index")); }
From source file:net.pms.dlna.protocolinfo.ProtocolInfo.java
/** * Parses {@code additionalInfo}.//from w w w . jav a2 s. co m * * @return The {@link SortedMap} of parsed {@link ProtocolInfoAttribute}s. */ protected SortedMap<ProtocolInfoAttributeName, ProtocolInfoAttribute> parseAdditionalInfo() { if (isBlank(additionalInfo) || WILDCARD.equals(additionalInfo.trim())) { return EMPTYMAP; } TreeMap<ProtocolInfoAttributeName, ProtocolInfoAttribute> result = createEmptyAttributesMap(); String[] attributeStrings = additionalInfo.trim().toUpperCase(Locale.ROOT).split("\\s*;\\s*"); for (String attributeString : attributeStrings) { if (isBlank(attributeString)) { continue; } String[] attributeEntry = attributeString.split("\\s*=\\s*"); if (attributeEntry.length == 2) { try { ProtocolInfoAttribute attribute = ProtocolInfoAttribute.FACTORY .createAttribute(attributeEntry[0], attributeEntry[1], protocol); if (attribute != null) { result.put(attribute.getName(), attribute); } else { LOGGER.debug("Failed to parse attribute \"{}\"", attributeString); } } catch (ParseException e) { LOGGER.debug("Failed to parse attribute \"{}\": {}", attributeString, e.getMessage()); LOGGER.trace("", e); } } else { LOGGER.debug("Invalid ProtocolInfo attribute \"{}\"", attributeString); } } return result; }
From source file:org.eclipse.swt.snippets.SnippetExplorer.java
/** * Update the info tabs (right side of the explorer) for the given item. * * @param item the selected item containing Snippet metadata (may be * <code>null</code>) * @param force the tabs are only updated if they not already show info for the * given item. If this is <code>true</code> the tabs are updated * anyway./*from w w w. j a va 2 s . c o m*/ */ private void updateInfoTab(TableItem item, boolean force) { final Snippet snippet = (item != null && item.getData() instanceof Snippet) ? (Snippet) item.getData() : null; if (!force && currentInfoSnippet == snippet) { return; } if (snippet == null) { descriptionView.setText(USAGE_EXPLANATION); sourceView.setText(""); updatePreviewImage(null, ""); } else { descriptionView.setText(snippet.snippetName + "\n\n" + snippet.description); if (snippet.source == null) { sourceView.setWordWrap(true); final String msg = "No source available for " + snippet.snippetName + " but you may find it at:\n\n"; final String link = String.format(Locale.ROOT, SNIPPET_SOURCE_LINK_TEMPLATE, snippet.snippetName); sourceView.setText(msg + link); final StyleRange linkStyle = new StyleRange(); linkStyle.start = msg.length(); linkStyle.length = link.length(); linkStyle.underline = true; linkStyle.underlineStyle = SWT.UNDERLINE_LINK; sourceView.setStyleRange(linkStyle); sourceView.addListener(SWT.MouseDown, event -> { int offset = sourceView.getOffsetAtPoint(new Point(event.x, event.y)); if (offset != -1) { try { final StyleRange style = sourceView.getStyleRangeAtOffset(offset); if (style != null && style.underline && style.underlineStyle == SWT.UNDERLINE_LINK) { Program.launch(link); } } catch (IllegalArgumentException e) { // no character under event.x, event.y } } }); } else { sourceView.setWordWrap(false); sourceView.setText(snippet.source); } try { final Image previewImage = getPreviewImage(snippet); updatePreviewImage(previewImage, previewImage == null ? "No preview image available." : ""); } catch (IOException e) { updatePreviewImage(null, "Failed to load preview image: " + e); } } currentInfoSnippet = snippet; }
From source file:com.puppycrawl.tools.checkstyle.CheckerTest.java
@Test public void testClearNonexistentCache() throws Exception { final DefaultConfiguration checkConfig = createCheckConfig(HiddenFieldCheck.class); final DefaultConfiguration treeWalkerConfig = createCheckConfig(TreeWalker.class); treeWalkerConfig.addChild(checkConfig); final DefaultConfiguration checkerConfig = new DefaultConfiguration("simpleConfig"); checkerConfig.addAttribute("charset", "UTF-8"); checkerConfig.addChild(treeWalkerConfig); final Checker checker = new Checker(); final Locale locale = Locale.ROOT; checker.setLocaleCountry(locale.getCountry()); checker.setLocaleLanguage(locale.getLanguage()); checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader()); checker.configure(checkerConfig);//w w w. j a v a 2 s. com checker.addListener(new BriefUtLogger(stream)); final String pathToEmptyFile = temporaryFolder.newFile("file.java").getPath(); final String[] expected = ArrayUtils.EMPTY_STRING_ARRAY; verify(checker, pathToEmptyFile, pathToEmptyFile, expected); checker.clearCache(); // one more time, but cache does not exist verify(checker, pathToEmptyFile, pathToEmptyFile, expected); }
From source file:com.google.gwt.emultest.java.util.IdentityHashMapTest.java
/** * Test method for 'java.util.IdentityHashMap.putAll(Map)'. */// w w w . j av a2 s.c o m public void testPutAll() { IdentityHashMap srcMap = new IdentityHashMap(); checkEmptyHashMapAssumptions(srcMap); srcMap.put(KEY_1, VALUE_1); srcMap.put(KEY_2, VALUE_2); srcMap.put(KEY_3, VALUE_3); // Make sure that the data is copied correctly IdentityHashMap dstMap = new IdentityHashMap(); checkEmptyHashMapAssumptions(dstMap); dstMap.putAll(srcMap); assertEquals(srcMap.size(), dstMap.size()); assertTrue(dstMap.containsKey(KEY_1)); assertTrue(dstMap.containsValue(VALUE_1)); assertFalse(dstMap.containsKey(KEY_1.toUpperCase(Locale.ROOT))); assertFalse(dstMap.containsValue(VALUE_1.toUpperCase(Locale.ROOT))); assertTrue(dstMap.containsKey(KEY_2)); assertTrue(dstMap.containsValue(VALUE_2)); assertFalse(dstMap.containsKey(KEY_2.toUpperCase(Locale.ROOT))); assertFalse(dstMap.containsValue(VALUE_2.toUpperCase(Locale.ROOT))); assertTrue(dstMap.containsKey(KEY_3)); assertTrue(dstMap.containsValue(VALUE_3)); assertFalse(dstMap.containsKey(KEY_3.toUpperCase(Locale.ROOT))); assertFalse(dstMap.containsValue(VALUE_3.toUpperCase(Locale.ROOT))); // Check that an empty map does not blow away the contents of the // destination map IdentityHashMap emptyMap = new IdentityHashMap(); checkEmptyHashMapAssumptions(emptyMap); dstMap.putAll(emptyMap); assertTrue(dstMap.size() == srcMap.size()); // Check that put all overwrite any existing mapping in the destination map srcMap.put(KEY_1, VALUE_2); srcMap.put(KEY_2, VALUE_3); srcMap.put(KEY_3, VALUE_1); dstMap.putAll(srcMap); assertEquals(dstMap.size(), srcMap.size()); assertEquals(dstMap.get(KEY_1), VALUE_2); assertEquals(dstMap.get(KEY_2), VALUE_3); assertEquals(dstMap.get(KEY_3), VALUE_1); // Check that a putAll does adds data but does not remove it srcMap.put(KEY_4, VALUE_4); dstMap.putAll(srcMap); assertEquals(dstMap.size(), srcMap.size()); assertTrue(dstMap.containsKey(KEY_4)); assertTrue(dstMap.containsValue(VALUE_4)); assertEquals(dstMap.get(KEY_1), VALUE_2); assertEquals(dstMap.get(KEY_2), VALUE_3); assertEquals(dstMap.get(KEY_3), VALUE_1); assertEquals(dstMap.get(KEY_4), VALUE_4); dstMap.putAll(dstMap); }
From source file:sk.datalan.solr.impl.HttpSolrServer.java
protected NamedList<Object> executeMethod(HttpRequestBase method, final ResponseParser processor) throws SolrServerException { // // XXX client already has this set, is this needed? // method.getParams().setParameter(ClientPNames.HANDLE_REDIRECTS, // followRedirects); method.addHeader("User-Agent", AGENT); InputStream respBody = null;//from w w w . j a v a 2s .co m boolean shouldClose = true; boolean success = false; try { // Execute the method. final HttpResponse response = httpClient.execute(method); int httpStatus = response.getStatusLine().getStatusCode(); // Read the contents respBody = response.getEntity().getContent(); Header ctHeader = response.getLastHeader("content-type"); String contentType; if (ctHeader != null) { contentType = ctHeader.getValue(); } else { contentType = ""; } // handle some http level checks before trying to parse the response switch (httpStatus) { case HttpStatus.SC_OK: case HttpStatus.SC_BAD_REQUEST: case HttpStatus.SC_CONFLICT: // 409 break; case HttpStatus.SC_MOVED_PERMANENTLY: case HttpStatus.SC_MOVED_TEMPORARILY: if (!followRedirects) { throw new SolrServerException( "Server at " + getBaseURL() + " sent back a redirect (" + httpStatus + ")."); } break; default: if (processor == null) { throw new RemoteSolrException(httpStatus, "Server at " + getBaseURL() + " returned non ok status:" + httpStatus + ", message:" + response.getStatusLine().getReasonPhrase(), null); } } if (processor == null) { // no processor specified, return raw stream NamedList<Object> rsp = new NamedList<>(); rsp.add("stream", respBody); // Only case where stream should not be closed shouldClose = false; success = true; return rsp; } String procCt = processor.getContentType(); if (procCt != null) { String procMimeType = ContentType.parse(procCt).getMimeType().trim().toLowerCase(Locale.ROOT); String mimeType = ContentType.parse(contentType).getMimeType().trim().toLowerCase(Locale.ROOT); if (!procMimeType.equals(mimeType)) { // unexpected mime type String msg = "Expected mime type " + procMimeType + " but got " + mimeType + "."; Header encodingHeader = response.getEntity().getContentEncoding(); String encoding; if (encodingHeader != null) { encoding = encodingHeader.getValue(); } else { encoding = "UTF-8"; // try UTF-8 } try { msg = msg + " " + IOUtils.toString(respBody, encoding); } catch (IOException e) { throw new RemoteSolrException(httpStatus, "Could not parse response with encoding " + encoding, e); } RemoteSolrException e = new RemoteSolrException(httpStatus, msg, null); throw e; } } // if(true) { // ByteArrayOutputStream copy = new ByteArrayOutputStream(); // IOUtils.copy(respBody, copy); // String val = new String(copy.toByteArray()); // System.out.println(">RESPONSE>"+val+"<"+val.length()); // respBody = new ByteArrayInputStream(copy.toByteArray()); // } NamedList<Object> rsp = null; ContentType ct = ContentType.getOrDefault(response.getEntity()); try { rsp = processor.processResponse(respBody, ct.getCharset().toString()); } catch (Exception e) { throw new RemoteSolrException(httpStatus, e.getMessage(), e); } if (httpStatus != HttpStatus.SC_OK) { String reason = null; try { NamedList err = (NamedList) rsp.get("error"); if (err != null) { reason = (String) err.get("msg"); if (reason == null) { reason = (String) err.get("trace"); } } } catch (Exception ex) { } if (reason == null) { StringBuilder msg = new StringBuilder(); msg.append(response.getStatusLine().getReasonPhrase()); msg.append("\n\n"); msg.append("request: ").append(method.getURI()); reason = java.net.URLDecoder.decode(msg.toString(), UTF_8); } throw new RemoteSolrException(httpStatus, reason, null); } success = true; return rsp; } catch (ConnectException e) { throw new SolrServerException("Server refused connection at: " + getBaseURL(), e); } catch (SocketTimeoutException e) { throw new SolrServerException("Timeout occured while waiting response from server at: " + getBaseURL(), e); } catch (IOException e) { throw new SolrServerException("IOException occured when talking to server at: " + getBaseURL(), e); } finally { if (respBody != null && shouldClose) { try { respBody.close(); } catch (IOException e) { log.error("", e); } finally { if (!success) { method.abort(); } } } } }
From source file:ec.util.chart.swing.Charts.java
@Nonnull private static String getMediaType(@Nonnull File file) { String ext = file.getPath().toLowerCase(Locale.ROOT); if (ext.endsWith(".png")) { return PNG_MEDIA_TYPE; }// ww w. ja v a2 s . c o m if (ext.endsWith(".jpeg") || ext.endsWith(".jpg")) { return JPEG_MEDIA_TYPE; } if (ext.endsWith(".svg")) { return SVG_MEDIA_TYPE; } if (ext.endsWith(".svgz")) { return SVG_COMP_MEDIA_TYPE; } return PNG_MEDIA_TYPE; }
From source file:com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDocument.java
/** * Returns the last modification date of the document. * @see <a href="https://developer.mozilla.org/en/DOM/document.lastModified">Mozilla documentation</a> * @return the date as string// www . j a v a 2 s. co m */ @JsxGetter public String getLastModified() { if (lastModified_ == null) { final WebResponse webResponse = getPage().getWebResponse(); String stringDate = webResponse.getResponseHeaderValue("Last-Modified"); if (stringDate == null) { stringDate = webResponse.getResponseHeaderValue("Date"); } final Date lastModified = parseDateOrNow(stringDate); lastModified_ = new SimpleDateFormat(LAST_MODIFIED_DATE_FORMAT, Locale.ROOT).format(lastModified); } return lastModified_; }