Guava Multimap - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Guava Multimap class.

This code example shows how to use the following methods:asMap, containsKey, get, isEmpty, keySet
  protected void assertGet(K key, V... values) {
    assertGet(key, Arrays.asList(values));
  } 
 
  protected void assertGet(K key, Collection<V> values) {
    ASSERT.that(multimap().get(key)).has().allFrom(values);
 
    if (!values.isEmpty()) {
      ASSERT.that(multimap().asMap().get(key)).has().allFrom(values);
      assertFalse(multimap().isEmpty());
    } else { 
      ASSERT.that(multimap().asMap().get(key)).isNull();
    } 
 
    // TODO(user): Add proper overrides to prevent autoboxing. 
    // Truth+autoboxing == compile error. Cast int to long to fix: 
    ASSERT.that(multimap().get(key).size()).is((long) values.size());
 
    assertEquals(values.size() > 0, multimap().containsKey(key));
    assertEquals(values.size() > 0, multimap().keySet().contains(key));

7
CodeRank
This code example shows how to use the following methods:containsEntry
        assertEquals(6, parameters.size());
        assertTestParams(parameters);
    } 
 
    private void assertTestParams(Multimap<String, String> parameters) {
        assertTrue(parameters.containsEntry("a", "1"));
        assertTrue(parameters.containsEntry("a", "2"));
        assertTrue(parameters.containsEntry("b", "b1"));
        assertTrue(parameters.containsEntry("b", "b2"));
        assertTrue(parameters.containsEntry("c", ""));
        assertTrue(parameters.containsEntry("d", "1"));
    } 
 
    @Test
    public void testAddParamsNoOverrides() throws Exception {
        URI uri = new URI("http://server:port/path1/path2?" + TEST_QUERY);
        Multimap<String, String> newParams = HashMultimap.create();
        newParams.put("a", "n1");
        newParams.put("e", "e1");
        Set<String> overrides = Sets.newHashSet();
7
CodeRank
This code example shows how to use the following methods:get, isEmpty, remove, toString
	} 
 
	public void addPosition(int offset, int length, String... id) {
		TextRegion region = new TextRegion(offset, length);
		Assert.assertEquals(1, id.length);
		Assert.assertFalse(region.toString(), expectedRegions.isEmpty());
		Collection<String> expectedIds = expectedRegions.get(region);
		if(expectedIds.size() > 0)
			Assert.assertTrue("expected: " + expectedRegions.toString() + " but was: " + region + " (" + id[0] + ")", expectedIds.contains(id[0]));
		if(expectedIds.contains(id[0]))
			expectedRegions.remove(region, id[0]);
	} 
} 
7
CodeRank
This code example shows how to use the following methods:put
 
   @Override 
   public Multimap<String, String> buildFormParameters() {
      Multimap<String, String> params = super.buildFormParameters();
      if (externalId != null)
         params.put("ExternalId", externalId.toString());
      if (durationSeconds != null)
         params.put("DurationSeconds", durationSeconds.toString());
      if (policy != null)
         params.put("Policy", policy);
      return params;
   } 
 
   /** 
    * {@inheritDoc} 
    */ 
   @Override 
   public int hashCode() { 
      return Objects.hashCode(externalId, durationSeconds, policy);
   } 
7
CodeRank
This code example shows how to use the following methods:put
		objectClasses.add("simpleSecurityObject");
	} 
 
	@Override 
	protected void getAdditionalProperties(Multimap<String, String> additionalProperties) {
		super.getAdditionalProperties(additionalProperties);
 
		additionalProperties.put("cn", getCn());
		if (getUserPasssword() != null) { 
			additionalProperties.put("userPassword", getUserPasssword());
		} 
	} 
 
	public String getCn() {
		return cn;
	} 
 
	public void setCn(String cn) {
		this.cn = cn;
	} 
7
CodeRank
This code example shows how to use the following methods:put, removeAll
      Collection<String> values = headers.get(string);
      return (values != null && values.size() >= 1) ? values.iterator().next() : null;
   } 
 
   protected void replaceHeader(String key, String value) {
      headers.removeAll(key);
      headers.put(key, value);
   } 
 
   /** 
    * {@inheritDoc} 
    */ 
   @Override 
   public Multimap<String, String> buildRequestHeaders() {
      return headers;
   } 
 
   /** 
    * {@inheritDoc} 
    */ 
6
CodeRank
This code example shows how to use the following methods:put
		} 
	} 
 
	@Override 
	protected void getAdditionalProperties(Multimap<String, String> additionalProperties) {
		super.getAdditionalProperties(additionalProperties);
 
		additionalProperties.put("o", organizationName);
		additionalProperties.put("dc", getCn());
	} 
 
	/** 
	 * Note that dn is the actual DN used; we don't prefix with o=XXX 
	 */ 
	public static OrganizationLdapEntry build(String o, String cn, LdapDN organizationDN) {
		OrganizationLdapEntry entry = OpsContext.get().getInjector().getInstance(OrganizationLdapEntry.class);
		entry.setOrganizationName(o);
		entry.setCn(cn);
		entry.setLdapDN(organizationDN);
		return entry;
7
CodeRank
This code example shows how to use the following methods:asMap, isEmpty
 * If you need a more robust serializer, you should consider 
 * <a href="https://github.com/nmorel/gwt-jackson/tree/master/extensions/guava">GWT-Jackson's Guava Extension</a>. 
 */ 
public class MultimapJsonSerializer { 
    public String serialize(Multimap<?, ?> parameters) {
        if (parameters.isEmpty()) {
            return "{}"; 
        } 
 
        return "{\"" + Joiner.on(",\"").withKeyValueSeparator("\":").join(parameters.asMap()) + "}";
    } 
} 
6
CodeRank
This code example shows how to use the following methods:get
         if (args.isEmpty()) { 
            if (any(extensions.getUnchecked(""), namespaceOrAliasEquals(namespace, aliases.get(namespace))))
               return input.getResult();
         } else if (args.size() == 1) { 
            String arg0 = checkNotNull(args.get(0), "arg[0] in %s", input).toString();
            if (any(extensions.getUnchecked(arg0), namespaceOrAliasEquals(namespace, aliases.get(namespace))))
               return input.getResult();
         } else { 
            throw new RuntimeException(String.format("expecting zero or one args %s", input));
         } 
         return Optional.absent();
      } else { 
         // No extension annotation, should check whether to return absent 
         return input.getResult();
      } 
   } 
 
   @Override 
   public String toString() {
      return "presentWhenExtensionAnnotationNamespaceEqualsAnyNamespaceInExtensionsSet()"; 
6
CodeRank
This code example shows how to use the following methods:containsKey, put, values
    } 
 
    public void put(String alias, Expression expression)
    { 
        alias = alias(alias);
        if (map.containsKey(alias)) {
            checkState(map.get(alias).contains(expression), "Alias '%s' points to different expression '%s' and '%s'", alias, expression, map.get(alias));
        } 
        else { 
            checkState(!map.values().contains(expression), "Expression '%s' is already pointed by different alias than '%s', check mapping for '%s'", expression, alias, map);
            map.put(alias, expression);
        } 
    } 
 
    private String alias(String alias)
    { 
        return alias.toLowerCase().replace("(", "").replace(")", "").replace("\"", "");
    } 
 
    public void updateAssignments(Map<Symbol, Expression> assignments)
6
CodeRank
See Code Examples for Guava Multimap Methods: