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

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

Introduction

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

Prototype

Set<K> keySet();

Source Link

Document

Returns a view collection of all distinct keys contained in this multimap.

Usage

From source file:org.eclipse.viatra.transformation.views.traceability.generic.GenericReferencedPQuery.java

/**
 * @throws ViatraQueryRuntimeException//from w w  w .jav  a 2s.  c om
 */
public GenericReferencedPQuery(PQuery baseQuery, Multimap<PParameter, PParameter> traceSources,
        Map<PParameter, String> traceIds, String traceabilityId) {
    this.baseQuery = baseQuery;
    this.parameters = Lists.newArrayList(baseQuery.getParameters());
    this.parameters.addAll(traceSources.keySet());
    this.traceSources = traceSources;
    this.traceIds = traceIds;
    this.traceabilityId = traceabilityId;
    ensureInitialized();
}

From source file:com.google.devtools.build.android.DensitySpecificResourceFilter.java

@VisibleForTesting
List<Path> getResourceToRemove(List<Path> resourcePaths) {
    Predicate<ResourceInfo> requestedDensityFilter = new Predicate<ResourceInfo>() {
        @Override/*from ww  w . j  ava 2s .c o  m*/
        public boolean apply(@Nullable ResourceInfo info) {
            return !densities.contains(info.getDensity());
        }
    };

    List<ResourceInfo> resourceInfos = getResourceInfos(resourcePaths);
    List<ResourceInfo> densityResourceInfos = filterDensityResourceInfos(resourceInfos);
    List<ResourceInfo> resourceInfoToRemove = new ArrayList<>();

    Multimap<String, ResourceInfo> fileGroups = groupResourceInfos(densityResourceInfos, GET_RESOURCE_ID);

    for (String key : fileGroups.keySet()) {
        Multimap<String, ResourceInfo> qualifierGroups = groupResourceInfos(fileGroups.get(key),
                GET_RESOURCE_QUALIFIERS);

        for (String qualifiers : qualifierGroups.keySet()) {
            Collection<ResourceInfo> qualifierResourceInfos = qualifierGroups.get(qualifiers);

            if (qualifierResourceInfos.size() != 1) {
                List<ResourceInfo> sortedResourceInfos = Ordering.natural()
                        .onResultOf(new Function<ResourceInfo, Double>() {
                            @Override
                            public Double apply(ResourceInfo info) {
                                return matchScore(info, densities);
                            }
                        }).immutableSortedCopy(qualifierResourceInfos);
                resourceInfoToRemove.addAll(Collections2.filter(
                        sortedResourceInfos.subList(1, sortedResourceInfos.size()), requestedDensityFilter));
            }
        }
    }

    return ImmutableList.copyOf(Lists.transform(resourceInfoToRemove, GET_RESOURCE_PATH));
}

From source file:com.rackspacecloud.blueflood.io.datastax.DPreaggregatedMetricsRW.java

private void insertMetricsInBatch(Multimap<Locator, IMetric> map, Granularity granularity) {
    BatchStatement batch = new BatchStatement(BatchStatement.Type.UNLOGGED);

    for (Locator locator : map.keySet()) {
        for (IMetric metric : map.get(locator)) {
            RollupType rollupType = metric.getRollupType();

            DAbstractMetricIO io = rollupTypeToIO.get(rollupType);
            BoundStatement boundStatement = io.getBoundStatementForMetric(metric, granularity);
            batch.add(boundStatement);//from  w w w. j  a  v a2s .  c o  m

            if (granularity == Granularity.FULL) {
                Instrumentation.markFullResPreaggregatedMetricWritten();
            }

            if (!LocatorCache.getInstance().isLocatorCurrentInBatchLayer(locator)) {
                LocatorCache.getInstance().setLocatorCurrentInBatchLayer(locator);
                batch.add(locatorIO.getBoundStatementForLocator(locator));
            }

            // if we are recording delayed metrics, we may need to do an
            // extra insert
            if (isRecordingDelayedMetrics) {
                BoundStatement bs = getBoundStatementForMetricIfDelayed(metric);
                if (bs != null) {
                    batch.add(bs);
                }
            }
        }
    }
    LOG.trace(String.format("insert preaggregated batch statement size=%d", batch.size()));

    try {
        DatastaxIO.getSession().execute(batch);
    } catch (Exception ex) {
        Instrumentation.markWriteError();
        LOG.error(String.format("error writing batch of %d preaggregated metrics", batch.size()), ex);
    }
}

From source file:org.robotframework.ide.eclipse.main.plugin.navigator.actions.ReloadLibraryAction.java

