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

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

Introduction

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

Prototype

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

Source Link

Document

Creates a new, empty HashMultimap with the default initial capacities.

Usage

From source file:org.apache.jclouds.profitbricks.rest.binder.volume.CreateSnapshotRequestBinder.java

@Inject
CreateSnapshotRequestBinder(@Provider Supplier<URI> endpointSupplier) {
    super("snapshot", null, endpointSupplier);
    this.formMap = HashMultimap.create();
}

From source file:eu.interedition.collatex.util.ParallelSegmentationApparatus.java

public static void generate(VariantGraphRanking ranking, GeneratorCallback callback) {

    callback.start();/*from ww w . java 2s  .  co  m*/

    final Set<Witness> allWitnesses = ranking.witnesses();
    for (Iterator<Map.Entry<Integer, Collection<VariantGraph.Vertex>>> rowIt = ranking.getByRank().asMap()
            .entrySet().iterator(); rowIt.hasNext();) {
        final Map.Entry<Integer, Collection<VariantGraph.Vertex>> row = rowIt.next();
        final int rank = row.getKey();
        final Collection<VariantGraph.Vertex> vertices = row.getValue();

        if (vertices.size() == 1 && Iterables.getOnlyElement(vertices).tokens().isEmpty()) {
            // skip start and end vertex
            continue;
        }

        // spreading vertices with same rank according to their registered transpositions
        final Multimap<Integer, VariantGraph.Vertex> verticesByTranspositionRank = HashMultimap.create();
        for (VariantGraph.Vertex v : vertices) {
            int transpositionRank = 0;
            for (VariantGraph.Transposition transposition : v.transpositions()) {
                for (VariantGraph.Vertex tv : transposition) {
                    transpositionRank += (ranking.apply(tv).intValue() - rank);
                }
            }
            verticesByTranspositionRank.put(transpositionRank, v);
        }

        // render segments
        for (Iterator<Integer> transpositionRankIt = Ordering.natural()
                .immutableSortedCopy(verticesByTranspositionRank.keySet()).iterator(); transpositionRankIt
                        .hasNext();) {
            final Multimap<Witness, Token> tokensByWitness = HashMultimap.create();
            for (VariantGraph.Vertex v : verticesByTranspositionRank.get(transpositionRankIt.next())) {
                for (Token token : v.tokens()) {
                    tokensByWitness.put(token.getWitness(), token);
                }
            }

            final SortedMap<Witness, Iterable<Token>> cellContents = Maps.newTreeMap(Witness.SIGIL_COMPARATOR);
            for (Witness witness : allWitnesses) {
                cellContents.put(witness,
                        tokensByWitness.containsKey(witness)
                                ? Iterables.unmodifiableIterable(tokensByWitness.get(witness))
                                : Collections.<Token>emptySet());
            }

            callback.segment(cellContents);
        }
    }

    callback.end();
}

From source file:org.terasology.utilities.gson.SetMultimapTypeAdapter.java

@Override
public SetMultimap<String, V> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    SetMultimap<String, V> result = HashMultimap.create();
    JsonObject obj = json.getAsJsonObject();
    for (Map.Entry<String, JsonElement> entry : obj.entrySet()) {
        if (entry.getValue().isJsonArray()) {
            for (JsonElement item : entry.getValue().getAsJsonArray()) {
                result.put(entry.getKey(), context.<V>deserialize(item, valueType));
            }/*from   ww  w .  java2s.c  o  m*/
        } else {
            result.put(entry.getKey(), context.<V>deserialize(entry.getValue(), valueType));
        }
    }
    return result;
}

From source file:org.apache.jclouds.profitbricks.rest.binder.volume.RestoreSnapshotRequestBinder.java

@Inject
RestoreSnapshotRequestBinder(@Provider Supplier<URI> endpointSupplier) {
    super("snapshot", null, endpointSupplier);
    this.formMap = HashMultimap.create();
}

From source file:org.terasology.utilities.gson.MultimapHandler.java

@Override
public Multimap<String, V> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    Multimap<String, V> result = HashMultimap.create();
    JsonObject obj = json.getAsJsonObject();
    for (Map.Entry<String, JsonElement> entry : obj.entrySet()) {
        if (entry.getValue().isJsonArray()) {
            for (JsonElement item : entry.getValue().getAsJsonArray()) {
                result.put(entry.getKey(), context.<V>deserialize(item, valueType));
            }//from   ww w  . j a v a 2  s.com
        } else {
            result.put(entry.getKey(), context.<V>deserialize(entry.getValue(), valueType));
        }
    }
    return result;
}

From source file:grakn.core.graql.reasoner.utils.conversion.SchemaConceptConverter.java

