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.opengamma.bbg.referencedata.MockReferenceDataProvider.java

@Override
protected ReferenceDataProviderGetResult doBulkGet(ReferenceDataProviderGetRequest request) {
    if (_expectedFields.size() > 0) {
        for (String field : _expectedFields) {
            assertTrue(request.getFields().contains(field));
        }/*from  w w  w. j ava 2 s  .co m*/
    }
    ReferenceDataProviderGetResult result = new ReferenceDataProviderGetResult();
    for (String identifier : request.getIdentifiers()) {
        if (_mockDataMap.containsKey(identifier)) {
            // known security
            ReferenceData refData = new ReferenceData(identifier);
            MutableFudgeMsg msg = OpenGammaFudgeContext.getInstance().newMessage();

            Multimap<String, String> fieldMap = _mockDataMap.get(identifier);
            if (fieldMap != null) {
                // security actually has data
                for (String field : request.getFields()) {
                    Collection<String> values = fieldMap.get(field);
                    assertTrue("Field not found: " + field + " in " + fieldMap.keySet(), values.size() > 0);
                    assertNotNull(values);
                    for (String value : values) {
                        if (value != null) {
                            if (value.contains("=")) {
                                MutableFudgeMsg submsg = OpenGammaFudgeContext.getInstance().newMessage();
                                submsg.add(StringUtils.substringBefore(value, "="),
                                        StringUtils.substringAfter(value, "="));
                                msg.add(field, submsg);
                            } else {
                                msg.add(field, value);
                            }
                        }
                    }
                }
            }
            refData.setFieldValues(msg);
            result.addReferenceData(refData);

        } else {
            // security wasn't marked as known
            fail("Security not found: " + identifier + " in " + _mockDataMap.keySet());
        }
    }
    return result;
}

From source file:org.zalando.logbook.servlet.TeeRequest.java

@Override
public Multimap<String, String> getHeaders() {
    final Multimap<String, String> headers = ArrayListMultimap.create();
    final UnmodifiableIterator<String> iterator = forEnumeration(getHeaderNames());

    while (iterator.hasNext()) {
        final String header = iterator.next();
        addAll(headers.get(header), forEnumeration(getHeaders(header)));
    }/*from w  w  w .  j a  v  a 2 s. com*/

    return headers;
}

From source file:io.github.fsm.StateMachine.java

/**
 * A stateMachine is said to be valid iff it meets the following conditions
 * <ul>/*w  w  w .jav  a  2 s.com*/
 *     <li>It should have a valid start state and a nonempty set of end states. It has to be halting</li>
 *     <li>For all the states defined, make sure there are transitions from each one of 'em except for the end state</li>
 *     <li>Make sure there are no transitions defined from the endstate</li>
 * </ul>
 * @throws InvalidStateException
 */
public void validate() throws InvalidStateException {
    if (Objects.isNull(stateManagementService.getFrom()))
        throw new InvalidStateException("No start state found");
    if (stateManagementService.getEndStates().isEmpty())
        throw new InvalidStateException("No end states found");

    Set<State> allStates = stateManagementService.getReferenceStates();
    Multimap<State, Transition> map = transitionService.getTransitionDetails();
    map.keySet().stream().forEach(state -> {
        allStates.add(state);
        map.get(state).stream().forEach(transition -> {
            allStates.add(transition.getFrom());
            allStates.add(transition.getTo());
        });
    });

    for (State state : allStates) {
        Set<Transition> transitions = (Set<Transition>) map.get(state);
        if (isNullOrEmpty(transitions)) {
            if (!stateManagementService.getEndStates().contains(state)) {
                throw new InvalidStateException(
                        "state :" + state + " is not an end state but" + " has no outgoing transitions");
            }
            if (stateManagementService.getEndStates().contains(state)) {
                if (!transitions.isEmpty()) {
                    throw new InvalidStateException("state :" + state + " is an end state"
                            + " and cannot have any out going transition");
                }
            }
        }
    }
}

From source file:org.franca.examples.validators.fidl.UniqueStateNameValidator.java

@Override
public void validateModel(FModel model, ValidationMessageAcceptor messageAcceptor) {

    for (FInterface _interface : model.getInterfaces()) {
        FContract contract = _interface.getContract();
        if (contract != null) {
            Multimap<String, FState> stateNameMap = ArrayListMultimap.create();

            for (FState state : contract.getStateGraph().getStates()) {
                stateNameMap.put(state.getName(), state);
            }//from w w w .j a va  2 s  .  c  om

            for (String name : stateNameMap.keySet()) {
                Collection<FState> states = stateNameMap.get(name);
                if (states.size() > 1) {
                    for (FState state : states) {
                        messageAcceptor.acceptError("The name of the state is not unique!", state,
                                FrancaPackage.Literals.FMODEL_ELEMENT__NAME,
                                ValidationMessageAcceptor.INSIGNIFICANT_INDEX, null);
                    }
                }
            }
        }
    }
}

From source file:org.jboss.errai.ioc.rebind.ioc.bootstrapper.ProducerFactoryBodyGenerator.java

@Override
protected List<Statement> generateDestroyInstanceStatements(final ClassStructureBuilder<?> bodyBlockBuilder,
        final Injectable injectable, final DependencyGraph graph, final InjectionContext injectionContext) {
    final List<Statement> destroyInstanceStmts = new ArrayList<Statement>();
    final Multimap<DependencyType, Dependency> depsByType = separateByType(injectable.getDependencies());
    final Collection<Dependency> producerMemberDeps = depsByType.get(DependencyType.ProducerMember);

    if (producerMemberDeps.size() != 1) {
        throw new RuntimeException("A produced type must have exactly 1 producing instance but "
                + producerMemberDeps.size() + " were found.");
    }/*from   w  w w  . ja  va  2 s.c  om*/

    final Collection<Dependency> disposerMethodDeps = depsByType.get(DependencyType.DisposerMethod);
    if (disposerMethodDeps.size() > 1) {
        // TODO error message with matching disposer names.
        throw new RuntimeException();
    } else if (disposerMethodDeps.size() == 1) {
        final DisposerMethodDependency disposerDep = (DisposerMethodDependency) disposerMethodDeps.iterator()
                .next();
        final MetaMethod disposer = disposerDep.getDisposerMethod();

        controller.ensureMemberExposed(disposer);
        final Statement invocation = controller.exposedMethodStmt(
                controller.getReferenceStmt(PRODUCER_INSTANCE, disposer.getDeclaringClass()), disposer,
                getDisposerParams(disposer, depsByType.get(DependencyType.DisposerParameter),
                        bodyBlockBuilder.getClassDefinition()));
        destroyInstanceStmts.add(invocation);
    }

    return destroyInstanceStmts;
}

From source file:org.eclipse.xtext.xbase.ui.imports.MultiImportOrganizer.java

/**
 * @param files// w w w . j ava 2s .com
 *            ordered by corresponding {@link IProject}
 * @param mon
 * @return Creates {@link Change}s for each {@link IFile} using {@link ImportOrganizer}
 * @throws InterruptedException
 */
public List<Change> organizeImports(Multimap<IProject, IFile> files, IProgressMonitor mon)
        throws InterruptedException {
    List<Change> result = Lists.newArrayList();
    for (IProject project : files.keySet()) {
        ResourceSet resSet = resSetProvider.get(project);
        for (IFile file : files.get(project)) {
            mon.subTask("Calculating imports in - " + file.getName());
            URI uri = storageMapper.getUri(file);
            if (uri != null) {
                XtextResource resource = (XtextResource) resSet.getResource(uri, true);
                List<ReplaceRegion> replace = importOrganizer.getOrganizedImportChanges(resource);
                //TODO - find out why \n\n changes are produced, even if there are any unused imports
                if (replace == null) {
                    continue;
                }
                TextEdit textEdit = replaceConverter.convertToTextEdit(replace);
                IRefactoringDocument iRefactoringDocument = provider.get(uri, status);
                Change change = iRefactoringDocument.createChange(Messages.OrganizeImports, textEdit);
                if (change instanceof EditorDocumentChange) {
                    if (((EditorDocument) iRefactoringDocument).getEditor().isDirty()) {
                        ((EditorDocumentChange) change).setDoSave(false);
                    }
                }
                result.add(change);
            }
            mon.worked(1);
            if (mon.isCanceled()) {
                throw new InterruptedException();
            }
        }
    }
    return result;
}

From source file:com.griddynamics.jagger.engine.e1.collector.BasicSessionCollector.java

@Override
public void onSessionStarted(String sessionId, Multimap<NodeType, NodeId> nodes) {
    taskCounter = 0;//from www  .j av  a  2  s .  co  m

    Namespace namespace = Namespace.of(SESSION, sessionId);
    Multimap<String, Object> objectsMap = HashMultimap.create();
    objectsMap.put(START_TIME, System.currentTimeMillis());
    Collection<NodeId> kernels = nodes.get(NodeType.KERNEL);
    objectsMap.put(KERNELS_COUNT, kernels.size());

    for (NodeId nodeId : kernels) {
        objectsMap.put(AVAILABLE_KERNELS, nodeId.toString());
    }
    keyValueStorage.putAll(namespace, objectsMap);
}

From source file:org.yakindu.sct.ui.editor.validation.DefaultValidationIssueStore.java

protected boolean changedSeverity(String semanticElementID, Multimap<String, SCTIssue> oldVisibleIssues,
        Multimap<String, SCTIssue> newVisibleIssues) {
    Severity minOldSeverity = getMinSeverity(oldVisibleIssues.get(semanticElementID));
    Severity minNewSeverity = getMinSeverity(newVisibleIssues.get(semanticElementID));
    return minNewSeverity.ordinal() != minOldSeverity.ordinal();
}

From source file:org.apache.metron.parsing.parsers.BasicFireEyeParser.java

private JSONObject parseMessage(String toParse) {

    // System.out.println("Received message: " + toParse);

    // MetronMatch gm = grok.match(toParse);
    // gm.captures();

    JSONObject toReturn = new JSONObject();
    //toParse = toParse.replaceAll("  ", " ");
    String[] mTokens = toParse.split("\\s+");
    //mTokens = toParse.split(" ");

    // toReturn.putAll(gm.toMap());

    String id = mTokens[4];//from   w  ww  . j a v a2 s. c  o m

    // We are not parsing the fedata for multi part message as we cannot
    // determine how we can split the message and how many multi part
    // messages can there be.
    // The message itself will be stored in the response.

    String[] tokens = id.split("\\.");
    if (tokens.length == 2) {

        String[] array = Arrays.copyOfRange(mTokens, 1, mTokens.length - 1);
        String syslog = Joiner.on(" ").join(array);

        Multimap<String, String> multiMap = formatMain(syslog);

        for (String key : multiMap.keySet()) {

            String value = Joiner.on(",").join(multiMap.get(key));
            toReturn.put(key, value.trim());
        }

    }

    toReturn.put("original_string", toParse);

    String ip_src_addr = (String) toReturn.get("dvc");
    String ip_src_port = (String) toReturn.get("src_port");
    String ip_dst_addr = (String) toReturn.get("dst_ip");
    String ip_dst_port = (String) toReturn.get("dst_port");

    if (ip_src_addr != null)
        toReturn.put("ip_src_addr", ip_src_addr);
    if (ip_src_port != null)
        toReturn.put("ip_src_port", ip_src_port);
    if (ip_dst_addr != null)
        toReturn.put("ip_dst_addr", ip_dst_addr);
    if (ip_dst_port != null)
        toReturn.put("ip_dst_port", ip_dst_port);

    System.out.println(toReturn);

    return toReturn;
}

From source file:org.mqnaas.api.providers.MultiMapSerializationProvider.java

@Override
public void writeTo(Object t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType,
        MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream)
        throws IOException, WebApplicationException {

    StringBuilder sb = new StringBuilder();

    Multimap<Class<?>, IIdentifiable> multimap = (Multimap<Class<?>, IIdentifiable>) t;

    sb.append("<services>");

    for (Class<?> capability : multimap.keySet()) {
        sb.append("<capability name=\"").append(capability.getName()).append("\">");

        for (IIdentifiable identifiable : multimap.get(capability)) {

            sb.append("<service>");
            sb.append(identifiable.getId());
            sb.append("</service>");
        }/*from  w w  w .  ja va2 s.  c o  m*/

        sb.append("</capability>");
    }

    sb.append("</services>");

    entityStream.write(sb.toString().getBytes());
}