Example usage for java.util Collections emptyMap

List of usage examples for java.util Collections emptyMap

Introduction

In this page you can find the example usage for java.util Collections emptyMap.

Prototype

@SuppressWarnings("unchecked")
public static final <K, V> Map<K, V> emptyMap() 

Source Link

Document

Returns an empty map (immutable).

Usage

From source file:org.trustedanalytics.serviceexposer.rest.CredentialsController.java

@ApiOperation(value = "Returns list of all service instance credentials of given type for given space.", notes = "Privilege level: Consumer of this endpoint must be a member of specified space based on valid access token")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK", response = ResponseEntity.class),
        @ApiResponse(code = 401, message = "User is Unauthorized"),
        @ApiResponse(code = 500, message = "Internal server error, see logs for details") })
@RequestMapping(value = GET_SERVICES_LIST_URL, method = GET, produces = APPLICATION_JSON_VALUE)

public ResponseEntity<?> getAllCredentials(@RequestParam(required = true) UUID space,
        @RequestParam(required = true) String service) {
    return ccOperations.getSpace(space)
            .map(s -> new ResponseEntity<>(getCredentialsInJson(service, s.getGuid()), HttpStatus.OK))
            .onErrorReturn(er -> {/*w ww .  ja v a  2s  . c om*/
                LOG.error("Exception occurred:", er);
                return new ResponseEntity<>(Collections.emptyMap(), HttpStatus.UNAUTHORIZED);
            }).toBlocking().single();
}

From source file:org.n52.io.extension.RenderingHintsExtension.java

@Override
public Map<String, Object> getExtras(DatasetOutput output, IoParameters parameters) {
    if (!hasExtrasToReturn(output, parameters)) {
        return Collections.emptyMap();
    }//from w  ww  . j  a  va  2s. c  om

    if (hasSeriesConfiguration(output)) {
        final StyleProperties style = createStyle(getSeriesStyle(output));
        checkForBackwardCompatiblity(output, style);// stay backward compatible
        return wrapSingleIntoMap(style);
    } else if (hasPhenomenonConfiguration(output)) {
        final StyleProperties style = createStyle(getPhenomenonStyle(output));
        checkForBackwardCompatiblity(output, style);// stay backward compatible
        return wrapSingleIntoMap(style);
    }

    LOGGER.error("No rendering style found for {} (id={})", output, output.getId());
    return Collections.emptyMap();
}