private void rebuildLibraries(final IProgressMonitor monitor) {
    final Multimap<IProject, LibrarySpecification> groupedSpecifications = groupSpecificationsByProject();
    monitor.beginTask("Regenerating library specifications", 10);
    new LibrariesBuilder(new BuildLogger()).forceLibrariesRebuild(groupedSpecifications,
            SubMonitor.convert(monitor));
    for (final IProject project : groupedSpecifications.keySet()) {
        final RobotProject robotProject = RedPlugin.getModelManager().createProject(project);
        robotProject.clearDirtyLibSpecs(groupedSpecifications.values());
        robotProject.clearConfiguration();
        robotProject.clearKwSources();/*from   ww w.j a  v  a 2  s .  co  m*/
    }

    SwtThread.asyncExec(new Runnable() {
        @Override
        public void run() {
            ((TreeViewer) selectionProvider).refresh();
        }
    });
}

From source file:org.apache.phoenix.hbase.index.write.LeaveIndexActiveFailurePolicy.java

@Override
public void handleFailure(Multimap<HTableInterfaceReference, Mutation> attempted, Exception cause)
        throws IOException {
    // get timestamp of first cell
    long ts = attempted.values().iterator().next().getFamilyCellMap().values().iterator().next().get(0)
            .getTimestamp();//ww  w . j  av  a 2s .  c  o m
    throw ServerUtil.wrapInDoNotRetryIOException(
            "Unable to update the following indexes: " + attempted.keySet(), cause, ts);
}

From source file:org.jclouds.s3.filters.RequestAuthorizeSignatureV2.java

@VisibleForTesting
void appendUriPath(HttpRequest request, StringBuilder toSign) {

    toSign.append(request.getEndpoint().getRawPath());

    // ...however, there are a few exceptions that must be included in the
    // signed URI.
    if (request.getEndpoint().getQuery() != null) {
        Multimap<String, String> params = queryParser().apply(request.getEndpoint().getQuery());
        char separator = '?';
        for (String paramName : Ordering.natural().sortedCopy(params.keySet())) {
            // Skip any parameters that aren't part of the canonical signed string
            if (!SIGNED_PARAMETERS.contains(paramName)) {
                continue;
            }/*  w  w w.  j a va2 s  .  c om*/
            toSign.append(separator).append(paramName);
            String paramValue = get(params.get(paramName), 0);
            if (paramValue != null) {
                toSign.append("=").append(paramValue);
            }
            separator = '&';
        }
    }
}

From source file:org.mule.util.journal.queue.LocalTxQueueTransactionRecoverer.java

/**
 * Recover all the pending transactions.
 *
 * Will undo all operations done over queues that were not commit or rolled back.
 *
 * Clears the transaction log after processing all the log entries since does entries are not longer
 * required.// ww w.  j a  va 2  s  .  c  o m
 */
