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.hadoop.hbase.index.coprocessor.regionserver.IndexRegionObserver.java

private static Multimap<Long, KeyValue> doGetAndGroupByTS(List<IndexSpecification> indexSpecs,
        HRegion userRegion, KeyValue deleteKV, List<IndexSpecification> indicesToConsider) throws IOException {

    Get get = new Get(deleteKV.getRow());
    long maxTS = HConstants.LATEST_TIMESTAMP;

    if (deleteKV.getTimestamp() < maxTS) {
        // Add +1 to make the current get includes the timestamp
        maxTS = deleteKV.getTimestamp() + 1;
    }/*  w w  w.  ja v  a2 s.c om*/
    get.setTimeRange(HConstants.OLDEST_TIMESTAMP, maxTS);

    for (IndexSpecification index : indexSpecs) {
        // Get all indices involves this family/qualifier
        if (index.contains(deleteKV.getFamily(), deleteKV.getQualifier())) {
            indicesToConsider.add(index);
            for (ColumnQualifier cq : index.getIndexColumns()) {
                get.addColumn(cq.getColumnFamily(), cq.getQualifier());
            }
        }
    }
    if (deleteKV.isDeleteType()) {
        get.setMaxVersions(1);
    } else if (deleteKV.isDeleteColumnOrFamily()) {
        get.setMaxVersions();
    }
    List<KeyValue> userKVs = userRegion.get(get, 0).list();

    // Group KV based on timestamp
    Multimap<Long, KeyValue> groupedKV = HashMultimap.create();

    if (userKVs != null) {
        for (KeyValue userKV : userKVs) {
            groupedKV.put(userKV.getTimestamp(), userKV);
        }
    }
    return groupedKV;
}

From source file:com.vsct.strowgr.monitoring.gui.cassandra.CassandraClient.java

private static AsyncFunction<ResultSet, Multimap<Key, Value>> iterate(Multimap<Key, Value> result) {
    return new AsyncFunction<ResultSet, Multimap<Key, Value>>() {
        @Override/*  w ww  .  j a v a 2  s. c o m*/
        public ListenableFuture<Multimap<Key, Value>> apply(ResultSet rs) throws Exception {
            int remaining = rs.getAvailableWithoutFetching();

            for (Row row : rs) {
                Date d = row.get(0, Date.class);
                String name = row.get(1, String.class);
                String correlationId = row.get(2, UUID.class).toString();

                Key k = new Key();
                k.correlationId = correlationId;
                Value v = new Value();
                v.name = name;
                v.timestamp = d;

                if (showPayload) {
                    v.payload = row.get(3, String.class);
                }

                result.put(k, v);

                messageProcessed.incrementAndGet();
                if (--remaining == 0)
                    break;
            }

            boolean wasLastPage = rs.getExecutionInfo().getPagingState() == null;
            if (wasLastPage) {
                return Futures.immediateFuture(result);
            } else {
                ListenableFuture<ResultSet> future = rs.fetchMoreResults();
                return Futures.transform(future, iterate(result));
            }

        }
    };
}

From source file:org.apache.hadoop.hive.llap.daemon.impl.TaskRunnerCallable.java

private static Multimap<String, String> createStartedInputMap(SignableVertexSpec vertex) {
    Multimap<String, String> startedInputMap = HashMultimap.create();
    // Let the Processor control start for Broadcast inputs.

    // TODO For now, this affects non broadcast unsorted cases as well. Make use of the edge
    // property when it's available.
    for (IOSpecProto inputSpec : vertex.getInputSpecsList()) {
        if (inputSpec.getIoDescriptor().getClassName().equals(UnorderedKVInput.class.getName())) {
            startedInputMap.put(vertex.getVertexName(), inputSpec.getConnectedVertexName());
        }// w  w  w . ja  v  a 2 s . co m
    }
    return startedInputMap;
}

From source file:com.opengamma.collect.io.PropertiesFile.java

private static PropertySet parse(CharSource source) throws IOException {
    ImmutableList<String> lines = source.readLines();
    Multimap<String, String> parsed = ArrayListMultimap.create();
    int lineNum = 0;
    for (String line : lines) {
        lineNum++;// w  w  w  .  ja  v a 2  s. c o m
        line = line.trim();
        if (line.length() == 0 || line.startsWith("#") || line.startsWith(";")) {
            continue;
        }
        int equalsPosition = line.indexOf('=');
        if (equalsPosition < 0) {
            throw new IllegalArgumentException(
                    "Invalid properties file, expected key=value property, line " + lineNum);
        }
        String key = line.substring(0, equalsPosition).trim();
        String value = line.substring(equalsPosition + 1).trim();
        if (key.length() == 0) {
            throw new IllegalArgumentException("Invalid properties file, empty key, line " + lineNum);
        }
        parsed.put(key, value);
    }
    return PropertySet.of(parsed);
}

