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

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

Introduction

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

Prototype

boolean containsKey(Object key);

Source Link

Document

Returns true if this map contains a mapping for the specified key.

Usage

From source file:edu.cuny.qc.speech.AuToBI.util.ClassifierUtils.java

/**
 * Normalizes features so they have 0 mean and unit variance.
 *
 * @param features    input (unscaled) features
 * @param feature_map a map of features to indices
 * @return normalized features//from  ww w  . j  a va2  s.c  o m
 */
public static de.bwaldvogel.liblinear.Feature[] normalizeLibLinearFeatures(
        de.bwaldvogel.liblinear.Feature[] features, BiMap<Integer, Feature> feature_map,
        HashMap<String, Aggregation> norm_params) {

    de.bwaldvogel.liblinear.Feature[] f_out = features.clone();

    for (de.bwaldvogel.liblinear.Feature fn : f_out) {
        if (!feature_map.containsKey(fn.getIndex())) {
            fn.setValue(0);
        } else {
            Aggregation agg = norm_params.get(feature_map.get(fn.getIndex()).getName());
            if (agg.getSize() < 2) {
                fn.setValue(0);
            } else {
                double u = agg.getMean();
                double sd = agg.getStdev();
                fn.setValue((fn.getValue() - u) / sd);
                if (Double.isNaN(fn.getValue())) {
                    fn.setValue(0);
                }
            }
        }
    }

    return f_out;
}

From source file:org.sosy_lab.cpachecker.cpa.smg.SMGIntersectStates.java

private static void intersectValueWithTop(int pValue, CLangSMG pSmg, CLangSMG pDestSMG,
        BiMap<SMGKnownSymValue, SMGKnownExpValue> pExplicitValues,
        BiMap<SMGKnownSymValue, SMGKnownExpValue> pDestExplicitValues, SMGNodeMapping pMapping) {

    if (pMapping.containsKey(pValue)) {
        return;//from www . j  av a 2s  . c om
    }

    pMapping.map(pValue, pValue);

    SMGKnownSymValue symVal = SMGKnownSymValue.valueOf(pValue);
    if (pExplicitValues.containsKey(symVal)) {
        SMGKnownExpValue pExpVal = pExplicitValues.get(symVal);
        pDestExplicitValues.put(symVal, pExpVal);
    }

    if (pSmg.isPointer(pValue)) {
        SMGEdgePointsTo pte = pSmg.getPointer(pValue);
        intersectPointerWithTop(pte, pSmg, pDestSMG, pExplicitValues, pDestExplicitValues, pMapping);
    }
}

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

public static LinkedHashMap<String, Integer> getReturnedSamplesPosition(StudyConfiguration studyConfiguration,
        LinkedHashSet<String> returnedSamples,
        Function<StudyConfiguration, BiMap<String, Integer>> getIndexedSamplesPosition) {
    LinkedHashMap<String, Integer> samplesPosition;
    if (returnedSamples == null || returnedSamples.isEmpty()) {
        BiMap<Integer, String> unorderedSamplesPosition = getIndexedSamplesPosition(studyConfiguration)
                .inverse();//from   w  ww  .  j a v a 2s . com
        samplesPosition = new LinkedHashMap<>(unorderedSamplesPosition.size());
        for (int i = 0; i < unorderedSamplesPosition.size(); i++) {
            samplesPosition.put(unorderedSamplesPosition.get(i), i);
        }
    } else {
        samplesPosition = new LinkedHashMap<>(returnedSamples.size());
        int index = 0;
        BiMap<String, Integer> indexedSamplesId = getIndexedSamplesPosition.apply(studyConfiguration);
        for (String returnedSample : returnedSamples) {
            if (!returnedSample.isEmpty() && StringUtils.isNumeric(returnedSample)) {
                returnedSample = studyConfiguration.getSampleIds().inverse()
                        .get(Integer.parseInt(returnedSample));
            }
            if (!samplesPosition.containsKey(returnedSample)) {
                if (indexedSamplesId.containsKey(returnedSample)) {
                    samplesPosition.put(returnedSample, index++);
                }
            }
        }
        //                for (String sample : indexedSamplesId.keySet()) {
        //                    samplesPosition.put(sample, index++);
        //                }
    }
    return samplesPosition;
}

From source file:org.apache.druid.indexing.firehose.IngestSegmentFirehoseFactory.java

