List of usage examples for java.util Collections emptyMap
@SuppressWarnings("unchecked") public static final <K, V> Map<K, V> emptyMap()
From source file:com.pactera.edg.am.metamanager.extractor.dao.impl.DBDictionaryDaoImpl.java
public Map<String, List<Map<String, String>>> getColInfoFromMM(List<String> sqlTables) { // ?,/*from ww w. jav a 2s. co m*/ if (sqlTables == null || sqlTables.size() == 0) { return Collections.emptyMap(); } if (!modelHasCheck) { // ? hasColumnId = checkModel(); modelHasCheck = true; } if (!hasColumnId) { // columnId,???,!! return Collections.emptyMap(); } columnSql = GenSqlUtil.getSql("QUERY_DICTIONARY_COLUMN"); columnSql = columnSql.replaceAll("#COLUMNPOSITION#", columnPosition); // ?? Collections.sort(sqlTables, new Comparator<String>() { public int compare(String o1, String o2) { return o1.compareTo(o2); } }); // ????,???:schema.table <schema,Set<table>> Set<String> schemaTables = verifyTables(sqlTables); if (schemaTables.size() == 0) { return Collections.emptyMap(); } // ?? Map<String, List<Map<String, String>>> returnColumns = new HashMap<String, List<Map<String, String>>>(); // ?SCHEMACODE??? for (Iterator<String> schemaTableNames = schemaTables.iterator(); schemaTableNames.hasNext();) { String schemaTableName = schemaTableNames.next(); if (schemaTablesCache.containsKey(schemaTableName)) { // ,? if (schemaTablesCache.get(schemaTableName) == null) { // null,?,? continue; } returnColumns.put(schemaTableName, schemaTablesCache.get(schemaTableName)); } else { getTable(schemaTableName, returnColumns); } } if (returnColumns.size() > 0) { log.info("???:"); } for (Iterator<String> iter = returnColumns.keySet().iterator(); iter.hasNext();) { log.info(iter.next()); } return returnColumns; }
From source file:com.aiven.seafox.controller.http.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 {/*w w w.j a va 2s . com*/ // 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) { Cache.Entry entry = request.getCacheEntry(); if (entry == null) { return new NetworkResponse(HttpStatus.SC_NOT_MODIFIED, null, responseHeaders, true, SystemClock.elapsedRealtime() - requestStart); } // 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, SystemClock.elapsedRealtime() - requestStart); } // Handle moved resources if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY || statusCode == HttpStatus.SC_MOVED_TEMPORARILY) { String newUrl = responseHeaders.get("Location"); request.setRedirectUrl(newUrl); } // 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, SystemClock.elapsedRealtime() - requestStart); } 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); } if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY || statusCode == HttpStatus.SC_MOVED_TEMPORARILY) { VolleyLog.e("Request at %s has been redirected to %s", request.getOriginUrl(), request.getUrl()); } else { VolleyLog.e("Unexpected response code %d for %s", statusCode, request.getUrl()); } if (responseContents != null) { networkResponse = new NetworkResponse(statusCode, responseContents, responseHeaders, false, SystemClock.elapsedRealtime() - requestStart); if (statusCode == HttpStatus.SC_UNAUTHORIZED || statusCode == HttpStatus.SC_FORBIDDEN) { attemptRetryOnException("auth", request, new AuthFailureError(networkResponse)); } else if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY || statusCode == HttpStatus.SC_MOVED_TEMPORARILY) { attemptRetryOnException("redirect", 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:se.uu.it.cs.recsys.constraint.builder.LevelDomainBuilder.java
public Map<CourseLevel, Set<Integer>> getLevelAndIdMappingFor(Set<Integer> idSet) { if (idSet == null || idSet.isEmpty()) { LOGGER.warn("Does not make sense to put null or empty set, right?"); return Collections.emptyMap(); }/*from w w w.j a v a 2 s .c o m*/ Map<CourseLevel, Set<Integer>> levelAndIds = new HashMap<>(); this.courseRepository.findByAutoGenIds(idSet).stream() .forEach(course -> checkCourseLevelAndPutToMap(course, levelAndIds)); return levelAndIds; }
From source file:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.BrowseDataGetter.java
@Override public Map<String, Object> getData(Map<String, Object> pageData) { try {//from ww w .j a v a 2 s . c o m Map params = vreq.getParameterMap(); Mode mode = getMode(vreq, params); switch (mode) { case VCLASS_ALPHA: return doClassAlphaDisplay(params, vreq, context); case CLASS_GROUP: return doClassGroupDisplay(params, vreq, context); case VCLASS: return doClassDisplay(params, vreq, context); case ALL_CLASS_GROUPS: return doAllClassGroupsDisplay(params, vreq, context); default: return doAllClassGroupsDisplay(params, vreq, context); } } catch (Throwable th) { log.error(th, th); return Collections.emptyMap(); } }
From source file:com.zyl.androidvolleyutils.MyBasicNetworkVolley.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 2 s.c o m*/ // Gather headers. Map<String, String> headers = new HashMap<>(); addCacheHeaders(headers, request.getCacheEntry()); // Accept-Encoding: gzip // headers.put("Accept-Encoding", "gzip"); if (headerMap != null) { for (Map.Entry<String, String> entry : headerMap.entrySet()) { headers.put(entry.getKey(), entry.getValue()); } } // ? //headers.put(MyVolley.APP_VERSION_KEY, getVersionCode() + ""); //?? // headers.put(MyVolley.APP_CHANNEL_KEY, MyApp.getInstance().getChannelId()); //APPID ? // headers.put(MyVolley.APP_JPUSH_ID, Constant.APP_PUSH_TYPE); //?platform // headers.put(MyVolley.APP_PLATFORM_KEY, Constant.APP_PLATFORM); //osVersion // headers.put(MyVolley.APP_OS_VERSION_KEY, AppUtils.getSystemRelease()); //?deviceModel // headers.put(MyVolley.APP_DEVICE_MODEL,AppUtils.getModel()); // MD5?imei // headers.put(MyVolley.APP_DEVICE_ID,AppUtils.getDeviceIdMd5(MyApp.context)); //??clientVersion // headers.put(MyVolley.APP_CLIENT_VERSION_KEY,AppUtils.getAppVersionName(MyApp.context)); 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, SystemClock.elapsedRealtime() - requestStart); } // 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, SystemClock.elapsedRealtime() - requestStart); } // 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, SystemClock.elapsedRealtime() - requestStart); } 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; 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, SystemClock.elapsedRealtime() - requestStart); 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:com.ikanow.aleph2.example.flume_harvester.services.FlumeHarvestTechnology.java
@Override public void onInit(IHarvestContext context) { _globals = BeanTemplateUtils.from(Optional.ofNullable(context.getTechnologyLibraryConfig().library_config()) .orElse(Collections.emptyMap()), FlumeGlobalConfigBean.class).get(); }
From source file:com.ikanow.aleph2.analytics.storm.assets.PassthroughTopology.java
@Override public Tuple2<Object, Map<String, String>> getTopologyAndConfiguration(final DataBucketBean bucket, final IEnrichmentModuleContext context) { final TopologyBuilder builder = new TopologyBuilder(); final Collection<Tuple2<BaseRichSpout, String>> entry_points = context .getTopologyEntryPoints(BaseRichSpout.class, Optional.of(bucket)); //DEBUG// w ww. j ava 2 s . c o m _logger.debug("Passthrough topology: loaded: " + entry_points.stream().map(x -> x.toString()).collect(Collectors.joining(":"))); entry_points.forEach(spout_name -> builder.setSpout(spout_name._2(), spout_name._1())); entry_points.stream() .reduce(builder.setBolt(BOLT_NAME, context.getTopologyStorageEndpoint(BaseRichBolt.class, Optional.of(bucket))), (acc, v) -> acc.localOrShuffleGrouping(v._2()), (acc1, acc2) -> acc1 // (not possible in practice) ); return Tuples._2T(builder.createTopology(), Collections.emptyMap()); }
From source file:org.elasticsearch.test.NativeRealmIntegTestCase.java
public void setupReservedPasswords(RestClient restClient) throws IOException { logger.info("setting up reserved passwords for test"); {//w ww . j a va2s .c o m String payload = "{\"password\": \"" + new String(reservedPassword.getChars()) + "\"}"; HttpEntity entity = new NStringEntity(payload, ContentType.APPLICATION_JSON); BasicHeader authHeader = new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER, UsernamePasswordToken.basicAuthHeaderValue(ElasticUser.NAME, BOOTSTRAP_PASSWORD)); String route = "/_xpack/security/user/elastic/_password"; Response response = restClient.performRequest("PUT", route, Collections.emptyMap(), entity, authHeader); assertEquals(response.getStatusLine().getReasonPhrase(), 200, response.getStatusLine().getStatusCode()); } for (String username : Arrays.asList(KibanaUser.NAME, LogstashSystemUser.NAME, BeatsSystemUser.NAME)) { String payload = "{\"password\": \"" + new String(reservedPassword.getChars()) + "\"}"; HttpEntity entity = new NStringEntity(payload, ContentType.APPLICATION_JSON); BasicHeader authHeader = new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER, UsernamePasswordToken.basicAuthHeaderValue(ElasticUser.NAME, reservedPassword)); String route = "/_xpack/security/user/" + username + "/_password"; Response response = restClient.performRequest("PUT", route, Collections.emptyMap(), entity, authHeader); assertEquals(response.getStatusLine().getReasonPhrase(), 200, response.getStatusLine().getStatusCode()); } logger.info("setting up reserved passwords finished"); }
From source file:com.spotworld.spotapp.widget.utils.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 ww w. j a va 2s . com*/ // 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, SystemClock.elapsedRealtime() - requestStart); } // 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, SystemClock.elapsedRealtime() - requestStart); } // 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, SystemClock.elapsedRealtime() - requestStart); } 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, SystemClock.elapsedRealtime() - requestStart); 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:fr.pilato.elasticsearch.crawler.fs.client.ElasticsearchClient.java
public void createIndex(String index, boolean ignoreErrors) throws IOException { logger.debug("create index [{}]", index); try {/*w w w . j a va 2 s . c o m*/ Response response = client.performRequest("PUT", "/" + index, Collections.emptyMap()); logger.trace("create index response: {}", response.getEntity().getContent()); } catch (ResponseException e) { if (e.getResponse().getStatusLine().getStatusCode() == 400 && (e.getMessage().contains("index_already_exists_exception") || e.getMessage().contains("IndexAlreadyExistsException"))) { if (!ignoreErrors) { throw new RuntimeException("index already exists"); } logger.trace("index already exists. Ignoring error..."); return; } throw e; } }