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:com.yahoo.bullet.parsing.SpecificationTest.java

@Test
public void testAggregationForced() {
    Specification specification = new Specification();
    specification.setAggregation(null);// www.ja  v a  2 s.  c  om
    Assert.assertNull(specification.getProjection());
    Assert.assertNull(specification.getFilters());
    // If you had null for aggregation
    Assert.assertNull(specification.getAggregation());
    specification.configure(Collections.emptyMap());
    Assert.assertTrue(specification.isAcceptingData());
    Assert.assertEquals(specification.getAggregate().getRecords(), emptyList());
}

From source file:com.formkiq.core.form.service.FormCalculatorServiceImpl.java

@Override
public Map<String, String> applyFieldValues(final ArchiveDTO archive, final FormJSON form,
        final HttpServletRequest request) throws IOException {

    Map<String, String[]> values = buildParameterMap(request, form);

    if (form != null) {

        Map<String, FormJSONField> idMap = transformToIdMap(form);

        applyFieldValues(archive, form, values, idMap);
        FormTransformer.updateOptionsGroup(form);

        // Reapply values due to certain fields being initially hidden
        applyFieldValues(archive, form, values, idMap);
    }//from   w  w w  . j  a v a 2s .  co m

    appleFieldValuesById(archive, values);

    return form != null ? calculate(archive, form.getUUID()) : Collections.emptyMap();
}

From source file:io.crate.operation.auth.HostBasedAuthenticationTest.java

@Test
public void testEmptyHbaConf() throws Exception {
    authService.updateHbaConfig(Collections.emptyMap());
    AuthenticationMethod method = authService.resolveAuthenticationType("crate",
            new ConnectionProperties(LOCALHOST, Protocol.POSTGRES, null));
    assertNull(method);/*from ww w.j  av  a  2 s .  co  m*/
}

From source file:com.medallia.spider.api.DynamicInputImpl.java

/**
 * Creates a new {@link DynamicInputImpl}
 * @param request from which to read the request parameters
 *//*from  www. j  av  a2 s .co  m*/
public DynamicInputImpl(HttpServletRequest request) {
    @SuppressWarnings("unchecked")
    Map<String, String[]> reqParams = Maps.newHashMap(request.getParameterMap());
    this.inputParams = reqParams;
    if (ServletFileUpload.isMultipartContent(request)) {
        this.fileUploads = Maps.newHashMap();
        Multimap<String, String> inputParamsWithList = ArrayListMultimap.create();

        ServletFileUpload upload = new ServletFileUpload();
        try {
            FileItemIterator iter = upload.getItemIterator(request);
            while (iter.hasNext()) {
                FileItemStream item = iter.next();
                String fieldName = item.getFieldName();
                InputStream stream = item.openStream();
                if (item.isFormField()) {
                    inputParamsWithList.put(fieldName, Streams.asString(stream, Charsets.UTF_8.name()));
                } else {
                    final String filename = item.getName();
                    final byte[] bytes = ByteStreams.toByteArray(stream);
                    fileUploads.put(fieldName, new UploadedFile() {
                        @Override
                        public String getFilename() {
                            return filename;
                        }

                        @Override
                        public byte[] getBytes() {
                            return bytes;
                        }

                        @Override
                        public int getSize() {
                            return bytes.length;
                        }
                    });
                }
            }
            for (Entry<String, Collection<String>> entry : inputParamsWithList.asMap().entrySet()) {
                inputParams.put(entry.getKey(), entry.getValue().toArray(new String[0]));
            }
        } catch (IOException | FileUploadException e) {
            throw new IllegalArgumentException("Failed to parse multipart", e);
        }
    } else {
        this.fileUploads = Collections.emptyMap();
    }
}

From source file:com.spotify.styx.api.MiddlewaresTest.java

@Test
public void testNoPayloadResponse() throws Exception {
    AsyncHandler<Response<ByteString>> outerHandler = Middlewares.json()
            .apply(rc -> Response.forStatus(Status.INTERNAL_SERVER_ERROR));

    CompletionStage<Response<ByteString>> completionStage = outerHandler
            .invoke(RequestContexts.create(mock(Request.class), mock(Client.class), Collections.emptyMap()));

    assertThat(completionStage.toCompletableFuture().get().payload().isPresent(), is(false));
}

From source file:com.liveramp.cascading_ext.CascadingUtil.java

private Map<String, String> getSerializationTokensProperty() {
    List<String> strings = new ArrayList<String>();
    for (Map.Entry<Integer, Class<?>> entry : serializationTokens.entrySet()) {
        strings.add(entry.getKey() + "=" + entry.getValue().getName());
    }/*from   ww  w  . jav  a 2 s.c  o  m*/
    if (strings.isEmpty()) {
        return Collections.emptyMap();
    } else {
        return Collections.singletonMap("cascading.serialization.tokens", StringUtils.join(strings, ","));
    }
}

