List of usage examples for java.util Collections emptyMap
@SuppressWarnings("unchecked") public static final <K, V> Map<K, V> emptyMap()
From source file:com.discovery.darchrow.util.MapUtil.java
/** * ??map??map./*from w w w .j a va 2 s .co m*/ * * <p style="color:green"> * {@link LinkedHashMap},??? ? <code>singleValueMap</code>?? * </p> * * <p> * ?? {@link #toSingleValueMap(Map)} * </p> * * <h3>:</h3> * <blockquote> * * <pre class="code"> * Map{@code <String, String>} singleValueMap = new LinkedHashMap{@code <String, String>}(); * * singleValueMap.put("province", "??"); * singleValueMap.put("city", "?"); * * LOGGER.info(JsonUtil.format(ParamUtil.toArrayValueMap(singleValueMap))); * </pre> * * : * * <pre class="code"> * { * "province": ["??"], * "city": ["?"] * } * </pre> * * </blockquote> * * @param <K> * the key type * @param singleValueMap * the name and value map * @return ? <code>singleValueMap</code> nullempty, {@link Collections#emptyMap()}<br> * ? <code>singleValueMap</code> value?, <code>arrayValueMap</code> * @since 1.6.2 */ public static <K> Map<K, String[]> toArrayValueMap(Map<K, String> singleValueMap) { if (Validator.isNullOrEmpty(singleValueMap)) { return Collections.emptyMap(); } Map<K, String[]> arrayValueMap = newLinkedHashMap(singleValueMap.size());//????singleValueMap?? for (Map.Entry<K, String> entry : singleValueMap.entrySet()) { arrayValueMap.put(entry.getKey(), ConvertUtil.toArray(entry.getValue()));//?Value???V,???Object } return arrayValueMap; }
From source file:ar.com.tadp.xml.rinzo.core.model.tags.dtd.DTDTagTypeDefinition.java
public DTDTagTypeDefinition(DTDElement tagDeclaration, DTDComment comment, Map<String, TagTypeDefinition> tagsInDocument, Map<String, DTDComment> attributeComments) { this.tagDeclaration = tagDeclaration; this.tagComment = comment; this.tagsInDocument = tagsInDocument; this.attributeComments = (Map<String, DTDComment>) ((attributeComments != null) ? attributeComments : Collections.emptyMap()); }
From source file:com.lovebridge.library.volley.toolbox.BasicNetwork.java
@Override public NetworkResponse performRequest(Request<?> request) throws VolleyError { long requestStart = SystemClock.elapsedRealtime(); while (true) { HttpResponse httpResponse = null; byte[] responseContents = null; Map<String, String> responseHeaders = Collections.emptyMap(); try {/*from w w w. j av a 2s . c o m*/ // Gather headers. Map<String, String> headers = new HashMap<String, String>(); addCacheHeaders(headers, request.getCacheEntry()); httpResponse = mHttpStack.performRequest(request, headers); StatusLine statusLine = httpResponse.getStatusLine(); int statusCode = statusLine.getStatusCode(); responseHeaders = convertHeaders(httpResponse.getAllHeaders()); // Handle cache validation. if (statusCode == HttpStatus.SC_NOT_MODIFIED) { Entry entry = request.getCacheEntry(); if (entry == null) { return new NetworkResponse(HttpStatus.SC_NOT_MODIFIED, null, responseHeaders, true); } // A HTTP 304 response does not have all header fields. We // have to use the header fields from the cache entry plus // the new ones from the response. // http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.5 entry.responseHeaders.putAll(responseHeaders); return new NetworkResponse(HttpStatus.SC_NOT_MODIFIED, entry.data, entry.responseHeaders, true); } // Some responses such as 204s do not have content. We must // check. if (httpResponse.getEntity() != null) { responseContents = entityToBytes(httpResponse.getEntity()); } else { // Add 0 byte response as a way of honestly representing a // no-content request. responseContents = new byte[0]; } // if the request is slow, log it. long requestLifetime = SystemClock.elapsedRealtime() - requestStart; logSlowRequests(requestLifetime, request, responseContents, statusLine); if (statusCode < 200 || statusCode > 299) { throw new IOException(); } return new NetworkResponse(statusCode, responseContents, responseHeaders, false); } catch (SocketTimeoutException e) { attemptRetryOnException("socket", request, new TimeoutError()); } catch (ConnectTimeoutException e) { attemptRetryOnException("connection", request, new TimeoutError()); } catch (MalformedURLException e) { throw new RuntimeException("Bad URL " + request.getUrl(), e); } catch (IOException e) { int statusCode = 0; NetworkResponse networkResponse = null; if (httpResponse != null) { statusCode = httpResponse.getStatusLine().getStatusCode(); } else { throw new NoConnectionError(e); } VolleyLog.e("Unexpected response code %d for %s", statusCode, request.getUrl()); if (responseContents != null) { networkResponse = new NetworkResponse(statusCode, responseContents, responseHeaders, false); if (statusCode == HttpStatus.SC_UNAUTHORIZED || statusCode == HttpStatus.SC_FORBIDDEN) { attemptRetryOnException("auth", request, new AuthFailureError(networkResponse)); } else { // TODO: Only throw ServerError for 5xx status codes. throw new ServerError(networkResponse); } } else { throw new NetworkError(networkResponse); } } } }
From source file:org.datacleaner.util.http.HttpXmlUtils.java
public String getUrlContent(String url, Map<String, String> params) throws IOException { if (params == null) { params = Collections.emptyMap(); }/*w w w.j a v a 2s . com*/ logger.info("getUrlContent({},{})", url, params); HttpPost method = new HttpPost(url); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); for (Entry<String, String> entry : params.entrySet()) { nameValuePairs.add(new BasicNameValuePair(entry.getKey(), entry.getValue())); } method.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8")); ResponseHandler<String> responseHandler = new BasicResponseHandler(); String response = getHttpClient().execute(method, responseHandler); return response; }
From source file:piecework.content.concrete.RemoteResource.java
@Override public Map<String, String> getMetadata() { return Collections.emptyMap(); }
From source file:io.fabric8.camel.FabricLocatorEndpoint.java
@Override public synchronized void groupEvent(Group<CamelNodeState> group, GroupEvent event) { Map<String, CamelNodeState> members; if (event == GroupEvent.DISCONNECTED || !isStarted()) { members = Collections.emptyMap(); } else {/*www . ja v a 2 s. c o m*/ members = group.members(); } //Find what has been removed. Set<String> removed = new LinkedHashSet<String>(); for (Map.Entry<String, Processor> entry : processors.entrySet()) { String key = entry.getKey(); if (!members.containsKey(key)) { removed.add(key); } } //Add existing processors for (Map.Entry<String, CamelNodeState> entry : members.entrySet()) { try { String key = entry.getKey(); if (!processors.containsKey(key)) { Processor p = getProcessor(entry.getValue().consumer); processors.put(key, p); loadBalancer.addProcessor(p); } } catch (URISyntaxException e) { LOG.warn("Unable to add endpoint " + entry.getValue().consumer, e); } } //Update the list by removing old and adding new. for (String key : removed) { Processor p = processors.remove(key); loadBalancer.removeProcessor(p); } }
From source file:enmasse.controller.flavor.FlavorController.java
@Override public void configUpdated(Watcher.Action action, ConfigMap configMap) throws IOException { if (action.equals(Watcher.Action.MODIFIED) || action.equals(Watcher.Action.ADDED)) { if (configMap.getData().containsKey("json")) { log.debug("Got new config for " + configMap.getMetadata().getName() + " with data: " + configMap.getData().get("json")); JsonNode root = mapper.readTree(configMap.getData().get("json")); flavorManager.flavorsUpdated(FlavorParser.parse(root)); } else {//from w ww.ja v a 2 s.co m log.debug("Got empty config for " + configMap.getMetadata().getName()); flavorManager.flavorsUpdated(Collections.emptyMap()); } } }
From source file:fr.gael.dhus.util.functional.collect.TransformedMapTest.java
/** Constructor: If Transformer param is null, must throw an IllegalArgumentException. */ @Test(expectedExceptions = NullPointerException.class) @SuppressWarnings("ResultOfObjectAllocationIgnored") public void nullComparatorTest() { new TransformedMap(Collections.emptyMap(), null); }
From source file:alfio.controller.api.admin.AdminWaitingQueueApiController.java
@RequestMapping(value = "/status", method = RequestMethod.GET) public Map<String, Boolean> getStatusForEvent(@PathVariable("eventName") String eventName, Principal principal) {//from w ww . ja va 2 s . c om return optionally(() -> eventManager.getSingleEvent(eventName, principal.getName())).map(this::loadStatus) .orElse(Collections.emptyMap()); }
From source file:com.amazon.speech.slu.Intent.java
/** * Private constructor used for JSON serialization. * * @param name// ww w . j av a 2 s .c o m * the intent name * @param slots * the slots associated with the intent */ private Intent(@JsonProperty("name") final String name, @JsonProperty("slots") final Map<String, Slot> slots) { this.name = name; if (slots != null) { this.slots = Collections.unmodifiableMap(slots); } else { this.slots = Collections.emptyMap(); } }