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(int expectedKeys, int expectedValuesPerKey) 

Source Link

Document

Constructs an empty HashMultimap with enough capacity to hold the specified numbers of keys and values without rehashing.

Usage

From source file:org.trnltk.morphology.lexicon.RootMapGenerator.java

public HashMultimap<String, ? extends Root> generate(Collection<? extends Root> allRoots) {
    final HashMultimap<String, Root> map = HashMultimap.create(allRoots.size(), 2);
    for (Root root : allRoots) {
        final String rootStr = root.getSequence().getUnderlyingString();
        map.put(rootStr, root);/*from   w ww  .j  a  va 2s.c om*/
    }

    return map;
}

From source file:uk.ac.ebi.mdk.domain.entity.AssociationMap.java

private AssociationMap(int capacity) {
    this.associations = HashMultimap.create(capacity, 4);
}

From source file:edu.uci.ics.sourcerer.tools.java.component.identifier.stats.SourcedFqnNode.java

protected SourcedFqnNode(String name, SourcedFqnNode parent) {
    super(name, parent);
    sources = HashMultimap.create(Source.values().length, 5);
}

From source file:com.continuuity.loom.scheduler.dag.TaskDag.java

public TaskDag() {
    this.nodes = Sets.newHashSet();
    this.edges = HashMultimap.create(100, 3);
}

From source file:cuchaz.enigma.translation.Translator.java

default <K extends Translatable, V extends Translatable> Multimap<K, V> translate(Multimap<K, V> translatable) {
    Multimap<K, V> result = HashMultimap.create(translatable.size(), 1);
    for (Map.Entry<K, Collection<V>> entry : translatable.asMap().entrySet()) {
        result.putAll(translate(entry.getKey()), translate(entry.getValue()));
    }/*from   w  w w. j av  a  2 s. co  m*/
    return result;
}

From source file:edu.tum.cs.vis.model.uima.analyser.ComplexHandleAnalyser.java

/**
 * Tries to find complex handle by region growing. Neighboring annotations are combined if their
 * angle is smaller than 180 degree to form a convex handle.
 * /*  www .ja v  a2  s .  c o m*/
 * @param cas
 *            MeshCas
 * @param pa
 *            Annotation from where to start region growing.
 * @param alreadyAdded
 *            Map of already added annotations and their complex handle
 * @return the new complex handle
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
private static ComplexHandleAnnotation regionGrowAnnotation(MeshCas cas, PrimitiveAnnotation pa,
        HashMap<PrimitiveAnnotation, ComplexHandleAnnotation> alreadyAdded) {
    Set<PrimitiveAnnotation> neighbors = pa.getNeighborAnnotations(cas, PrimitiveAnnotation.class);
    ComplexHandleAnnotation newHandle = null;
    if (alreadyAdded.containsKey(pa)) {
        newHandle = alreadyAdded.get(pa);
    }

    for (PrimitiveAnnotation n : neighbors) {
        if (n instanceof SphereAnnotation && ((SphereAnnotation) n).isConcave())
            continue;
        if (n instanceof ConeAnnotation && ((ConeAnnotation) n).isConcave())
            continue;

        HashMultimap<Triangle, Triangle> edgeTriangles = HashMultimap
                .create(n.getMesh().getTriangles().size() / 3, 2);
        Set<Vertex> edgeVertices = new HashSet<Vertex>();
        pa.getNeighborEdge(cas, n, edgeVertices, edgeTriangles);

        // check for a triangle pair where the angle between triangle normals is bigger or equal
        // to 180 degree.
        for (Triangle t : edgeTriangles.keySet()) {
            Set<Triangle> partnerSet = edgeTriangles.get(t);

            for (Triangle partner : partnerSet) {

                float dot = t.getNormalVector().dot(partner.getNormalVector());
                // allow a small error
                if (dot > ComplexHandleAnnotation.DOT_NORMAL_TOLERANCE) {
                    // angle is smaller than 180 degree
                    continue;
                }
                // we have found two triangles, let's merge the two annotations into a complex
                // handle

                if (newHandle == null) {
                    newHandle = new ComplexHandleAnnotation(cas.getModel());
                    alreadyAdded.put(pa, newHandle);
                    newHandle.addAnnotation(pa);
                }

                // first check if neighbor annotation is already a part of complex handle
                if (alreadyAdded.containsKey(n)) {
                    ComplexHandleAnnotation neighborHandle = alreadyAdded.get(n);
                    if (neighborHandle == newHandle)
                        continue;
                    if (!newHandle.allowMerge(neighborHandle))
                        continue;
                    newHandle.merge(neighborHandle);
                    alreadyAdded.remove(n);

                    // update reference list
                    for (PrimitiveAnnotation an : neighborHandle.getPrimitiveAnnotations()) {
                        alreadyAdded.put(an, newHandle);
                    }
                } else {
                    newHandle.addAnnotation(n);
                }
                alreadyAdded.put(n, newHandle);
                break;
            }
        }
    }

    return newHandle;
}

