Example usage for com.google.common.collect HashBiMap create

List of usage examples for com.google.common.collect HashBiMap create

Introduction

In this page you can find the example usage for com.google.common.collect HashBiMap create.

Prototype

public static <K, V> HashBiMap<K, V> create() 

Source Link

Document

Returns a new, empty HashBiMap with the default initial capacity (16).

Usage

From source file:net.automatalib.serialization.etf.writer.Mealy2ETFWriterIO.java

private <S, T> void writeETFInternal(PrintWriter pw, MealyMachine<S, I, T, O> mealy, Alphabet<I> inputs) {
    final StateIDs<S> stateIDs = mealy.stateIDs();

    // write the initial state
    pw.println("begin init");
    pw.printf("%d%n", stateIDs.getStateId(mealy.getInitialState()));
    pw.println("end init");

    // write the state ids
    pw.println("begin sort id");
    mealy.getStates().forEach(s -> pw.printf("\"%s\"%n", s));
    pw.println("end sort");

    // create a new bi-map that contains indices for the output alphabet
    final BiMap<O, Integer> outputIndices = HashBiMap.create();

    // write the transitions
    pw.println("begin trans");
    for (S s : mealy.getStates()) {
        for (I i : inputs) {
            final T t = mealy.getTransition(s, i);
            if (t != null) {
                final O o = mealy.getTransitionOutput(t);
                outputIndices.computeIfAbsent(o, ii -> outputIndices.size());
                final S n = mealy.getSuccessor(t);
                pw.printf("%s/%s %d %d%n", stateIDs.getStateId(s), stateIDs.getStateId(n),
                        inputs.getSymbolIndex(i), outputIndices.get(o));
            }/*  ww  w .  ja v a 2 s.c o m*/
        }
    }
    pw.println("end trans");

    // write the letters in the input alphabet
    pw.println("begin sort input");
    inputs.forEach(i -> pw.printf("\"%s\"%n", i));
    pw.println("end sort");

    // write the letters in the output alphabet
    pw.println("begin sort output");
    for (int i = 0; i < outputIndices.size(); i++) {
        pw.printf("\"%s\"%n", outputIndices.inverse().get(i));
    }
    pw.println("end sort");
}

From source file:com.google.errorprone.bugpatterns.testdata.URLEqualsHashCodePositiveCases.java

public void hashBiMapOfCompleteURL() {
    // BUG: Diagnostic contains: java.net.URL
    HashBiMap<java.net.URL, String> urlBiMap = HashBiMap.create();

    // BUG: Diagnostic contains: java.net.URL
    HashBiMap<String, java.net.URL> toUrlBiMap = HashBiMap.create();
}

From source file:org.thingsboard.server.actors.app.AppActor.java

private AppActor(ActorSystemContext systemContext) {
    super(systemContext, new SystemRuleChainManager(systemContext));
    this.tenantService = systemContext.getTenantService();
    this.tenantActors = HashBiMap.create();
}

From source file:org.biokoframework.systema.injection.SystemAMainModule.java

@Override
protected void configureMain() {
    bindProperty("systemName").to("system-a");
    bindProperty("systemVersion").to("1.0");

    bindProperty("Commands").to(SystemACommands.class);
    bind(IHandlerLocator.class).to(AnnotationHandlerLocator.class);

    BiMap<String, String> headerToFieldMap = HashBiMap.create();
    headerToFieldMap.put("Engaged-Auth-Token", "authToken");
    headerToFieldMap.put("Engaged-Auth-Token-Expire", "authTokenExpire");
    headerToFieldMap = Maps.unmodifiableBiMap(headerToFieldMap);
    bind(new TypeLiteral<Map<String, String>>() {
    }).annotatedWith(Names.named("httpHeaderToFieldsMap")).toInstance(headerToFieldMap);
    bind(new TypeLiteral<Map<String, String>>() {
    }).annotatedWith(Names.named("fieldsHttpHeaderToMap")).toInstance(headerToFieldMap.inverse());
}

From source file:de.uni_potsdam.hpi.asg.logictool.netlist.Netlist.java

public Netlist(BDDFactory fac, StateGraph sg, Reset reset) {
    this.fac = fac;
    this.reset = reset;
    this.nameVarMap = new HashMap<>();
    this.idVarMap = new HashMap<>();
    this.terms = new TreeMap<>(new BDDComparator());
    this.unmappedTerms = new HashSet<>();
    this.mappedTerms = new HashMap<>();
    this.quasiSignals = new HashMap<>();
    this.tmpid = 0;

    this.sigVarMap = HashBiMap.create();
    for (Signal sig : sg.getAllSignals()) {
        sigVarMap.put(sig, getNetlistVariableByName(sig.getName()));
    }//  w w  w  . j a  va 2  s. co  m

    initReset();
}