From source file:com.ardor3d.util.TextureManager.java

/**
 * Delete all textures from card. This will gather all texture ids believed to be on the card and try to delete
 * them. If a deleter is passed in, textures that are part of the currently active context (if one is active) will
 * be deleted immediately. If a deleter is not passed in, we do not have an active context, or we encounter textures
 * that are not part of the current context, then we will queue those textures to be deleted later using the
 * GameTaskQueueManager.//from w  w w . j ava  2s.c o m
 * 
 * If a non null map is passed into futureStore, it will be populated with Future objects for each queued context.
 * These objects may be used to discover when the deletion tasks have all completed.
 * 
 * @param deleter
 *            if not null, this renderer will be used to immediately delete any textures in the currently active
 *            context. All other textures will be queued to delete in their own contexts.
 * @param futureStore
 *            if not null, this map will be populated with any Future task handles created during cleanup.
 */
public static void cleanAllTextures(final Renderer deleter, final Map<Object, Future<Void>> futureStore) {
    // gather up expired textures... these don't exist in our cache
    Multimap<Object, Integer> idMap = gatherGCdIds();

    // Walk through the cached items and gather those too.
    for (final TextureKey key : _tCache.keySet()) {
        // possibly lazy init
        if (idMap == null) {
            idMap = ArrayListMultimap.create();
        }

        if (Constants.useMultipleContexts) {
            final Set<Object> contextObjects = key.getContextObjects();
            for (final Object o : contextObjects) {
                // Add id to map
                idMap.put(o, key.getTextureIdForContext(o));
            }
        } else {
            idMap.put(ContextManager.getCurrentContext().getGlContextRep(), key.getTextureIdForContext(null));
        }
        key.removeFromIdCache();
    }

    // delete the ids
    if (idMap != null && !idMap.isEmpty()) {
        handleTextureDelete(deleter, idMap, futureStore);
    }
}

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

/**
 * Ensure that no {@link PCollection} output by any of the {@code stages} or {@code
 * unfusedTransforms} is produced by more than one of those stages or transforms.
 *
 * <p>For each {@link PCollection} output by multiple stages and/or transforms, each producer is
 * rewritten to produce a partial {@link PCollection}, which are then flattened together via an
 * introduced Flatten node which produces the original output.
 */// w w  w  . j  a v  a 2  s.c om
static DeduplicationResult ensureSingleProducer(QueryablePipeline pipeline, Collection<ExecutableStage> stages,
        Collection<PTransformNode> unfusedTransforms) {
    RunnerApi.Components.Builder unzippedComponents = pipeline.getComponents().toBuilder();

    Multimap<PCollectionNode, StageOrTransform> pcollectionProducers = getProducers(pipeline, stages,
            unfusedTransforms);
    Multimap<StageOrTransform, PCollectionNode> requiresNewOutput = HashMultimap.create();
    // Create a synthetic PCollection for each of these nodes. The transforms in the runner
    // portion of the graph that creates them should be replaced in the result components. The
    // ExecutableStage must also be rewritten to have updated outputs and transforms.
    for (Map.Entry<PCollectionNode, Collection<StageOrTransform>> collectionProducer : pcollectionProducers
            .asMap().entrySet()) {
        if (collectionProducer.getValue().size() > 1) {
            for (StageOrTransform producer : collectionProducer.getValue()) {
                requiresNewOutput.put(producer, collectionProducer.getKey());
            }
        }
    }

    Map<ExecutableStage, ExecutableStage> updatedStages = new LinkedHashMap<>();
    Map<String, PTransformNode> updatedTransforms = new LinkedHashMap<>();
    Multimap<String, PCollectionNode> originalToPartial = HashMultimap.create();
    for (Map.Entry<StageOrTransform, Collection<PCollectionNode>> deduplicationTargets : requiresNewOutput
            .asMap().entrySet()) {
        if (deduplicationTargets.getKey().getStage() != null) {
            StageDeduplication deduplication = deduplicatePCollections(deduplicationTargets.getKey().getStage(),
                    deduplicationTargets.getValue(), unzippedComponents::containsPcollections);
            for (Entry<String, PCollectionNode> originalToPartialReplacement : deduplication
                    .getOriginalToPartialPCollections().entrySet()) {
                originalToPartial.put(originalToPartialReplacement.getKey(),
                        originalToPartialReplacement.getValue());
                unzippedComponents.putPcollections(originalToPartialReplacement.getValue().getId(),
                        originalToPartialReplacement.getValue().getPCollection());
            }
            updatedStages.put(deduplicationTargets.getKey().getStage(), deduplication.getUpdatedStage());
        } else if (deduplicationTargets.getKey().getTransform() != null) {
            PTransformDeduplication deduplication = deduplicatePCollections(
                    deduplicationTargets.getKey().getTransform(), deduplicationTargets.getValue(),
                    unzippedComponents::containsPcollections);
            for (Entry<String, PCollectionNode> originalToPartialReplacement : deduplication
                    .getOriginalToPartialPCollections().entrySet()) {
                originalToPartial.put(originalToPartialReplacement.getKey(),
                        originalToPartialReplacement.getValue());
                unzippedComponents.putPcollections(originalToPartialReplacement.getValue().getId(),
                        originalToPartialReplacement.getValue().getPCollection());
            }
            updatedTransforms.put(deduplicationTargets.getKey().getTransform().getId(),
                    deduplication.getUpdatedTransform());
        } else {
            throw new IllegalStateException(
                    String.format("%s with no %s or %s", StageOrTransform.class.getSimpleName(),
                            ExecutableStage.class.getSimpleName(), PTransformNode.class.getSimpleName()));
        }
    }

    Set<PTransformNode> introducedFlattens = new LinkedHashSet<>();
    for (Map.Entry<String, Collection<PCollectionNode>> partialFlattenTargets : originalToPartial.asMap()
            .entrySet()) {
        String flattenId = SyntheticComponents.uniqueId("unzipped_flatten",
                unzippedComponents::containsTransforms);
        PTransform flattenPartialPCollections = createFlattenOfPartials(flattenId,
                partialFlattenTargets.getKey(), partialFlattenTargets.getValue());
        unzippedComponents.putTransforms(flattenId, flattenPartialPCollections);
        introducedFlattens.add(PipelineNode.pTransform(flattenId, flattenPartialPCollections));
    }

    Components components = unzippedComponents.build();
    return DeduplicationResult.of(components, introducedFlattens, updatedStages, updatedTransforms);
}

