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

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

Introduction

In this page you can find the example usage for com.google.common.collect Multimap 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:org.apache.samza.execution.IntermediateStreamManager.java

/**
 * Sets partition counts of intermediate streams participating in joins operations.
 *//*from  w w w.  j  av  a 2s. c  o  m*/
private static void setJoinedIntermediateStreamPartitions(Collection<StreamSet> joinedStreamSets) {
    // Map every intermediate stream to all the stream-sets it appears in
    Multimap<StreamEdge, StreamSet> intermediateStreamToStreamSets = HashMultimap.create();
    for (StreamSet streamSet : joinedStreamSets) {
        for (StreamEdge streamEdge : streamSet.getStreamEdges()) {
            if (streamEdge.getPartitionCount() == StreamEdge.PARTITIONS_UNKNOWN) {
                intermediateStreamToStreamSets.put(streamEdge, streamSet);
            }
        }
    }

    Set<StreamSet> streamSets = new HashSet<>(joinedStreamSets);
    Set<StreamSet> processedStreamSets = new HashSet<>();

    while (!streamSets.isEmpty()) {
        // Retrieve and remove one stream set
        StreamSet streamSet = streamSets.iterator().next();
        streamSets.remove(streamSet);

        // Find any stream with set partitions in this set
        Optional<StreamEdge> streamWithSetPartitions = streamSet.getStreamEdges().stream()
                .filter(streamEdge -> streamEdge.getPartitionCount() != StreamEdge.PARTITIONS_UNKNOWN)
                .findAny();

        if (streamWithSetPartitions.isPresent()) {
            // Mark this stream-set as processed since we won't need to re-examine it ever again.
            // It is important that we do this first before processing any intermediate streams
            // that may be in this stream-set.
            processedStreamSets.add(streamSet);

            // Set partitions of all intermediate streams in this set (if any)
            int partitions = streamWithSetPartitions.get().getPartitionCount();
            for (StreamEdge streamEdge : streamSet.getStreamEdges()) {
                if (streamEdge.getPartitionCount() == StreamEdge.PARTITIONS_UNKNOWN) {
                    streamEdge.setPartitionCount(partitions);
                    // Add all unprocessed stream-sets in which this intermediate stream appears
                    Collection<StreamSet> streamSetsIncludingIntStream = intermediateStreamToStreamSets
                            .get(streamEdge);
                    streamSetsIncludingIntStream.stream().filter(s -> !processedStreamSets.contains(s))
                            .forEach(streamSets::add);
                }
            }
        }
    }
}

From source file:org.apache.brooklyn.core.typereg.TypePlanTransformers.java

/** returns a list of {@link BrooklynTypePlanTransformer} instances for this {@link ManagementContext}
 * which may be able to handle the given plan; the list is sorted with highest-score transformer first */
@Beta//  www .j  av a  2s  .  co m
public static List<BrooklynTypePlanTransformer> forType(ManagementContext mgmt, RegisteredType type,
        RegisteredTypeLoadingContext constraint) {
    Multimap<Double, BrooklynTypePlanTransformer> byScoreMulti = ArrayListMultimap.create();
    Collection<BrooklynTypePlanTransformer> transformers = all(mgmt);
    for (BrooklynTypePlanTransformer transformer : transformers) {
        double score = transformer.scoreForType(type, constraint);
        if (score > 0)
            byScoreMulti.put(score, transformer);
    }
    Map<Double, Collection<BrooklynTypePlanTransformer>> tree = new TreeMap<Double, Collection<BrooklynTypePlanTransformer>>(
            byScoreMulti.asMap());
    List<Collection<BrooklynTypePlanTransformer>> highestFirst = new ArrayList<Collection<BrooklynTypePlanTransformer>>(
            tree.values());
    Collections.reverse(highestFirst);
    return ImmutableList.copyOf(Iterables.concat(highestFirst));
}

From source file:com.ardor3d.util.scenegraph.DisplayListDelegate.java

