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:com.google.devtools.build.lib.rules.platform.Platform.java

private ImmutableMap<ConstraintSettingInfo, ConstraintValueInfo> validateConstraints(RuleContext ruleContext,
        Iterable<ConstraintValueInfo> constraintValues) {
    Multimap<ConstraintSettingInfo, ConstraintValueInfo> constraints = ArrayListMultimap.create();

    for (ConstraintValueInfo constraintValue : constraintValues) {
        constraints.put(constraintValue.constraint(), constraintValue);
    }/*from  w  w w  .  j av a 2 s .c o  m*/

    // Are there any settings with more than one value?
    boolean foundError = false;
    for (ConstraintSettingInfo constraintSetting : constraints.keySet()) {
        if (constraints.get(constraintSetting).size() > 1) {
            foundError = true;
            // error
            StringBuilder constraintValuesDescription = new StringBuilder();
            for (ConstraintValueInfo constraintValue : constraints.get(constraintSetting)) {
                if (constraintValuesDescription.length() > 0) {
                    constraintValuesDescription.append(", ");
                }
                constraintValuesDescription.append(constraintValue.label());
            }
            ruleContext.attributeError(PlatformRule.CONSTRAINT_VALUES_ATTR,
                    String.format("Duplicate constraint_values for constraint_setting %s: %s",
                            constraintSetting.label(), constraintValuesDescription.toString()));
        }
    }

    if (foundError) {
        return null;
    }

    // Convert to a flat map.
    ImmutableMap.Builder<ConstraintSettingInfo, ConstraintValueInfo> builder = new ImmutableMap.Builder<>();
    for (ConstraintSettingInfo constraintSetting : constraints.keySet()) {
        ConstraintValueInfo constraintValue = Iterables.getOnlyElement(constraints.get(constraintSetting));
        builder.put(constraintSetting, constraintValue);
    }

    return builder.build();
}

From source file:dk.dma.ais.abnormal.analyzer.reports.RecentEventsReportJob.java

private String generateReportBody(Date date0, Date date1,
        Multimap<Class<? extends Event>, Event> eventsByType) {
    StringBuffer email = new StringBuffer();

    email.append("<html>");
    email.append("<h2>Abnormal events</h2>");
    email.append("<h4>Detected between " + date0 + " and " + date1 + "</h4>");
    email.append("<br/>");

    email.append("<pre>");
    eventsByType.keySet().forEach(eventType -> {
        email.append(eventType.getSimpleName() + " (" + eventsByType.get(eventType).size() + ")\n\n");
        email.append(String.format("%-8s %-16s %-16s %-9s %-20s %-3s %-9s %-7s %-7s %-4s %-5s %-3s%n", "#",
                "BEGIN", "END", "MMSI", "NAME", "LOA", "TYPE", "LAT", "LON", "SOG", "COG", "HDG"));
        email.append(/* www  . j av a  2 s  .c  o m*/
                "----------------------------------------------------------------------------------------------------------------------\n");
        eventsByType.get(eventType).forEach(event -> {
            Vessel vessel = event.getBehaviours().iterator().next().getVessel();
            TrackingPoint tp = event.getBehaviours().iterator().next().getTrackingPoints().last();
            email.append(String.format("%8d ", event.getId()));
            email.append(String.format("%16s ", DATE_FORMAT.format(event.getStartTime())));
            email.append(String.format("%16s ",
                    event.getEndTime() == null ? " " : DATE_FORMAT.format(event.getStartTime())));
            email.append(String.format("%9d ", vessel.getMmsi()));
            email.append(String.format("%-20s ", vessel.getName() == null ? "" : vessel.getName()));
            email.append(String.format("%3d ", vessel.getLength() == null ? -1 : vessel.getLength()));
            email.append(String
                    .format("%-9s ",
                            vessel.getType() == null ? ""
                                    : Categorizer.mapShipTypeCategoryToString(
                                            Categorizer.mapShipTypeToCategory(vessel.getType())))
                    .toUpperCase());
            email.append(String.format("%7.4f ", tp.getLatitude() == null ? Float.NaN : tp.getLatitude()));
            email.append(String.format("%7.4f ", tp.getLongitude() == null ? Float.NaN : tp.getLongitude()));
            email.append(String.format("%4.1f ",
                    tp.getSpeedOverGround() == null ? Float.NaN : tp.getSpeedOverGround()));
            email.append(String.format("%5.1f ",
                    tp.getCourseOverGround() == null ? Float.NaN : tp.getCourseOverGround()));
            email.append(
                    String.format("%3.0f ", tp.getTrueHeading() == null ? Float.NaN : tp.getTrueHeading()));
            email.append('\n');
        });
        email.append(
                "======================================================================================================================\n");
        email.append("\n");
    });
    email.append("\n");
    email.append("</pre>");
    email.append("</html>");

    return email.toString();
}

From source file:com.android.tools.idea.navigator.nodes.AndroidResFolderTypeNode.java

@NotNull
@Override/*  ww w. j a  v a  2s. c  om*/
public Collection<? extends AbstractTreeNode> getChildren() {
    // all resource folders of a given folder type
    List<PsiDirectory> folders = getValue();

    Multimap<String, PsiFile> multimap = HashMultimap.create();
    for (PsiDirectory res : folders) {
        for (PsiFile file : res.getFiles()) {
            String resName = file.getName();
            multimap.put(resName, file);
        }
    }

    List<AbstractTreeNode> children = Lists.newArrayListWithExpectedSize(multimap.size());
    for (String resName : multimap.keySet()) {
        List<PsiFile> files = Lists.newArrayList(multimap.get(resName));
        if (files.size() > 1) {
            children.add(new AndroidResGroupNode(myProject, myFacet, files, resName, getSettings()));
        } else {
            children.add(new AndroidResFileNode(myProject, files.get(0), getSettings(), myFacet));
        }
    }
    return children;
}

From source file:org.hudsonci.maven.plugin.dependencymonitor.internal.ProjectArtifactCacheImpl.java

private boolean projectsContain(final Multimap<AbstractProject, MavenCoordinatesDTO> source,
        final MavenCoordinatesDTO artifact) {
    assert source != null;
    assert artifact != null;
    for (AbstractProject project : source.keySet()) {
        if (source.containsEntry(project, artifact)) {
            return true;
        }//  ww w  .  j a v a2 s.com
    }
    return false;
}

From source file:eu.mondo.driver.fourstore.FourStoreGraphDriverReadWrite.java

@Override
public void insertEdges(final Multimap<String, String> edges, final String type) throws IOException {
    if (edges.isEmpty()) {
        return;/*from w  ww  .  j a v  a 2s  .  c  om*/
    }

    final ArrayList<String> sourceVertices = new ArrayList<>(edges.keySet());
    final List<List<String>> sourceVerticesPartitions = Lists.partition(sourceVertices, PARTITION_SIZE);
    for (final List<String> sourceVerticesPartition : sourceVerticesPartitions) {

        final Multimap<String, String> edgePartition = ArrayListMultimap.create();
        for (final String sourceVertexURI : sourceVerticesPartition) {
            final Collection<String> targetVertexURIs = edges.get(sourceVertexURI);
            edgePartition.putAll(sourceVertexURI, targetVertexURIs);
        }

        insertEdgesPartition(edgePartition, type);
    }
}

From source file:eu.mondo.driver.mongo.MongoGraphDriver.java

@Override
public void insertEdges(final Multimap<String, String> edges, final String edgeURI) throws IOException {
    if (edges.isEmpty()) {
        return;/*from www  .ja v  a2 s  . co m*/
    }

    for (String sourceVertexURI : edges.keySet()) {
        for (String destinationVertexURI : edges.get(sourceVertexURI)) {
            insertEdge(sourceVertexURI, destinationVertexURI, edgeURI);
        }
    }

}

From source file:com.google.api.explorer.client.embedded.EmbeddedParameterForm.java

private void setParameterValues(Multimap<String, String> paramValues) {
    if (paramValues != null && !paramValues.isEmpty()) {
        for (String key : paramValues.keySet()) {
            if (nameToEditor.containsKey(key)) {
                nameToEditor.get(key).setValue(Lists.newArrayList(paramValues.get(key)));
            }/*w w  w.  j  a v  a2s .  c  o  m*/
        }
    }
}

From source file:org.apache.gobblin.data.management.copy.publisher.CopyDataPublisher.java

@Override
public void publishData(Collection<? extends WorkUnitState> states) throws IOException {

    /*//  w  w w.  j av  a 2 s . co  m
     * This mapping is used to set WorkingState of all {@link WorkUnitState}s to {@link
     * WorkUnitState.WorkingState#COMMITTED} after a {@link CopyableDataset} is successfully published
     */
    Multimap<CopyEntity.DatasetAndPartition, WorkUnitState> datasets = groupByFileSet(states);

    boolean allDatasetsPublished = true;
    for (CopyEntity.DatasetAndPartition datasetAndPartition : datasets.keySet()) {
        try {
            this.publishFileSet(datasetAndPartition, datasets.get(datasetAndPartition));
        } catch (Throwable e) {
            CopyEventSubmitterHelper.submitFailedDatasetPublish(this.eventSubmitter, datasetAndPartition);
            log.error("Failed to publish " + datasetAndPartition.getDataset().getDatasetURN(), e);
            allDatasetsPublished = false;
        }
    }

    if (!allDatasetsPublished) {
        throw new IOException("Not all datasets published successfully");
    }
}

From source file:com.bazaarvoice.snitch.servlet.VariableServlet.java

@SuppressWarnings("unchecked")
@Override/*from ww  w.j  a va2s  .co m*/
protected void doGet(HttpServletRequest req, HttpServletResponse response)
        throws ServletException, IOException {
    addClientNoCacheHeaders(response);
    response.setContentType("application/json");

    // Organize the variables into a multimap indexed by key
    Multimap<String, Variable> variables = HashMultimap.create();
    for (Variable variable : _snitch.getVariables()) {
        variables.put(variable.getName(), variable);
    }

    JsonWriter writer = new JsonWriter(new BufferedWriter(response.getWriter()));
    writer.setIndent("  "); // Pretty print by default

    try {
        writer.beginObject();
        for (String name : variables.keySet()) {
            Collection<Variable> vars = variables.get(name);

            writer.name(name);
            if (vars.size() > 1) {
                // Only render as an array if we have a name collision
                writer.beginArray();
            }
            for (Variable variable : vars) {
                Formatter formatter = _snitch.getFormatter(variable);
                formatter.format(variable.getValue(), writer);
            }
            if (vars.size() > 1) {
                writer.endArray();
            }
        }
        writer.endObject();
    } finally {
        Closeables.closeQuietly(writer);
    }
}

From source file:eu.mondo.driver.mongo.MongoGraphDriver.java

@Override
public void deleteEdges(final Multimap<String, String> vertexURIs, final String edgeURI) throws IOException {
    if (vertexURIs.isEmpty()) {
        return;/*w w  w . jav  a 2s  .  com*/
    }

    for (String sourceVertexURI : vertexURIs.keySet()) {
        for (String destinationVertexURI : vertexURIs.get(sourceVertexURI)) {
            deleteEdge(sourceVertexURI, destinationVertexURI, edgeURI);
        }
    }
}