From source file:org.sourcepit.maven.dependency.model.aether.DependencyUtils.java

public static Collection<List<DependencyNode>> computeConflictingNodeGroups(DependencyNode node) {
    final Collection<Collection<VersionConflictKey>> conflictKeyGroups = computeConflictKeyGroups(node);

    final Multimap<Collection<VersionConflictKey>, DependencyNode> conflictNodes = LinkedHashMultimap.create();
    node.accept(new AbstractDependencyVisitor(false) {
        @Override//ww  w  .  j  a  va  2 s  . co m
        protected boolean onVisitEnter(DependencyNode parent, DependencyNode node) {
            final DependencyNode2 adapter = DependencyNode2Adapter.get(node);
            final VersionConflictKey originGroupKey = adapter.getDependencyConflictKey();
            if (originGroupKey != null) {
                boolean put = false;
                for (Collection<VersionConflictKey> conflictGroup : conflictKeyGroups) {
                    if (conflictGroup.contains(originGroupKey)) {
                        checkState(!put);
                        conflictNodes.put(conflictGroup, node);
                        put = true;
                    }
                }
                checkState(put);
            }
            return true;
        }
    });

    final Collection<List<DependencyNode>> conflictNodeGroups = new ArrayList<List<DependencyNode>>();

    for (Collection<DependencyNode> conflictNodeGroup : conflictNodes.asMap().values()) {
        if (conflictNodeGroup.size() > 1) {
            conflictNodeGroups.add(new ArrayList<DependencyNode>(conflictNodeGroup));
        }
    }

    return conflictNodeGroups;
}

From source file:org.sonar.server.computation.filemove.FileMoveDetectionStep.java

private static ElectedMatches electMatches(Set<String> dbFileKeys, Map<String, File> reportFileSourcesByKey,
        MatchesByScore matchesByScore) {
    ElectedMatches electedMatches = new ElectedMatches(matchesByScore, dbFileKeys, reportFileSourcesByKey);
    Multimap<String, Match> matchesPerFileForScore = ArrayListMultimap.create();
    for (List<Match> matches : matchesByScore) {
        // no match for this score value, ignore
        if (matches == null) {
            continue;
        }/*from  w w w  .  j a  v a 2 s. c o  m*/

        List<Match> matchesToValidate = electedMatches.filter(matches);
        if (matches.isEmpty()) {
            continue;
        }
        if (matches.size() == 1) {
            Match match = matches.get(0);
            electedMatches.add(match);
        } else {
            matchesPerFileForScore.clear();
            for (Match match : matches) {
                matchesPerFileForScore.put(match.getDbKey(), match);
                matchesPerFileForScore.put(match.getReportKey(), match);
            }
            // validate non ambiguous matches (ie. the match is the only match of either the db file and the report file)
            for (Match match : matchesToValidate) {
                int dbFileMatchesCount = matchesPerFileForScore.get(match.getDbKey()).size();
                int reportFileMatchesCount = matchesPerFileForScore.get(match.getReportKey()).size();
                if (dbFileMatchesCount == 1 && reportFileMatchesCount == 1) {
                    electedMatches.add(match);
                }
            }
        }
    }
    return electedMatches;
}

