Example usage for com.google.common.collect Multiset size

List of usage examples for com.google.common.collect Multiset size

Introduction

In this page you can find the example usage for com.google.common.collect Multiset size.

Prototype

int size();

Source Link

Document

Returns the number of elements in this collection.

Usage

From source file:uk.ac.ebi.intact.editor.services.admin.report.AssignmentReportService.java

@Transactional(value = "jamiTransactionManager", propagation = Propagation.REQUIRED, readOnly = true)
public List<AssignmentInfo> calculatePublicationReviewerAssignments(Date fromDate, Date toDate) {
    List<AssignmentInfo> assignmentInfos = new ArrayList<AssignmentInfo>();

    Query query = getIntactDao().getEntityManager()
            .createQuery("select distinct p from IntactPublication p join p.lifecycleEvents as e where "
                    + "e.cvEvent.shortName = :cvEvent and e.when >= :dateFrom and e.when <= :dateTo and e.note is null");
    query.setParameter("cvEvent", LifeCycleEventType.READY_FOR_CHECKING.shortLabel());
    query.setParameter("dateFrom", fromDate);
    query.setParameter("dateTo", new DateTime(toDate).plusDays(1).minusSeconds(1).toDate());

    List<IntactPublication> pubs = query.getResultList();

    Multiset<String> multiset = HashMultiset.create();

    for (IntactPublication pub : pubs) {
        for (LifeCycleEvent event : pub.getLifecycleEvents()) {
            multiset.add(pub.getCurrentReviewer().getLogin());
        }/*from  w ww  .java  2  s  .c o m*/
    }

    int total = multiset.size();

    for (String reviewer : multiset.elementSet()) {
        int count = multiset.count(reviewer);
        int percentage = count * 100 / total;
        assignmentInfos.add(new AssignmentInfo(reviewer, count, percentage));
    }

    return assignmentInfos;
}

From source file:uk.ac.ebi.intact.editor.services.admin.report.AssignmentReportService.java

@Transactional(value = "jamiTransactionManager", propagation = Propagation.REQUIRED, readOnly = true)
public List<AssignmentInfo> calculateComplexReviewerAssignments(Date fromDate, Date toDate) {
    List<AssignmentInfo> assignmentInfos = new ArrayList<AssignmentInfo>();

    Query query = getIntactDao().getEntityManager()
            .createQuery("select distinct c from IntactComplex c join c.lifecycleEvents as e where "
                    + "e.cvEvent.shortName = :cvEvent and e.when >= :dateFrom and e.when <= :dateTo and e.note is null");
    query.setParameter("cvEvent", LifeCycleEventType.READY_FOR_CHECKING.shortLabel());
    query.setParameter("dateFrom", fromDate);
    query.setParameter("dateTo", new DateTime(toDate).plusDays(1).minusSeconds(1).toDate());

    List<IntactComplex> complexes = query.getResultList();

    Multiset<String> multiset = HashMultiset.create();

    for (IntactComplex pub : complexes) {
        for (LifeCycleEvent event : pub.getLifecycleEvents()) {
            multiset.add(pub.getCurrentReviewer().getLogin());
        }//from  w w  w  .j a v  a2s. c  o m
    }

    int total = multiset.size();

    for (String reviewer : multiset.elementSet()) {
        int count = multiset.count(reviewer);
        int percentage = count * 100 / total;
        assignmentInfos.add(new AssignmentInfo(reviewer, count, percentage));
    }

    return assignmentInfos;
}

From source file:com.b2international.snowowl.snomed.reasoner.server.diff.DefaultNamespaceAndModuleAssigner.java

@Override
public void allocateRelationshipIdsAndModules(Multiset<String> conceptIds,
        final SnomedEditingContext editingContext) {
    if (conceptIds.isEmpty())
        return;//from  w w  w . j  ava  2  s.  c  o m

    ISnomedIdentifierService identifierService = getServiceForClass(ISnomedIdentifierService.class);
    String defaultNamespace = editingContext.getDefaultNamespace();
    reservedIds = identifierService.reserve(defaultNamespace, ComponentCategory.RELATIONSHIP,
            conceptIds.size());
    relationshipIds = reservedIds.iterator();
    defaultRelationshipModuleConcept = editingContext.getDefaultModuleConcept();
}

From source file:edu.cmu.lti.oaqa.baseqa.answer.score.scorers.ConceptTypeAnswerScorer.java

@Override
public Map<String, Double> score(JCas jcas, Answer answer) {
    Set<CandidateAnswerOccurrence> caos = TypeUtil.getCandidateAnswerVariants(answer).stream()
            .map(TypeUtil::getCandidateAnswerOccurrences).flatMap(Collection::stream).collect(toSet());
    Multiset<String> ctypes = HashMultiset.create();
    caos.stream().map(TypeUtil::annotationOffset).map(offset2ctypes::get).forEach(ctypes::addAll);
    ImmutableMap.Builder<String, Double> feat2value = ImmutableMap.builder();
    for (Multiset.Entry<String> entry : ctypes.entrySet()) {
        String type = "ctype-" + entry.getElement();
        feat2value.put(type + "/ratio", Scorer.safeDividedBy(entry.getCount(), ctypes.size()));
        feat2value.put(type + "/binary", 1.0);
    }/*from www  .ja v a 2  s  . c o m*/
    return feat2value.build();
}

From source file:bacter.model.ACGLikelihood.java

/**
 * Set leaf states in a likelihood core.
 * //from www .ja  va 2 s  . c  om
 * @param lhc       likelihood core object
 * @param patterns  leaf state patterns
 */
void setStates(LikelihoodCore lhc, Multiset<int[]> patterns) {

    for (Node node : acg.getExternalNodes()) {
        int[] states = new int[patterns.size()];
        int taxon = alignment.getTaxonIndex(node.getID());
        int i = 0;
        for (int[] pattern : patterns.elementSet()) {
            int code = pattern[taxon];
            int[] statesForCode = alignment.getDataType().getStatesForCode(code);
            if (statesForCode.length == 1)
                states[i] = statesForCode[0];
            else
                states[i] = code; // Causes ambiguous states to be ignored.

            i += 1;
        }
        lhc.setNodeStates(node.getNr(), states);
    }
}

From source file:bacter.model.ACGLikelihoodBeagle.java

/**
 * Set leaf states in a Beagle instance/*w  w  w. j  av a  2s.  co m*/
 * 
 * @param beagle beagle instance object
 * @param patterns leaf state patterns
 */
void setStates(Beagle beagle, Multiset<int[]> patterns) {

    for (Node node : acg.getExternalNodes()) {
        int[] states = new int[patterns.size()];
        int taxon = alignment.getTaxonIndex(node.getID());
        int i = 0;
        for (int[] pattern : patterns.elementSet()) {
            //                int code = pattern[taxon];
            //                int[] statesForCode = alignment.getDataType().getStatesForCode(code);
            //                if (statesForCode.length==1)
            //                    states[i] = statesForCode[0];
            //                else
            //                    states[i] = code; // Causes ambiguous states to be ignored.
            states[i] = pattern[taxon];

            i += 1;
        }
        beagle.setTipStates(node.getNr(), states);
    }
}

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

private void flushWrites(Multiset<String> writes, Set<String> clears) {
    if (writes.isEmpty() && clears.isEmpty()) {
        log.debug("No writes to flush");
        return;//from   w  w  w .j av  a  2 s.  c  o m
    }

    log.debug("Flushing stats for {} writes and {} clears", writes.size(), clears.size());
    log.trace("Flushing writes: {}", writes);
    log.trace("Flushing clears: {}", clears);
    try {
        Set<String> tableNames = Sets.difference(writes.elementSet(), clears);
        Iterable<byte[]> rows = Collections2.transform(tableNames, Functions
                .compose(Persistables.persistToBytesFunction(), SweepPriorityRow.fromFullTableNameFun()));
        Map<Cell, Value> oldWriteCounts = delegate().getRows(SWEEP_PRIORITY_TABLE, rows,
                SweepPriorityTable.getColumnSelection(SweepPriorityNamedColumn.WRITE_COUNT), Long.MAX_VALUE);
        Map<Cell, byte[]> newWriteCounts = Maps.newHashMapWithExpectedSize(writes.elementSet().size());
        byte[] col = SweepPriorityNamedColumn.WRITE_COUNT.getShortName();
        for (String tableName : tableNames) {
            Preconditions.checkState(!tableName.startsWith(AtlasDbConstants.NAMESPACE_PREFIX),
                    "The sweep stats kvs should wrap the namespace mapping kvs, not the other way around.");
            byte[] row = SweepPriorityRow.of(tableName).persistToBytes();
            Cell cell = Cell.create(row, col);
            Value oldValue = oldWriteCounts.get(cell);
            long oldCount = oldValue == null || oldValue.getContents().length == 0 ? 0
                    : SweepPriorityTable.WriteCount.BYTES_HYDRATOR.hydrateFromBytes(oldValue.getContents())
                            .getValue();
            long newValue = clears.contains(tableName) ? writes.count(tableName)
                    : oldCount + writes.count(tableName);
            log.debug("Sweep priority for {} has {} writes (was {})", tableName, newValue, oldCount);
            newWriteCounts.put(cell, SweepPriorityTable.WriteCount.of(newValue).persistValue());
        }
        long timestamp = timestampService.getFreshTimestamp();

        // Committing before writing is intentional, we want the start timestamp to
        // show up in the transaction table before we write do our writes.
        commit(timestamp);
        delegate().put(SWEEP_PRIORITY_TABLE, newWriteCounts, timestamp);
    } catch (RuntimeException e) {
        Set<String> allTableNames = delegate().getAllTableNames();
        if (!allTableNames.contains(SWEEP_PRIORITY_TABLE)
                || !allTableNames.contains(TransactionConstants.TRANSACTION_TABLE)) {
            // ignore problems when sweep or transaction tables don't exist
            log.warn("Ignoring failed sweep stats flush due to {}", e.getMessage(), e);
        }
        log.error("Unable to flush sweep stats for writes {} and clears {}: {}", writes, clears, e.getMessage(),
                e);
        throw e;
    }
}

