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(Map<? extends K, ? extends V> map) 

Source Link

Document

Constructs a new bimap containing initial values from map .

Usage

From source file:com.hpcloud.mon.app.AlarmService.java

/**
 * Returns an entry containing Maps of old, changed, and new sub expressions by comparing the
 * {@code alarmExpression} to the existing sub expressions for the {@code alarmId}.
 *//*w w w . j  a v  a2s.c  o  m*/
SubExpressions subExpressionsFor(String alarmId, AlarmExpression alarmExpression) {
    BiMap<String, AlarmSubExpression> oldExpressions = HashBiMap.create(repo.findSubExpressions(alarmId));
    Set<AlarmSubExpression> oldSet = oldExpressions.inverse().keySet();
    Set<AlarmSubExpression> newSet = new HashSet<>(alarmExpression.getSubExpressions());

    // Identify old or changed expressions
    Set<AlarmSubExpression> oldOrChangedExpressions = new HashSet<>(Sets.difference(oldSet, newSet));

    // Identify new or changed expressions
    Set<AlarmSubExpression> newOrChangedExpressions = new HashSet<>(Sets.difference(newSet, oldSet));

    // Find changed expressions
    Map<String, AlarmSubExpression> changedExpressions = new HashMap<>();
    for (Iterator<AlarmSubExpression> oldIt = oldOrChangedExpressions.iterator(); oldIt.hasNext();) {
        AlarmSubExpression oldExpr = oldIt.next();
        for (Iterator<AlarmSubExpression> newIt = newOrChangedExpressions.iterator(); newIt.hasNext();) {
            AlarmSubExpression newExpr = newIt.next();
            if (sameKeyFields(oldExpr, newExpr)) {
                oldIt.remove();
                newIt.remove();
                changedExpressions.put(oldExpressions.inverse().get(oldExpr), newExpr);
            }
        }
    }

    // Create the list of unchanged expressions
    BiMap<String, AlarmSubExpression> unchangedExpressions = HashBiMap.create(oldExpressions);
    unchangedExpressions.values().removeAll(oldOrChangedExpressions);
    unchangedExpressions.keySet().removeAll(changedExpressions.keySet());

    // Remove old sub expressions
    oldExpressions.values().retainAll(oldOrChangedExpressions);

    // Create IDs for new expressions
    Map<String, AlarmSubExpression> newExpressions = new HashMap<>();
    for (AlarmSubExpression expression : newOrChangedExpressions)
        newExpressions.put(UUID.randomUUID().toString(), expression);

    SubExpressions subExpressions = new SubExpressions();
    subExpressions.oldAlarmSubExpressions = oldExpressions;
    subExpressions.changedSubExpressions = changedExpressions;
    subExpressions.unchangedSubExpressions = unchangedExpressions;
    subExpressions.newAlarmSubExpressions = newExpressions;
    return subExpressions;
}

From source file:org.sosy_lab.cpachecker.cpa.octagon.OctagonState.java

public OctagonState declareVariable(MemoryLocation pTempVarName, Type type) {
    assert !variableToIndexMap.containsKey(pTempVarName);
    OctagonState newState = new OctagonState(octagonManager.addDimensionAndEmbed(octagon, 1),
            HashBiMap.create(variableToIndexMap), new HashMap<>(variableToTypeMap), logger);
    newState.variableToIndexMap.put(pTempVarName, sizeOfVariables());
    newState.variableToTypeMap.put(pTempVarName, type);
    return newState;
}

From source file:org.apache.mahout.classifier.sequencelearning.hmm.HmmModel.java

/**
 * Register a map of hidden state Names/state IDs
 *
 * @param stateNames <String,Integer> Map that assigns each state name an integer ID
 *//*from  ww  w .  ja  v a 2 s . c  om*/
public void registerOutputStateNames(Map<String, Integer> stateNames) {
    if (stateNames != null) {
        outputStateNames = HashBiMap.create(stateNames);
    }
}

From source file:com.twitter.aurora.scheduler.http.SchedulerzJob.java

