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.torodb.backend.AbstractReadInterface.java

@Override
@SuppressFBWarnings(value = { "OBL_UNSATISFIED_OBLIGATION",
        "ODR_OPEN_DATABASE_RESOURCE" }, justification = "ResultSet is wrapped in a Cursor<Integer>. It's iterated and closed in caller code")
public Cursor<Integer> getCollectionDidsWithFieldsIn(DSLContext dsl, MetaDatabase metaDatabase,
        MetaCollection metaCol, MetaDocPart metaDocPart, Multimap<MetaField, KvValue<?>> valuesMultimap)
        throws SQLException {
    assert metaDatabase.getMetaCollectionByIdentifier(metaCol.getIdentifier()) != null;
    assert metaCol.getMetaDocPartByIdentifier(metaDocPart.getIdentifier()) != null;
    assert valuesMultimap.keySet().stream()
            .allMatch(metafield -> metaDocPart.getMetaFieldByIdentifier(metafield.getIdentifier()) != null);

    if (valuesMultimap.size() > 500) {
        @SuppressWarnings("checkstyle:LineLength")
        Stream<Entry<Long, List<Tuple2<Entry<MetaField, KvValue<?>>, Long>>>> valuesEntriesBatchStream = Seq
                .seq(valuesMultimap.entries().stream()).zipWithIndex().groupBy(t -> t.v2 / 500).entrySet()
                .stream();//from   www.j a  v  a 2s.  co m
        Stream<Stream<Entry<MetaField, KvValue<?>>>> valuesEntryBatchStreamOfStream = valuesEntriesBatchStream
                .map(e -> e.getValue().stream().map(se -> se.v1));
        Stream<Multimap<MetaField, KvValue<?>>> valuesMultimapBatchStream = valuesEntryBatchStreamOfStream
                .map(e -> toValuesMultimap(e));
        Stream<Cursor<Integer>> didCursorStream = valuesMultimapBatchStream
                .map(Unchecked.function(valuesMultimapBatch -> getCollectionDidsWithFieldsInBatch(dsl,
                        metaDatabase, metaCol, metaDocPart, valuesMultimapBatch)));
        Stream<Integer> didStream = didCursorStream.flatMap(cursor -> cursor.getRemaining().stream());

        return new IteratorCursor<>(didStream.iterator());
    }

    return getCollectionDidsWithFieldsInBatch(dsl, metaDatabase, metaCol, metaDocPart, valuesMultimap);
}

From source file:cc.kave.commons.pointsto.analysis.inclusion.InclusionAnalysis.java

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

    ConstraintGenerationVisitor visitor = new ConstraintGenerationVisitor();
    ConstraintGenerationVisitorContext visitorContext = new ConstraintGenerationVisitorContext(context,
            new EmptyContextFactory());
    context.getSST().accept(visitor, visitorContext);

    ConstraintGraph graph = visitorContext.createConstraintGraph();
    graph.computeClosure();
    Multimap<DistinctReference, ConstraintEdge> ls = graph.computeLeastSolution();
    Map<ConstructedTerm, AbstractLocation> locations = new HashMap<>();

    DistinctReferenceContextCollector contextCollector = new DistinctReferenceContextCollector(context,
            ThisReferenceOption.PER_MEMBER);
    context.getSST().accept(new DistinctReferenceContextCollectorVisitor(), contextCollector);
    QueryKeyTransformer queryKeyTransformer = new QueryKeyTransformer(true);

    for (DistinctReference distRef : ls.keySet()) {
        // System.out.println(distRef.toString() + ":");

        Collection<ConstraintEdge> edges = ls.get(distRef);
        for (ConstraintEdge edge : edges) {
            ConstructedTerm cTerm = (ConstructedTerm) edge.getTarget().getSetExpression();
            AbstractLocation location = locations.get(cTerm);
            if (location == null) {
                location = new AbstractLocation();
                locations.put(cTerm, location);
            }
            // System.out.println("\t\t" + edge.toString());
            // System.out.println("\t\t" + location.toString());

            List<PointsToQuery> queries = distRef.accept(queryKeyTransformer, contextCollector);
            for (PointsToQuery query : queries) {
                contextToLocations.put(query, location);
            }
        }
    }

    return new PointsToContext(context, this);
}

From source file:org.apache.brooklyn.entity.nosql.cassandra.CassandraFabricImpl.java