@SuppressWarnings("unchecked")
private static Multimap<Object, Integer> gatherGCdIds(Multimap<Object, Integer> store) {
    // Pull all expired display lists from ref queue and add to an id multimap.
    SimpleContextIdReference<DisplayListDelegate> ref;
    while ((ref = (SimpleContextIdReference<DisplayListDelegate>) _refQueue.poll()) != null) {
        if (store == null) { // lazy init
            store = ArrayListMultimap.create();
        }//from   w  w  w . j  ava2s .c  om
        store.put(ref.getGlContext(), ref.getId());
        ref.clear();
    }
    return store;
}

From source file:org.apache.beam.runners.core.construction.graph.OutputDeduplicator.java

/**
 * Returns the map from each {@link PCollectionNode} produced by any of the {@link ExecutableStage
 * stages} or {@link PTransformNode transforms} to all of the {@link ExecutableStage stages} or
 * {@link PTransformNode transforms} that produce it.
 *///from w  w w  .j a v  a 2  s  .  c  om
private static Multimap<PCollectionNode, StageOrTransform> getProducers(QueryablePipeline pipeline,
        Iterable<ExecutableStage> stages, Iterable<PTransformNode> unfusedTransforms) {
    Multimap<PCollectionNode, StageOrTransform> pcollectionProducers = HashMultimap.create();
    for (ExecutableStage stage : stages) {
        for (PCollectionNode output : stage.getOutputPCollections()) {
            pcollectionProducers.put(output, StageOrTransform.stage(stage));
        }
    }
    for (PTransformNode unfused : unfusedTransforms) {
        for (PCollectionNode output : pipeline.getOutputPCollections(unfused)) {
            pcollectionProducers.put(output, StageOrTransform.transform(unfused));
        }
    }
    return pcollectionProducers;
}

From source file:org.eclipse.incquery.viewers.runtime.specifications.ContainmentQuerySpecificationDescriptor.java

private static void insertToTraces(IQuerySpecification<?> specification,
        Multimap<PParameter, PParameter> traces, String parameter) {
    String targetName = "trace<" + parameter + ">";
    PParameter var_target = new PParameter(targetName,
            NotationPackage.eINSTANCE.getNsURI() + "||" + NotationPackage.eINSTANCE.getItem().getName());
    int positionOfParameter = specification.getPositionOfParameter(parameter);
    PParameter var_source = specification.getParameters().get(positionOfParameter);
    traces.put(var_target, var_source);
}

From source file:org.eclipse.wb.internal.core.model.property.event.ListenerInfo.java

static void useSimpleNamesWherePossible(List<ListenerInfo> listeners) {
    // prepare map: simple name -> qualified names
    Multimap<String, String> simplePropertyNames = HashMultimap.create();
    for (ListenerInfo listener : listeners) {
        String qualifiedName = listener.getName();
        String simpleName = getSimpleName(qualifiedName);
        simplePropertyNames.put(simpleName, qualifiedName);
    }//www.j av  a2 s . c o m
    // if simple name is unique, use it
    for (ListenerInfo listener : listeners) {
        String qualifiedName = listener.getName();
        String simpleName = getSimpleName(qualifiedName);
        if (simplePropertyNames.get(simpleName).size() == 1) {
            listener.m_name = simpleName;
        }
    }
}

From source file:com.yahoo.yqlplus.engine.internal.java.sequences.Sequences.java

public static <ROW, LEFT, RIGHT, KEY> List<ROW> doJoin(boolean inner, List<LEFT> left, List<RIGHT> right,
        List<KEY> leftKeys, Function<RIGHT, KEY> rightKey, JoinEmit<ROW, LEFT, RIGHT> output) {
    List<ROW> result = Lists.newArrayList();
    Multimap<KEY, RIGHT> rights = ArrayListMultimap.create(leftKeys.size(), 4);
    for (RIGHT row : right) {
        rights.put(rightKey.apply(row), row);
    }//w w  w. j av  a  2 s.c  o m
    for (int i = 0; i < left.size(); ++i) {
        LEFT leftRow = left.get(i);
        KEY leftKey = leftKeys.get(i);
        Collection<RIGHT> match = rights.get(leftKey);
        if (match == null || match.isEmpty()) {
            if (!inner) {
                ROW row = output.create();
                output.setLeft(row, leftRow);
                result.add(row);
            }
            continue;
        }
        for (RIGHT rightRow : match) {
            ROW row = output.create();
            output.setLeft(row, leftRow);
            output.setRight(row, rightRow);
            result.add(row);
        }
    }
    return result;
}

