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

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

Introduction

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

Prototype

Collection<Map.Entry<K, V>> entries();

Source Link

Document

Returns a view collection of all key-value pairs contained in this multimap, as Map.Entry instances.

Usage

From source file:org.opendaylight.controller.config.facade.xml.ConfigSubsystemFacade.java

private void setOnTransaction(ConfigTransactionClient ta, ConfigExecution execution)
        throws DocumentedException {

    for (Multimap<String, ModuleElementResolved> modulesToResolved : execution.getResolvedXmlElements(ta)
            .values()) {//  w ww. j  ava  2 s .  co m

        for (Map.Entry<String, ModuleElementResolved> moduleToResolved : modulesToResolved.entries()) {
            String moduleName = moduleToResolved.getKey();

            ModuleElementResolved moduleElementResolved = moduleToResolved.getValue();
            String instanceName = moduleElementResolved.getInstanceName();

            InstanceConfigElementResolved ice = moduleElementResolved.getInstanceConfigElementResolved();
            EditConfigStrategy strategy = ice.getEditStrategy();
            strategy.executeConfiguration(moduleName, instanceName, ice.getConfiguration(), ta,
                    execution.getServiceRegistryWrapper(ta));
        }
    }
}

From source file:org.pentaho.di.job.entries.deletefiles.JobEntryDeleteFiles.java

public Result execute(Result result, int nr) throws KettleException {
    List<RowMetaAndData> resultRows = result.getRows();

    int numberOfErrFiles = 0;
    result.setResult(false);//from   w  w w. j  a  v  a  2 s .  c  om
    result.setNrErrors(1);

    if (argFromPrevious && log.isDetailed()) {
        logDetailed(BaseMessages.getString(PKG, "JobEntryDeleteFiles.FoundPreviousRows",
                String.valueOf((resultRows != null ? resultRows.size() : 0))));
    }

    Multimap<String, String> pathToMaskMap = populateDataForJobExecution(resultRows);

    for (Map.Entry<String, String> pathToMask : pathToMaskMap.entries()) {
        final String filePath = environmentSubstitute(pathToMask.getKey());
        if (filePath.trim().isEmpty()) {
            // Relative paths are permitted, and providing an empty path means deleting all files inside a root pdi-folder.
            // It is much more likely to be a mistake than a desirable action, so we don't delete anything (see PDI-15181)
            if (log.isDetailed()) {
                logDetailed(BaseMessages.getString(PKG, "JobEntryDeleteFiles.NoPathProvided"));
            }
        } else {
            final String fileMask = environmentSubstitute(pathToMask.getValue());

            if (parentJob.isStopped()) {
                break;
            }

            if (!processFile(filePath, fileMask, parentJob)) {
                numberOfErrFiles++;
            }
        }
    }

    if (numberOfErrFiles == 0) {
        result.setResult(true);
        result.setNrErrors(0);
    } else {
        result.setNrErrors(numberOfErrFiles);
        result.setResult(false);
    }

    return result;
}

From source file:org.apache.cassandra.dht.RangeStreamer.java

/**
 * Add ranges to be streamed for given keyspace.
 *
 * @param keyspaceName keyspace name//from w  w w.j a  va 2 s. c  o  m
 * @param ranges ranges to be streamed
 */
public void addRanges(String keyspaceName, Collection<Range<Token>> ranges) {
    Multimap<Range<Token>, InetAddress> rangesForKeyspace = useStrictSourcesForRanges(keyspaceName)
            ? getAllRangesWithStrictSourcesFor(keyspaceName, ranges)
            : getAllRangesWithSourcesFor(keyspaceName, ranges);

    if (logger.isTraceEnabled()) {
        for (Map.Entry<Range<Token>, InetAddress> entry : rangesForKeyspace.entries())
            logger.trace(
                    String.format("%s: range %s exists on %s", description, entry.getKey(), entry.getValue()));
    }

    for (Map.Entry<InetAddress, Collection<Range<Token>>> entry : getRangeFetchMap(rangesForKeyspace,
            sourceFilters, keyspaceName).asMap().entrySet()) {
        if (logger.isTraceEnabled()) {
            for (Range<Token> r : entry.getValue())
                logger.trace(String.format("%s: range %s from source %s for keyspace %s", description, r,
                        entry.getKey(), keyspaceName));
        }
        toFetch.put(keyspaceName, entry);
    }
}

