Example usage for com.google.common.collect SetMultimap put

List of usage examples for com.google.common.collect SetMultimap put

Introduction

In this page you can find the example usage for com.google.common.collect SetMultimap put.

Prototype

boolean put(@Nullable K key, @Nullable V value);

Source Link

Document

Stores a key-value pair in this multimap.

Usage

From source file:eu.esdihumboldt.hale.app.bgis.ade.propagate.CityGMLPropagate.java

private void generateMapping() {
    System.out.println("Indexing example cells...");

    // index all cells based on the target property name
    SetMultimap<String, Cell> bgisExamples = HashMultimap.create();
    SetMultimap<QName, Cell> cityGMLExamples = HashMultimap.create();

    for (Cell cell : examples.getCells()) {
        if (cell.getTarget().size() == 1) {
            // only supports cells with one target
            EntityDefinition entityDef = CellUtil.getFirstEntity(cell.getTarget()).getDefinition();
            // XXX check source?!
            if (entityDef.getDefinition() instanceof PropertyDefinition) {
                QName name = entityDef.getDefinition().getName();
                if (ADE_NS.equals(name.getNamespaceURI())) {
                    bgisExamples.put(name.getLocalPart(), cell);
                } else if (name.getNamespaceURI().startsWith(CITYGML_NAMESPACE_CORE)) {
                    // XXX only support level 1 properties?
                    cityGMLExamples.put(name, cell);
                } else
                    System.out.println(
                            "WARNING: ignoring cell with target property neither from CityGML nor from BGIS ADE");
            } else
                System.out.println("WARNING: ignoring type cell");
        } else/* www.  j  a v  a  2 s .com*/
            System.out.println("WARNING: ignoring cell with multiple or no targets");
    }

    // collect all ADE feature types
    List<TypeDefinition> featureTypes = BGISAppUtil.getADEFeatureTypes(targetSchema);

    // collect ADE display names
    Set<String> adeTypeNames = new HashSet<String>();
    for (TypeDefinition type : featureTypes) {
        adeTypeNames.add(type.getDisplayName());
    }

    // collect possibly relevant target CityGML feature types
    for (TypeDefinition type : targetSchema.getTypes()) {
        if (type.getName().getNamespaceURI().startsWith(CITYGML_NAMESPACE_CORE)
                && BGISAppUtil.isFeatureType(type)) {
            if (!adeTypeNames.contains(type.getDisplayName())) {
                /*
                 * But ensure to only add those that do not share the
                 * display name with an ADE type, as in the feature map the
                 * type identification is only done on based on the display
                 * name, and ADE types take precedent.
                 */
                featureTypes.add(type);
            }
        }
    }

    // visit ADE properties and create cells
    System.out.println("Generating mapping from example cells for");
    String cellNote = MessageFormat
            .format("Generated through propagation of example cells on CityGML and BGIS ADE feature types.\n"
                    + "{0,date,medium}", new Date());
    CityGMLPropagateVisitor visitor = new CityGMLPropagateVisitor(cityGMLSource, bgisExamples, cityGMLExamples,
            config, cellNote);
    for (TypeDefinition type : featureTypes) {
        System.out.println(type.getDisplayName() + "...");
        visitor.accept(new TypeEntityDefinition(type, SchemaSpaceID.TARGET, null));
    }

    if (visitor.getCells().isEmpty()) {
        System.out.println("WARNING: no cells were created");
    } else {
        System.out.println(visitor.getCells().size() + " cells were created.");
    }

    // create alignment
    MutableAlignment align = new DefaultAlignment();
    for (MutableCell cell : visitor.getCells()) {
        align.addCell(cell);
    }

    this.alignment = align;
}

From source file:org.jakstab.transformation.VpcCfgReconstruction.java

/**
 * Fold ART into a map from VPC locations to sets of abstract states, and
 * then flatten the state sets into single abstract states by joining.
 * /*  w w  w  . j  a  va2s . c o m*/
 * @return a map from VPC locations to the join of all abstract states at 
 * that VPC location
 */
