Example usage for org.apache.commons.lang.mutable MutableDouble MutableDouble

List of usage examples for org.apache.commons.lang.mutable MutableDouble MutableDouble

Introduction

In this page you can find the example usage for org.apache.commons.lang.mutable MutableDouble MutableDouble.

Prototype

public MutableDouble() 

Source Link

Document

Constructs a new MutableDouble with the default value of zero.

Usage

From source file:com.google.gerrit.server.ReviewerRecommender.java

private Map<Account.Id, MutableDouble> baseRankingForCandidateList(List<Account.Id> candidates,
        ProjectControl projectControl, double baseWeight) throws OrmException {
    // Get each reviewer's activity based on number of applied labels
    // (weighted 10d), number of comments (weighted 0.5d) and number of owned
    // changes (weighted 1d).
    Map<Account.Id, MutableDouble> reviewers = new LinkedHashMap<>();
    if (candidates.size() == 0) {
        return reviewers;
    }//from   w ww  .  ja  v a  2 s  . co m
    List<Predicate<ChangeData>> predicates = new ArrayList<>();
    for (Account.Id id : candidates) {
        try {
            Predicate<ChangeData> projectQuery = changeQueryBuilder
                    .project(projectControl.getProject().getName());

            // Get all labels for this project and create a compound OR query to
            // fetch all changes where users have applied one of these labels
            List<LabelType> labelTypes = projectControl.getLabelTypes().getLabelTypes();
            List<Predicate<ChangeData>> labelPredicates = new ArrayList<>(labelTypes.size());
            for (LabelType type : labelTypes) {
                labelPredicates.add(changeQueryBuilder.label(type.getName() + ",user=" + id));
            }
            Predicate<ChangeData> reviewerQuery = Predicate.and(projectQuery, Predicate.or(labelPredicates));

            Predicate<ChangeData> ownerQuery = Predicate.and(projectQuery,
                    changeQueryBuilder.owner(id.toString()));
            Predicate<ChangeData> commentedByQuery = Predicate.and(projectQuery,
                    changeQueryBuilder.commentby(id.toString()));

            predicates.add(reviewerQuery);
            predicates.add(ownerQuery);
            predicates.add(commentedByQuery);
            reviewers.put(id, new MutableDouble());
        } catch (QueryParseException e) {
            // Unhandled: If an exception is thrown, we won't increase the
            // candidates's score
            log.error("Exception while suggesting reviewers", e);
        }
    }

    List<List<ChangeData>> result = internalChangeQuery.setLimit(25).setRequestedFields(ImmutableSet.of())
            .query(predicates);

    Iterator<List<ChangeData>> queryResultIterator = result.iterator();
    Iterator<Account.Id> reviewersIterator = reviewers.keySet().iterator();

    int i = 0;
    Account.Id currentId = null;
    while (queryResultIterator.hasNext()) {
        List<ChangeData> currentResult = queryResultIterator.next();
        if (i % WEIGHTS.length == 0) {
            currentId = reviewersIterator.next();
        }

        reviewers.get(currentId).add(WEIGHTS[i % WEIGHTS.length] * baseWeight * currentResult.size());
        i++;
    }
    return reviewers;
}