@Override
public void init() {
    super.init();

    if (!config().getRaw(CassandraDatacenter.SEED_SUPPLIER).isPresentAndNonNull())
        config().set(CassandraDatacenter.SEED_SUPPLIER, getSeedSupplier());

    // track members
    policies().add(PolicySpec.create(MemberTrackingPolicy.class).displayName("Cassandra Fabric Tracker")
            .configure("group", this));

    // Track first node's startup
    subscriptions().subscribeToMembers(this, CassandraDatacenter.FIRST_NODE_STARTED_TIME_UTC,
            new SensorEventListener<Long>() {
                @Override/*from w w  w.  jav  a  2 s  . com*/
                public void onEvent(SensorEvent<Long> event) {
                    Long oldval = getAttribute(CassandraDatacenter.FIRST_NODE_STARTED_TIME_UTC);
                    Long newval = event.getValue();
                    if (oldval == null && newval != null) {
                        sensors().set(CassandraDatacenter.FIRST_NODE_STARTED_TIME_UTC, newval);
                        for (CassandraDatacenter member : Iterables.filter(getMembers(),
                                CassandraDatacenter.class)) {
                            ((EntityInternal) member).sensors()
                                    .set(CassandraDatacenter.FIRST_NODE_STARTED_TIME_UTC, newval);
                        }
                    }
                }
            });

    // Track the datacenters for this cluster
    subscriptions().subscribeToMembers(this, CassandraDatacenter.DATACENTER_USAGE,
            new SensorEventListener<Multimap<String, Entity>>() {
                @Override
                public void onEvent(SensorEvent<Multimap<String, Entity>> event) {
                    Multimap<String, Entity> usage = calculateDatacenterUsage();
                    sensors().set(DATACENTER_USAGE, usage);
                    sensors().set(DATACENTERS, usage.keySet());
                }
            });
    subscriptions().subscribe(this, DynamicGroup.MEMBER_REMOVED, new SensorEventListener<Entity>() {
        @Override
        public void onEvent(SensorEvent<Entity> event) {
            Multimap<String, Entity> usage = calculateDatacenterUsage();
            sensors().set(DATACENTER_USAGE, usage);
            sensors().set(DATACENTERS, usage.keySet());
        }
    });
}

From source file:hu.bme.mit.trainbenchmark.benchmark.fourstore.driver.FourStoreDriver.java