public void recover() {
    if (logger.isDebugEnabled()) {
        logger.debug("Executing transaction recovery");
    }
    Multimap<Integer, LocalQueueTxJournalEntry> allEntries = this.localTxQueueTransactionJournal
            .getAllLogEntries();
    if (logger.isDebugEnabled()) {
        logger.debug("Found " + allEntries.size() + " txs to recover");
    }
    int txRecovered = 0;
    for (Integer txId : allEntries.keySet()) {
        Collection<LocalQueueTxJournalEntry> entries = allEntries.get(txId);
        Object commitOrRollback = CollectionUtils.find(entries, new Predicate() {
            @Override
            public boolean evaluate(Object object) {
                LocalQueueTxJournalEntry logEntry = (LocalQueueTxJournalEntry) object;
                return logEntry.isCommit() || logEntry.isRollback();
            }
        });
        if (commitOrRollback != null) {
            continue;
        }
        txRecovered++;
        for (LocalQueueTxJournalEntry logEntry : entries) {
            if (logEntry.isRemove()) {
                String queueName = logEntry.getQueueName();
                RecoverableQueueStore queue = queueProvider.getRecoveryQueue(queueName);
                Serializable polledValue = logEntry.getValue();
                if (!queue.contains(polledValue)) {
                    if (logger.isDebugEnabled()) {
                        logger.debug(
                                "re-adding polled element that was not commited to queue " + queue.getName());
                    }
                    try {
                        queue.putNow(polledValue);
                    } catch (InterruptedException e) {
                        throw new MuleRuntimeException(e);
                    }
                }
            } else if (logEntry.isAdd() || logEntry.isAddFirst()) {
                Serializable offeredValue = logEntry.getValue();
                String queueName = logEntry.getQueueName();
                RecoverableQueueStore queue = queueProvider.getRecoveryQueue(queueName);
                if (queue.contains(offeredValue)) {
                    if (logger.isDebugEnabled()) {
                        logger.debug(
                                "removing offer element that was not commited to queue " + queue.getName());
                    }
                    queue.remove(offeredValue);
                }
            }
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Recovered " + txRecovered + " txs to recover");
    }
    this.localTxQueueTransactionJournal.clear();
}

From source file:com.github.sprial404.ss.item.crafting.RecipeRegistry.java

private void discoverStacks(Multimap<CustomWrappedStack, List<CustomWrappedStack>> recipes) {
    Set<CustomWrappedStack> recipeKeySet = recipes.keySet();
    Iterator<CustomWrappedStack> recipeKeySetIterator = recipeKeySet.iterator();
    CustomWrappedStack recipeOutput = null;

    // Discover all stacks involved in the recipes we know about
    while (recipeKeySetIterator.hasNext()) {
        recipeOutput = recipeKeySetIterator.next();

        if (!discoveredStacks.contains(new CustomWrappedStack(recipeOutput.getWrappedStack()))
                && recipeOutput.getWrappedStack() != null) {
            discoveredStacks.add(new CustomWrappedStack(recipeOutput.getWrappedStack()));
        }/*from   w ww.  j  a  v  a2s. c om*/

        for (List<CustomWrappedStack> recipeInputs : recipes.get(recipeOutput)) {
            for (CustomWrappedStack recipeInput : recipeInputs) {

                CustomWrappedStack unwrappedRecipeInput = new CustomWrappedStack(recipeInput.getWrappedStack());

                if (!discoveredStacks.contains(unwrappedRecipeInput) && recipeInput.getWrappedStack() != null) {
                    discoveredStacks.add(unwrappedRecipeInput);
                }
            }
        }
    }

    CustomWrappedStack customWrappedStack;

    // Discover all stacks from the vanilla Items array
    for (int i = 0; i < Item.itemsList.length; i++) {

        if (Item.itemsList[i] != null) {

            if (Item.itemsList[i].getHasSubtypes()) {

                for (int meta = 0; meta < 16; meta++) {

                    customWrappedStack = new CustomWrappedStack(
                            new ItemStack(Item.itemsList[i].itemID, 1, meta));

                    if (!discoveredStacks.contains(customWrappedStack)) {
                        discoveredStacks.add(customWrappedStack);
                    }
                }
            } else {

                customWrappedStack = new CustomWrappedStack(new ItemStack(Item.itemsList[i]));

                if (!discoveredStacks.contains(customWrappedStack)) {
                    discoveredStacks.add(customWrappedStack);
                }
            }
        }
    }

    /*
     * For every stack we have discovered, check to see if we know a recipe
     * for it. If we don't and we haven't already added it to the recipeless
     * stack list, add it to the recipeless stack list
     */
    for (CustomWrappedStack discoveredStack : discoveredStacks) {
        if (recipes.get(discoveredStack).size() == 0 && !recipelessStacks.contains(discoveredStack)) {
            recipelessStacks.add(discoveredStack);
        }
    }
}

From source file:com.rackspacecloud.blueflood.io.astyanax.AstyanaxWriter.java

public void insertMetrics(Collection<IMetric> metrics, ColumnFamily cf, boolean isRecordingDelayedMetrics,
        Clock clock) throws ConnectionException {
    Timer.Context ctx = Instrumentation.getWriteTimerContext(cf.getName());
    Multimap<Locator, IMetric> map = asMultimap(metrics);
    MutationBatch batch = keyspace.prepareMutationBatch();
    try {/*from w  w w.ja  v a2s . co m*/
        for (Locator locator : map.keySet()) {
            ColumnListMutation<Long> mutation = batch.withRow(cf, locator);

            for (IMetric metric : map.get(locator)) {

                mutation.putColumn(metric.getCollectionTime(), metric.getMetricValue(),
                        (AbstractSerializer) (Serializers.serializerFor(metric.getMetricValue().getClass())),
                        metric.getTtlInSeconds());
                if (cf.getName().equals(CassandraModel.CF_METRICS_PREAGGREGATED_FULL_NAME)) {
                    Instrumentation.markFullResPreaggregatedMetricWritten();
                }

                if (isRecordingDelayedMetrics) {
                    //retaining the same conditional logic that was used to perform insertLocator(locator, batch).
                    insertLocatorIfDelayed(metric, batch, clock);
                }
            }

            if (!LocatorCache.getInstance().isLocatorCurrentInBatchLayer(locator)) {
                insertLocator(locator, batch);
                LocatorCache.getInstance().setLocatorCurrentInBatchLayer(locator);
            }
        }
        try {
            batch.execute();
        } catch (ConnectionException e) {
            Instrumentation.markWriteError(e);
            log.error("Connection exception persisting data", e);
            throw e;
        }
    } finally {
        ctx.stop();
    }
}

From source file:org.jclouds.s3.filters.RequestAuthorizeSignature.java

@VisibleForTesting
void appendUriPath(HttpRequest request, StringBuilder toSign) {

    toSign.append(request.getEndpoint().getRawPath());

    // ...however, there are a few exceptions that must be included in the
    // signed URI.
    if (request.getEndpoint().getQuery() != null) {
        Multimap<String, String> params = queryParser().apply(request.getEndpoint().getQuery());
        char separator = '?';
        for (String paramName : Ordering.natural().sortedCopy(params.keySet())) {
            // Skip any parameters that aren't part of the canonical signed string
            if (!SIGNED_PARAMETERS.contains(paramName))
                continue;
            toSign.append(separator).append(paramName);
            String paramValue = get(params.get(paramName), 0);
            if (paramValue != null) {
                toSign.append("=").append(paramValue);
            }/*from w w w .java  2 s.co  m*/
            separator = '&';
        }
    }
}