private static Map<String, SchedulingDetails> buildSchedulingTable(Iterable<IAssignedTask> tasks) {

    Map<Integer, ITaskConfig> byInstance = Maps
            .transformValues(Maps.uniqueIndex(tasks, Tasks.ASSIGNED_TO_INSTANCE_ID), Tasks.ASSIGNED_TO_INFO);
    Map<Integer, SchedulingDetails> detailsByInstance = Maps.transformValues(byInstance, CONFIG_TO_DETAILS);
    Multimap<SchedulingDetails, Integer> instancesByDetails = Multimaps
            .invertFrom(Multimaps.forMap(detailsByInstance), HashMultimap.<SchedulingDetails, Integer>create());
    Map<SchedulingDetails, String> instanceStringsByDetails = Maps.transformValues(instancesByDetails.asMap(),
            TransformationUtils.INSTANCES_TOSTRING);
    return HashBiMap.create(instanceStringsByDetails).inverse();
}

From source file:org.sosy_lab.cpachecker.cpa.octagon.OctagonState.java

/**
 * This method makes an assignment to a variable
 */// w ww .  j  a va 2s .co  m
private OctagonState makeAssignment(MemoryLocation leftVarName, OctagonSimpleCoefficients oct) {
    assert sizeOfVariables() == oct.size() : "coefficients do not have the right size";

    if (getVariableIndexFor(leftVarName) == -1) {
        return this;
    }

    NumArray arr = oct.getNumArray(octagonManager);
    int varIdx = getVariableIndexFor(leftVarName);

    if (varIdx == -1) {
        return this;
    }

    OctagonState newState = new OctagonState(octagonManager.assingVar(octagon, varIdx, arr),
            HashBiMap.create(variableToIndexMap), new HashMap<>(variableToTypeMap), logger);
    octagonManager.num_clear_n(arr, oct.size());
    return newState;
}

From source file:org.opencb.opencga.storage.core.metadata.StudyConfiguration.java

/**
 * Return all the indexed samples of an study plus the samples from a set of files.
 * Return a map between the sampleName and its position.
 *
 * @param studyConfiguration    Selected study
 * @param fileIds               Additional files to include
 * @return      Map between sampleName and position
 *//*from  w w w . j a  v  a  2s . c  om*/
public static BiMap<String, Integer> getIndexedSamplesPosition(StudyConfiguration studyConfiguration,
        int... fileIds) {
    Objects.requireNonNull(studyConfiguration, "StudyConfiguration is required");
    BiMap<String, Integer> samplesPosition = HashBiMap.create(studyConfiguration.getSampleIds().size());
    int position = 0;
    BiMap<Integer, String> idSamples = studyConfiguration.sampleIds.inverse();
    for (Integer indexedFileId : studyConfiguration.getIndexedFiles()) {
        for (Integer sampleId : studyConfiguration.getSamplesInFiles().get(indexedFileId)) {
            samplesPosition.putIfAbsent(idSamples.get(sampleId), position++);
        }
    }
    for (int fileId : fileIds) {
        for (Integer sampleId : studyConfiguration.getSamplesInFiles().get(fileId)) {
            samplesPosition.putIfAbsent(idSamples.get(sampleId), position++);
        }
    }
    return samplesPosition;
}

From source file:org.ietr.preesm.codegen.xtend.task.CodegenModelGenerator.java

/**
 * Constructor of the {@link CodegenModelGenerator}. The constructor
 * performs verification to ensure that the inputs are valid:
 * <ul>//from   ww  w .j  a va 2 s.com
 * <li>The {@link DirectedAcyclicGraph DAG} is scheduled</li>
 * <li>The {@link DirectedAcyclicGraph DAG} is mapped on the input
 * {@link Design architecture}</li>
 * <li>The {@link MemoryExclusionGraph MemEx} is derived from the
 * {@link DirectedAcyclicGraph DAG}</li>
 * <li>The {@link MemoryExclusionGraph MemEx} is allocated</li>
 * </ul>
 * 
 * @param archi
 *            See {@link AbstractCodegenPrinter#archi}
 * @param dag
 *            See {@link AbstractCodegenPrinter#dag}
 * @param memEx
 *            See {@link AbstractCodegenPrinter#memEx}
 * @param scenario
 *            See {@link AbstractCodegenPrinter#scenario}
 * @throws CodegenException
 *             When one of the previous verification fails.
 */