From source file:org.simmetrics.metrics.GeneralizedJaccard.java

@Override
public float compare(Multiset<T> a, Multiset<T> b) {

    if (a.isEmpty() && b.isEmpty()) {
        return 1.0f;
    }/* w  w  w  .  j a v  a  2 s .  c  o  m*/

    if (a.isEmpty() || b.isEmpty()) {
        return 0.0f;
    }

    final int intersection = intersection(a, b).size();

    // a  b / a  b
    // Implementation note: The size of the union of two sets is equal to
    // the size of both sets minus the duplicate elements.
    return intersection / (float) (a.size() + b.size() - intersection);
}

From source file:com.davidsoergel.stats.DistributionXYSeries.java

public int size() {
    int result = 0;
    for (Multiset<Double> doubles : yValsPerX.values()) {
        result += doubles.size();
    }//from  w w  w .j  ava2  s  . com
    return result;
}

From source file:de.hzi.helmholtz.Compare.SimpleCompareUsingModules.java

public void comparePathways(String ALGORITHM, String windowsize, String ProcessID) {
    try {/*from   ww  w. j  av  a 2  s . c  o m*/

        Iterator<DBPathwayUsingModules> firstIter = QueryPathway.iterator();
        Iterator<DBPathwayUsingModules> secondIter = allPathways.iterator();
        SizeofTargetPathwaysInDatabase = allPathways.size();
        maxWindowSize = Integer.parseInt(windowsize.trim());
        UniqueJobID = ProcessID;

        while (firstIter.hasNext()) {
            DBPathwayUsingModules source = firstIter.next();

            //secondIter.next();
            //////System.out.println("**************************************************");
            secondIter = allPathways.iterator();
            while (secondIter.hasNext()) {

                SizeofQueryPathway = 0;
                DBPathwayUsingModules target = secondIter.next();
                //////System.out.println(source.getPathwayID() + " && " + target.getPathwayID());

                Map<String, Integer> srcGeneIdToPositionMap = new TreeMap<String, Integer>();
                int temp = 0;

                sourcecopy = new PathwayUsingModules(source.convertToPathwayObj());
                targetcopy = new PathwayUsingModules(target.convertToPathwayObj());
                for (Map.Entry<String, List<String>> e : source.getPathway().entrySet()) {

                    SizeofQueryPathway += e.getValue().size();
                    srcGeneIdToPositionMap.put(e.getKey(), temp++);
                }
                Map<String, Integer> tgtGeneIdToPositionMap = new TreeMap<String, Integer>();
                temp = 0;
                for (Map.Entry<String, List<String>> e : target.getPathway().entrySet()) {
                    tgtGeneIdToPositionMap.put(e.getKey(), temp++);
                }
                source.printPathway();
                target.printPathway();
                //source.convertToPathwayObj().getModules()
                Iterator<Module> sourceGeneIt = source.convertToPathwayObj().geneIterator();
                Multiset<String> qfunction = LinkedHashMultiset.create();
                while (sourceGeneIt.hasNext()) {
                    Module queryGene = sourceGeneIt.next();
                    for (Domain d : queryGene.getDomains()) {
                        qfunction.add(d.getDomainFunctionString());
                    }
                }
                Iterator<Module> targetGeneIt = target.convertToPathwayObj().geneIterator();
                Multiset<String> tfunction = LinkedHashMultiset.create();
                while (targetGeneIt.hasNext()) {
                    Module targetGene = targetGeneIt.next();
                    for (Domain d : targetGene.getDomains()) {
                        tfunction.add(d.getDomainFunctionString());
                    }
                }
                Multiset<String> DomainsCommon = Multisets.intersection(qfunction, tfunction);
                if (DomainsCommon.size() > 5) {
                    PathwayComparisonUsingModules pComparison = new PathwayComparisonUsingModules(
                            source.convertToPathwayObj(), target.convertToPathwayObj(), maxWindowSize,
                            UniqueJobID, ALGORITHM, self);
                }

                //PathwayComparison pComparison = new PathwayComparison(target.convertToPathwayObj(), source.convertToPathwayObj());
                //
                //  //////System.out.println(SizeofQueryPathway + "                 " + SizeofTargetPathwaysInDatabase);
                //break;
            }

            //System.out.println("**************************************************");
        }
        //System.out.println("Done ... Enjoy with your results");
    } catch (Exception ex) {
        //System.out.println("Error in SimpleCompare:" + ex);
        Logger.getLogger(ThriftServer.class.getName()).log(Level.SEVERE, null, ex);
    }
    ////System.out.println("done");
    //  JOptionPane.showMessageDialog(null, "Done", "less arguments" + " sdsdsd321321", JOptionPane.INFORMATION_MESSAGE);

}