From source file:com.ning.arecibo.util.timeline.persistent.DefaultTimelineDAO.java

@Override
public BiMap<Integer, String> getHosts() throws UnableToObtainConnectionException, CallbackFailedException {
    final HashBiMap<Integer, String> accumulator = HashBiMap.create();
    for (final Map<String, Object> sampleKind : delegate.getHosts()) {
        accumulator.put(Integer.valueOf(sampleKind.get("host_id").toString()),
                sampleKind.get("host_name").toString());
    }//  w  ww .ja  v a  2 s.co m
    return accumulator;
}

From source file:org.apache.gobblin.converter.filter.GobblinTrackingEventFlattenFilterConverter.java

@Override
public Converter init(WorkUnitState workUnitState) {
    try {/* w w w  .  j a  va  2  s . co  m*/
        gobblinTrackingEventSchema = new Schema.Parser()
                .parse(getClass().getClassLoader().getResourceAsStream("GobblinTrackingEvent.avsc"));
    } catch (IOException e) {
        throw new RuntimeException("Cannot parse GobblinTrackingEvent schema.", e);
    }
    config = ConfigUtils.propertiesToConfig(workUnitState.getProperties())
            .getConfig(this.getClass().getSimpleName());
    List<String> entryList = ConfigUtils.getStringList(config, FIELDS_RENAME_MAP);
    this.fieldsRenameMap = HashBiMap.create();
    for (String entry : entryList) {
        List<String> oldNewNames = Splitter.on(OLD_NEW_NAME_SEPARATOR).omitEmptyStrings().splitToList(entry);
        Preconditions.checkArgument(oldNewNames.size() == 2, "Wrong format for key " + FIELDS_RENAME_MAP);
        this.fieldsRenameMap.put(oldNewNames.get(0), oldNewNames.get(1));
    }

    this.nonMapFields = new HashSet<>();
    this.newFields = new ArrayList<>();
    List<String> mapFieldNames = new ArrayList<>();
    for (Field field : gobblinTrackingEventSchema.getFields()) {
        String curFieldName = field.name();
        if (!field.schema().getType().equals(Schema.Type.MAP)) {
            if (fieldsRenameMap.containsKey(curFieldName)) {
                newFields.add(new Schema.Field(fieldsRenameMap.get(curFieldName), field.schema(), field.doc(),
                        field.defaultValue()));
            } else {
                newFields
                        .add(new Schema.Field(curFieldName, field.schema(), field.doc(), field.defaultValue()));
            }
            this.nonMapFields.add(curFieldName);
        } else {
            mapFieldNames.add(curFieldName);
        }
    }

    Preconditions.checkArgument(mapFieldNames.size() == 1, "Input schema does not match GobblinTrackingEvent.");
    this.mapFieldName = mapFieldNames.get(0);

    for (String fieldToFlatten : ConfigUtils.getStringList(config, FIELDS_TO_FLATTEN)) {
        String newFieldName = this.fieldsRenameMap.containsKey(fieldToFlatten)
                ? this.fieldsRenameMap.get(fieldToFlatten)
                : fieldToFlatten;
        newFields.add(new Field(newFieldName, Schema.create(Schema.Type.STRING), "", null));
    }

    return this;
}

From source file:org.linqs.psl.experimental.optimizer.conic.partition.ObjectiveCoefficientPartitioner.java

