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

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

Introduction

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

Prototype

@Override
@Nullable
V put(@Nullable K key, @Nullable V value);

Source Link

Usage

From source file:com.opengamma.bbg.util.BloombergDataUtils.java

private static <TKey, TValue> void changeKey(final TKey oldKey, final TKey newKey,
        final BiMap<TKey, TValue> map) {
    //REVIEW simon : is it ok that we discard duplicates here
    final TValue oldValue = map.remove(oldKey);
    map.put(newKey, oldValue);
}

From source file:org.jpmml.evaluator.GeneralRegressionModelEvaluator.java

static private BiMap<FieldName, Predictor> parsePredictorRegistry(PredictorList predictorList) {
    BiMap<FieldName, Predictor> result = HashBiMap.create();

    List<Predictor> predictors = predictorList.getPredictors();
    for (Predictor predictor : predictors) {
        result.put(predictor.getName(), predictor);
    }//  w w  w. j  ava 2s .c  om

    return result;
}

From source file:com.wolvereness.overmapped.MembersSubRoutine.java

/**
 *
 * @return true if cache does not contain original (or similarly interpreted as attempted to update as it has not attempted to do so thus far)
 *//*  w  w w. ja v a 2s . co  m*/
private static boolean updateMember(final Store store, final BiMap<Signature, Signature> signatureMaps,
        final BiMap<Signature, Signature> inverseSignatureMaps, final Signature.MutableSignature signature,
        final String oldName, final String newName, final String description, final String clazz,
        final Map<String, String> classes, final String originalDescription, final String originalClass)
        throws MojoFailureException {
    if (!store.searchCache.add(clazz))
        return false;

    signature.update(clazz, oldName, description);

    final Signature originalSignature = inverseSignatureMaps.get(signature);
    if (originalSignature != null) {
        try {
            signatureMaps.put(originalSignature, signature.forElementName(newName));
        } catch (final IllegalArgumentException ex) {
            final MojoFailureException mojoEx = new MojoFailureException(String.format(
                    "Cannot map %s (currently %s) to pre-existing member %s (in class %s)", originalSignature,
                    signature, signature.forElementName(newName), classes.get(clazz)));
            mojoEx.initCause(ex);
            throw mojoEx;
        }
    } else {
        store.instance.missingAction.actMember(store.instance.getLog(), originalClass, oldName, newName,
                originalDescription, inverseSignatureMaps);
    }
    return true;
}

From source file:org.datacleaner.job.JaxbJobWriter.java

private static String getColumnId(InputColumn<?> inputColumn, BiMap<InputColumn<?>, String> columnMappings) {
    if (inputColumn == null) {
        throw new IllegalArgumentException("InputColumn cannot be null");
    }//from w w w .  ja  v a2  s. c  o m

    String id = columnMappings.get(inputColumn);
    if (id == null) {
        final String baseColumnId = getBaseColumnId(inputColumn);
        id = baseColumnId;
        int addition = 1;
        while (columnMappings.containsValue(id)) {
            addition++;
            id = baseColumnId + addition;
        }
        columnMappings.put(inputColumn, id);
    }
    return id;
}

From source file:com.palantir.atlasdb.keyvalue.impl.StaticTableMappingService.java

@Override
protected BiMap<TableReference, String> readTableMap() {
    Set<String> tables = kv.getAllTableNames();
    BiMap<TableReference, String> ret = HashBiMap.create();
    for (String table : tables) {
        ret.put(getTableReference(table), table);
    }//from  w  ww. j a  va 2  s .c o  m

    return ret;
}

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: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++);
                }/* w w w.j a  va  2s.co m*/
            }
        }
    }

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

From source file:com.google.javascript.jscomp.IdMappingUtil.java

/**
 * The expected format looks like this:/* ww  w.  j a  v  a2s  . c om*/
 *
 * <p>[generatorName1]
 * someId1:someFile:theLine:theColumn
 * ...
 *
 * <p>[[generatorName2]
 * someId2:someFile:theLine:theColumn]
 * ...
 *
 * <p>The returned data is grouped by generator name (the map key). The inner map provides
 * mappings from id to content (file, line and column info). In a glimpse, the structure is
 * Map<geneartor name, BiMap<id, value>>.
 *
 * <p>@throws IllegalArgumentException malformed input where there it 1) has duplicate generator
 *     name, or 2) the line has no ':' for id and its content.
 */
public static Map<String, BiMap<String, String>> parseSerializedIdMappings(String idMappings) {
    if (Strings.isNullOrEmpty(idMappings)) {
        return Collections.emptyMap();
    }

    Map<String, BiMap<String, String>> resultMap = new HashMap<>();
    BiMap<String, String> currentSectionMap = null;

    int lineIndex = 0;
    for (String line : LINE_SPLITTER.split(idMappings)) {
        lineIndex++;
        if (line.isEmpty()) {
            continue;
        }
        if (line.charAt(0) == '[') {
            String currentSection = line.substring(1, line.length() - 1);
            currentSectionMap = resultMap.get(currentSection);
            if (currentSectionMap == null) {
                currentSectionMap = HashBiMap.create();
                resultMap.put(currentSection, currentSectionMap);
            } else {
                throw new IllegalArgumentException(SimpleFormat.format(
                        "Cannot parse id map: %s\n Line: $s, lineIndex: %s", idMappings, line, lineIndex));
            }
        } else {
            int split = line.indexOf(':');
            if (split != -1) {
                String name = line.substring(0, split);
                String location = line.substring(split + 1, line.length());
                currentSectionMap.put(name, location);
            } else {
                throw new IllegalArgumentException(SimpleFormat.format(
                        "Cannot parse id map: %s\n Line: $s, lineIndex: %s", idMappings, line, lineIndex));
            }
        }
    }
    return resultMap;
}

From source file:buildcraft.transport.network.PacketGateExpansionMap.java

@Override
public void readData(ByteBuf data) {
    int numEntries = data.readByte();
    BiMap<Byte, String> map = HashBiMap.create(numEntries);
    for (int i = 0; i < numEntries; i++) {
        byte id = data.readByte();
        String identifier = Utils.readUTF(data);
        map.put(id, identifier);
    }//from  ww w . ja  v a  2s .  c  o  m
    GateExpansions.setClientMap(map);
}

From source file:com.cloudera.oryx.computation.common.summary.Summary.java

public Map<Integer, BiMap<String, Integer>> getCategoryLevelsMapping() {
    Map<Integer, BiMap<String, Integer>> levelsMap = Maps.newHashMap();
    for (int i = 0; i < stats.size(); i++) {
        if (stats.get(i) != null && !stats.get(i).isNumeric()) {
            List<String> levels = stats.get(i).getLevels();
            BiMap<String, Integer> bm = HashBiMap.create(levels.size());
            for (int j = 0; j < levels.size(); j++) {
                bm.put(levels.get(j), j);
            }//  w  w w  . ja va2 s.  c om
            levelsMap.put(i, bm);
        }
    }
    return levelsMap;
}