public void insertEdges(final Multimap<String, String> edges, final String type) throws IOException {
    if (edges.isEmpty()) {
        return;/*  w  w  w  . j a v  a 2s. co m*/
    }

    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:org.javersion.store.jdbc.AbstractVersionStoreJdbc.java

/**
 * NOTE: publish() is called in a new transaction to ensure it sees only committed versions.
 *///from   w  w  w.  j  av  a2s. c  o  m
@Override
public Multimap<Id, Revision> publish() {
    Multimap<Id, Revision> result = options.transactions.writeNewRequired(this::doPublish);
    if (this.cache != null) {
        result.keySet().forEach(this.cache::refresh);
    }
    return result;
}

From source file:org.jetbrains.kotlin.resolve.DeclarationResolver.java

private void reportRedeclarations(@NotNull Multimap<Name, DeclarationDescriptor> descriptorMap) {
    Set<Pair<PsiElement, Name>> redeclarations = Sets.newHashSet();
    for (Name name : descriptorMap.keySet()) {
        Collection<DeclarationDescriptor> descriptors = descriptorMap.get(name);
        if (descriptors.size() > 1) {
            // We mustn't compare PropertyDescriptor with PropertyDescriptor because we do this at OverloadResolver
            for (DeclarationDescriptor descriptor : descriptors) {
                if (descriptor instanceof ClassDescriptor) {
                    for (DeclarationDescriptor descriptor2 : descriptors) {
                        if (descriptor == descriptor2) {
                            continue;
                        }/*from www .ja  v  a2  s. c  o  m*/

                        redeclarations.add(Pair.create(DescriptorToSourceUtils.classDescriptorToDeclaration(
                                (ClassDescriptor) descriptor), descriptor.getName()));
                        if (descriptor2 instanceof PropertyDescriptor) {
                            redeclarations.add(
                                    Pair.create(DescriptorToSourceUtils.descriptorToDeclaration(descriptor2),
                                            descriptor2.getName()));
                        }
                    }
                }
            }
        }
    }
    for (Pair<PsiElement, Name> redeclaration : redeclarations) {
        trace.report(REDECLARATION.on(redeclaration.getFirst(), redeclaration.getSecond().asString()));
    }
}

From source file:org.gradle.plugins.ide.internal.resolver.DefaultIdeDependencyResolver.java

/**
 * Finds all project dependencies that are inaccessible from any other project dependencies of the component, only from root.
 * Direct and transitive dependencies are both considered accessible here.
 *
 * @param root root component/*from w w w  . j a  v  a 2s . com*/
 * @return Resolved dependency results
 */
private Set<ResolvedComponentResult> findAllResolvedProjectDependencyResultsAccessibleOnlyFromRoot(
        ResolvedComponentResult root) {
    Multimap<ResolvedComponentResult, ResolvedComponentResult> parents = LinkedHashMultimap.create();
    findAllResolvedDependencyResultsAndTheirDependenciesAndRecordTheirParents(parents, root);

    Set<ResolvedComponentResult> matches = new LinkedHashSet<ResolvedComponentResult>();

    for (ResolvedComponentResult component : parents.keySet()) {
        if (component.getId() instanceof ProjectComponentIdentifier) {
            boolean hasNoParentOtherThanRoot = true;
            for (ResolvedComponentResult parent : parents.get(component)) {
                if (!parent.getId().equals(root.getId())
                        && parent.getId() instanceof ProjectComponentIdentifier) {
                    hasNoParentOtherThanRoot = false;
                    break;
                }
            }
            if (hasNoParentOtherThanRoot) {
                matches.add(component);
            }
        }
    }

    return matches;
}

From source file:edu.harvard.med.screensaver.model.screens.LibraryScreening.java

@Transient
public SortedSet<LibraryPlate> getLibraryPlatesScreened() {
    Multimap<Integer, AssayPlate> index = Multimaps.index(getAssayPlatesScreened(),
            new Function<AssayPlate, Integer>() {
                @Override//from w  ww. j a v a2s.  com
                public Integer apply(AssayPlate p) {
                    return p.getPlateNumber();
                }
            });
    SortedSet<LibraryPlate> libraryPlates = Sets.newTreeSet();
    for (Integer plateNumber : index.keySet()) {
        Set<AssayPlate> assayPlates = Sets.newHashSet(index.get(plateNumber));
        libraryPlates.add(new LibraryPlate(plateNumber,
                assayPlates.iterator().next().getPlateScreened().getCopy().getLibrary(), assayPlates));
    }
    return libraryPlates;
}

From source file:com.greensopinion.swagger.jaxrsgen.model.ServiceBuilder.java

public ServiceBuilder methods(Class<?> clazz) {
    checkNotNull(clazz, "Must provide a class");

    Multimap<String, ServiceOperation> operationByPath = HashMultimap.create();
    for (Method method : clazz.getMethods()) {
        if (isApi(method)) {
            ServiceOperation operation = ServiceOperation.builder().method(method).create();
            operationByPath.put(operation.getPath(), operation);
        }/*from w w w  . j a  va2  s.co  m*/
    }
    Set<Class<?>> modelClasses = Sets.newHashSet();

    List<ServiceApi> serviceApis = Lists.newArrayList();
    for (String path : operationByPath.keySet()) {
        List<ServiceOperation> operations = Lists.newArrayList();
        operations.addAll(operationByPath.get(path));
        Collections.sort(operations);
        ServiceApi serviceApi = new ServiceApi(path, description, operations);
        serviceApis.add(serviceApi);

        modelClasses.addAll(serviceApi.getModelClasses());
    }

    for (Class<?> modelClass : ImmutableSet.copyOf(modelClasses)) {
        modelClasses.addAll(getJsonIntrospector().fieldModelClasses(modelClass));
    }

    Collections.sort(serviceApis);
    this.serviceApis = serviceApis;

    List<ApiModel> models = Lists.newArrayList();
    for (Class<?> modelClass : modelClasses) {
        if (ApiTypes.isModelClass(modelClass)) {
            models.add(getJsonIntrospector().createApiModel(modelClass));
        }
    }
    this.models = models;

    return this;
}

From source file:org.killbill.billing.invoice.tree.ItemsInterval.java

/**
 * Remove all the cancelling pairs (ADD/CANCEL) for which CANCEL linkedId points to ADD id.
 *
 * @return true if there is no more items
 *//*from  w  w w. jav  a  2s .  c  om*/
public boolean mergeCancellingPairs() {
    final Multimap<UUID, Item> cancellingPairPerInvoiceItemId = LinkedListMultimap.<UUID, Item>create();
    for (final Item item : items) {
        final UUID invoiceItemId = (item.getAction() == ItemAction.ADD) ? item.getId() : item.getLinkedId();
        cancellingPairPerInvoiceItemId.put(invoiceItemId, item);
    }

    for (final UUID invoiceItemId : cancellingPairPerInvoiceItemId.keySet()) {
        final Collection<Item> itemsToRemove = cancellingPairPerInvoiceItemId.get(invoiceItemId);
        Preconditions.checkState(itemsToRemove.size() <= 2, "Too many repairs for invoiceItemId='%s': %s",
                invoiceItemId, itemsToRemove);
        if (itemsToRemove.size() == 2) {
            for (final Item itemToRemove : itemsToRemove) {
                items.remove(itemToRemove);
            }
        }
    }

    return items.isEmpty();
}