From source file:com.llbt.meepwn.lincolnblock.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 {/*w  w  w  .j a v  a 2  s. 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;
            if (httpResponse != null) {
                statusCode = httpResponse.getStatusLine().getStatusCode();
            } else {
                throw new NoConnectionError(e);
            }
            VolleyLog.e("Unexpected response code %d for %s", statusCode, request.getUrl());
            NetworkResponse networkResponse;
            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 >= 400 && statusCode <= 499) {
                    // Don't retry other client errors.
                    throw new ClientError(networkResponse);
                } else if (statusCode >= 500 && statusCode <= 599) {
                    if (request.shouldRetryServerErrors()) {
                        attemptRetryOnException("server", request, new ServerError(networkResponse));
                    } else {
                        throw new ServerError(networkResponse);
                    }
                } else {
                    // 3xx? No reason to retry.
                    throw new ServerError(networkResponse);
                }
            } else {
                attemptRetryOnException("network", request, new NetworkError());
            }
        }
    }
}

From source file:com.haulmont.cuba.security.app.LoginServiceBean.java

@Override
public UserSession loginByRememberMe(String login, String rememberMeToken, Locale locale)
        throws LoginException {
    return loginByRememberMe(login, rememberMeToken, locale, Collections.emptyMap());
}

From source file:com.daidiansha.acarry.control.network.core.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  a  v a  2  s . co  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,
                            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;
            String info = String.format("network-http-primary:lifetime=%d, size=%s, code=%d, retryCount=%s",
                    requestLifetime, responseContents != null ? responseContents.length : "null",
                    statusLine.getStatusCode(), request.getRetryPolicy().getCurrentRetryCount());
            request.addMarker(info);
            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:nu.yona.server.subscriptions.service.PrivateUserDataMigrationServiceIntegrationStepSequenceTestConfiguration.java

@Override
protected Map<Class<?>, Repository<?, ?>> getRepositories() {
    return Collections.emptyMap();
}

From source file:org.apache.metamodel.elasticsearch.rest.ElasticSearchRestClient.java

private static Request putMapping(final PutMappingRequest putMappingRequest) {
    final String endpoint = "/" + putMappingRequest.indices()[0] + "/_mapping/" + putMappingRequest.type();
    final ByteArrayEntity entity = new ByteArrayEntity(putMappingRequest.source().getBytes(),
            ContentType.APPLICATION_JSON);
    return new Request(HttpPut.METHOD_NAME, endpoint, Collections.emptyMap(), entity);
}

From source file:com.ikanow.aleph2.harvest.logstash.services.LogstashHarvestService.java

@Override
public void onInit(IHarvestContext context) {
    _globals.set(//from   ww w. j av  a 2s . c  o  m
            BeanTemplateUtils.from(Optional.ofNullable(context.getTechnologyLibraryConfig().library_config())
                    .orElse(Collections.emptyMap()), LogstashHarvesterConfigBean.class).get());
    _context.set(context);
    _global_propertes.set(context.getServiceContext().getGlobalProperties());
}

From source file:com.adobe.acs.commons.httpcache.engine.impl.HttpCacheEngineImplTest.java

@Before
public void init() throws NotCompliantMBeanException {
    systemUnderTest = new HttpCacheEngineImpl();

    systemUnderTest.activate(Collections.emptyMap());

    sharedMemConfigProps.put(HttpCacheStore.KEY_CACHE_STORE_TYPE, VALUE_MEM_CACHE_STORE_TYPE);
    sharedJcrConfigProps.put(HttpCacheStore.KEY_CACHE_STORE_TYPE, VALUE_JCR_CACHE_STORE_TYPE);
    when(memCacheConfig.isValid()).thenReturn(true);
    when(jcrCacheConfig.isValid()).thenReturn(true);
    when(memCacheConfig.getCacheStoreName()).thenReturn(VALUE_MEM_CACHE_STORE_TYPE);
    when(jcrCacheConfig.getCacheStoreName()).thenReturn(VALUE_JCR_CACHE_STORE_TYPE);
    systemUnderTest.bindHttpCacheConfig(memCacheConfig, sharedMemConfigProps);
    systemUnderTest.bindHttpCacheConfig(jcrCacheConfig, sharedJcrConfigProps);
    systemUnderTest.bindHttpCacheStore(memCacheStore, sharedMemConfigProps);
    systemUnderTest.bindHttpCacheStore(jcrCacheStore, sharedJcrConfigProps);
}

From source file:com.feilong.core.util.RegexUtil.java

/**
 * ??????./* w  ww  .j a v  a  2s.co  m*/
 * 
 * <p>
 * ? m?? s  g,? m.group(g)  s.substring(m.start(g), m.end(g)).<br>
 * ? 1?.0?,? m.group(0) m.group().
 * </p>
 * 
 * <h3>:</h3>
 * 
 * <blockquote>
 * 
 * <pre class="code">
 * String regexPattern = "(.*?)@(.*?)";
 * String email = "venusdrogon@163.com";
 * RegexUtil.group(regexPattern, email);
 * </pre>
 * 
 * <b>:</b>
 * 
 * <pre class="code">
 *    0 venusdrogon@163.com
 *    1 venusdrogon
 *    2 163.com
 * </pre>
 * 
 * </blockquote>
 * 
 * @param regexPattern
 *            ?,pls use {@link RegexPattern}
 * @param input
 *            The character sequence to be matched,support {@link String},{@link StringBuffer},{@link StringBuilder}... and so on
 * @return  <code>regexPattern</code> null, {@link NullPointerException}<br>
 *          <code>input</code> null, {@link NullPointerException}<br>
 *          ??, {@link java.util.Collections#emptyMap()}
 * @see #getMatcher(String, CharSequence)
 * @see Matcher#group(int)
 * @since 1.0.7
 */
public static Map<Integer, String> group(String regexPattern, CharSequence input) {
    Matcher matcher = getMatcher(regexPattern, input);
    if (!matcher.matches()) {
        LOGGER.trace("[not matches] ,\n\tregexPattern:[{}] \n\tinput:[{}]", regexPattern, input);
        return Collections.emptyMap();
    }
    int groupCount = matcher.groupCount();
    Map<Integer, String> map = newLinkedHashMap(groupCount + 1);
    for (int i = 0; i <= groupCount; ++i) {
        //?
        String groupValue = matcher.group(i); //map.put(0, matcher.group());// ? 1 ?.0?,? m.group(0)  m.group().
        LOGGER.trace("matcher group[{}],start-end:[{}-{}],groupValue:[{}]", i, matcher.start(i), matcher.end(i),
                groupValue);
        map.put(i, groupValue);//groupValue
    }

    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("regexPattern:[{}],input:[{}],groupMap:{}", regexPattern, input, JsonUtil.format(map));
    }
    return map;
}