From source file:org.eclipse.incquery.runtime.base.api.QueryResultMultimap.java

/**
 * {@inheritDoc}// ww w. j ava  2  s . co  m
 * 
 * <p>
 * Throws {@link UnsupportedOperationException} if there is no {@link IQueryResultSetter}
 */
@Override
public boolean putAll(Multimap<? extends KeyType, ? extends ValueType> multimap) {
    if (getSetter() == null) {
        throw new UnsupportedOperationException(NOT_ALLOW_MODIFICATIONS);
    }
    boolean changed = false;
    for (Entry<? extends KeyType, ? extends ValueType> entry : multimap.entries()) {
        changed |= modifyThroughQueryResultSetter(entry.getKey(), entry.getValue(), Direction.INSERT);
    }
    return changed;
}

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

/**
 * Examines the specified query string parameters and returns a
 * canonicalized form.//w  w w . j ava2  s.c  o  m
 * <p/>
 * The canonicalized query string is formed by first sorting all the query
 * string parameters, then URI encoding both the key and value and then
 * joining them, in order, separating key value pairs with an '&'.
 *
 * @param queryString The query string parameters to be canonicalized.
 * @return A canonicalized form for the specified query string parameters.
 */
protected String getCanonicalizedQueryString(String queryString) {
    Multimap<String, String> params = queryParser().apply(queryString);
    SortedMap<String, String> sorted = Maps.newTreeMap();
    if (params == null) {
        return "";
    }
    Iterator<Map.Entry<String, String>> pairs = params.entries().iterator();
    while (pairs.hasNext()) {
        Map.Entry<String, String> pair = pairs.next();
        String key = pair.getKey();
        String value = pair.getValue();
        sorted.put(urlEncode(key), urlEncode(value));
    }

    return Joiner.on("&").withKeyValueSeparator("=").join(sorted);
}

From source file:com.github.haixing_hu.lang.Assignment.java

@SuppressWarnings("unchecked")
public static <K, V extends Assignable<? super V>> Multimap<K, V> deepAssign(@Nullable Multimap<K, V> left,
        @Nullable final Multimap<K, V> right) {
    if (right == null) {
        return null;
    } else {// w  w w  . jav  a  2 s .  c om
        if (left == null) {
            left = LinkedHashMultimap.create();
        } else {
            left.clear();
        }
        final Collection<Map.Entry<K, V>> entries = right.entries();
        for (final Map.Entry<K, V> entry : entries) {
            final K key = entry.getKey();
            final V value = entry.getValue();
            if (value == null) {
                left.put(key, null);
            } else {
                left.put(key, (V) value.clone());
            }
        }
        return left;
    }
}

From source file:org.assertj.guava.api.MultimapAssert.java

/**
 * Verifies that the actual {@link Multimap} has the same entries as the given one.<br>
 * It allows to compare two multimaps having the same content but who are not equal because being of different types
 * like {@link SetMultimap} and {@link ListMultimap}.
 * <p>/* www.  j  av a  2s .c o  m*/
 * Example :
 *
 * <pre><code class='java'> Multimap&lt;String, String&gt; actual = ArrayListMultimap.create();
 * listMultimap.putAll("Spurs", newArrayList("Tony Parker", "Tim Duncan", "Manu Ginobili"));
 * listMultimap.putAll("Bulls", newArrayList("Michael Jordan", "Scottie Pippen", "Derrick Rose"));
 *
 * Multimap&lt;String, String&gt; setMultimap = TreeMultimap.create();
 * setMultimap.putAll("Spurs", newHashSet("Tony Parker", "Tim Duncan", "Manu Ginobili"));
 * setMultimap.putAll("Bulls", newHashSet("Michael Jordan", "Scottie Pippen", "Derrick Rose"));
 *
 * // assertion will pass as listMultimap and setMultimap have the same content
 * assertThat(listMultimap).hasSameEntriesAs(setMultimap);
 * 
 * // this assertion FAILS even though both multimaps have the same content
 * assertThat(listMultimap).isEqualTo(setMultimap);</code></pre>
 *
 * @param other {@link Multimap} to compare actual's entries with.
 * @return this {@link MultimapAssert} for assertions chaining.
 * @throws AssertionError if the actual {@link Multimap} is {@code null}.
 * @throws IllegalArgumentException if the other {@link Multimap} is {@code null}.
 * @throws AssertionError if actual {@link Multimap} does not have the same entries as the other {@link Multimap}.
 */