private Map<Location, AbstractState> flattenArtOntoVpcLocations() {

    SetMultimap<Location, AbstractState> vpcSensitiveReached = HashMultimap.create();

    Deque<AbstractState> worklist = new LinkedList<AbstractState>();
    worklist.add(art.getRoot());
    Set<AbstractState> visited = new HashSet<AbstractState>();
    visited.add(art.getRoot());

    while (!worklist.isEmpty()) {
        AbstractState headState = worklist.removeFirst();
        if (isVpcStateBot(headState))
            continue;

        BasedNumberElement vpcVal = getVPC(headState);
        VpcLocation headVpcLoc = new VpcLocation(vpcVal, (RTLLabel) headState.getLocation());

        vpcSensitiveReached.put(headVpcLoc, headState);

        Set<Pair<CFAEdge, AbstractState>> successors = art.getChildren(headState);
        for (Pair<CFAEdge, AbstractState> sPair : successors) {
            AbstractState nextState = sPair.getRight();

            if (!visited.contains(nextState)) {
                visited.add(nextState);
                worklist.add(nextState);
            }
        }
    }

    Map<Location, AbstractState> constants = new HashMap<Location, AbstractState>();
    for (Location l : vpcSensitiveReached.keySet()) {
        constants.put(l, Lattices.joinAll(vpcSensitiveReached.get(l)));
    }

    return constants;
}

From source file:org.glowroot.central.repo.GaugeValueDaoImpl.java

private SetMultimap<Long, String> getRollupCaptureTimes(List<GaugeValue> gaugeValues) {
    SetMultimap<Long, String> rollupCaptureTimes = HashMultimap.create();
    List<RollupConfig> rollupConfigs = configRepository.getRollupConfigs();
    for (GaugeValue gaugeValue : gaugeValues) {
        String gaugeName = gaugeValue.getGaugeName();
        long captureTime = gaugeValue.getCaptureTime();
        long intervalMillis = rollupConfigs.get(0).intervalMillis();
        long rollupCaptureTime = CaptureTimes.getRollup(captureTime, intervalMillis);
        rollupCaptureTimes.put(rollupCaptureTime, gaugeName);
    }/*from  w w  w . j av  a  2s.  c  o  m*/
    return rollupCaptureTimes;
}

From source file:org.apache.brooklyn.feed.jmx.JmxFeed.java

protected JmxFeed(Builder builder) {
    super();//  w  w w.j  av  a 2  s  .  co  m
    if (builder.helper != null) {
        JmxHelper helper = builder.helper;
        setConfig(HELPER, helper);
        setConfig(OWN_HELPER, false);
        setConfig(JMX_URI, helper.getUrl());
    }
    setConfig(JMX_CONNECTION_TIMEOUT, builder.jmxConnectionTimeout);

    SetMultimap<String, JmxAttributePollConfig<?>> attributePolls = HashMultimap
            .<String, JmxAttributePollConfig<?>>create();
    for (JmxAttributePollConfig<?> config : builder.attributePolls) {
        if (!config.isEnabled())
            continue;
        @SuppressWarnings({ "rawtypes", "unchecked" })
        JmxAttributePollConfig<?> configCopy = new JmxAttributePollConfig(config);
        if (configCopy.getPeriod() < 0)
            configCopy.period(builder.period, builder.periodUnits);
        attributePolls.put(configCopy.getObjectName().getCanonicalName() + configCopy.getAttributeName(),
                configCopy);
    }
    setConfig(ATTRIBUTE_POLLS, attributePolls);

    SetMultimap<List<?>, JmxOperationPollConfig<?>> operationPolls = HashMultimap
            .<List<?>, JmxOperationPollConfig<?>>create();
    for (JmxOperationPollConfig<?> config : builder.operationPolls) {
        if (!config.isEnabled())
            continue;
        @SuppressWarnings({ "rawtypes", "unchecked" })
        JmxOperationPollConfig<?> configCopy = new JmxOperationPollConfig(config);
        if (configCopy.getPeriod() < 0)
            configCopy.period(builder.period, builder.periodUnits);
        operationPolls.put(configCopy.buildOperationIdentity(), configCopy);
    }
    setConfig(OPERATION_POLLS, operationPolls);

    SetMultimap<NotificationFilter, JmxNotificationSubscriptionConfig<?>> notificationSubscriptions = HashMultimap
            .create();
    for (JmxNotificationSubscriptionConfig<?> config : builder.notificationSubscriptions) {
        if (!config.isEnabled())
            continue;
        notificationSubscriptions.put(config.getNotificationFilter(), config);
    }
    setConfig(NOTIFICATION_SUBSCRIPTIONS, notificationSubscriptions);
    initUniqueTag(builder.uniqueTag, attributePolls, operationPolls, notificationSubscriptions);
}

From source file:brooklyn.event.feed.shell.ShellFeed.java

protected ShellFeed(Builder builder) {
    super();//from  ww  w .  j a  va  2  s.c  o m

    SetMultimap<ShellPollIdentifier, ShellPollConfig<?>> polls = HashMultimap
            .<ShellPollIdentifier, ShellPollConfig<?>>create();
    for (ShellPollConfig<?> config : builder.polls) {
        @SuppressWarnings({ "unchecked", "rawtypes" })
        ShellPollConfig<?> configCopy = new ShellPollConfig(config);
        if (configCopy.getPeriod() < 0)
            configCopy.period(builder.period, builder.periodUnits);
        String command = config.getCommand();
        Map<String, String> env = config.getEnv();
        File dir = config.getDir();
        String input = config.getInput();
        String context = config.getSensor().getName();
        long timeout = config.getTimeout();

        polls.put(new ShellPollIdentifier(command, env, dir, input, context, timeout), configCopy);
    }
    setConfig(POLLS, polls);
    initUniqueTag(builder.uniqueTag, polls.values());
}

From source file:org.terasology.recording.EventSystemReplayImpl.java

private void addToComponentSpecificHandlers(Class<? extends Event> type,
        EventSystemReplayImpl.EventHandlerInfo handlerInfo, Class<? extends Component> c) {
    SetMultimap<Class<? extends Component>, EventSystemReplayImpl.EventHandlerInfo> componentMap = componentSpecificHandlers
            .get(type);/*from ww w.java2s.  com*/
    if (componentMap == null) {
        componentMap = HashMultimap.create();
        componentSpecificHandlers.put(type, componentMap);
    }
    componentMap.put(c, handlerInfo);
}

From source file:exm.stc.ic.opt.WaitCoalescer.java

private static void findRelocatableBlockingInstructions(Program prog, Block block,
        SetMultimap<Var, InstOrCont> waitMap) {
    for (Statement stmt : block.getStatements()) {
        if (stmt.type() != StatementType.INSTRUCTION) {
            continue; // Only interested in instructions
        }//from   w  w w . jav a2  s.  co  m

        Instruction inst = stmt.instruction();
        // check all outputs are non-alias futures - if not can't safely reorder
        boolean canMove = true;
        for (Var out : inst.getOutputs()) {
            if (!Types.isFuture(out) || out.storage() == Alloc.ALIAS) {
                canMove = false;
                break;
            }
        }
        if (canMove) {
            // Put in map based on which inputs will block execution of task
            List<Var> bi = inst.getBlockingInputs(prog);
            if (bi != null) {
                for (Var in : bi) {
                    if (trackForPushdown(in)) {
                        waitMap.put(in, new InstOrCont(inst));
                    }
                }
            }
        }
    }
}

From source file:org.eclipse.rdf4j.sail.lucene.AbstractSearchIndex.java

/**
 * Add a complete Lucene Document based on these statements. Do not search for an existing document with
 * the same subject id. (assume the existing document was deleted)
 * /*from   w w w  .  jav  a2 s .c o  m*/
 * @param statements
 *        the statements that make up the resource
 * @throws IOException
 */
@Override
public final synchronized void addDocuments(Resource subject, List<Statement> statements) throws IOException {

    String resourceId = SearchFields.getResourceID(subject);

    SetMultimap<String, Statement> stmtsByContextId = HashMultimap.create();

    String contextId;
    for (Statement statement : statements) {
        contextId = SearchFields.getContextID(statement.getContext());

        stmtsByContextId.put(contextId, statement);
    }

    BulkUpdater batch = newBulkUpdate();
    for (Entry<String, Collection<Statement>> entry : stmtsByContextId.asMap().entrySet()) {
        // create a new document
        String id = SearchFields.formIdString(resourceId, entry.getKey());
        SearchDocument document = newDocument(id, resourceId, entry.getKey());

        for (Statement stmt : entry.getValue()) {
            // determine stuff to store
            addProperty(stmt, document);
        }
        // add it to the index
        batch.add(document);
    }
    batch.end();
}

From source file:org.jakstab.ProgramGraphWriter.java

public void writeDisassembly(Program program, String filename) {
    logger.info("Writing assembly file to " + filename);

    SetMultimap<AbsoluteAddress, CFAEdge> branchEdges = HashMultimap.create();
    SetMultimap<AbsoluteAddress, CFAEdge> branchEdgesRev = HashMultimap.create();
    if (!Options.noGraphs.getValue()) {
        for (CFAEdge e : program.getCFA()) {
            AbsoluteAddress sourceAddr = e.getSource().getAddress();
            AbsoluteAddress targetAddr = e.getTarget().getAddress();
            if (program.getInstruction(sourceAddr) instanceof BranchInstruction
                    && !sourceAddr.equals(targetAddr)) {
                branchEdges.put(sourceAddr, e);
                branchEdgesRev.put(targetAddr, e);
            }/*from w w  w  .  j a  v  a 2  s .co m*/
        }
    }

    try {
        FileWriter out = new FileWriter(filename);
        for (Map.Entry<AbsoluteAddress, Instruction> entry : program.getAssemblyMap().entrySet()) {
            AbsoluteAddress pc = entry.getKey();
            Instruction instr = entry.getValue();
            StringBuilder sb = new StringBuilder();
            SymbolFinder symFinder = program.getModule(pc).getSymbolFinder();
            if (symFinder.hasSymbolFor(pc)) {
                sb.append(Characters.NEWLINE);
                sb.append(symFinder.getSymbolFor(pc));
                sb.append(":").append(Characters.NEWLINE);
            }
            sb.append(pc).append(":\t");
            sb.append(instr.toString(pc.getValue(), symFinder));

            if (instr instanceof BranchInstruction) {
                Set<CFAEdge> targets = branchEdges.get(pc);
                sb.append("\t; targets: ");
                if (targets.isEmpty()) {
                    sb.append("unresolved");
                } else {
                    boolean first = true;
                    for (CFAEdge e : targets) {
                        if (first)
                            first = false;
                        else
                            sb.append(", ");
                        sb.append(e.getTarget().getAddress());
                        sb.append('(').append(e.getKind()).append(')');
                    }
                }
            }

            if (branchEdgesRev.containsKey(pc)) {
                Set<CFAEdge> referers = branchEdgesRev.get(pc);
                sb.append("\t; from: ");
                boolean first = true;
                for (CFAEdge e : referers) {
                    if (first)
                        first = false;
                    else
                        sb.append(", ");
                    sb.append(e.getSource().getAddress());
                    sb.append('(').append(e.getKind()).append(')');
                }
            }

            sb.append(Characters.NEWLINE);
            if (instr instanceof ReturnInstruction)
                sb.append(Characters.NEWLINE);
            out.write(sb.toString());
        }
        out.close();

    } catch (IOException e) {
        logger.fatal(e);
        return;
    }
}

From source file:de.bund.bfr.knime.gis.views.canvas.CanvasUtils.java

private static <E extends Element> HighlightResult<E> getResult(Collection<E> elements,
        HighlightConditionList highlightConditions) {
    List<Color> colorList = new ArrayList<>();
    ListMultimap<E, Double> alphaValues = ArrayListMultimap.create();
    Map<E, Double> thicknessValues = new LinkedHashMap<>();
    SetMultimap<E, String> labelLists = LinkedHashMultimap.create();
    Map<E, NamedShape> shapes = new LinkedHashMap<>();

    elements.forEach(e -> thicknessValues.put(e, 0.0));

    for (HighlightCondition condition : highlightConditions.getConditions()) {
        if (condition.isInvisible()) {
            continue;
        }/*from  w w w .  ja  v  a2  s . co  m*/

        Map<E, Double> values = condition.getValues(elements);

        if (condition.getColor() != null) {
            colorList.add(condition.getColor());

            for (E e : elements) {
                List<Double> alphas = alphaValues.get(e);

                if (!highlightConditions.isPrioritizeColors() || alphas.isEmpty()
                        || Collections.max(alphas) == 0.0) {
                    alphas.add(values.get(e));
                } else {
                    alphas.add(0.0);
                }
            }
        }

        if (condition.isUseThickness()) {
            elements.forEach(e -> thicknessValues.put(e, thicknessValues.get(e) + values.get(e)));
        }

        if (condition.getLabelProperty() != null) {
            String property = condition.getLabelProperty();

            for (E e : elements) {
                if (values.get(e) != 0.0 && e.getProperties().get(property) != null) {
                    labelLists.put(e, toString(e.getProperties().get(property)));
                }
            }
        }

        if (condition.getShape() != null) {
            for (E e : elements) {
                if (values.get(e) != 0.0 && !shapes.containsKey(e)) {
                    shapes.put(e, condition.getShape());
                }
            }
        }
    }

    Map<E, Paint> colors = new LinkedHashMap<>();
    Map<E, String> labels = new LinkedHashMap<>();

    Multimaps.asMap(alphaValues).forEach((e, alphas) -> colors.put(e, CanvasUtils
            .mixColors(e instanceof Edge ? Color.BLACK : Color.WHITE, colorList, alphas, e instanceof Edge)));
    Multimaps.asMap(labelLists).forEach((e, labelList) -> labels.put(e, Joiner.on("/").join(labelList)));

    HighlightResult<E> result = new HighlightResult<>();

    result.colors = colors;
    result.thicknessValues = thicknessValues;
    result.labels = labels;
    result.shapes = shapes;

    return result;
}