@Override public OkHttpWebTarget queryParamsSet(String name, Set<?> values) { SetMultimap<String, String> newQueryParams = HashMultimap.create(queryParams); newQueryParams.replaceValues(name, values.stream().filter(Objects::nonNull).map(Object::toString).collect(Collectors.toSet())); return this.withQueryParams(newQueryParams); }
public static Map<TblColRef, Dictionary<String>> buildDictionary(final CubeInstance cubeInstance, Iterable<List<String>> recordList) throws IOException { final List<TblColRef> columnsNeedToBuildDictionary = cubeInstance.getDescriptor() .listDimensionColumnsExcludingDerived(true); final HashMap<Integer, TblColRef> tblColRefMap = Maps.newHashMap(); int index = 0; for (TblColRef column : columnsNeedToBuildDictionary) { tblColRefMap.put(index++, column); } HashMap<TblColRef, Dictionary<String>> result = Maps.newHashMap(); HashMultimap<TblColRef, String> valueMap = HashMultimap.create(); for (List<String> row : recordList) { for (int i = 0; i < row.size(); i++) { String cell = row.get(i); if (tblColRefMap.containsKey(i)) { valueMap.put(tblColRefMap.get(i), cell); } } } for (TblColRef tblColRef : valueMap.keySet()) { Set<String> values = valueMap.get(tblColRef); Dictionary<String> dict = DictionaryGenerator.buildDictionary(tblColRef.getType(), new IterableDictionaryValueEnumerator(values)); result.put(tblColRef, dict); } return result; }
void putIfWorkExists(Operator<?> opToAdd, Operator<?> existingOp) { List<Operator<?>> c = ImmutableList.copyOf(operatorToWorkOperators.get(existingOp)); if (!c.isEmpty()) { for (Operator<?> op : c) { operatorToWorkOperators.get(op).add(opToAdd); } operatorToWorkOperators.putAll(opToAdd, c); operatorToWorkOperators.put(opToAdd, opToAdd); } }
void removeOp(Operator<?> opToRemove) { Set<Operator<?>> s = operatorToWorkOperators.get(opToRemove); s.remove(opToRemove); List<Operator<?>> c1 = ImmutableList.copyOf(s); if (!c1.isEmpty()) { for (Operator<?> op1 : c1) { operatorToWorkOperators.remove(op1, opToRemove); // Remove operator } operatorToWorkOperators.removeAll(opToRemove); // Remove entry for operator } }
.filter(m -> m instanceof ConvertToFrequency) .map(m -> (ConvertToFrequency) m) .collect(Collectors.toList()); Multimap<TripPattern, TripTimes> newScheduledPatterns = HashMultimap.create(); for (TripTimes tt : scheduled) { newScheduledPatterns.put(graph.index.patternForTrip.get(tt.trip), tt); Multimap<TripPattern, FrequencyEntry> newFreqEntries = HashMultimap.create(); for (FrequencyEntry fe : frequencyEntries) { newFreqEntries.put(graph.index.patternForTrip.get(fe.tripTimes.trip), fe); .filter(p -> newScheduledPatterns.containsKey(p) || newFreqEntries.containsKey(p)) .map(p -> { TripPattern newp = new TripPattern(p.route, p.stopPattern);
@RequestParam("namespaceName") String namespaceName, @RequestParam("releaseIds") String releaseIds) { Set<Long> releaseIdSet = RELEASES_SPLITTER.splitToList(releaseIds).stream().map(Long::parseLong) .collect(Collectors.toSet()); Set<String> releaseKeys = releases.stream().map(Release::getReleaseKey).collect(Collectors .toSet()); releaseKeys); Multimap<Long, InstanceConfig> instanceConfigMap = HashMultimap.create(); Set<String> otherReleaseKeys = Sets.newHashSet(); instanceConfigMap.put(instanceConfig.getInstanceId(), instanceConfig); otherReleaseKeys.add(instanceConfig.getReleaseKey()); List<Instance> instances = instanceService.findInstancesByIds(instanceConfigMap.keySet()); Map<String, ReleaseDTO> releaseMap = Maps.newHashMap(); Collection<InstanceConfig> configs = instanceConfigMap.get(instanceDTO.getId()); List<InstanceConfigDTO> configDTOs = configs.stream().map(instanceConfig -> { InstanceConfigDTO instanceConfigDTO = new InstanceConfigDTO();
Types types = state.getTypes(); Multimap<String, MethodSymbol> methods = HashMultimap.create(); for (Symbol sym : types.membersClosure(getType(tree), /*skipInterface=*/ false).getSymbols()) { if (!(sym instanceof MethodSymbol)) { .noneMatch(p -> maybeFunctionalInterface(p.type, types, state))) { continue; continue; methods.put(functionalInterfaceSignature(state, msym), msym); .noneMatch(p -> maybeFunctionalInterface(p.type, types, state))) { continue; new ArrayList<>(methods.removeAll(functionalInterfaceSignature(state, msym))); ImmutableList<MethodSymbol> overrides = clash.stream() .filter(m -> msym2.overrides(m, origin, types, /*checkResult=*/ false)) .collect(toImmutableList()); worklist.addAll(overrides);
Map<String, Rule> ruleNameMap = Maps.newHashMap(); ruleService.loadAll().forEach(ruleDao -> { Rule rule; final HashMultimap<String, Pipeline> connections = HashMultimap.create(); for (PipelineConnections streamConnection : pipelineStreamConnectionsService.loadAll()) { streamConnection.pipelineIds().stream() .map(currentPipelines::get) .filter(Objects::nonNull) .forEach(pipeline -> connections.put(streamConnection.streamId(), pipeline));
/** * This method creates a mapping from each index source lookup symbol (directly applied to the index) * to the corresponding probe key Input */ private SetMultimap<Symbol, Integer> mapIndexSourceLookupSymbolToProbeKeyInput(IndexJoinNode node, Map<Symbol, Integer> probeKeyLayout) { Set<Symbol> indexJoinSymbols = node.getCriteria().stream() .map(IndexJoinNode.EquiJoinClause::getIndex) .collect(toImmutableSet()); // Trace the index join symbols to the index source lookup symbols // Map: Index join symbol => Index source lookup symbol Map<Symbol, Symbol> indexKeyTrace = IndexJoinOptimizer.IndexKeyTracer.trace(node.getIndexSource(), indexJoinSymbols); // Map the index join symbols to the probe key Input Multimap<Symbol, Integer> indexToProbeKeyInput = HashMultimap.create(); for (IndexJoinNode.EquiJoinClause clause : node.getCriteria()) { indexToProbeKeyInput.put(clause.getIndex(), probeKeyLayout.get(clause.getProbe())); } // Create the mapping from index source look up symbol to probe key Input ImmutableSetMultimap.Builder<Symbol, Integer> builder = ImmutableSetMultimap.builder(); for (Map.Entry<Symbol, Symbol> entry : indexKeyTrace.entrySet()) { Symbol indexJoinSymbol = entry.getKey(); Symbol indexLookupSymbol = entry.getValue(); builder.putAll(indexLookupSymbol, indexToProbeKeyInput.get(indexJoinSymbol)); } return builder.build(); }
@Override public Map<Long, Long> get(Iterable<Long> startTimestamps) { Multimap<T, Long> queryMap = HashMultimap.create(); for (Long startTimestamp : startTimestamps) { T mappedValue = timestampToServiceKey.apply(startTimestamp); if (mappedValue != null) { queryMap.put(mappedValue, startTimestamp); } } Set<T> unknownKeys = Sets.difference(queryMap.keySet(), keyedServices.keySet()); if (!unknownKeys.isEmpty()) { throw new SafeIllegalStateException("A batch of timestamps {} produced some transaction service keys which" + " are unknown: {}. Known transaction service keys were {}.", SafeArg.of("timestamps", startTimestamps), SafeArg.of("unknownKeys", unknownKeys), SafeArg.of("knownServiceKeys", keyedServices.keySet())); } return queryMap.asMap() .entrySet() .stream() .map(entry -> keyedServices.get(entry.getKey()).get(entry.getValue())) .collect(HashMap::new, Map::putAll, Map::putAll); }
@Override public Multimap<ConfigurationModel, ConfigurationProvider> load(ExtensionModel key) throws Exception { List<ConfigurationProvider> providers = registry.lookupAllByType(ConfigurationProvider.class).stream() .filter(provider -> provider.getExtensionModel() == key).collect(toImmutableList()); Multimap multimap = HashMultimap.create(); providers.forEach(p -> multimap.put(p.getConfigurationModel(), p)); return multimap; } });
private void sanityCheckRingConsistency() { Multimap<Set<TokenRange>, InetSocketAddress> tokenRangesToHost = HashMultimap.create(); for (InetSocketAddress host : getCachedServers()) { CassandraClient client = null; return; // don't care to check for ring consistency when we're not even fully initialized tokenRangesToHost.put(ImmutableSet.copyOf(client.describe_ring(config.getKeyspaceOrThrow())), host); } catch (Exception e) { log.warn("Failed to get ring info from host: {}", if (tokenRangesToHost.isEmpty()) { log.warn("Failed to get ring info for entire Cassandra cluster ({});" + " ring could not be checked for consistency.", if (tokenRangesToHost.keySet().size() == 1) { // all nodes agree on a consistent view of the cluster. Good. return; if (tokenRangesToHost.size() > 2) { tokenRangesToHost.asMap().entrySet().stream() .filter(entry -> entry.getValue().size() == 1) .forEach(entry -> {
private TimestampsToSweep getTimestampsToSweepDescendingAndCleanupAborted(ShardAndStrategy shardStrategy, long minTsExclusive, long sweepTs, Multimap<Long, WriteInfo> writesByStartTs) { Map<Long, Long> startToCommitTs = commitTsCache.loadBatch(writesByStartTs.keySet()); Map<TableReference, Multimap<Cell, Long>> cellsToDelete = new HashMap<>(); List<Long> committedTimestamps = new ArrayList<>(); boolean processedAll = true; List<Long> sortedStartTimestamps = startToCommitTs.keySet().stream().sorted().collect(Collectors.toList()); for (long startTs : sortedStartTimestamps) { long commitTs = startToCommitTs.get(startTs); if (commitTs == TransactionConstants.FAILED_COMMIT_TS) { lastSweptTs = startTs; writesByStartTs.get(startTs) .forEach(write -> cellsToDelete .computeIfAbsent(write.tableRef(), ignore -> HashMultimap.create()) .put(write.cell(), write.timestamp())); } else if (commitTs < sweepTs) { lastSweptTs = startTs;
@Override public JsonElement serialize(BindsConfig bindsConfig, Type typeOfBindsConfig, JsonSerializationContext context) { JsonObject result = new JsonObject(); SetMultimap<Name, SimpleUri> bindingByModuleName = listBindingsByModuleName(bindsConfig); List<Name> sortedModuleNames = bindingByModuleName.keySet().stream().sorted().collect(toList()); for (Name moduleName : sortedModuleNames) { SetMultimap<String, Input> moduleBinds = HashMultimap.create(); for (SimpleUri bindingUri : bindingByModuleName.get(moduleName)) { moduleBinds.putAll(bindingUri.getObjectName().toString(), bindsConfig.uriBoundInputs.get(bindingUri)); } JsonElement map = context.serialize(moduleBinds, SetMultimap.class); result.add(moduleName.toString(), map); } return result; }
private <T extends Predicate> Multimap<Role, T> getRolePredicateMap(Class<T> type) { HashMultimap<Role, T> rolePredicateMap = HashMultimap.create(); HashMultimap<Var, T> predicateMap = HashMultimap.create(); getPredicates(type).forEach(p -> p.getVarNames().forEach(v -> predicateMap.put(v, p))); Multimap<Role, Var> roleMap = getRoleVarMap(); roleMap.entries().stream() .filter(e -> predicateMap.containsKey(e.getValue())) .forEach(e -> rolePredicateMap.putAll(e.getKey(), predicateMap.get(e.getValue()))); return rolePredicateMap; }
Set<TableReference> tables = Sets.newHashSet(); for (Multimap<TableReference, Cell> v : scrubTimestampToTableNameToCell.values()) { tables.addAll(v.keySet()); numCells += v.size(); List<Future<Void>> scrubFutures = Lists.newArrayList(); Map<TableReference, Multimap<Cell, Long>> failedWrites = Maps.newHashMap(); final Multimap<TableReference, Cell> tableNameToCell = entry.getValue(); numCellsReadFromScrubTable += tableNameToCell.size(); for (final List<Entry<TableReference, Cell>> batch : Iterables.partition(tableNameToCell.entries(), batchSizeSupplier.get())) { final Multimap<TableReference, Cell> batchMultimap = HashMultimap.create(); for (Entry<TableReference, Cell> e : batch) { batchMultimap.put(e.getKey(), e.getValue()); Set<TableReference> tables = Sets.newHashSet(); for (Multimap<TableReference, Cell> v : scrubTimestampToTableNameToCell.values()) { tables.addAll(v.keySet());
Iterable<? extends Class<?>> classes, Iterable<String> explicitTestNames) { TreeMap<String, Class<?>> classMap = Maps.newTreeMap(); for (Class<?> cls : classes) { classMap.put(cls.getName(), cls); Multimap<Class<?>, Class<?>> testClasses = HashMultimap.create(); LinkedHashSet<Class<?>> candidateClasses = Sets.newLinkedHashSet(); for (Class<?> cls : classes) { Optional<String> testedClassName = TEST_SUFFIX.chop(cls.getName()); Class<?> testedClass = classMap.get(testedClassName.get()); if (testedClass != null) { testClasses.put(testedClass, cls); List<Class<?>> result = Lists.newArrayList(); NEXT_CANDIDATE: for (Class<?> candidate : Iterables.filter(candidateClasses, classFilter)) { for (Class<?> testClass : testClasses.get(candidate)) { if (hasTest(testClass, explicitTestNames)) {
transfersFromStopCluster = HashMultimap.create(); final double TRANSFER_RADIUS = 500.0; // meters Map<P2<TripPattern>, ProfileTransfer.GoodTransferList> transfers = Maps.newHashMap(); LOG.info("Finding transfers between clusters..."); for (StopCluster sc0 : stopClusterForId.values()) { ProfileTransfer.GoodTransferList list = transfers.get(pair); Map<StopCluster, ProfileTransfer> transfersByFromCluster = Maps.newHashMap(); for (ProfileTransfer transfer : list.good) { transfersByFromCluster.put(transfer.sc1, transfer); List<ProfileTransfer> retainedTransfers = Lists.newArrayList(); boolean inSeries = false; // true whenever a transfer existed for the last stop in the stop pattern for (Stop stop : fromPattern.stopPattern.stops) { transfersFromStopCluster.put(tr.sc1, tr);