Example usage for java.util Collections singletonMap

List of usage examples for java.util Collections singletonMap

Introduction

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

Prototype

public static <K, V> Map<K, V> singletonMap(K key, V value) 

Source Link

Document

Returns an immutable map, mapping only the specified key to the specified value.

Usage

From source file:org.neo4j.cineasts.movieimport.MovieDbLocalStorage.java

private Map loadJsonValue(File storageFile) {
    try {//from w ww . j a va2  s  . co  m
        final Object value = mapper.readValue(storageFile, Object.class);
        if (value instanceof List) {
            List list = (List) value;
            if (list.isEmpty() || list.get(0).equals("Nothing found.")) {
                return Collections.singletonMap("not_found", System.currentTimeMillis());
            }
            return asMap(list.get(0));
        }
        return asMap(value);
    } catch (Exception e) {
        throw new MovieDbException("Failed to load JSON from storage for file " + storageFile.getPath(), e);
    }
}

From source file:at.ac.univie.isc.asio.tool.MediaTypeSerializerTest.java

@Test
public void should_omit_mime_properties() throws Exception {
    final MediaType input = new MediaType("text", "test", Collections.singletonMap("param", "value"));
    assertThat(serialize(input), equalTo("\"text/test\""));
}

From source file:com.ethlo.kfka.mysql.MysqlKfkaMapStore.java

@Override
public T load(Long key) {
    logger.debug("Loading for key {}", key);
    final List<T> res = tpl.query("SELECT * from kfka WHERE id = :key", Collections.singletonMap("key", key),
            mapper);//from www . j  a  v  a2s.c  om
    if (!res.isEmpty()) {
        return res.get(0);
    }
    return null;
}

From source file:de.hybris.platform.catalog.references.daos.impl.DefaultProductReferencesDao.java

@Override
public List<ProductReferenceModel> findAllReferences(final ProductModel product) {
    ServicesUtil.validateParameterNotNull(product, "product must not be null");
    final StringBuffer sql = new StringBuffer(70);

    sql.append("SELECT {").append(ProductReferenceModel.PK).append("} ");
    sql.append("FROM {").append(ProductReferenceModel._TYPECODE).append("*} ");
    sql.append("WHERE {").append(ProductReferenceModel.TARGET).append("}=?item OR ");
    sql.append('{').append(ProductReferenceModel.SOURCE).append("}=?item");

    final SearchResult<ProductReferenceModel> result = getFlexibleSearchService().search(sql.toString(),
            Collections.singletonMap("item", product));
    return result.getResult();
}

From source file:ru.mystamps.web.dao.impl.JdbcUserDao.java

@Override
public long countByLogin(String login) {
    return jdbcTemplate.queryForObject(countByLoginSql, Collections.singletonMap("login", login), Long.class);
}

From source file:ru.mystamps.web.dao.impl.JdbcImageDao.java

@Override
public Integer add(String type) {
    KeyHolder holder = new GeneratedKeyHolder();

    int affected = jdbcTemplate.update(addImageSql,
            new MapSqlParameterSource(Collections.singletonMap("type", type)), holder);

    Validate.validState(affected == 1, "Unexpected number of affected rows after adding image: %d", affected);

    return Integer.valueOf(holder.getKey().intValue());
}

From source file:org.elasticsearch.http.DetailedErrorsDisabledIT.java

public void testThatErrorTraceParamReturns400() throws IOException {
    ResponseException e = expectThrows(ResponseException.class, () -> getRestClient().performRequest("DELETE",
            "/", Collections.singletonMap("error_trace", "true")));

    Response response = e.getResponse();
    assertThat(response.getHeader("Content-Type"), is("application/json; charset=UTF-8"));
    assertThat(EntityUtils.toString(e.getResponse().getEntity()),
            containsString("\"error\":\"error traces in responses are disabled.\""));
    assertThat(response.getStatusLine().getStatusCode(), is(400));
}

From source file:playground.app.StubPersonController.java

@RequestMapping("/me")
public Map<String, String> me(@AuthenticationPrincipal UserDetails user) {
    return Collections.singletonMap("username", user.getUsername());
}

From source file:com.thoughtworks.go.remote.work.PluggableArtifactMetadataTest.java

@Test
public void shouldAddMetadataWhenMetadataOfOtherArtifactIsAlreadyPresetForAPlugin() {
    final PluggableArtifactMetadata pluggableArtifactMetadata = new PluggableArtifactMetadata();

    assertTrue(pluggableArtifactMetadata.getMetadataPerPlugin().isEmpty());

    pluggableArtifactMetadata.addMetadata("docker", "centos", Collections.singletonMap("image", "centos"));
    pluggableArtifactMetadata.addMetadata("docker", "alpine", Collections.singletonMap("image", "alpine"));

    final Map<String, Map> docker = pluggableArtifactMetadata.getMetadataPerPlugin().get("docker");
    assertNotNull(docker);//  w  w  w  .  j  av a  2 s  .  c  om
    assertThat(docker, Matchers.hasEntry("centos", Collections.singletonMap("image", "centos")));
    assertThat(docker, Matchers.hasEntry("alpine", Collections.singletonMap("image", "alpine")));
}

From source file:com.gm.bamboo.dao.UserHibernateDao.java

/**
 * {@inheritDoc}/*from w  w w . ja  v a2s.  c  o m*/
 * 
 * @since 2012-9-4
 * @see com.gm.bamboo.api.UserDao#batchDelete(java.util.List)
 */
@Override
public void batchDelete(List<Long> ids) {
    String hql = "delete from User where id in(:ids)";
    Map<String, List<Long>> values = Collections.singletonMap("ids", ids);
    super.batchExecute(hql, values);

}