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.bigdata.dastor.locator.TokenMetadata.java

/**
 * Create a copy of TokenMetadata with only tokenToEndPointMap. That is, pending ranges,
 * bootstrap tokens and leaving endpoints are not included in the copy.
 *//*from w  w  w.j  av a 2  s.c  om*/
public TokenMetadata cloneOnlyTokenMap() {
    lock.readLock().lock();
    try {
        return new TokenMetadata(HashBiMap.create(tokenToEndPointMap));
    } finally {
        lock.readLock().unlock();
    }
}

From source file:com.google.api.tools.framework.processors.merger.Merger.java

/**
 * Returns the given config aspects as list of group of aspects in merge dependency order.
 * This performs a 'longest path layering' algorithm by placing aspects at different levels
 * (layers). First place all sink nodes at level-1 and then each node n is placed at level
 * level-p+1, where p is the longest path from n to sink. Aspects in each level are independent of
 * each other and can only depend on aspects in lower levels.
 * Detailed algorithm : 13.3.2 Layer Assignment Algorithms :
 * https://cs.brown.edu/~rt/gdhandbook/chapters/hierarchical.pdf
 *//* w  ww. ja va 2 s  .  c  om*/
private static List<Set<ConfigAspect>> sortForMerge(Iterable<ConfigAspect> aspects) {
    Map<Class<? extends ConfigAspect>, ConfigAspect> aspectsByType = HashBiMap
            .create(Maps.toMap(aspects, new Function<ConfigAspect, Class<? extends ConfigAspect>>() {
                @Override
                public Class<? extends ConfigAspect> apply(ConfigAspect aspect) {
                    return aspect.getClass();
                }
            })).inverse();
    List<Class<? extends ConfigAspect>> visiting = Lists.newArrayList();
    Map<ConfigAspect, Integer> aspectsToLevel = Maps.newLinkedHashMap();
    for (ConfigAspect aspect : aspects) {
        assignLevelToAspect(aspect, aspectsByType, visiting, aspectsToLevel);
    }
    Map<Integer, Set<ConfigAspect>> aspectsByLevel = Maps.newLinkedHashMap();
    for (ConfigAspect aspect : aspectsToLevel.keySet()) {
        Integer aspectLevel = aspectsToLevel.get(aspect);
        if (!aspectsByLevel.containsKey(aspectLevel)) {
            aspectsByLevel.put(aspectLevel, Sets.<ConfigAspect>newLinkedHashSet());
        }
        aspectsByLevel.get(aspectLevel).add(aspect);
    }
    List<Set<ConfigAspect>> aspectListByLevels = Lists.newArrayList();
    for (int level = 1; level <= aspectsByLevel.size(); ++level) {
        aspectListByLevels.add(aspectsByLevel.get(level));
    }
    return aspectListByLevels;
}

From source file:fi.hsl.parkandride.back.RequestLogDao.java

private BiMap<Long, String> getAllUrlPatterns() {
    return HashBiMap.create(
            queryFactory.from(qRequestLogUrl).transform(groupBy(qRequestLogUrl.id).as(qRequestLogUrl.url)));
}

From source file:jenjinn.ui.chessboard.ChessBoard.java

private void rotatePoints() {
    final BiMap<Point2D, Sq> newMap = HashBiMap.create(64);
    final PointTransform rotate = getRotationTransform();

    for (final Point2D p : squareLocations.keySet()) {

        newMap.put(rotate.transform(p), squareLocations.get(p));
    }// w  w  w . j  a  v  a 2s.c  o  m

    squareLocations = newMap;
}

From source file:fi.hsl.parkandride.back.RequestLogDao.java

private BiMap<Long, String> getAllSources() {
    return HashBiMap.create(queryFactory.from(qRequestLogSource)
            .transform(groupBy(qRequestLogSource.id).as(qRequestLogSource.source)));
}

From source file:org.apache.cassandra.locator.TokenMetadata.java

/**
 * Create a copy of TokenMetadata with only tokenToEndpointMap. That is, pending ranges,
 * bootstrap tokens and leaving endpoints are not included in the copy.
 *//*w  w  w  . ja  v a  2 s  . co m*/
public TokenMetadata cloneOnlyTokenMap() {
    lock.readLock().lock();
    try {
        return new TokenMetadata(HashBiMap.create(tokenToEndpointMap));
    } finally {
        lock.readLock().unlock();
    }
}

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
 *///  w  w w.  j a v  a 2s . c  om
public void registerHiddenStateNames(Map<String, Integer> stateNames) {
    if (stateNames != null) {
        hiddenStateNames = HashBiMap.create(stateNames);
    }
}

From source file:mvm.rya.indexing.external.tupleSet.AccumuloIndexSet.java

private String prefixToOrder(String order) {

    Map<String, String> invMap = HashBiMap.create(this.getTableVarMap()).inverse();
    String[] temp = order.split("\u0000");

    for (int i = 0; i < temp.length; i++) {
        temp[i] = this.getTableVarMap().get(temp[i]);
    }// ww w .  ja v a 2  s .co  m

    order = Joiner.on("\u0000").join(temp);

    for (String s : varOrder) {
        if (s.startsWith(order)) {

            temp = s.split("\u0000");

            for (int i = 0; i < temp.length; i++) {
                temp[i] = invMap.get(temp[i]);
            }
            return Joiner.on("\u0000").join(temp);
        }
    }
    throw new NoSuchElementException("Order is not a prefix of any locality group value!");
}

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

/**
 * This method sets the coefficients/ the value of a variable to undefined.
 *//*from www  .j  a  v a2 s .c  om*/
public OctagonState forget(MemoryLocation pVariableName) {
    int varIdx = getVariableIndexFor(pVariableName);

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

    return new OctagonState(octagonManager.forget(octagon, varIdx), HashBiMap.create(variableToIndexMap),
            new HashMap<>(variableToTypeMap), logger);
}

From source file:org.batoo.jpa.core.impl.nativeQuery.NativeQuery.java

/**
 * Transforms the column names for idField Map using a field,column-name map
 * //from w w w . ja v a  2  s.  co  m
 * @return
 * @param idFields
 * @param _fieldMap
 * @since $version
 */
private HashMap<AbstractColumn, String> getIdFieldTransformed(HashMap<AbstractColumn, String> idFields,
        HashMap<String, Object> fieldIdMap) {
    if (fieldIdMap == null) {
        return idFields;
    }
    final HashMap<AbstractColumn, String> idFieldsMod = Maps.newHashMap();
    final BiMap<String, AbstractColumn> inverse = HashBiMap.create(idFields).inverse();
    for (final String field : idFields.values()) {
        final AbstractColumn column = inverse.get(field);
        final String _field = column.getMapping().getName();

        final Object colmVal = fieldIdMap.get(_field);

        if (colmVal != null && colmVal.toString() != null) {
            idFieldsMod.put(column, colmVal.toString());
        } else {
            idFieldsMod.put(column, _field);
        }

    }
    return idFieldsMod;
}