From source file:org.elasticsearch.client.RestHighLevelClientTests.java

public void testPingSuccessful() throws IOException {
    Header[] headers = RestClientTestUtil.randomHeaders(random(), "Header");
    Response response = mock(Response.class);
    when(response.getStatusLine()).thenReturn(newStatusLine(RestStatus.OK));
    when(restClient.performRequest(anyString(), anyString(), anyMapOf(String.class, String.class), anyObject(),
            anyVararg())).thenReturn(response);
    assertTrue(restHighLevelClient.ping(headers));
    verify(restClient).performRequest(eq("HEAD"), eq("/"), eq(Collections.emptyMap()),
            Matchers.isNull(HttpEntity.class), argThat(new HeadersVarargMatcher(headers)));
}

From source file:org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.java

private ElasticsearchSearchResult httpRequest(String query) throws IOException {
    Objects.requireNonNull(query, "query");
    String uri = String.format(Locale.ROOT, "/%s/%s/_search", indexName, typeName);
    HttpEntity entity = new StringEntity(query, ContentType.APPLICATION_JSON);
    Response response = restClient.performRequest("POST", uri, Collections.emptyMap(), entity);
    if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
        final String error = EntityUtils.toString(response.getEntity());
        final String message = String.format(Locale.ROOT,
                "Error while querying Elastic (on %s/%s) status: %s\nQuery:\n%s\nError:\n%s\n",
                response.getHost(), response.getRequestLine(), response.getStatusLine(), query, error);
        throw new RuntimeException(message);
    }//w w w .  ja v a2s .c  om

    try (InputStream is = response.getEntity().getContent()) {
        return mapper.readValue(is, ElasticsearchSearchResult.class);
    }
}

From source file:org.kitodo.data.elasticsearch.search.SearchRestClient.java

/**
 * Get document by id./*w w w. j a v  a 2 s. c  om*/
 *
 * @param id
 *            of searched document
 * @return http entity as String
 */
Map<String, Object> getDocument(Integer id) throws CustomResponseException, DataException {
    try {
        GetRequest getRequest = new GetRequest(this.index, this.type, String.valueOf(id));
        GetResponse getResponse = highLevelClient.get(getRequest);
        if (getResponse.isExists()) {
            Map<String, Object> response = getResponse.getSourceAsMap();
            response.put("id", getResponse.getId());
            return response;
        }
    } catch (ResponseException e) {
        handleResponseException(e);
    } catch (IOException e) {
        throw new DataException(e);
    }
    return Collections.emptyMap();
}

From source file:com.yahoo.bard.webservice.web.filters.QueryParameterNormalizationFilter.java

/**
 * Build a parameter map that searches for @QueryParam annotations on the jersey endpoints
 * and extract their names.// w  w  w.java 2 s  . com
 * This map enables us to perform case insensitive translations.
 *
 * Detail:
 *   This method extracts all classes contained within the packages specified as "jersey provider packages."
 *   It then conditions these methods by enumerating all methods and keeping only those that are annotated
 *   as JAX-RS endpoints (+ the bard @PATCH annotation). After harvesting this list of method, it then enumerates
 *   all of the parameters for each method and keeps a list of the @QueryParam values. It then extracts the values
 *   from these @QueryParam annotations to retain its codified casing while also constructing a map of lowercase'd
 *   values to map in a case insensitive way.
 *
 * NOTE: The ClassLoader provided with the ResourceConfig is used to find classes.
 *
 * @param providers Set of provider classes to seek for @QueryParam
 * @param classLoader Class loader to use while searching for specified packages
 * @return  Parameter map containing all of the case insensitive to case sensitive @QueryParam values
 */
private static Map<String, String> buildParameterMap(Set<Class<?>> providers, ClassLoader classLoader) {
    if (providers == null) {
        LOG.warn("No providers defined. Disabling QueryParameterNormalizationFilter.");
        return Collections.emptyMap();
    } else if (classLoader == null) {
        LOG.warn("No valid ClassLoader found from context. Disabling QueryParameterNormalizationFilter.");
        return Collections.emptyMap();
    }
    return providers.stream()
            // Extract all of the corresponding methods from these classes
            .flatMap(QueryParameterNormalizationFilter::extractMethods)
            // Determine which methods are annotated as a JAX-RS endpoint
            .filter(QueryParameterNormalizationFilter::isWebEndpoint)
            // For each of these methods, extract the @QueryParam annotations from the parameter list
            .flatMap(QueryParameterNormalizationFilter::extractQueryParameters)
            // Extract the parameter value
            .map(QueryParam::value).distinct()
            // Map the lower-case'd parameter value to its @QueryParam case'd counterpart
            .collect(Collectors.toMap(param -> param.toLowerCase(Locale.ENGLISH), Function.identity(),
                    QueryParameterNormalizationFilter::resolveMapConflicts));
}