From source file:uk.ac.ebi.mnb.dialog.tools.ChokePoint.java

public void actionPerformed(ActionEvent ae) {

    int n = DefaultReconstructionManager.getInstance().active().getMetabolome().size();

    final Multimap<Metabolite, MetabolicReaction> reactants = HashMultimap.create(n, 5);
    final Multimap<Metabolite, MetabolicReaction> products = HashMultimap.create(n, 5);

    // count number of reactions producing and consuming each metabolite
    for (final MetabolicReaction rxn : getSelection().get(MetabolicReaction.class)) {

        for (final MetabolicParticipant reactant : rxn.getReactants()) {
            Metabolite metabolite = reactant.getMolecule();
            reactants.put(metabolite, rxn);
        }//w w  w.  jav  a 2  s  .  c  o  m

        for (final MetabolicParticipant product : rxn.getProducts()) {
            Metabolite metabolite = product.getMolecule();
            products.put(metabolite, rxn);
        }

    }

    final List<MetabolicReaction> chokePoints = new ArrayList<MetabolicReaction>();

    // unique consumed metabolites
    for (Entry<Metabolite, Collection<MetabolicReaction>> entry : reactants.asMap().entrySet()) {
        if (entry.getValue().size() == 1) {
            Metabolite metabolite = entry.getKey();
            // use a better annotation
            Annotation note = new Note("Reaction uniquely consumes " + metabolite.getName() + " ("
                    + metabolite.getIdentifier() + ")");
            entry.getValue().iterator().next().addAnnotation(note);
            chokePoints.addAll(entry.getValue());
        }
    }

    // unique produced metabolites
    for (Entry<Metabolite, Collection<MetabolicReaction>> entry : products.asMap().entrySet()) {
        if (entry.getValue().size() == 1) {
            Metabolite metabolite = entry.getKey();
            // use a better annotation
            Annotation note = new Note("Reaction uniquely produces " + metabolite.getName() + " ("
                    + metabolite.getIdentifier() + ")");
            entry.getValue().iterator().next().addAnnotation(note);
            chokePoints.addAll(entry.getValue());
        }
    }

    LOGGER.debug("identified " + chokePoints.size() + " choke points");

    EntityMap map = new EntityMap(DefaultEntityFactory.getInstance());
    map.addAll(chokePoints);
    setSelection(map);

}

From source file:data.MVDataEntry.java

/**
 * Build a fresh empty MVDataEntry with hints about expected attr/values count.
 * @param key Unique key identifying this entry
 */// w  ww  .  ja  v a  2s  .co m
public MVDataEntry(String key, int expectedAttribs, int expectedValuesPerAttrib) {
    if (key == null) {
        throw new IllegalArgumentException("key must be non-null");
    }
    this.key = key;
    this.attrValPairs = HashMultimap.create(expectedAttribs, expectedValuesPerAttrib);
}

From source file:com.bigdata.dastor.locator.AbstractReplicationStrategy.java

/**
 * returns multimap of {live destination: ultimate targets}, where if target is not the same
 * as the destination, it is a "hinted" write, and will need to be sent to
 * the ultimate target when it becomes alive again.
 */// ww w  .j a v a 2 s.  c om
public Multimap<InetAddress, InetAddress> getHintedEndpoints(String table, Collection<InetAddress> targets) {
    Multimap<InetAddress, InetAddress> map = HashMultimap.create(targets.size(), 1);

    IEndPointSnitch endPointSnitch = DatabaseDescriptor.getEndPointSnitch(table);

    // first, add the live endpoints
    for (InetAddress ep : targets) {
        if (FailureDetector.instance.isAlive(ep))
            map.put(ep, ep);
    }

    // if everything was alive or we're not doing HH on this keyspace, stop with just the live nodes
    if (map.size() == targets.size() || !StorageProxy.isHintedHandoffEnabled())
        return map;

    // assign dead endpoints to be hinted to the closest live one, or to the local node
    // (since it is trivially the closest) if none are alive.  This way, the cost of doing
    // a hint is only adding the hint header, rather than doing a full extra write, if any
    // destination nodes are alive.
    //
    // we do a 2nd pass on targets instead of using temporary storage,
    // to optimize for the common case (everything was alive).
    InetAddress localAddress = FBUtilities.getLocalAddress();
    for (InetAddress ep : targets) {
        if (map.containsKey(ep))
            continue;

        InetAddress destination = map.isEmpty() ? localAddress
                : endPointSnitch.getSortedListByProximity(localAddress, map.keySet()).get(0);
        map.put(destination, ep);
    }

    return map;
}