public CodegenModelGenerator(final Design archi, final DirectedAcyclicGraph dag,
        final MemoryExclusionGraph memEx, final PreesmScenario scenario, Workflow workflow)
        throws CodegenException {
    this.archi = archi;
    this.dag = dag;
    this.memEx = memEx;
    this.scenario = scenario;
    this.workflow = workflow;

    checkInputs(this.archi, this.dag, this.memEx);
    this.bufferNames = new HashMap<String, Integer>();
    this.coreBlocks = new HashMap<ComponentInstance, CoreBlock>();
    this.srSDFEdgeBuffers = new HashMap<BufferProperties, Buffer>();
    this.dagEdgeBuffers = HashBiMap.create(dag.edgeSet().size());
    this.dagFifoBuffers = new HashMap<Pair<DAGVertex, DAGVertex>, Pair<Buffer, Buffer>>();
    this.dagVertexCalls = HashBiMap.create(dag.vertexSet().size());
    this.communications = new HashMap<String, List<Communication>>();
    this.popFifoCalls = new HashMap<SDFInitVertex, FifoCall>();
}

From source file:org.openscience.cdk.pharmacophore.PharmacophoreMatcher.java

/**
 * Return a list of HashMap's that allows one to get the query constraint for a given pharmacophore bond.
 * <p/>//  ww w  .  j a  v  a2s.  c  o m
 * If the matching is successful, the return value is a List of HashMaps, each
 * HashMap corresponding to a separate match. Each HashMap is keyed on the {@link org.openscience.cdk.pharmacophore.PharmacophoreBond}
 * in the target molecule that matched a constraint ({@link org.openscience.cdk.pharmacophore.PharmacophoreQueryBond} or
 * {@link org.openscience.cdk.pharmacophore.PharmacophoreQueryAngleBond}. The value is the corresponding query bond.
 *
 * @return A List of HashMaps, identifying the query constraint corresponding to a matched constraint in the target
 *         molecule.
 */
public List<HashMap<IBond, IBond>> getTargetQueryBondMappings() {
    if (mappings == null)
        return null;

    List<HashMap<IBond, IBond>> bondMap = new ArrayList<>();

    // query -> target so need to inverse the mapping
    // XXX: re-subsearching the query
    for (Map<IBond, IBond> map : mappings.toBondMap()) {
        bondMap.add(new HashMap<>(HashBiMap.create(map).inverse()));
    }

    return bondMap;
}

From source file:org.sosy_lab.cpachecker.cpa.octagon.OctagonState.java

/**
 * This method makes an interval assignment to a variable. The OctCoefficients
 * need to be twice as long as for normal assignments! (upper and lower bound)
 *//*from w ww .  ja v a2 s .co m*/
private OctagonState makeAssignment(MemoryLocation leftVarName, OctagonIntervalCoefficients oct) {
    assert sizeOfVariables() == oct.size() : "coefficients do not have the right size";

    if (getVariableIndexFor(leftVarName) == -1) {
        return this;
    }

    NumArray arr = oct.getNumArray(octagonManager);
    int varIdx = getVariableIndexFor(leftVarName);

    if (varIdx == -1) {
        return this;
    }

    OctagonState newState = new OctagonState(octagonManager.intervAssingVar(octagon, varIdx, arr),
            HashBiMap.create(variableToIndexMap), new HashMap<>(variableToTypeMap), logger);
    octagonManager.num_clear_n(arr, oct.size());
    return newState;
}

From source file:org.sosy_lab.cpachecker.cpa.octagon.OctagonState.java

/**
 * Helper method for all addXXXXConstraint methods
 */// www. j a v a  2  s .c om
private OctagonState addConstraint(BinaryConstraints cons, int leftIndex, int rightIndex,
        OctagonNumericValue constantValue) {
    NumArray arr = octagonManager.init_num_t(4);
    octagonManager.num_set_int(arr, 0, cons.getNumber());
    octagonManager.num_set_int(arr, 1, leftIndex);
    octagonManager.num_set_int(arr, 2, rightIndex);
    if (constantValue instanceof OctagonDoubleValue) {
        octagonManager.num_set_float(arr, 3, constantValue.getValue().doubleValue());
    } else {
        octagonManager.num_set_int(arr, 3, constantValue.getValue().longValue());
    }

    OctagonState newState = new OctagonState(octagonManager.addBinConstraint(octagon, 1, arr),
            HashBiMap.create(variableToIndexMap), new HashMap<>(variableToTypeMap), logger);
    octagonManager.num_clear_n(arr, 4);
    return newState;
}