From source file:com.google.devtools.build.lib.packages.AspectDefinition.java

/**
 * Collects all attribute labels from the specified aspectDefinition.
 *//*from  w  w  w .j a v  a  2 s.com*/
public static void addAllAttributesOfAspect(Rule from, Multimap<Attribute, Label> labelBuilder, Aspect aspect,
        DependencyFilter dependencyFilter) {
    ImmutableMap<String, Attribute> attributes = aspect.getDefinition().getAttributes();
    for (Attribute aspectAttribute : attributes.values()) {
        if (!dependencyFilter.apply(aspect, aspectAttribute)) {
            continue;
        }
        if (aspectAttribute.getType() == BuildType.LABEL) {
            Label label = maybeGetRepositoryRelativeLabel(from,
                    BuildType.LABEL.cast(aspectAttribute.getDefaultValue(from)));
            if (label != null) {
                labelBuilder.put(aspectAttribute, label);
            }
        } else if (aspectAttribute.getType() == BuildType.LABEL_LIST) {
            List<Label> defaultLabels = BuildType.LABEL_LIST.cast(aspectAttribute.getDefaultValue(from));
            if (defaultLabels != null) {
                for (Label defaultLabel : defaultLabels) {
                    Label label = maybeGetRepositoryRelativeLabel(from, defaultLabel);
                    if (label != null) {
                        labelBuilder.put(aspectAttribute, label);
                    }
                }
            }
        }
    }
}

From source file:com.palantir.atlasdb.keyvalue.cassandra.CassandraVerifier.java

protected static void sanityCheckRingConsistency(Set<InetSocketAddress> currentAddrs, String keyspace,
        boolean isSsl, boolean safetyDisabled, int socketTimeoutMillis, int socketQueryTimeoutMillis) {
    Multimap<Set<TokenRange>, InetSocketAddress> tokenRangesToHost = HashMultimap.create();
    for (InetSocketAddress addr : currentAddrs) {
        Cassandra.Client client = null;/*  w  w w  .  j  av  a  2  s  .  c  o  m*/
        try {
            client = CassandraClientFactory.getClientInternal(addr, isSsl, socketTimeoutMillis,
                    socketQueryTimeoutMillis);
            try {
                client.describe_keyspace(keyspace);
            } catch (NotFoundException e) {
                log.info(
                        "Tried to check ring consistency for node {} before keyspace was fully setup; aborting check for now.",
                        addr, e);
                return;
            }
            tokenRangesToHost.put(ImmutableSet.copyOf(client.describe_ring(keyspace)), addr);
        } catch (Exception e) {
            log.warn("failed to get ring info from host: {}", addr, e);
        } finally {
            if (client != null) {
                client.getOutputProtocol().getTransport().close();
            }
        }
    }

    if (tokenRangesToHost.isEmpty()) {
        log.error(
                "Failed to get ring info for entire Cassandra cluster ({}); ring could not be checked for consistency.",
                keyspace);
        return;
    }

    if (tokenRangesToHost.keySet().size() == 1) {
        return;
    }

    RuntimeException e = new IllegalStateException(
            "Hosts have differing ring descriptions.  This can lead to inconsistent reads and lost data. ");
    log.error("QA-86204 " + e.getMessage() + tokenRangesToHost, e);

    if (tokenRangesToHost.size() > 2) {
        for (Entry<Set<TokenRange>, Collection<InetSocketAddress>> entry : tokenRangesToHost.asMap()
                .entrySet()) {
            if (entry.getValue().size() == 1) {
                log.error("Host: " + entry.getValue().iterator().next()
                        + " disagrees with the other nodes about the ring state.");
            }
        }
    }

    if (tokenRangesToHost.keySet().size() == 2) {
        ImmutableList<Set<TokenRange>> sets = ImmutableList.copyOf(tokenRangesToHost.keySet());
        Set<TokenRange> set1 = sets.get(0);
        Set<TokenRange> set2 = sets.get(1);
        log.error("Hosts are split.  group1: " + tokenRangesToHost.get(set1) + " group2: "
                + tokenRangesToHost.get(set2));
    }

    logErrorOrThrow(e.getMessage(), safetyDisabled);
}