Java 8 Map - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Map class.

This code example shows how to use the following methods:get
        XContentBuilder builder = jsonBuilder().startObject();
        completionFieldMapper.toXContent(builder, null).endObject();
        builder.close();
        Map<String, Object> serializedMap = JsonXContent.jsonXContent.createParser(builder.bytes()).mapAndClose();
        Map<String, Object> configMap = (Map<String, Object>) serializedMap.get("completion");
        assertThat(configMap.get("index_analyzer").toString(), is("simple"));
        assertThat(configMap.get("search_analyzer").toString(), is("standard"));
        assertThat(Boolean.valueOf(configMap.get("payloads").toString()), is(true));
        assertThat(Boolean.valueOf(configMap.get("preserve_separators").toString()), is(false));
        assertThat(Boolean.valueOf(configMap.get("preserve_position_increments").toString()), is(true));
        assertThat(Integer.valueOf(configMap.get("max_input_len").toString()), is(14));
    } 
 
    @Test 
    public void testThatSerializationCombinesToOneAnalyzerFieldIfBothAreEqual() throws Exception { 
        String mapping = jsonBuilder().startObject().startObject("type1")
                .startObject("properties").startObject("completion") 
                .field("type", "completion") 
                .field("index_analyzer", "simple") 
                .field("search_analyzer", "simple") 
10
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:clear, get, size
    @Test 
    public void testDecodeQueryString() { 
        Map<String, String> params = newHashMap();
 
        String uri = "something?test=value";
        RestUtils.decodeQueryString(uri, uri.indexOf('?') + 1, params);
        assertThat(params.size(), equalTo(1));
        assertThat(params.get("test"), equalTo("value"));
 
        params.clear();
        uri = "something?test=value&test1=value1";
        RestUtils.decodeQueryString(uri, uri.indexOf('?') + 1, params);
        assertThat(params.size(), equalTo(2));
        assertThat(params.get("test"), equalTo("value"));
        assertThat(params.get("test1"), equalTo("value1"));
 
        params.clear();
        uri = "something";
        RestUtils.decodeQueryString(uri, uri.length(), params);
        assertThat(params.size(), equalTo(0));

10
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:clear, get
        PathTrie<String> trie = new PathTrie<String>();
        trie.insert("/a/{type}", "test1");
        trie.insert("/b/{name}", "test2");
 
        Map<String, String> params = newHashMap();
        assertThat(trie.retrieve("/a/test", params), equalTo("test1"));
        assertThat(params.get("type"), equalTo("test"));
 
        params.clear();
        assertThat(trie.retrieve("/b/testX", params), equalTo("test2"));
        assertThat(params.get("name"), equalTo("testX"));
    } 
 
    @Test 
    public void testSameNameOnDifferentPath() { 
        PathTrie<String> trie = new PathTrie<String>();
        trie.insert("/a/c/{name}", "test1");
        trie.insert("/b/{name}", "test2");
 
        Map<String, String> params = newHashMap();
10
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:get
 
    public String getHeader(String name) {
        if (headers == null) {
            return null; 
        } 
        List<String> vals = headers.get(name);
        if (vals == null || vals.size() == 0) {
            return null; 
        } 
        return vals.iterator().next();
    } 
} 
10
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:put
        result.putExtra("com.jakewharton.android.viewpagerindicator.sample.Path", path);
        return result;
    } 
 
    protected void addItem(List<Map<String, Object>> data, String name, Intent intent) {
        Map<String, Object> temp = new HashMap<String, Object>();
        temp.put("title", name);
        temp.put("intent", intent);
        data.add(temp);
    } 
 
    @Override 
    @SuppressWarnings("unchecked") 
    protected void onListItemClick(ListView l, View v, int position, long id) {
        Map<String, Object> map = (Map<String, Object>)l.getItemAtPosition(position);
 
        Intent intent = (Intent) map.get("intent");
        startActivity(intent);
    } 
} 
9
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:containsKey, get
    public static BlockVector deserialize(Map<String, Object> args) {
        double x = 0;
        double y = 0;
        double z = 0;
 
        if (args.containsKey("x")) {
            x = (Double) args.get("x");
        } 
        if (args.containsKey("y")) {
            y = (Double) args.get("y");
        } 
        if (args.containsKey("z")) {
            z = (Double) args.get("z");
        } 
 
        return new BlockVector(x, y, z);
    } 
} 
9
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:containsKey, get, size
        assertThat(yamlSuites.containsKey(dir.getName()), equalTo(true));
        assertSingleFile(yamlSuites.get(dir.getName()), dir.getName(), file.getName());
    } 
 
    private static void assertSingleFile(Map<String, Set<File>> yamlSuites, String dirName, String fileName) {
        assertThat(yamlSuites, notNullValue());
        assertThat(yamlSuites.size(), equalTo(1));
        assertThat(yamlSuites.containsKey(dirName), equalTo(true));
        assertSingleFile(yamlSuites.get(dirName), dirName, fileName);
    } 
 
    private static void assertSingleFile(Set<File> files, String dirName, String fileName) {
        assertThat(files.size(), equalTo(1));
        File file = files.iterator().next();
        assertThat(file.getName(), equalTo(fileName));
        assertThat(file.getParentFile().getName(), equalTo(dirName));
    } 
} 
9
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:put
    } 
 
    private void deployParticipant() { 
        undeployServlet(); 
 
        final Map<String, String> initialParameters = new HashMap<String, String>();
        initialParameters.put("javax.ws.rs.Application", "org.wildfly.extension.rts.jaxrs.VolatileParticipantApplication");
 
        final DeploymentInfo participantDeploymentInfo = getDeploymentInfo(DEPLOYMENT_NAME, CONTEXT_PATH, initialParameters);
 
        deployServlet(participantDeploymentInfo);
    } 
 
} 
9
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:get
        this.map.clear();
        return this;
    } 
 
    public V get(K key) {
        return map.get(key);
    } 
 
    public boolean containsKey(K key) {
        return map.containsKey(key);
    } 
 
    public boolean isEmpty() { 
        return map.isEmpty();
    } 
 
    public Map<K, V> map() {
        return this.map;
    } 
 
