Map size - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Map size method.

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
This code example shows how to use the following methods:get, size
        assertThat(trie.retrieve("a/b"), nullValue());
        assertThat(trie.retrieve("a/b/c/d"), nullValue());
        assertThat(trie.retrieve("g/t/x"), equalTo("three"));
 
        Map<String, String> params = newHashMap();
        assertThat(trie.retrieve("index1/insert/12", params), equalTo("bingo"));
        assertThat(params.size(), equalTo(2));
        assertThat(params.get("index"), equalTo("index1"));
        assertThat(params.get("docId"), equalTo("12"));
    } 
 
    @Test 
    public void testEmptyPath() { 
        PathTrie<String> trie = new PathTrie<String>();
        trie.insert("/", "walla");
        assertThat(trie.retrieve(""), equalTo("walla"));
    } 
 
    @Test 
    public void testDifferentNamesOnDifferentPath() { 
9
CodeRank
This code example shows how to use the following methods:containsKey, get, size
  } 
   
  public void testGetMap() throws IOException { 
    MetricsServlet servlet = new MetricsServlet();
    Map<String, Map<String, List<TagsMetricsPair>>> m = servlet.makeMap(contexts);
    assertEquals("Map missing contexts", 2, m.size());
    assertTrue(m.containsKey("test1"));
    
    Map<String, List<TagsMetricsPair>> m2 = m.get("test1");
     
    assertEquals("Missing records", 1, m2.size());
    assertTrue(m2.containsKey("testRecord"));
    assertEquals("Wrong number of tags-values pairs.", 1, m2.get("testRecord").size());
  } 
   
  public void testPrintMap() throws IOException { 
    StringWriter sw = new StringWriter();
    PrintWriter out = new PrintWriter(sw);
    MetricsServlet servlet = new MetricsServlet();
    servlet.printMap(out, servlet.makeMap(contexts));
9
CodeRank
This code example shows how to use the following methods:get, keySet, size
        return extractMapping(type, root);
    } 
 
    @SuppressWarnings({"unchecked"}) 
    private Tuple<String, Map<String, Object>> extractMapping(String type, Map<String, Object> root) throws MapperParsingException {
        int size = root.size();
        switch (size) {
            case 0: 
                // if we don't have any keys throw an exception 
                throw new MapperParsingException("malformed mapping no root object found"); 
            case 1: 
                break; 
            default: 
                // we always assume the first and single key is the mapping type root 
                throw new MapperParsingException("mapping must have the `type` as the root object"); 
        } 
 
        String rootName = root.keySet().iterator().next();
        if (type == null) {
            type = rootName;

9
CodeRank
This code example shows how to use the following methods:get, size
    public void testParseTemplate() throws Exception { 
        URL url = this.getClass().getResource("subsystems.xml");
        SubsystemsParser templateParser = new SubsystemsParser(new File(url.toURI()));
        templateParser.parse();
        Map<String, SubsystemConfig[]> config = templateParser.getSubsystemConfigs();
        Assert.assertEquals(3, config.size());
        SubsystemConfig[] defaultConfig = config.get("default");
        Assert.assertNotNull(defaultConfig);
        Assert.assertEquals(2, defaultConfig.length);
        Assert.assertEquals("simple-with-text-and-comments.xml", defaultConfig[0].getSubsystem());
        Assert.assertNull(defaultConfig[0].getSupplement());
        Assert.assertEquals("empty-with-attributes.xml", defaultConfig[1].getSubsystem());
        Assert.assertNull(defaultConfig[1].getSupplement());
 
        SubsystemConfig[] haConfig = config.get("ha");
        Assert.assertNotNull(haConfig);
        Assert.assertEquals(2, haConfig.length);
        Assert.assertEquals("empty.xml", haConfig[0].getSubsystem());
        Assert.assertNull(haConfig[0].getSupplement());
        Assert.assertEquals("ha-only.xml", haConfig[1].getSubsystem());

9
CodeRank
This code example shows how to use the following methods:entrySet, size
    public V putAtomic(C instance, K key, V value, Map<K, V> snapshot) {
        if (key == null) {
            throw MESSAGES.nullVar("key"); 
        } 
        final Map<K, V> newMap;
        final int oldSize = snapshot.size();
        if (oldSize == 0) {
            newMap = Collections.singletonMap(key, value);
        } else if (oldSize == 1) {
            final Map.Entry<K, V> entry = snapshot.entrySet().iterator().next();
            final K oldKey = entry.getKey();
            if (oldKey.equals(key)) {
                return entry.getValue();
            } else { 
                newMap = new FastCopyHashMap<K, V>(snapshot);
                newMap.put(key, value);
            } 
        } else { 
            newMap = new FastCopyHashMap<K, V>(snapshot);
            newMap.put(key, value);

8
CodeRank
This code example shows how to use the following methods:get, size
   @Resource 
   protected Logger logger = Logger.NULL; 
 
   @Override 
   public ProfileInfo apply(Map<String, String> from) {
      if (from.size() == 0)
         return null; 
      if (from.size() == 0)
         return null; 
      ProfileInfo.Builder builder = new ProfileInfo.Builder();
      builder.uuid(from.get("uuid"));
      builder.email(from.get("email"));
      builder.firstName(from.get("first_name"));
      builder.lastName(from.get("last_name"));
      builder.nickName(from.get("nick_name"));
      builder.type(ProfileType.fromValue(from.get("type")));
      try { 
         return builder.build();
      } catch (NullPointerException e) {
         logger.trace("entry missing data: %s; %s", e.getMessage(), from);

8
CodeRank
This code example shows how to use the following methods:get, put, size
 
    @Test 
    public void testAsMapKey() { 
        MetaqTopic metaQTopic1 = new MetaqTopic("test", 1024, new ConsumerConfig("test-group")); 
        MetaqTopic metaQTopic2 = new MetaqTopic("test", 1024, new ConsumerConfig("test-group")); 
        Map<MetaqTopic, Boolean> map = new HashMap<MetaqTopic, Boolean>(); 
        assertEquals(metaQTopic1, metaQTopic2); 
        map.put(metaQTopic1, true); 
        assertEquals("test", metaQTopic1.getTopic()); 
        assertEquals("test-group", metaQTopic1.getConsumerConfig().getGroup()); 
        assertEquals(1024, metaQTopic1.getMaxBufferSize()); 
        assertEquals(1, map.size()); 
        assertTrue(map.get(metaQTopic1)); 
        assertTrue(map.get(metaQTopic2)); 
        metaQTopic2.setAlwaysConsumeFromMaxOffset(true); 
        assertNull(map.get(metaQTopic2)); 
        assertTrue(map.get(metaQTopic1)); 
    } 
} 

8
CodeRank
This code example shows how to use the following methods:get, keySet, size
        return extractMapping(type, root);
    } 
 
    @SuppressWarnings({"unchecked"}) 
    private Tuple<String, Map<String, Object>> extractMapping(String type, Map<String, Object> root) throws MapperParsingException {
        if (root.size() == 0) { 
            // if we don't have any keys throw an exception 
            throw new MapperParsingException("malformed mapping no root object found"); 
        } 
        String rootName = root.keySet().iterator().next();
        Tuple<String, Map<String, Object>> mapping;
        if (type == null || type.equals(rootName)) {
            mapping = new Tuple<>(rootName, (Map<String, Object>) root.get(rootName));
        } else { 
            mapping = new Tuple<>(type, root);
        } 
        return mapping; 
    } 
} 
8
CodeRank
This code example shows how to use the following methods:containsKey, containsValue, get, size
        return map;
    } 
 
    @Override 
    protected void validate(Map<String, String> before, Map<String, String> after) {
        super.validate(before, after);
        validate(before);
        validate(after);
    } 
 
    private static void validate(Map<String, String> map) {
        switch (map.size()) {
        case 3: 
            validate(map, null, "null-value");
            validate(map, "key", "value");
            validate(map, "key-null", null);
            break; 
        case 4: 
            validate(map, null, null);
            validate(map, "key", "value");

8
CodeRank
size Method Overview
Returns the number of key-value mappings in this map.
See Code Examples for other Java 8 Map Methods: