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

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

Introduction

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

Prototype

Map<K, Collection<V>> asMap();

Source Link

Document

Returns a view of this multimap as a Map from each distinct key to the nonempty collection of that key's associated values.

Usage

From source file:com.sk89q.eduardo.service.event.EventBus.java

/**
 * Unregisters the given handlers./*from w  w w.  ja v a  2  s  .c  o  m*/
 *
 * @param handlers a map of handlers
 */
public synchronized void unsubscribeAll(Multimap<Class<?>, EventHandler> handlers) {
    checkNotNull(handlers);
    for (Map.Entry<Class<?>, Collection<EventHandler>> entry : handlers.asMap().entrySet()) {
        Set<EventHandler> currentHandlers = getHandlersForEventType(entry.getKey());
        Collection<EventHandler> eventMethodsInListener = entry.getValue();

        if (currentHandlers != null && !currentHandlers.containsAll(entry.getValue())) {
            currentHandlers.removeAll(eventMethodsInListener);
        }
    }
}

From source file:com.sun.tools.hat.internal.server.RootsQuery.java

@Override
public void run() {
    long id = parseHex(query);
    JavaHeapObject target = snapshot.findThing(id);
    if (target == null) {
        startHtml("Object not found for rootset");
        error("object not found");
        endHtml();//  w w w  .ja  v  a2  s.c  o  m
        return;
    }
    if (includeWeak) {
        startHtml("Rootset references to " + target + " (includes weak refs)");
    } else {
        startHtml("Rootset references to " + target + " (excludes weak refs)");
    }
    out.flush();

    out.print("<h1>References to ");
    printThing(target);
    out.println("</h1>");
    // More interesting values are *higher*
    Multimap<Integer, ReferenceChain> refs = Multimaps.index(snapshot.rootsetReferencesTo(target, includeWeak),
            chain -> chain.getObj().getRoot().getType());
    refs.asMap().entrySet().stream().sorted(Ordering.natural().reverse().onResultOf(entry -> entry.getKey()))
            .forEach(entry -> {
                out.print("<h2>");
                print(Root.getTypeName(entry.getKey()) + " References");
                out.println("</h2>");
                entry.getValue().stream().sorted(Ordering.natural().onResultOf(ReferenceChain::getDepth))
                        .forEach(ref -> {
                            Root root = ref.getObj().getRoot();
                            out.print("<h3>");
                            printRoot(root);
                            if (root.getReferer() != null) {
                                out.print("<small> (from ");
                                printThingAnchorTag(root.getReferer().getId());
                                print(root.getReferer().toString());
                                out.print(")</a></small>");

                            }
                            out.print(" :</h3>");
                            while (ref != null) {
                                ReferenceChain next = ref.getNext();
                                JavaHeapObject obj = ref.getObj();
                                print("--> ");
                                printThing(obj);
                                if (next != null) {
                                    print(" (" + obj.describeReferenceTo(next.getObj(), snapshot) + ":)");
                                }
                                out.println("<br>");
                                ref = next;
                            }
                        });
            });

    out.println("<h2>Other queries</h2>");

    if (includeWeak) {
        printAnchorStart();
        out.print("roots/");
        printHex(id);
        out.print("\">");
        out.println("Exclude weak refs</a><br>");
        endHtml();
    }

    if (!includeWeak) {
        printAnchorStart();
        out.print("allRoots/");
        printHex(id);
        out.print("\">");
        out.println("Include weak refs</a><br>");
    }
}

From source file:edu.harvard.med.screensaver.service.screens.ScreenDerivedPropertiesUpdater.java

private SortedSet<Integer> findMaxReplicatesPerPlateNumber(SortedSet<AssayPlate> assayPlatesScreened) {
    Multimap<Integer, AssayPlate> plateNumbersToAssayPlates = Multimaps.index(assayPlatesScreened,
            AssayPlate.ToPlateNumber);/*  w w w  .  j  a  v  a  2 s .  c  o m*/
    SortedSet<Integer> maxReplicatesPerPlateNumber = Sets
            .newTreeSet(Iterables.transform(plateNumbersToAssayPlates.asMap().entrySet(),
                    new Function<Map.Entry<Integer, Collection<AssayPlate>>, Integer>() {
                        @Override
                        public Integer apply(Map.Entry<Integer, Collection<AssayPlate>> e) {
                            Iterable<Integer> replicateOrdinals = Iterables.transform(e.getValue(),
                                    AssayPlate.ToReplicateOrdinal);
                            return Ordering.natural().max(replicateOrdinals) + 1;
                        }
                    }));
    return maxReplicatesPerPlateNumber;
}

From source file:com.facebook.buck.apple.clang.VFSOverlay.java

@JsonProperty("roots")
private ImmutableList<VirtualDirectory> computeRoots() {
    Multimap<Path, Pair<Path, Path>> byParent = MultimapBuilder.hashKeys().hashSetValues().build();
    overlays.forEach((virtual, real) -> {
        byParent.put(virtual.getParent(), new Pair<>(virtual.getFileName(), real));
    });//from   www. j  a  v  a 2 s.c o m
    return byParent.asMap().entrySet().stream()
            .map(e -> new VirtualDirectory(e.getKey(),
                    e.getValue().stream().map(x -> new VirtualFile(x.getFirst(), x.getSecond()))
                            .collect(ImmutableList.toImmutableList())))
            .collect(ImmutableList.toImmutableList());
}

From source file:com.facebook.buck.util.FakeListeningProcessExecutor.java

public FakeListeningProcessExecutor(Multimap<ProcessExecutorParams, FakeListeningProcessState> processStates,
        SettableFakeClock clock) {/*from   ww  w .  java2s. c  o m*/
    this(Functions.forMap(processStates.asMap()), clock);
}

From source file:nl.tue.gale.ae.processor.XMLProcessor.java

public Map<List<String>, Module> getModuleTable() {
    Map<List<String>, Module> result = new HashMap<List<String>, Module>();
    Multimap<Module, String> buildMap = HashMultimap.create();
    for (Map.Entry<String, Module> entry : moduleTable.entrySet())
        buildMap.put(entry.getValue(), entry.getKey());
    for (Map.Entry<Module, Collection<String>> entry : buildMap.asMap().entrySet())
        result.put(new ArrayList<String>(entry.getValue()), entry.getKey());
    return result;
}

From source file:org.chaston.oakfunds.storage.mgmt.SchemaBuilder.java

private Map<String, TableDef.Builder> createBaseTables(Multimap<RecordType, RecordType> typesBySuperType) {
    ImmutableMap.Builder<String, TableDef.Builder> baseTables = ImmutableMap.builder();
    for (Map.Entry<RecordType, Collection<RecordType>> entry : typesBySuperType.asMap().entrySet()) {
        RecordType rootType = entry.getKey();
        TableDef.Builder tableDefBuilder = TableDef.builder(SystemColumnDefs.SCHEMA, rootType.getName());
        tableDefBuilder.addColumnDef(//from  ww  w . j  a  va2  s  .c  om
                rootType.isAutoIncrementId() ? SystemColumnDefs.AUTO_NUMBERED_ID : SystemColumnDefs.MANUAL_ID);
        tableDefBuilder.addColumnDef(SystemColumnDefs.TYPE);

        switch (rootType.getTemporalType()) {
        case NONE:
            // Nothing more to add.
            break;
        case INSTANT:
            tableDefBuilder.addColumnDef(SystemColumnDefs.INSTANT);
            break;
        case INTERVAL:
            tableDefBuilder.addColumnDef(SystemColumnDefs.START_TIME);
            tableDefBuilder.addColumnDef(SystemColumnDefs.END_TIME);
            break;
        default:
            throw new UnsupportedOperationException(
                    "Temporal type " + rootType.getTemporalType() + " is not supported.");
        }

        if (rootType.getContainingType() != null) {
            tableDefBuilder.addColumnDef(SystemColumnDefs.CONTAINER_ID);
        }

        Collection<RecordType> subTypes = entry.getValue();
        for (RecordType<?> subType : subTypes) {
            for (AttributeType attributeType : subType.getAttributes().values()) {
                tableDefBuilder.addColumnDef(new ColumnDef(attributeType.getColumnName(),
                        toSqlType(attributeType.getType()), false)); // Never make user defined types required.
            }
        }
        baseTables.put(rootType.getName(), tableDefBuilder);
    }
    return baseTables.build();
}

From source file:org.opentestsystem.shared.security.domain.SbacUser.java

public SbacUser(final Multimap<String, SbacRole> inUserRoles, final Map<String, String> userAttributes) {
    this.sbacRolesMap = inUserRoles == null ? EMPTY_MAP : ImmutableMap.copyOf(inUserRoles.asMap());
    this.authorities = inUserRoles == null ? EMPTY_LIST
            : SbacRole.calculateGrantedAuthority(inUserRoles.values());
    this.authoritesByTenantId = calculateAuthoritiesByTenantId(inUserRoles);
    Map<String, String> userAttribsToUse = userAttributes;
    if (userAttributes == null) {
        userAttribsToUse = BLANK_USER_ATTRIBS;
    }//from   w w  w  . j a v  a  2  s .c o m
    firstName = userAttribsToUse.get(FIRST_NAME_KEY);
    lastName = userAttribsToUse.get(LAST_NAME_KEY);
    fullName = userAttribsToUse.get(FULL_NAME_KEY);
    email = userAttribsToUse.get(EMAIL_KEY);
    uniqueId = userAttribsToUse.get(USER_UNIQUE_ID_KEY);
    phoneNumber = userAttribsToUse.get(PHONE_KEY);
}

From source file:org.sonar.server.qualitygate.QualityGateEvaluatorImpl.java

@Override
public EvaluatedQualityGate evaluate(QualityGate gate, Measures measures) {
    EvaluatedQualityGate.Builder result = EvaluatedQualityGate.newBuilder().setQualityGate(gate);

    boolean isSmallChangeset = isSmallChangeset(measures);
    Multimap<String, Condition> conditionsPerMetric = gate.getConditions().stream()
            .collect(MoreCollectors.index(Condition::getMetricKey, Function.identity()));

    for (Map.Entry<String, Collection<Condition>> entry : conditionsPerMetric.asMap().entrySet()) {
        String metricKey = entry.getKey();
        Collection<Condition> conditionsOnSameMetric = entry.getValue();

        EvaluatedCondition evaluation = evaluateConditionsOnMetric(conditionsOnSameMetric, measures);

        if (isSmallChangeset && evaluation.getStatus() != EvaluationStatus.OK
                && METRICS_TO_IGNORE_ON_SMALL_CHANGESETS.contains(metricKey)) {
            result.addCondition(new EvaluatedCondition(evaluation.getCondition(), EvaluationStatus.OK,
                    evaluation.getValue().orElse(null)));
            result.setIgnoredConditionsOnSmallChangeset(true);
        } else {/*from   www . j ava  2 s.  co  m*/
            result.addCondition(evaluation);
        }
    }

    result.setStatus(overallStatusOf(result.getEvaluatedConditions()));

    return result.build();
}

From source file:org.bugkillers.bus.eventbus.SubscriberRegistry_.java

/**
 * Registers all subscriber methods on the given listener object.
 *//*  ww  w . j a  v a 2s  .  c o m*/
void register(Object listener) {
    Multimap<Class<?>, Subscriber_> listenerMethods = findAllSubscribers(listener);

    for (Map.Entry<Class<?>, Collection<Subscriber_>> entry : listenerMethods.asMap().entrySet()) {
        Class<?> eventType = entry.getKey();
        Collection<Subscriber_> eventMethodsInListener = entry.getValue();

        CopyOnWriteArraySet<Subscriber_> eventSubscribers = subscribers.get(eventType);

        if (eventSubscribers == null) {
            CopyOnWriteArraySet<Subscriber_> newSet = new CopyOnWriteArraySet<Subscriber_>();
            eventSubscribers = MoreObjects.firstNonNull(subscribers.putIfAbsent(eventType, newSet), newSet);
        }

        eventSubscribers.addAll(eventMethodsInListener);
    }
}