Guava BiMap - 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 BiMap class.

This code example shows how to use the following methods:inverse, get
        return MODEL_NAME_MAP.get(modelType); 
    } 
 
    @Nullable 
    public String getModelNameFromProtocolType(Class<?> protocolType) { 
        Class<?> modelType = MODEL_TO_PROTOCOL_MAP.inverse().get(protocolType); 
        if (modelType == null) { 
            return null; 
        } 
        return MODEL_NAME_MAP.get(modelType); 
    } 
 
    @Nullable 
    public Class<?> getProtocolTypeFromModelName(String name) { 
        Class<?> modelType = MODEL_NAME_MAP.inverse().get(name); 
        if (modelType == null) { 
            return null; 
        } 
        return getProtocolType(modelType); 
    } 
8
CodeRank
This code example shows how to use the following methods:put
public class StatsAdapter implements JsonDeserializer<IEquipmentStats>, JsonSerializer<IEquipmentStats> {
 
  private final BiMap<String, Class> classesToTypes = HashBiMap.create();
 
  public StatsAdapter() { 
    classesToTypes.put("Melee Weapon", MeleeWeaponStats.class);
    classesToTypes.put("Ranged Weapon", RangedWeaponStats.class);
    classesToTypes.put("Artifact", ArtifactStats.class);
    classesToTypes.put("Armour", ArmourStats.class);
    classesToTypes.put("Trait Modifier", TraitModifyingStats.class);
  } 
 
  @Override 
  public IEquipmentStats deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    JsonObject object = (JsonObject) json;
    JsonElement type = object.get("type");
    String typeAsString = type.getAsString();
    Class classToBuild = classesToTypes.get(typeAsString);
    return context.deserialize(json, classToBuild);
  } 
8
CodeRank
This code example shows how to use the following methods:inverse, containsKey, containsValue, get
    return ImmutableMap.copyOf(canonicalPathNames);
  } 
 
  public Repository getRepositoryByCanonicalName(Optional<String> canonicalName)
      throws IOException, InterruptedException {
    if (!canonicalPathNames.containsValue(canonicalName)) {
      throw new HumanReadableException("No repository with canonical name '%s'.", canonicalName);
    } 
    Path repoPath = canonicalPathNames.inverse().get(canonicalName);
    return getRepositoryByAbsolutePath(repoPath);
  } 
 
  public Repository getRootRepository() 
      throws IOException, InterruptedException {
    return getRepositoryByCanonicalName(Optional.<String>absent());
  } 
 
  public Repository getRepositoryByAbsolutePath(Path absolutePath)
      throws IOException, InterruptedException {
    Preconditions.checkArgument(absolutePath.isAbsolute());

7
CodeRank
This code example shows how to use the following methods:inverse
        } 
        return out;
    } 
 
    public void write(Encoder encoder, ComponentSelectionReason value) throws IOException {
        Byte id = REASONS.inverse().get(value);
        if (id == null) {
            throw new IllegalArgumentException("Unknown selection reason: " + value);
        } 
        encoder.writeByte(id);
    } 
} 
7
CodeRank
This code example shows how to use the following methods:inverse, containsKey, containsValue, get
    } 
 
    protected EnumProtocol a(int i, Class oclass) {
        String s;
 
        if (this.h.containsKey(Integer.valueOf(i))) {
            s = "Serverbound packet ID " + i + " is already assigned to " + this.h.get(Integer.valueOf(i)) + "; cannot re-assign to " + oclass;
            LogManager.getLogger().fatal(s);
            throw new IllegalArgumentException(s);
        } else if (this.h.containsValue(oclass)) {
            s = "Serverbound packet " + oclass + " is already assigned to ID " + this.h.inverse().get(oclass) + "; cannot re-assign to " + i;
            LogManager.getLogger().fatal(s);
            throw new IllegalArgumentException(s);
        } else { 
            this.h.put(Integer.valueOf(i), oclass);
            return this;
        } 
    } 
 
    protected EnumProtocol b(int i, Class oclass) {
7
CodeRank
This code example shows how to use the following methods:inverse, containsValue, get
        } 
        return column;
    } 
 
    public String toColumn(final String attribute) {
        if (this.mapping.containsValue(attribute)) {
            return this.mapping.inverse().get(attribute);
        } 
        return attribute;
    } 
 
    public void setMappings(final Map<String, String> mappings) {
        this.mapping.clear();
        this.mapping.putAll(mappings);
    } 
} 
7
CodeRank
This code example shows how to use the following methods:inverse, get
			return expansions.get(clientIDMap.get((byte) id));
		} 
	} 
 
	public static byte getServerExpansionID(String identifier) {
		return serverIDMap.inverse().get(identifier);
	} 
 
	public static Set<IGateExpansion> getExpansions() {
		Set<IGateExpansion> set = new HashSet<IGateExpansion>();
		set.addAll(expansions.values());
		return set;
	} 
 
	public static BiMap<Byte, String> getServerMap() {
		return serverIDMap;
	} 
 
	public static void setClientMap(BiMap<Byte, String> map) {
		clientIDMap.clear();
7
CodeRank
This code example shows how to use the following methods:put, get
		BiMap<String, Integer> inverseMap = biMap.inverse();
 
		// 在biMap这边插入,在inserserMap可以用value取到key。 
		biMap.put(1, "a");
		biMap.put(2, "b");
		assertThat(inverseMap.get("b")).isEqualTo(2);
 
		// 在inverseMap这边插入,在bimap这边也能用value取到key。 
		inverseMap.put("c", 3);
		assertThat(biMap.get(3)).isEqualTo("c");
 
		// value也必须唯一,如果将key 4的value强行设为"a", 原来的key 1消失 
		biMap.forcePut(4, "a");
		assertThat(biMap.containsKey(1)).isFalse();
	} 
 
	/* 
	 * Guava Table, 等于有兩个key的Map,可用来替代Map<String,Map<String,Object> 
	 */ 
	@Test
7
CodeRank
This code example shows how to use the following methods:inverse, get
     * {@inheritDoc} 
     */ 
    @Override 
    public String getPrefix(String namespaceURI)
    { 
        return prefixToNamespaceMap.inverse().get(namespaceURI);
    } 
 
    /** 
     * {@inheritDoc} 
     */ 
    @Override 
    public Iterator getPrefixes(String namespaceURI)
    { 
        return ImmutableList.<String>builder()
                .addAll(prefixToNamespaceMap.inverse().keySet())
                .build()
                .iterator();
    } 
 
7
CodeRank
This code example shows how to use the following methods:inverse, get
		result = getLexerRuleName(result);
		return result;
	} 
	 
	protected int getTokenType(String ruleNameWithRulePrefix) {
		int result = tokenDefs.inverse().get(ruleNameWithRulePrefix);
		return result;
	} 
	 
	public String getLexerRuleName(String antlrTokenDef) {
		if (antlrTokenDef.startsWith(LEXER_RULE_PREFIX))
			return antlrTokenDef.substring(LEXER_RULE_PREFIX.length());
		return antlrTokenDef;
	} 
	 
	@Inject 
	public void initializeTokenDefsFrom(ITokenDefProvider provider) {
		tokenDefs.clear();
		tokenDefs.putAll(provider.getTokenDefMap());
	} 
7
CodeRank
See Code Examples for Guava BiMap Methods: