Example usage for com.google.common.collect Multimap get

List of usage examples for com.google.common.collect Multimap get

Introduction

In this page you can find the example usage for com.google.common.collect Multimap get.

Prototype

Collection<V> get(@Nullable K key);

Source Link

Document

Returns a view collection of the values associated with key in this multimap, if any.

Usage

From source file:com.spotify.heroic.cluster.NodeRegistry.java

public Optional<ClusterNode> getNodeInShardButNotWithId(final Map<String, String> shard,
        final Predicate<ClusterNode> exclude) {
    final Multimap<Map<String, String>, ClusterNode> shardToNode = buildShards(entries);

    final Collection<ClusterNode> nodesInShard = shardToNode.get(shard);

    final List<ClusterNode> randomizedList = nodesInShard.stream().filter(ClusterNode::isAlive)
            .collect(Collectors.toList());
    Collections.shuffle(randomizedList, random);

    for (final ClusterNode n : randomizedList) {
        if (exclude.test(n)) {
            continue;
        }/*ww w  .  j a va 2s  .c  o m*/
        return Optional.of(n);
    }

    return Optional.empty();
}

From source file:grakn.core.graql.reasoner.plan.QueryCollectionBase.java

private Set<ReasonerQueryImpl> getAllNeighbours(ReasonerQueryImpl entryQuery) {
    Set<ReasonerQueryImpl> neighbours = new HashSet<>();
    Set<Equivalence.Wrapper<ReasonerQueryImpl>> visitedQueries = new HashSet<>();
    Stack<Equivalence.Wrapper<ReasonerQueryImpl>> queryStack = new Stack<>();

    Multimap<ReasonerQueryImpl, ReasonerQueryImpl> neighbourMap = immediateNeighbourMap();

    neighbourMap.get(entryQuery).stream().map(q -> equality().wrap(q)).forEach(queryStack::push);
    while (!queryStack.isEmpty()) {
        Equivalence.Wrapper<ReasonerQueryImpl> wrappedQuery = queryStack.pop();
        ReasonerQueryImpl query = wrappedQuery.get();
        if (!visitedQueries.contains(wrappedQuery) && query != null) {
            neighbourMap.get(query).stream().peek(neighbours::add).flatMap(q -> neighbourMap.get(q).stream())
                    .map(q -> equality().wrap(q)).filter(q -> !visitedQueries.contains(q))
                    .filter(q -> !queryStack.contains(q)).forEach(queryStack::add);
            visitedQueries.add(wrappedQuery);
        }/*from  ww  w.ja va 2  s .  c om*/
    }
    return neighbours;
}

From source file:com.synflow.cx.internal.instantiation.ConnectionInfo.java

private Collection<Port> getPorts(Multimap<EObject, Port> portMap, DPN dpn, String type) {
    if (instance == null) {
        if (TYPE_READS.equals(type)) {
            return portMap.get(dpn);
        } else { // TYPE_WRITES
            return dpn.getInputs();
        }/*from w  w w .ja va2s.  c o m*/
    } else {
        Entity entity = instance.getEntity();
        if (TYPE_READS.equals(type)) {
            return portMap.get(instance);
        } else { // TYPE_WRITES
            return entity.getOutputs();
        }
    }
}

From source file:org.sonar.server.issue.notification.MyNewIssuesNotificationDispatcher.java

@Override
public void dispatch(Notification notification, Context context) {
    String projectKey = notification.getFieldValue("projectKey");
    String assignee = notification.getFieldValue("assignee");
    Multimap<String, NotificationChannel> subscribedRecipients = manager.findNotificationSubscribers(this,
            projectKey);/*  w w w  . ja va2s  . c  om*/

    Collection<NotificationChannel> channels = subscribedRecipients.get(assignee);
    for (NotificationChannel channel : channels) {
        context.addUser(assignee, channel);
    }
}

From source file:org.pau.assetmanager.viewmodel.chart.ChartDataModel.java

/**
 * Returns the total balance along one year in a monthly basis.
 * /* w  w  w  .  j av  a2s.  c  o  m*/
 * @param year
 *            the balance
 * @param yearToAnnotationMultimap
 *            year --> annotations multimap
 * @param selectedBook
 *            book selected for the balance
 * @param bookSelectionType
 *            type of book
 * @return
 */
public static DefaultCategoryDataset getBalance(Integer year,
        Multimap<Integer, Annotation> yearToAnnotationMultimap, BookSelection bookSelection,
        Boolean includePurchasedStocks, Optional<String> optionalStockLabel) {
    Book selectedBook = bookSelection.getSelectedBook();
    Double previousYearsTotals = 0.0;
    for (Integer currentYear : yearToAnnotationMultimap.keySet()) {
        if (currentYear < year) {
            for (Annotation currentAnnotation : yearToAnnotationMultimap.get(currentYear)) {
                previousYearsTotals += currentAnnotation.getSignedAmount();
            }
        }
    }
    Set<StocksBook> stockBooks = new HashSet<StocksBook>();
    Map<String, Double> totalData = new HashMap<String, Double>();
    for (int month = 0; month < 12; month++) {
        Calendar currentcalendar = GregorianCalendar.getInstance();
        currentcalendar.set(Calendar.MONTH, month);
        currentcalendar.set(Calendar.YEAR, year);
        currentcalendar.set(Calendar.DAY_OF_MONTH, 1);
        String mainLabel = getTimeLabel(currentcalendar.getTime());
        totalData.put(mainLabel, 0.0);
        Collection<Annotation> annotations = yearToAnnotationMultimap.get(year);
        if (annotations != null) {
            for (Annotation annotation : annotations) {
                String currentAnnotationLabel = getTimeLabel(annotation.getDate());
                if (currentAnnotationLabel.equals(mainLabel)) {
                    if (annotation.getBook() instanceof StocksBook) {
                        stockBooks.add((StocksBook) annotation.getBook());
                    }
                    totalData.put(mainLabel, totalData.get(mainLabel) + annotation.getSignedAmount());
                }
            }
        }
    }

    DefaultCategoryDataset model = new DefaultCategoryDataset();
    List<String> listOfLabels = getListOfMonthTimeLabelsForYear(year);

    Map<String, Double> labelToToalCumulativeMap = new HashMap<String, Double>();

    Double total = 0.0;
    for (String currentLabel : listOfLabels) {
        Double currentValue = totalData.get(currentLabel);
        if (currentValue != null) {
            total += currentValue;
        }
        labelToToalCumulativeMap.put(currentLabel, total + previousYearsTotals);
    }

    for (String currentLabel : listOfLabels) {
        model.addValue(labelToToalCumulativeMap.get(currentLabel), TOTAL_CUMULATIVE, currentLabel);
    }

    // add stock information in case it is necessary
    if ((selectedBook instanceof StocksBook) && includePurchasedStocks) {
        Table<Integer, Integer, Set<StockState>> historicalStockBalanceStateTable = HistoricalStockBalanceState
                .getConiniousHistoricalStockBalanceStateTable(bookSelection, year, optionalStockLabel);
        Collection<Annotation> annotationsForYear = yearToAnnotationMultimap.get(year);
        if (annotationsForYear == null) {
            annotationsForYear = Lists.newLinkedList();
        }
        Collection<Annotation> movementAnnotationsForYear = Collections2.filter(annotationsForYear,
                new Predicate<Annotation>() {
                    @Override
                    public boolean apply(Annotation input) {
                        return input instanceof MovementExpensesAnnotation
                                || input instanceof MovementIncomeAnnotation;
                    }
                });
        movementAnnotationsForYear = Collections2.filter(movementAnnotationsForYear,
                new Predicate<Annotation>() {
                    @Override
                    public boolean apply(Annotation input) {
                        return input instanceof MovementExpensesAnnotation
                                || input instanceof MovementIncomeAnnotation;
                    }
                });
        final Calendar currentcalendar = GregorianCalendar.getInstance();
        Multimap<Integer, Annotation> monthToAnnotationMultimap = Multimaps.index(movementAnnotationsForYear,
                new Function<Annotation, Integer>() {
                    @Override
                    public Integer apply(Annotation input) {
                        currentcalendar.setTime(input.getDate());
                        return currentcalendar.get(Calendar.MONTH);
                    }
                });

        Double movementBalance = getAllPreviousMovementCumulative(yearToAnnotationMultimap, year);
        if (historicalStockBalanceStateTable != null) {
            Map<Integer, Set<StockState>> historyForYear = historicalStockBalanceStateTable.rowMap().get(year);
            for (Integer currentMonth = 0; currentMonth <= 11; currentMonth++) {
                Double balance = 0.0;
                if (historyForYear != null && historyForYear.get(currentMonth) != null) {
                    for (StockState currentStockState : historyForYear.get(currentMonth)) {
                        balance += currentStockState.getVirtualBalanceForForcedYearAndMonth(year, currentMonth);
                    }
                } else {
                    balance = getYearBeforeFinalVirtualStockBalance(year, historicalStockBalanceStateTable);
                }
                if (monthToAnnotationMultimap.get(currentMonth) != null) {
                    for (Annotation movementAnnotation : monthToAnnotationMultimap.get(currentMonth)) {
                        movementBalance += movementAnnotation.getSignedAmount();
                    }
                }
                model.addValue(balance, TOTAL_CUMULATIVE_STOCKS_PURCHASED, listOfLabels.get(currentMonth));
                Double cumulativeBalance = labelToToalCumulativeMap.get(listOfLabels.get(currentMonth));

                model.addValue(balance + cumulativeBalance - movementBalance, TOTAL_CUMULATIVE_STOCKS_COMBINED,
                        listOfLabels.get(currentMonth));
            }

        }
    }

    return model;
}

From source file:com.google.caliper.EnvironmentGetter.java

private void getLinuxEnvironment(Map<String, String> propertyMap) {
    // the following probably doesn't work on ALL linux
    Multimap<String, String> cpuInfo = propertiesFromLinuxFile("/proc/cpuinfo");
    propertyMap.put("host.cpus", Integer.toString(cpuInfo.get("processor").size()));
    String s = "cpu cores";
    propertyMap.put("host.cpu.cores", describe(cpuInfo, s));
    propertyMap.put("host.cpu.names", describe(cpuInfo, "model name"));
    propertyMap.put("host.cpu.cachesize", describe(cpuInfo, "cache size"));

    Multimap<String, String> memInfo = propertiesFromLinuxFile("/proc/meminfo");
    // TODO redo memInfo.toString() so we don't get square brackets
    propertyMap.put("host.memory.physical", memInfo.get("MemTotal").toString());
    propertyMap.put("host.memory.swap", memInfo.get("SwapTotal").toString());

    getAndroidEnvironment(propertyMap);//from w  w w .  j a v  a 2  s  .c o m
}

From source file:org.pau.assetmanager.viewmodel.chart.ChartDataModel.java

private static Double getAllPreviousMovementCumulative(Multimap<Integer, Annotation> yearToAnnotationMultimap,
        Integer year) {/*from w w w.j  a  v  a2s  . com*/
    List<Integer> listOfYears = Lists.newLinkedList(yearToAnnotationMultimap.keys());
    if (listOfYears.size() == 0) {
        return 0.0;
    }
    Collections.sort(listOfYears);
    double allPreviousMovementCumulative = 0.0;
    for (int currentYearIndex = 0; currentYearIndex < listOfYears.size()
            && listOfYears.get(currentYearIndex) < year; currentYearIndex++) {
        for (Annotation annotation : yearToAnnotationMultimap.get(listOfYears.get(currentYearIndex))) {
            allPreviousMovementCumulative += annotation.getSignedAmount();
        }

    }
    return allPreviousMovementCumulative;
}

From source file:foo.domaintest.http.HttpApiModule.java

@Provides
@Param("mime")//  ww w .  ja va 2 s  .  c  o  m
String provideMime(Multimap<String, String> params) {
    return getFirst(params.get("mime"), null);
}

From source file:foo.domaintest.http.HttpApiModule.java

@Provides
@Param("token")/*  w  w w  .  j  av a2s . co  m*/
String provideToken(Multimap<String, String> params) {
    return getFirst(params.get("token"), null);
}

From source file:foo.domaintest.http.HttpApiModule.java

@Provides
@Param("addcookie")
Map<String, String> provideAddCookie(Multimap<String, String> params) {
    return parseMap(params.get("addcookie"));
}