@VisibleForTesting
static List<String> getUniqueDimensions(List<TimelineObjectHolder<String, DataSegment>> timelineSegments,
        @Nullable Set<String> excludeDimensions) {
    final BiMap<String, Integer> uniqueDims = HashBiMap.create();

    // Here, we try to retain the order of dimensions as they were specified since the order of dimensions may be
    // optimized for performance.
    // Dimensions are extracted from the recent segments to olders because recent segments are likely to be queried more
    // frequently, and thus the performance should be optimized for recent ones rather than old ones.

    // timelineSegments are sorted in order of interval
    int index = 0;
    for (TimelineObjectHolder<String, DataSegment> timelineHolder : Lists.reverse(timelineSegments)) {
        for (PartitionChunk<DataSegment> chunk : timelineHolder.getObject()) {
            for (String dimension : chunk.getObject().getDimensions()) {
                if (!uniqueDims.containsKey(dimension)
                        && (excludeDimensions == null || !excludeDimensions.contains(dimension))) {
                    uniqueDims.put(dimension, index++);
                }/*from w  w  w.ja va 2 s  .  co  m*/
            }
        }
    }

    final BiMap<Integer, String> orderedDims = uniqueDims.inverse();
    return IntStream.range(0, orderedDims.size()).mapToObj(orderedDims::get).collect(Collectors.toList());
}

From source file:net.sourcedestination.sai.comparison.matching.MatchingGenerator.java

public static GraphMatching createBasicNodeMatching(final Graph g1, final Graph g2,
        BiMap<Integer, Integer> nodeMatch) {
    final BiMap<Integer, Integer> copyNodeMatch = ImmutableBiMap.copyOf(nodeMatch);

    // transform Map.Entry to Pair instances
    final ImmutableSet<Pair<Integer>> matchedNode = ImmutableSet.copyOf(copyNodeMatch.entrySet().stream()
            .map((arg) -> Pair.makePair(arg.getKey(), arg.getValue())).collect(toSet()));
    return new GraphMatching() {

        @Override/*from  ww  w .  j a v a  2 s.co m*/
        public Graph getGraph1() {
            return g1;
        }

        @Override
        public Graph getGraph2() {
            return g2;
        }

        @Override
        public int getMatchedNodeInGraph2(int g1NodeID) {
            if (copyNodeMatch.containsKey(g1NodeID))
                return copyNodeMatch.get(g1NodeID);
            return -1;
        }

        @Override
        public int getMatchedNodeInGraph1(int g2NodeID) {
            if (copyNodeMatch.inverse().containsKey(g2NodeID))
                return copyNodeMatch.inverse().get(g2NodeID);
            return -1;
        }

        @Override
        public Set<Pair<Integer>> getAllNodeMatches() {
            return matchedNode;
        }

        @Override
        public int getMatchedEdgeInGraph2(int g1NodeID) {
            return -1;
        }

        @Override
        public int getMatchedEdgeInGraph1(int g2NodeID) {
            return -1;
        }

        @Override
        public Set<Pair<Integer>> getAllEdgeMatches() {
            return Sets.newHashSet();
        }

    };
}

From source file:cuchaz.enigma.convert.MappingsConverter.java

public static void convertMappings(Mappings mappings, BiMap<ClassEntry, ClassEntry> changes) {

    // sort the changes so classes are renamed in the correct order
    // ie. if we have the mappings a->b, b->c, we have to apply b->c before a->b
    LinkedHashMap<ClassEntry, ClassEntry> sortedChanges = Maps.newLinkedHashMap();
    int numChangesLeft = changes.size();
    while (!changes.isEmpty()) {
        Iterator<Map.Entry<ClassEntry, ClassEntry>> iter = changes.entrySet().iterator();
        while (iter.hasNext()) {
            Map.Entry<ClassEntry, ClassEntry> change = iter.next();
            if (changes.containsKey(change.getValue())) {
                sortedChanges.put(change.getKey(), change.getValue());
                iter.remove();/*from   w w  w  .  j ava2  s. c o m*/
            }
        }

        // did we remove any changes?
        if (numChangesLeft - changes.size() > 0) {
            // keep going
            numChangesLeft = changes.size();
        } else {
            // can't sort anymore. There must be a loop
            break;
        }
    }
    if (!changes.isEmpty()) {
        throw new Error("Unable to sort class changes! There must be a cycle.");
    }

    // convert the mappings in the correct class order
    for (Map.Entry<ClassEntry, ClassEntry> entry : sortedChanges.entrySet()) {
        mappings.renameObfClass(entry.getKey().getName(), entry.getValue().getName());
    }
}

From source file:compile.type.visit.EquivState.java

/**
 *
 *///from w  w  w  . j ava 2  s .com