From source file:org.apache.samza.execution.ExecutionPlanner.java

/**
 * This function traverses the {@link OperatorSpec} graph to find and update mappings for all Joins reachable
 * from this input {@link StreamEdge}.//from w  ww . j  a  v  a  2  s .  c o  m
 * @param operatorSpec the {@link OperatorSpec} to traverse
 * @param sourceStreamEdge source {@link StreamEdge}
 * @param joinSpecToStreamEdges mapping from join spec to its source {@link StreamEdge}s
 * @param streamEdgeToJoinSpecs mapping from source {@link StreamEdge} to the join specs that consumes it
 * @param joinQ queue that contains joinSpecs where at least one of the input stream edge partitions is known.
 */
private static void findReachableJoins(OperatorSpec operatorSpec, StreamEdge sourceStreamEdge,
        Multimap<OperatorSpec, StreamEdge> joinSpecToStreamEdges,
        Multimap<StreamEdge, OperatorSpec> streamEdgeToJoinSpecs, Queue<OperatorSpec> joinQ,
        Set<OperatorSpec> visited) {
    if (operatorSpec instanceof JoinOperatorSpec) {
        joinSpecToStreamEdges.put(operatorSpec, sourceStreamEdge);
        streamEdgeToJoinSpecs.put(sourceStreamEdge, operatorSpec);

        if (!visited.contains(operatorSpec) && sourceStreamEdge.getPartitionCount() > 0) {
            // put the joins with known input partitions into the queue and mark as visited
            joinQ.add(operatorSpec);
            visited.add(operatorSpec);
        }
    }

    Collection<OperatorSpec> registeredOperatorSpecs = operatorSpec.getRegisteredOperatorSpecs();
    for (OperatorSpec registeredOpSpec : registeredOperatorSpecs) {
        findReachableJoins(registeredOpSpec, sourceStreamEdge, joinSpecToStreamEdges, streamEdgeToJoinSpecs,
                joinQ, visited);
    }
}

From source file:org.apache.calcite.rel.metadata.RelMdNodeTypes.java

private static Multimap<Class<? extends RelNode>, RelNode> getNodeTypes(RelNode rel, Class<? extends RelNode> c,
        RelMetadataQuery mq) {//  www. j  a  v  a2s. com
    final Multimap<Class<? extends RelNode>, RelNode> nodeTypeCount = ArrayListMultimap.create();
    for (RelNode input : rel.getInputs()) {
        Multimap<Class<? extends RelNode>, RelNode> partialNodeTypeCount = mq.getNodeTypes(input);
        if (partialNodeTypeCount == null) {
            return null;
        }
        nodeTypeCount.putAll(partialNodeTypeCount);
    }
    nodeTypeCount.put(c, rel);
    return nodeTypeCount;
}

From source file:org.apache.beam.sdk.util.IOChannelUtils.java

@VisibleForTesting
static void checkDuplicateScheme(Set<IOChannelFactoryRegistrar> registrars) {
    Multimap<String, IOChannelFactoryRegistrar> registrarsBySchemes = TreeMultimap
            .create(Ordering.<String>natural(), Ordering.arbitrary());

    for (IOChannelFactoryRegistrar registrar : registrars) {
        registrarsBySchemes.put(registrar.getScheme(), registrar);
    }//from   w w  w  .j  av  a 2  s. co  m
    for (Entry<String, Collection<IOChannelFactoryRegistrar>> entry : registrarsBySchemes.asMap().entrySet()) {
        if (entry.getValue().size() > 1) {
            String conflictingRegistrars = Joiner.on(", ").join(FluentIterable.from(entry.getValue())
                    .transform(new Function<IOChannelFactoryRegistrar, String>() {
                        @Override
                        public String apply(@Nonnull IOChannelFactoryRegistrar input) {
                            return input.getClass().getName();
                        }
                    }).toSortedList(Ordering.<String>natural()));
            throw new IllegalStateException(String.format("Scheme: [%s] has conflicting registrars: [%s]",
                    entry.getKey(), conflictingRegistrars));
        }
    }
}