/**
 * convert a given type to a map of relation types in which it can play roles
 * and the corresponding role types including entity type hierarchy
 * @param entryConcept to be converted//www .j  a  v a2 s .c  o  m
 * @return map of relation types in which it can play roles and the corresponding role types
 */
default Multimap<RelationType, Role> toRelationMultimap(T entryConcept) {
    Multimap<RelationType, Role> relationMap = HashMultimap.create();

    toCompatibleRoles(entryConcept)
            .forEach(role -> role.relations().forEach(rel -> relationMap.put(rel, role)));
    return relationMap;
}

From source file:com.github.restdriver.clientdriver.HttpRealRequest.java

public HttpRealRequest(HttpServletRequest request) {
    this.path = request.getPathInfo();
    this.method = Method.custom(request.getMethod().toUpperCase());
    this.params = HashMultimap.create();

    if (request.getQueryString() != null) {
        MultiMap<String> parameterMap = new MultiMap<String>();
        UrlEncoded.decodeTo(request.getQueryString(), parameterMap, "UTF-8", 0);
        for (Entry<String, String[]> paramEntry : parameterMap.toStringArrayMap().entrySet()) {
            String[] values = paramEntry.getValue();
            for (String value : values) {
                this.params.put(paramEntry.getKey(), value);
            }//ww w . ja va  2s.  c  o m
        }
    }

    headers = new HashMap<String, Object>();
    Enumeration<String> headerNames = request.getHeaderNames();
    if (headerNames != null) {
        while (headerNames.hasMoreElements()) {
            String headerName = headerNames.nextElement();
            headers.put(headerName.toLowerCase(), request.getHeader(headerName));
        }
    }

    try {
        this.bodyContent = IOUtils.toByteArray(request.getInputStream());
    } catch (IOException e) {
        throw new RuntimeException("Failed to read body of request", e);
    }

    this.bodyContentType = request.getContentType();
}

From source file:tachyon.worker.eviction.EvictLRU.java

@Override
public synchronized Pair<StorageDir, List<BlockInfo>> getDirCandidate(StorageDir[] storageDirs,
        Set<Integer> pinList, long requestSize) {
    List<BlockInfo> blockInfoList = new ArrayList<BlockInfo>();
    Map<StorageDir, Pair<Long, Long>> dir2LRUBlocks = new HashMap<StorageDir, Pair<Long, Long>>();
    HashMultimap<StorageDir, Long> dir2BlocksToEvict = HashMultimap.create();
    Map<StorageDir, Long> sizeToEvict = new HashMap<StorageDir, Long>();
    // If no StorageDir has enough space for the request size, continue; if no block can be evicted,
    // return null; and if eviction size plus free space of some StorageDir is larger than request
    // size, return the Pair of StorageDir and blockInfoList
    while (true) {
        // Get oldest block in StorageDir candidates
        Pair<StorageDir, Long> candidate = getLRUBlockCandidate(storageDirs, dir2LRUBlocks, dir2BlocksToEvict,
                pinList);//from   w w w.j a v a 2s.  c o m
        StorageDir dirCandidate = candidate.getFirst();
        long blockId = candidate.getSecond();
        long blockSize = 0;
        if (dirCandidate == null) {
            return null;
        } else {
            blockSize = dirCandidate.getBlockSize(blockId);
        }
        // Add info of the block to the list
        blockInfoList.add(new BlockInfo(dirCandidate, blockId, blockSize));
        dir2BlocksToEvict.put(dirCandidate, blockId);
        dir2LRUBlocks.remove(dirCandidate);
        long evictionSize;
        // Update eviction size for this StorageDir
        if (sizeToEvict.containsKey(dirCandidate)) {
            evictionSize = sizeToEvict.get(dirCandidate) + blockSize;
        } else {
            evictionSize = blockSize;
        }
        sizeToEvict.put(dirCandidate, evictionSize);
        if (evictionSize + dirCandidate.getAvailableBytes() >= requestSize) {
            return new Pair<StorageDir, List<BlockInfo>>(dirCandidate, blockInfoList);
        }
    }
}

From source file:com.github.explainable.labeler.policy.PolicyLabeler.java

private PolicyLabeler(List<View> securityViews) {
    Preconditions.checkNotNull(securityViews);

    this.hashedSecurityViews = HashMultimap.create();
    for (View securityView : securityViews) {
        this.hashedSecurityViews.put(securityView.bodyRelation(), securityView);
    }/*from   ww w. j a  va  2  s . co m*/
}

From source file:com.publictransitanalytics.scoregenerator.scoring.MappingScoreCard.java

public MappingScoreCard(final int taskCount, final SetMultimap<PointLocation, Sector> pointSectorMap) {
    super(taskCount);
    locations = Multimaps.synchronizedSetMultimap(HashMultimap.create());
    this.pointSectorMap = pointSectorMap;
}