Example usage for com.google.common.collect BiMap forcePut

List of usage examples for com.google.common.collect BiMap forcePut

Introduction

In this page you can find the example usage for com.google.common.collect BiMap forcePut.

Prototype

@Nullable
V forcePut(@Nullable K key, @Nullable V value);

Source Link

Document

An alternate form of put that silently removes any existing entry with the value value before proceeding with the #put operation.

Usage

From source file:org.spongepowered.tools.obfuscation.mapping.mcp.MappingProviderSrg.java

@Override
public void read(final File input) throws IOException {
    // Locally scoped to avoid synthetic accessor
    final BiMap<String, String> packageMap = this.packageMap;
    final BiMap<String, String> classMap = this.classMap;
    final BiMap<MappingField, MappingField> fieldMap = this.fieldMap;
    final BiMap<MappingMethod, MappingMethod> methodMap = this.methodMap;

    Files.readLines(input, Charset.defaultCharset(), new LineProcessor<String>() {
        @Override/* w  w  w  . ja  v  a 2s  . c  o  m*/
        public String getResult() {
            return null;
        }

        @Override
        public boolean processLine(String line) throws IOException {
            if (Strings.isNullOrEmpty(line) || line.startsWith("#")) {
                return true;
            }

            String type = line.substring(0, 2);
            String[] args = line.substring(4).split(" ");

            if (type.equals("PK")) {
                packageMap.forcePut(args[0], args[1]);
            } else if (type.equals("CL")) {
                classMap.forcePut(args[0], args[1]);
            } else if (type.equals("FD")) {
                fieldMap.forcePut(new MappingFieldSrg(args[0]).copy(), new MappingFieldSrg(args[1]).copy());
            } else if (type.equals("MD")) {
                methodMap.forcePut(new MappingMethod(args[0], args[1]), new MappingMethod(args[2], args[3]));
            } else {
                throw new MixinException("Invalid SRG file: " + input);
            }

            return true;
        }
    });
}