private boolean matchScope(final ScopeType left, final ScopeType right) {
    if (scopes.containsKey(left)) {
        final ScopeType prevRight = scopes.get(left);
        if (!right.equals(prevRight)) {
            if (Session.isDebug())
                Session.debug(left.getLoc(), "scope {0} already matched with scope {1}, can''t match {2}",
                        left.dump(), prevRight.dump(), right.dump());

            return false;
        } else {
            if (Session.isDebug())
                Session.debug(left.getLoc(), "scope {0} matches scope {1}", left.dump(), right.dump());

            return true;
        }
    } else {
        final BiMap<ScopeType, ScopeType> inv = scopes.inverse();
        if (inv.containsKey(right)) {
            final ScopeType prevLeft = inv.get(right);

            if (Session.isDebug())
                Session.debug(right.getLoc(), "scope {0} already matched with scope {1}, can''t match {2}",
                        right.dump(), prevLeft.dump(), left.dump());

            return false;
        } else {
            if (Session.isDebug())
                Session.debug(left.getLoc(), "adding scope equiv {0} <=> {1}", left.dump(), right.dump());

            scopes.put(left, right);

            return true;
        }
    }
}

From source file:blue.lapis.pore.converter.data.DataTypeConverter.java

@SuppressWarnings({ "rawtypes", "unchecked" })
public byte of(Collection<DataManipulator<?, ?>> data) {
    HashMap<String, DataManipulator> dataMap = Maps.newHashMap();
    for (DataManipulator datum : data) {
        dataMap.put(datum.getClass().getName().split("\\$")[0], datum);
    }/*from   w  w w  .j  a  v a  2  s.c  om*/
    BiMap<AbstractDataValue, Byte>[] biMapList = new BiMap[converters.size()];
    converters.keySet().toArray(biMapList);
    Byte[] bitSetSizes = new Byte[converters.size()];
    converters.values().toArray(bitSetSizes);
    byte finalValue = 0;
    byte bitOffset = 0;
    for (int i = 0; i < applicableTypes.size(); i++) {
        byte bitsToConsider = bitSetSizes[i];
        assert bitOffset + bitsToConsider <= 8;
        if (dataMap.containsKey(applicableTypes.get(i).getName())) {
            DataManipulator datum = dataMap.get(applicableTypes.get(i).getName());
            BiMap<AbstractDataValue, Byte> bm = biMapList[i];
            AbstractDataValue adv = AbstractDataValue.of(datum);
            finalValue |= bm.containsKey(adv) ? bm.get(adv) << bitOffset : 0; // mask the value onto the data byte
        }
        bitOffset += bitsToConsider;
    }
    return finalValue;
}

From source file:compile.type.visit.EquivState.java

/**
 *
 *//*from   ww w  .j av a 2 s  .c  o m*/
public boolean matchParam(final TypeParam left, final TypeParam right) {
    if (left.getKind() != right.getKind()) {
        Session.error(left.getLoc(), "param {0} kind differs from param {1} kind", left.dump(), right.dump());

        return false;
    }

    final ScopeType leftScope = left.getTypeScope();
    final ScopeType rightScope = right.getTypeScope();

    if (!matchScope(leftScope, rightScope)) {
        Session.error(left.getLoc(), "param {0} scoped at {1} is not compatible with param {2} scoped at {3}",
                left.dump(), leftScope.getLoc(), right.dump(), rightScope.getLoc());

        return false;
    }

    if (params.containsKey(left)) {
        final TypeParam prev = params.get(left);

        if (!right.equals(prev)) {
            if (Session.isDebug())
                Session.debug(left.getLoc(), "param {0} already matched with param {1}, can''t match {2}",
                        left.dump(), prev.dump(), right.dump());

            return false;
        }

        return true;
    } else {
        final BiMap<TypeParam, TypeParam> inv = params.inverse();

        if (inv.containsKey(right)) {
            final TypeParam prevLeft = inv.get(right);

            if (Session.isDebug())
                Session.debug(right.getLoc(), "param {0} already matched with param {1}, can''t match {2}",
                        right.dump(), prevLeft.dump(), left.dump());

            return false;
        }

        params.put(left, right);

        return true;
    }
}

From source file:de.iteratec.iteraplan.elasticeam.util.I18nMap.java

/**
 * Adds a new metamodel element and name to the map.
 * /*from   www.  j  a  v a 2  s.  com*/
 * @param locale
 *    The locale of the name.
 * @param key
 *    The name.
 * @param value
 *    The metamodel element.
 */
public void set(Locale locale, String key, N value) {
    if (!this.valueByLocalizedName.containsKey(locale)) {
        BiMap<String, N> localeValues = HashBiMap.create();
        this.valueByLocalizedName.put(locale, localeValues);
    }
    BiMap<String, N> localeValues = this.valueByLocalizedName.get(locale);
    if (localeValues.containsKey(key) && !value.equals(localeValues.get(key))) {
        throw new MetamodelException(ElasticeamException.GENERAL_ERROR,
                "Duplicate locale name " + key + " in locale " + locale + ".");
    }
    if (key == null) {
        localeValues.inverse().remove(value);
    } else {
        if (localeValues.inverse().containsKey(value)) {
            localeValues.inverse().remove(value);
        }
        localeValues.put(key, value);
    }
}