9
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:put
    @SuppressWarnings("unchecked") 
    public B param(String name, Object value) {
        if (this.params == null) {
            this.params = Maps.newHashMap();
        } 
        this.params.put(name, value);
        return (B) this;
    } 
 
    @Override 
    protected void internalXContent(XContentBuilder builder, Params params) throws IOException {
        if (field != null) {
            builder.field("field", field);
        } 
 
        if (script != null) {
            builder.field("script", script);
        } 
 
        if (lang != null) {
9
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Java 8 Map Questions & Answers:

Other Java 8 Map Examples

26:	
27:				@Override
28:				protected Map<String, String> getParams() {
29:					Map<String, String> params = new HashMap<String, String>();
30:					params.put("name", "Androidhive");
-
27:				@Override
28:				protected Map<String, String> getParams() {
29:					Map<String, String> params = new HashMap<String, String>();
30:					params.put("name", "Androidhive");
31:					params.put("email", "abc@androidhive.info");

Read More

29:				 * */
30:				@Override
31:				public Map<String, String> getHeaders() throws AuthFailureError {
32:					HashMap<String, String> headers = new HashMap<String, String>();
33:					headers.put("Content-Type", "application/json");

Read More

33:	        Log.i(TAG, "registering device (regId = " + regId + ")");
34:	        String serverUrl = SERVER_URL;
35:	        Map<String, String> params = new HashMap<String, String>();
36:	        params.put("regId", regId);
37:	        params.put("name", name);
-
69:	                    return;
70:	                }
71:	                // increase backoff exponentially
72:	                backoff *= 2;
73:	            }

Read More

See Code Examples for Java 8 Map Methods: