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

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

Introduction

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

Prototype

public static <E> LinkedHashMultiset<E> create() 

Source Link

Document

Creates a new, empty LinkedHashMultiset using the default initial capacity.

Usage

From source file:com.github.fhirschmann.clozegen.lib.multiset.ReadMultisets.java

/**
 * Parses frequencies from a URL. The subject and the count for a subject
 * need to be delimited by {@code \t} with the count on the right-hand
 * side.//from w  w  w .j  a  v  a 2s  .  co m
 *
 * <p>For example, assuming your frequency file contains the following lines:
 * <pre>
 * one of the   200
 * because of the  100
 * members of the   50
 * </pre>
 * Then getting the count of "because of the" will yield 100.
 *
 * @param url the URL to the file to parse
 * @param charset the charset of the file
 * @return the parsed frequencies
 * @throws IOException on errors reading from the file
 */
public static Multiset<String> parseMultiset(final URL url, final Charset charset) throws IOException {
    final Multiset<String> multiset = LinkedHashMultiset.create();
    final List<String> lines = Resources.readLines(checkNotNull(url), charset);

    for (String line : lines) {
        final String[] tokens = line.split("\t");
        multiset.add(tokens[0], Integer.parseInt(tokens[1]));
    }

    return multiset;
}

From source file:com.github.rinde.logistics.pdptw.mas.route.RandomRoutePlanner.java

/**
 * Creates a random route planner using the specified random seed.
 * @param seed The random seed./* ww  w.j a  va  2s . c om*/
 */
public RandomRoutePlanner(long seed) {
    LOGGER.info("constructor {}", seed);
    assignedParcels = LinkedHashMultiset.create();
    current = Optional.absent();
    rng = new RandomAdaptor(new MersenneTwister(seed));
}

From source file:com.github.nmorel.gwtjackson.guava.client.deser.MultisetJsonDeserializer.java

@Override
protected Multiset<T> newCollection() {
    return LinkedHashMultiset.create();
}

From source file:com.github.nmorel.gwtjackson.guava.client.deser.LinkedHashMultisetJsonDeserializer.java

@Override
protected LinkedHashMultiset<T> newCollection() {
    return LinkedHashMultiset.create();
}

From source file:it.units.malelab.ege.ge.mapper.SGEMapper.java

public Node<T> map(SGEGenotype<T> genotype, Map<String, Object> report) throws MappingException {
    int[] usages = new int[genotype.size()];
    //map//from   w  ww .ja v  a2s . com
    Multiset<Pair<T, Integer>> expandedSymbols = LinkedHashMultiset.create();
    Node<Pair<T, Integer>> tree = new Node<>(nonRecursiveGrammar.getStartingSymbol());
    while (true) {
        Node<Pair<T, Integer>> nodeToBeReplaced = null;
        for (Node<Pair<T, Integer>> node : tree.leafNodes()) {
            if (nonRecursiveGrammar.getRules().keySet().contains(node.getContent())) {
                nodeToBeReplaced = node;
                break;
            }
        }
        if (nodeToBeReplaced == null) {
            break;
        }
        //get codon
        List<Integer> values = genotype.getGenes().get(nodeToBeReplaced.getContent());
        int value = values.get(expandedSymbols.count(nodeToBeReplaced.getContent()));
        int usageIndex = geneFirstIndexes.get(nodeToBeReplaced.getContent())
                + expandedSymbols.count(nodeToBeReplaced.getContent());
        usages[usageIndex] = usages[usageIndex] + 1;
        List<List<Pair<T, Integer>>> options = nonRecursiveGrammar.getRules()
                .get(nodeToBeReplaced.getContent());
        int optionIndex = value;
        //add children
        for (Pair<T, Integer> symbol : options.get(optionIndex)) {
            Node<Pair<T, Integer>> newChild = new Node<>(symbol);
            nodeToBeReplaced.getChildren().add(newChild);
        }
        expandedSymbols.add(nodeToBeReplaced.getContent());
    }
    report.put(BIT_USAGES_INDEX_NAME, usages);
    return transform(tree);
}

From source file:org.eclipse.sirius.tree.business.internal.dialect.common.tree.TreeItemContainerChildSupport.java

@Override
public void reorderChilds(Iterable<CreatedOutput> outDesc) {
    final Multiset<TreeItemMapping> subMappings = LinkedHashMultiset.create();
    Set<TreeItemMapping> mappings = new HashSet<TreeItemMapping>();
    final Map<EObject, CreatedOutput> outputToItem = Maps.newHashMap();
    for (CreatedOutput createdOutput : outDesc) {
        EObject createdElement = createdOutput.getCreatedElement();
        outputToItem.put(createdElement, createdOutput);
        if (createdElement instanceof DTreeItem) {
            DTreeItem createdDTreeItem = (DTreeItem) createdElement;
            TreeItemMapping actualMapping = createdDTreeItem.getActualMapping();
            subMappings.add(actualMapping);
            mappings.add(actualMapping);
        }//  ww  w  .j a  v  a  2 s  . com
    }

    // Does not need to sort DTreeItem according to their mapping if there
    // is only one mapping
    if (mappings.size() > 1) {

        // Counts subMappings to correctly sort tree items regarding mapping
        // order (items have been created regarding the semantic candidates
        // order)
        int startIndex = 0;
        final Map<TreeItemMapping, Integer> startIndexes = Maps.newHashMap();
        for (TreeItemMapping itemMapping : subMappings) {
            startIndexes.put(itemMapping, startIndex);
            startIndex += subMappings.count(itemMapping);
        }

        Function<DTreeItem, Integer> getNewIndex = new Function<DTreeItem, Integer>() {

            @Override
            public Integer apply(DTreeItem from) {
                // init with element count : elements with unknown mapping
                // will
                // be placed at
                // the end.
                int index = outputToItem.size();
                TreeItemMapping itemMapping = from.getActualMapping();
                if (itemMapping != null && startIndexes.containsKey(itemMapping)) {
                    index = startIndexes.get(itemMapping);
                }

                CreatedOutput createdOutput = outputToItem.get(from);
                if (createdOutput != null) {
                    return index + createdOutput.getNewIndex();
                }
                return -1;
            }
        };

        ECollections.sort(container.getOwnedTreeItems(), Ordering.natural().onResultOf(getNewIndex));
    }
}

From source file:org.sonar.server.es.request.ProxyBulkRequestBuilder.java

@Override
public String toString() {
    StringBuilder message = new StringBuilder();
    message.append("Bulk[");
    Multiset<BulkRequestKey> groupedRequests = LinkedHashMultiset.create();
    for (int i = 0; i < request.requests().size(); i++) {
        ActionRequest<?> item = request.requests().get(i);
        String requestType;/*from w  w w .  j  a va 2s.c  om*/
        String index;
        String docType;
        if (item instanceof IndexRequest) {
            IndexRequest request = (IndexRequest) item;
            requestType = "index";
            index = request.index();
            docType = request.type();
        } else if (item instanceof UpdateRequest) {
            UpdateRequest request = (UpdateRequest) item;
            requestType = "update";
            index = request.index();
            docType = request.type();
        } else if (item instanceof DeleteRequest) {
            DeleteRequest request = (DeleteRequest) item;
            requestType = "delete";
            index = request.index();
            docType = request.type();
        } else {
            // Cannot happen, not allowed by BulkRequest's contract
            throw new IllegalStateException("Unsupported bulk request type: " + item.getClass());
        }
        groupedRequests.add(new BulkRequestKey(requestType, index, docType));
    }

    Set<Multiset.Entry<BulkRequestKey>> entrySet = groupedRequests.entrySet();
    int size = entrySet.size();
    int current = 0;
    for (Multiset.Entry<BulkRequestKey> requestEntry : entrySet) {
        message.append(requestEntry.getCount()).append(" ").append(requestEntry.getElement().toString());
        current++;
        if (current < size) {
            message.append(", ");
        }
    }

    message.append("]");
    return message.toString();
}

From source file:org.splevo.ui.sourceconnection.handler.CopyContainingFilenameHandler.java

/**
 * Collect the file paths of the variation points of the selected elements.
 *
 * Each variation point is registered only once, even if several variants of the same variation
 * point have been selected./*  w w  w. j  ava 2 s. co  m*/
 *
 * @param selection
 *            The current selection
 * @return The multi-set of variation point file paths.
 */
private LinkedHashMultiset<String> collectFilePaths(IStructuredSelection selection) {
    LinkedHashMultiset<String> filePaths = LinkedHashMultiset.create();

    Set<VariationPoint> vps = Sets.newLinkedHashSet();

    for (Object selectedItem : selection.toList()) {
        if (selectedItem instanceof Variant) {
            vps.add(((Variant) selectedItem).getVariationPoint());
        } else if (selectedItem instanceof VariationPoint) {
            vps.add((VariationPoint) selectedItem);
        }
    }

    for (VariationPoint vp : vps) {
        if (vp != null) {
            filePaths.add(getFile(vp));
        }
    }

    return filePaths;
}

From source file:org.sonar.plugins.issuesdensity.batch.WeightedIssuesDecorator.java

@Override
public void decorate(Resource resource, DecoratorContext context) {
    double value = 0.0;
    Multiset<String> distribution = LinkedHashMultiset.create();

    for (String severity : Severity.ALL) {
        Measure measure = context.getMeasure(severityToIssueMetric(severity));
        if (measure != null && MeasureUtils.hasValue(measure)) {
            distribution.add(severity, measure.getIntValue());
            double add = weightsBySeverity.get(severity) * measure.getIntValue();
            value += add;// w  w  w.  j  a  va 2  s . c  o m
        }
    }

    String distributionFormatted = KeyValueFormat.format(distribution);
    // SONAR-4987 We should store an empty string for the distribution value
    Measure measure = new Measure(IssuesDensityMetrics.WEIGHTED_ISSUES, value,
            Strings.emptyToNull(distributionFormatted));
    context.saveMeasure(measure);
}

From source file:com.google.inject.internal.WeakKeySet.java

public void add(Key<?> key, State state, Object source) {
    if (backingMap == null) {
        backingMap = Maps.newHashMap();/* w  w  w .j  a v  a 2  s  .c  o  m*/
    }
    // if it's an instanceof Class, it was a JIT binding, which we don't
    // want to retain.
    if (source instanceof Class || source == SourceProvider.UNKNOWN_SOURCE) {
        source = null;
    }
    BlacklistKey blacklistKey = new BlacklistKey(key);
    Multiset<Object> sources = backingMap.get(blacklistKey);
    if (sources == null) {
        sources = LinkedHashMultiset.create();
        backingMap.put(blacklistKey, sources);
    }
    Object convertedSource = Errors.convert(source);
    sources.add(convertedSource);

    // Avoid all the extra work if we can.
    if (state.parent() != State.NONE) {
        Set<KeyAndSource> keyAndSources = evictionCache.getIfPresent(state);
        if (keyAndSources == null) {
            evictionCache.put(state, keyAndSources = Sets.newHashSet());
        }
        keyAndSources.add(new KeyAndSource(blacklistKey, convertedSource));
    }
}