public final MultimapAssert<K, V> hasSameEntriesAs(Multimap<? extends K, ? extends V> other) {
    Objects.instance().assertNotNull(info, actual);
    throwIllegalArgumentExceptionIfTrue(other == null,
            "The multimap to compare actual with should not be null");

    Set<?> entriesNotExpectedInActual = difference(newLinkedHashSet(actual.entries()),
            newLinkedHashSet(other.entries()));
    Set<?> entriesNotFoundInActual = difference(newLinkedHashSet(other.entries()),
            newLinkedHashSet(actual.entries()));
    if (entriesNotFoundInActual.isEmpty() && entriesNotExpectedInActual.isEmpty())
        return myself;
    throw failures.failure(info,
            shouldContainOnly(actual, other, entriesNotFoundInActual, entriesNotExpectedInActual));
}

From source file:cc.kave.commons.pointsto.analysis.ReferenceBasedAnalysis.java

@Override
public PointsToContext compute(Context context) {
    checkContextBinding();/*from  www.j  a v  a2  s .  c  om*/

    ReferenceCollectionVisitor collectionVisitor = new ReferenceCollectionVisitor();
    ReferenceCollectionContext collectionContext = new ReferenceCollectionContext();
    collectionVisitor.visit(context.getSST(), collectionContext);
    Multimap<IReference, ITypeName> referenceTypes = collectionContext.getReferences();

    LanguageOptions languageOptions = LanguageOptions.getInstance();
    ITypeHierarchy typeHierarchy = context.getTypeShape().getTypeHierarchy();
    referenceTypes.put(SSTBuilder.variableReference(languageOptions.getThisName()), typeHierarchy.getElement());
    referenceTypes.put(SSTBuilder.variableReference(languageOptions.getSuperName()),
            languageOptions.getSuperType(typeHierarchy));

    for (Map.Entry<IReference, ITypeName> entry : referenceTypes.entries()) {
        PointsToQuery query = new PointsToQuery(entry.getKey(), entry.getValue(), null, null);
        if (!contextToLocations.containsKey(query)) {
            contextToLocations.put(query, new AbstractLocation());
        }
    }

    return new PointsToContext(context, this);
}

From source file:org.mitreid.multiparty.service.InMemoryResourceService.java

@Override
public SharedResourceSet getSharedResourceSetForResource(final Resource res) {
    Multimap<String, Resource> filtered = Multimaps.filterEntries(resources,
            new Predicate<Entry<String, Resource>>() {

                @Override// ww w  .j  a v a 2 s . co  m
                public boolean apply(Entry<String, Resource> input) {
                    if (input.getValue().equals(res)) {
                        return true;
                    } else {
                        return false;
                    }
                }

            });

    String principalName = Iterators.getOnlyElement(filtered.entries().iterator()).getKey();

    return sharedResourceSets.get(principalName);
}

From source file:com.twitter.crunch.StableRdfMapping.java

private Node findCandidate(Node ownerNode, Map<Node, List<Node>> candidateMap,
        Multimap<Integer, Node> nodeReplicaSizeMap, Map<Node, List<Node>> rdfMap) {
    Node candidate = null;/*from  w w  w.ja v a 2s .co m*/
    List<Node> candidates = candidateMap.get(ownerNode);

    if (candidates == null)
        return null;

    // Find candidate
    for (Map.Entry<Integer, Node> entry : nodeReplicaSizeMap.entries()) {
        Node node = entry.getValue();
        int replicaSize = entry.getKey();

        if (!candidates.contains(node))
            continue;

        if (replicaSize >= this.rdfMax) {
            // Remove nodes with RDF >= rdfMax
            candidates.remove(node);
        } else if (!hasCapacity(node)) {
            continue;
        } else if (hasConflict(node, rdfMap.get(ownerNode)) || hasConflict(ownerNode, rdfMap.get(node))) {
            candidates.remove(node);
            candidateMap.get(node).remove(ownerNode);
            continue;
        } else {
            if (migrationMap == null || !migrationMap.containsKey(ownerNode.getName())
                    || migrationMap.get(ownerNode.getName()).contains(node.getName())) {
                candidate = node;
                break;
            } else {
                if (candidate == null) {
                    candidate = node;
                    continue;
                }
            }
        }
    }

    return candidate;
}