protected void doPartition() {
    Graph graph;//ww  w  .  ja v a 2s  .  co m
    Node node;

    int numElements = (int) Math.ceil((double) program.getNumLinearConstraints() / 5000);

    List<List<Node>> graphPartition = null;

    List<Set<Cone>> blocks;

    /* Partitions conic program graph into elements */
    HierarchicalPartitioning partitioner = new HyperPartitioning();
    partitioner.setNoPartitioningTrials(10);
    partitioner.setSize(numElements);

    boolean redoPartition = false;

    do {
        graph = new MemoryGraph();
        graph.createRelationshipType(LC_REL);

        coneMap = HashBiMap.create();
        lcMap = HashBiMap.create();

        for (Cone cone : program.getCones()) {
            node = graph.createNode();
            coneMap.put(cone, node);
        }

        Set<Cone> coneSet = new HashSet<Cone>();
        for (LinearConstraint con : program.getConstraints()) {
            node = graph.createNode();
            lcMap.put(con, node);

            for (Variable var : con.getVariables().keySet()) {
                coneSet.add(var.getCone());
            }

            for (Cone cone : coneSet) {
                node.createRelationship(LC_REL, coneMap.get(cone));
            }

            coneSet.clear();
        }

        graphPartition = partitioner.partition(graph, graph.getNodeSnapshot(), new RelationshipWeighter() {
            @Override
            public double getWeight(Relationship r) {
                if (r.getRelationshipType().equals(LC_REL)) {
                    LinearConstraint lc = (LinearConstraint) lcMap.inverse().get(r.getStart());
                    Cone cone = coneMap.inverse().get(r.getEnd());
                    return ObjectiveCoefficientPartitioner.this.getWeight(lc, cone);
                } else
                    return Double.POSITIVE_INFINITY;
            }
        });

        log.trace("Partition finished. Checking for balance.");

        /* Checks if blocks are sufficiently balanced */
        boolean balanced = true;
        if (numElements > 1) {
            int totalSize = 0;
            for (List<Node> block : graphPartition)
                totalSize += block.size();

            for (List<Node> block : graphPartition) {
                if (block.size() > 2 * (totalSize - block.size())) {
                    //                  log.debug("{} > {}", block.size(), 2*(totalSize - block.size()));
                    balanced = false;
                }
                if (!balanced) {
                    redoPartition = true;
                    break;
                }
            }

            if (!balanced) {
                redoPartition = true;
            }
        }

        /* Partition accepted */
        if (!redoPartition) {
            /* Collects cones in blocks */
            blocks = new Vector<Set<Cone>>();
            for (int i = 0; i < graphPartition.size(); i++) {
                Set<Cone> block = new HashSet<Cone>();
                for (Node n : graphPartition.get(i)) {
                    /* Adds cone to block */
                    if (coneMap.containsValue(n)) {
                        block.add(coneMap.inverse().get(n));
                    }
                }
                blocks.add(block);
            }

            /* Initializes the partition */
            partition = new ConicProgramPartition(program, blocks);
            return;
        }
    } while (true);
}

From source file:de.uniwuerzburg.info3.ofcprobe.vswitch.main.config.HostMapper.java

/**
 * Constructor/*from w w  w. j  a  v  a 2 s.  c  om*/
 *
 * @param config Overallconfiguration
 * @param ofSwitches
 */
public HostMapper(Config config, List<IOFConnection> ofSwitches) {
    this.config = config;
    this.deviceToIP = new HashMap<>();
    this.ipToDevice = new HashMap<>();

    this.deviceToMac = new HashMap<>();
    this.macToDevice = new HashMap<>();

    this.ipCounter = new HashMap<>();

    this.macIPmap = HashBiMap.create();

    this.macGen = new SerialMacGen();
    this.ipGen = new SerialIPGenerator();

    logger.debug("Hostmapper initialized, setting up Stuff...");
    setupStuff(ofSwitches);
    logger.debug("Arping set up!");
}

From source file:com.cloudera.oryx.common.pmml.PMMLUtils.java

public static Map<Integer, BiMap<String, Integer>> buildColumnCategoryMapping(DataDictionary dictionary) {
    Preconditions.checkNotNull(dictionary);
    InboundSettings settings = InboundSettings.create(ConfigUtils.getDefaultConfig());
    List<String> columnNames = settings.getColumnNames();

    Preconditions.checkNotNull(dictionary);
    Map<Integer, BiMap<String, Integer>> columnToCategoryNameToIDMapping = Maps.newHashMap();
    for (TypeDefinitionField field : dictionary.getDataFields()) {
        Collection<Value> values = field.getValues();
        if (values != null && !values.isEmpty()) {
            String columnName = field.getName().getValue();
            int columnNumber = columnNames.indexOf(columnName);
            BiMap<String, Integer> categoryNameToID = columnToCategoryNameToIDMapping.get(columnNumber);
            if (categoryNameToID == null) {
                categoryNameToID = HashBiMap.create();
                columnToCategoryNameToIDMapping.put(columnNumber, categoryNameToID);
            }/*  w w  w. ja  v  a 2s .c  o m*/
            for (Value value : values) {
                categoryNameToID.put(value.getValue(), categoryNameToID.size());
            }
        }
    }
    return columnToCategoryNameToIDMapping;
}