List of usage examples for com.google.common.collect Multimap putAll
boolean putAll(@Nullable K key, Iterable<? extends V> values);
From source file:org.crypto.sse.EMM2Lev.java
public static RH2Lev constructEMMParGMM(final byte[] key, final Multimap<String, String> lookup, final int bigBlock, final int smallBlock, final int dataSize) throws InterruptedException, ExecutionException, IOException { final Multimap<String, byte[]> dictionary = ArrayListMultimap.create(); for (int i = 0; i < dataSize; i++) { // initialize all buckets with random values free.add(i);// ww w . j a v a 2 s .c om } random.setSeed(CryptoPrimitives.randomSeed(16)); List<String> listOfKeyword = new ArrayList<String>(lookup.keySet()); int threads = 0; if (Runtime.getRuntime().availableProcessors() > listOfKeyword.size()) { threads = listOfKeyword.size(); } else { threads = Runtime.getRuntime().availableProcessors(); } ExecutorService service = Executors.newFixedThreadPool(threads); ArrayList<String[]> inputs = new ArrayList<String[]>(threads); for (int i = 0; i < threads; i++) { String[] tmp; if (i == threads - 1) { tmp = new String[listOfKeyword.size() / threads + listOfKeyword.size() % threads]; for (int j = 0; j < listOfKeyword.size() / threads + listOfKeyword.size() % threads; j++) { tmp[j] = listOfKeyword.get((listOfKeyword.size() / threads) * i + j); } } else { tmp = new String[listOfKeyword.size() / threads]; for (int j = 0; j < listOfKeyword.size() / threads; j++) { tmp[j] = listOfKeyword.get((listOfKeyword.size() / threads) * i + j); } } inputs.add(i, tmp); } Printer.debugln("End of Partitionning \n"); List<Future<Multimap<String, byte[]>>> futures = new ArrayList<Future<Multimap<String, byte[]>>>(); for (final String[] input : inputs) { Callable<Multimap<String, byte[]>> callable = new Callable<Multimap<String, byte[]>>() { public Multimap<String, byte[]> call() throws Exception { Multimap<String, byte[]> output = setup(key, input, lookup, bigBlock, smallBlock, dataSize); return output; } }; futures.add(service.submit(callable)); } service.shutdown(); for (Future<Multimap<String, byte[]>> future : futures) { Set<String> keys = future.get().keySet(); for (String k : keys) { dictionary.putAll(k, future.get().get(k)); } } return new RH2Lev(dictionary, array); }
From source file:org.killbill.billing.subscription.engine.dao.DefaultSubscriptionDao.java
@Override public Map<UUID, List<SubscriptionBase>> getSubscriptionsForAccount(final InternalTenantContext context) throws CatalogApiException { final Map<UUID, List<SubscriptionBase>> subscriptionsFromAccountId = getSubscriptionsFromAccountId(context); final List<SubscriptionBaseEvent> eventsForAccount = getEventsForAccountId(context); final Map<UUID, List<SubscriptionBase>> result = new HashMap<UUID, List<SubscriptionBase>>(); for (final UUID bundleId : subscriptionsFromAccountId.keySet()) { final List<SubscriptionBase> subscriptionsForBundle = subscriptionsFromAccountId.get(bundleId); final Multimap<UUID, SubscriptionBaseEvent> eventsForSubscriptions = ArrayListMultimap.create(); for (final SubscriptionBase cur : subscriptionsForBundle) { final Collection<SubscriptionBaseEvent> events = Collections2.filter(eventsForAccount, new Predicate<SubscriptionBaseEvent>() { @Override public boolean apply(final SubscriptionBaseEvent input) { return input.getSubscriptionId().equals(cur.getId()); }//from w w w. j av a 2 s. c o m }); eventsForSubscriptions.putAll(cur.getId(), ImmutableList.copyOf(events)); } result.put(bundleId, buildBundleSubscriptions(subscriptionsForBundle, eventsForSubscriptions, null, context)); } return result; }
From source file:com.clarkparsia.sbol.editor.SBOLDesign.java
private void computePrecedesTransitive(SequenceAnnotation ann, Multimap<SequenceAnnotation, SequenceAnnotation> precedes, Set<SequenceAnnotation> visited) { if (!visited.add(ann)) { LOGGER.warn("Circular precedes relation: " + Iterators .toString(Iterators.transform(visited.iterator(), new Function<SequenceAnnotation, String>() { public String apply(SequenceAnnotation ann) { return ann.getURI().toString(); }/*from w ww . ja va2 s . co m*/ }))); return; } if (!precedes.containsKey(ann)) { for (SequenceAnnotation nextAnn : ann.getPrecedes()) { computePrecedesTransitive(nextAnn, precedes, visited); precedes.put(ann, nextAnn); precedes.putAll(ann, precedes.get(nextAnn)); } } visited.remove(ann); }
From source file:com.palantir.atlasdb.transaction.impl.SnapshotTransaction.java
private Multimap<String, Cell> getCellsToScrubByTable(State expectedState) { Multimap<String, Cell> tableNameToCells = HashMultimap.create(); State actualState = state.get(); if (expectedState == actualState) { for (Entry<String, ConcurrentNavigableMap<Cell, byte[]>> entry : writesByTable.entrySet()) { String table = entry.getKey(); Set<Cell> cells = entry.getValue().keySet(); tableNameToCells.putAll(table, cells); }/*from w w w . j a v a2 s. c o m*/ } else { AssertUtils.assertAndLog(false, "Expected state: " + expectedState + "; actual state: " + actualState); } return tableNameToCells; }
From source file:org.onebusaway.nyc.vehicle_tracking.impl.inference.BlockStateService.java
/** * /*from w ww . j av a 2s . c om*/ * Build the maps and STR tree for look-up. * */ private void buildShapeSpatialIndex() throws IOException, ClassNotFoundException { try { _linesToTripInfoByAgencyId = new HashMap<String, Multimap<LocationIndexedLine, TripInfo>>(); final Multimap<AgencyAndId, AgencyAndId> allUniqueShapePointsToBlockId = HashMultimap.create(); final Multimap<AgencyAndId, BlockTripIndex> blockTripIndicesByShapeId = HashMultimap.create(); final Multimap<AgencyAndId, BlockLayoverIndex> blockLayoverIndicesByShapeId = HashMultimap.create(); final Multimap<AgencyAndId, FrequencyBlockTripIndex> frequencyBlockTripIndicesByShapeId = HashMultimap .create(); final Multimap<Envelope, LocationIndexedLine> envToLines = HashMultimap.create(); _log.info("generating shapeId & blockConfig to block trips map..."); for (final BlockEntry blockEntry : _transitGraphDao.getAllBlocks()) { for (final BlockConfigurationEntry blockConfig : blockEntry.getConfigurations()) { for (final BlockTripEntry blockTrip : blockConfig.getTrips()) { final TripEntry trip = blockTrip.getTrip(); final AgencyAndId shapeId = trip.getShapeId(); final AgencyAndId blockId = blockEntry.getId(); if (shapeId != null) { allUniqueShapePointsToBlockId.put(shapeId, blockId); blockTripIndicesByShapeId.putAll(shapeId, _blockIndexService.getBlockTripIndicesForBlock(blockId)); blockLayoverIndicesByShapeId.putAll(shapeId, _blockIndexService.getBlockLayoverIndicesForBlock(blockId)); frequencyBlockTripIndicesByShapeId.putAll(shapeId, _blockIndexService.getFrequencyBlockTripIndicesForBlock(blockId)); } } } } _log.info("\tshapePoints=" + allUniqueShapePointsToBlockId.keySet().size()); for (final Entry<AgencyAndId, Collection<AgencyAndId>> shapePointsEntry : allUniqueShapePointsToBlockId .asMap().entrySet()) { final AgencyAndId shapeId = shapePointsEntry.getKey(); final ShapePoints shapePoints = _shapePointService.getShapePointsForShapeId(shapeId); if (shapePoints == null || shapePoints.isEmpty()) { _log.warn("blocks with no shapes: " + shapePointsEntry.getValue()); continue; } final Collection<BlockTripIndex> indices = blockTripIndicesByShapeId.get(shapeId); final Collection<BlockLayoverIndex> layoverIndices = blockLayoverIndicesByShapeId.get(shapeId); final Collection<FrequencyBlockTripIndex> frequencyIndices = frequencyBlockTripIndicesByShapeId .get(shapeId); final Collection<AgencyAndId> blockIds = shapePointsEntry.getValue(); if (blockIds.isEmpty()) continue; // shape agency ID cannot be used when the bundle builder is configured for agency ID remapping, // so we use the agency ID from the block ID, since shapes are not shared across agencies, they should all be the same. final String agencyId = blockIds.iterator().next().getAgencyId(); Multimap<LocationIndexedLine, TripInfo> linesToTripInfoForThisAgencyId = _linesToTripInfoByAgencyId .get(agencyId); if (linesToTripInfoForThisAgencyId == null) { linesToTripInfoForThisAgencyId = HashMultimap.create(); } for (int i = 0; i < shapePoints.getSize() - 1; ++i) { final CoordinatePoint from = shapePoints.getPointForIndex(i); final CoordinatePoint to = shapePoints.getPointForIndex(i + 1); final Coordinate fromJts = new Coordinate(from.getLon(), from.getLat()); final Coordinate toJts = new Coordinate(to.getLon(), to.getLat()); final Geometry lineGeo = _geometryFactory.createLineString(new Coordinate[] { fromJts, toJts }); final LocationIndexedLine line = new LocationIndexedLine(lineGeo); final Envelope env = lineGeo.getEnvelopeInternal(); final double distanceFrom = shapePoints.getDistTraveledForIndex(i); final double distanceTo = shapePoints.getDistTraveledForIndex(i + 1); linesToTripInfoForThisAgencyId.put(line, new TripInfo(distanceFrom, distanceTo, indices, layoverIndices, frequencyIndices)); envToLines.put(env, line); } _linesToTripInfoByAgencyId.put(agencyId, linesToTripInfoForThisAgencyId); addShapeToDetourGeometryMap(shapePoints); } if (envToLines.size() > 0) { _log.info("\ttree size=" + envToLines.keySet().size()); _index = new STRtree(envToLines.keySet().size()); for (final Entry<Envelope, Collection<LocationIndexedLine>> envLines : envToLines.asMap() .entrySet()) { _index.insert(envLines.getKey(), envLines.getValue()); } } } catch (final Exception ex) { ex.printStackTrace(); } _log.info("done."); }
From source file:com.google.devtools.build.lib.analysis.constraints.TopLevelConstraintSemantics.java
/** * Checks that if this is an environment-restricted build, all top-level targets support expected * top-level environments. Expected top-level environments can be declared explicitly through * {@code --target_environment} or implicitly through {@code --auto_cpu_environment_group}. For * the latter, top-level targets must be compatible with the build's target configuration CPU. * * <p>If any target doesn't support an explicitly expected environment declared through {@link * BuildConfiguration.Options#targetEnvironments}, the entire build fails with an error. * * <p>If any target doesn't support an implicitly expected environment declared through {@link * BuildConfiguration.Options#autoCpuEnvironmentGroup}, the target is skipped during execution * while remaining targets execute as normal. * * @param topLevelTargets the build's top-level targets * @param packageManager object for retrieving loaded targets * @param eventHandler the build's event handler * @return the set of bad top-level targets. * @throws ViewCreationFailedException if any target doesn't support an explicitly expected * environment declared through {@link BuildConfiguration.Options#targetEnvironments} *///from w w w.j ava2 s. c o m public static Set<ConfiguredTarget> checkTargetEnvironmentRestrictions( Iterable<ConfiguredTarget> topLevelTargets, PackageManager packageManager, ExtendedEventHandler eventHandler) throws ViewCreationFailedException, InterruptedException { ImmutableSet.Builder<ConfiguredTarget> badTargets = ImmutableSet.builder(); // Maps targets that are missing *explicitly* required environments to the set of environments // they're missing. These targets trigger a ViewCreationFailedException, which halts the build. // Targets with missing *implicitly* required environments don't belong here, since the build // continues while skipping them. Multimap<ConfiguredTarget, Label> exceptionInducingTargets = ArrayListMultimap.create(); for (ConfiguredTarget topLevelTarget : topLevelTargets) { BuildConfiguration config = topLevelTarget.getConfiguration(); boolean failBuildIfTargetIsBad = true; if (config == null) { // TODO(bazel-team): support file targets (they should apply package-default constraints). continue; } else if (!config.enforceConstraints()) { continue; } List<Label> targetEnvironments = config.getTargetEnvironments(); if (targetEnvironments.isEmpty()) { try { targetEnvironments = autoConfigureTargetEnvironments(config, config.getAutoCpuEnvironmentGroup(), packageManager, eventHandler); failBuildIfTargetIsBad = false; } catch (NoSuchPackageException | NoSuchTargetException | ConstraintSemantics.EnvironmentLookupException e) { throw new ViewCreationFailedException("invalid target environment", e); } } if (targetEnvironments.isEmpty()) { continue; } // Parse and collect this configuration's environments. EnvironmentCollection.Builder builder = new EnvironmentCollection.Builder(); for (Label envLabel : targetEnvironments) { try { Target env = packageManager.getTarget(eventHandler, envLabel); builder.put(ConstraintSemantics.getEnvironmentGroup(env), envLabel); } catch (NoSuchPackageException | NoSuchTargetException | ConstraintSemantics.EnvironmentLookupException e) { throw new ViewCreationFailedException("invalid target environment", e); } } EnvironmentCollection expectedEnvironments = builder.build(); // Now check the target against those environments. TransitiveInfoCollection asProvider; if (topLevelTarget instanceof OutputFileConfiguredTarget) { asProvider = ((OutputFileConfiguredTarget) topLevelTarget).getGeneratingRule(); } else { asProvider = topLevelTarget; } SupportedEnvironmentsProvider provider = Verify .verifyNotNull(asProvider.getProvider(SupportedEnvironmentsProvider.class)); Collection<Label> missingEnvironments = ConstraintSemantics .getUnsupportedEnvironments(provider.getRefinedEnvironments(), expectedEnvironments); if (!missingEnvironments.isEmpty()) { badTargets.add(topLevelTarget); if (failBuildIfTargetIsBad) { exceptionInducingTargets.putAll(topLevelTarget, missingEnvironments); } } } if (!exceptionInducingTargets.isEmpty()) { throw new ViewCreationFailedException(getBadTargetsUserMessage(exceptionInducingTargets)); } return ImmutableSet.copyOf(badTargets.build()); }
From source file:com.bigdata.dastor.service.StorageService.java
public static void calculatePendingRanges(AbstractReplicationStrategy strategy, String table) { TokenMetadata tm = StorageService.instance.getTokenMetadata(); Multimap<Range, InetAddress> pendingRanges = HashMultimap.create(); Map<Token, InetAddress> bootstrapTokens = tm.getBootstrapTokens(); Set<InetAddress> leavingEndPoints = tm.getLeavingEndPoints(); if (bootstrapTokens.isEmpty() && leavingEndPoints.isEmpty()) { if (logger_.isDebugEnabled()) logger_.debug("No bootstrapping or leaving nodes -> empty pending ranges for " + table); tm.setPendingRanges(table, pendingRanges); return;//from www.j ava 2 s .com } Multimap<InetAddress, Range> addressRanges = strategy.getAddressRanges(table); // Copy of metadata reflecting the situation after all leave operations are finished. TokenMetadata allLeftMetadata = tm.cloneAfterAllLeft(); // get all ranges that will be affected by leaving nodes Set<Range> affectedRanges = new HashSet<Range>(); for (InetAddress endPoint : leavingEndPoints) affectedRanges.addAll(addressRanges.get(endPoint)); // for each of those ranges, find what new nodes will be responsible for the range when // all leaving nodes are gone. for (Range range : affectedRanges) { List<InetAddress> currentEndPoints = strategy.getNaturalEndpoints(range.right, tm, table); List<InetAddress> newEndPoints = strategy.getNaturalEndpoints(range.right, allLeftMetadata, table); newEndPoints.removeAll(currentEndPoints); pendingRanges.putAll(range, newEndPoints); } // At this stage pendingRanges has been updated according to leave operations. We can // now finish the calculation by checking bootstrapping nodes. // For each of the bootstrapping nodes, simply add and remove them one by one to // allLeftMetadata and check in between what their ranges would be. for (Map.Entry<Token, InetAddress> entry : bootstrapTokens.entrySet()) { InetAddress endPoint = entry.getValue(); allLeftMetadata.updateNormalToken(entry.getKey(), endPoint); for (Range range : strategy.getAddressRanges(allLeftMetadata, table).get(endPoint)) pendingRanges.put(range, endPoint); allLeftMetadata.removeEndpoint(endPoint); } tm.setPendingRanges(table, pendingRanges); if (logger_.isDebugEnabled()) logger_.debug("Pending ranges:\n" + (pendingRanges.isEmpty() ? "<empty>" : tm.printPendingRanges())); }
From source file:org.apache.sentry.provider.file.SimpleFileProviderBackend.java
private void parsePrivileges(@Nullable String database, Ini.Section rolesSection, Ini.Section groupsSection, List<? extends PrivilegeValidator> validators, Path policyPath, Table<String, String, Set<String>> groupRolePrivilegeTable) { Multimap<String, String> roleNameToPrivilegeMap = HashMultimap.create(); for (Map.Entry<String, String> entry : rolesSection.entrySet()) { String roleName = stringInterner.intern(Strings.nullToEmpty(entry.getKey()).trim()); String roleValue = Strings.nullToEmpty(entry.getValue()).trim(); boolean invalidConfiguration = false; if (roleName.isEmpty()) { String errMsg = String.format("Empty role name encountered in %s", policyPath); LOGGER.warn(errMsg);//from w w w. j a v a2s . c o m configErrors.add(errMsg); invalidConfiguration = true; } if (roleValue.isEmpty()) { String errMsg = String.format("Empty role value encountered in %s", policyPath); LOGGER.warn(errMsg); configErrors.add(errMsg); invalidConfiguration = true; } if (roleNameToPrivilegeMap.containsKey(roleName)) { String warnMsg = String.format("Role %s defined twice in %s", roleName, policyPath); LOGGER.warn(warnMsg); configWarnings.add(warnMsg); } Set<String> privileges = PrivilegeUtils.toPrivilegeStrings(roleValue); if (!invalidConfiguration && privileges != null) { Set<String> internedPrivileges = Sets.newHashSet(); for (String privilege : privileges) { for (PrivilegeValidator validator : validators) { validator.validate(new PrivilegeValidatorContext(database, privilege.trim())); } internedPrivileges.add(stringInterner.intern(privilege)); } roleNameToPrivilegeMap.putAll(roleName, internedPrivileges); } } Splitter roleSplitter = ROLE_SPLITTER.omitEmptyStrings().trimResults(); for (Map.Entry<String, String> entry : groupsSection.entrySet()) { String groupName = stringInterner.intern(Strings.nullToEmpty(entry.getKey()).trim()); String groupPrivileges = Strings.nullToEmpty(entry.getValue()).trim(); for (String roleName : roleSplitter.split(groupPrivileges)) { roleName = stringInterner.intern(roleName); if (roleNameToPrivilegeMap.containsKey(roleName)) { Set<String> privileges = groupRolePrivilegeTable.get(groupName, roleName); if (privileges == null) { privileges = new HashSet<String>(); groupRolePrivilegeTable.put(groupName, roleName, privileges); } privileges.addAll(roleNameToPrivilegeMap.get(roleName)); } else { String warnMsg = String.format( "Role %s for group %s does not exist in privileges section in %s", roleName, groupName, policyPath); LOGGER.warn(warnMsg); configWarnings.add(warnMsg); } } } }
From source file:org.apache.pulsar.broker.loadbalance.impl.SimpleLoadManagerImpl.java
private Multimap<Long, ResourceUnit> getFinalCandidates(ServiceUnitId serviceUnit, Map<Long, Set<ResourceUnit>> availableBrokers) { synchronized (brokerCandidateCache) { final Multimap<Long, ResourceUnit> result = TreeMultimap.create(); availableBrokersCache.clear();/* ww w . j av a2s .c o m*/ for (final Set<ResourceUnit> resourceUnits : availableBrokers.values()) { for (final ResourceUnit resourceUnit : resourceUnits) { availableBrokersCache.add(resourceUnit.getResourceId().replace("http://", "")); } } brokerCandidateCache.clear(); try { LoadManagerShared.applyPolicies(serviceUnit, policies, brokerCandidateCache, availableBrokersCache); } catch (Exception e) { log.warn("Error when trying to apply policies: {}", e); for (final Map.Entry<Long, Set<ResourceUnit>> entry : availableBrokers.entrySet()) { result.putAll(entry.getKey(), entry.getValue()); } return result; } // As long as there is at least one broker left, this will always leave brokerCandidateCache non-empty. LoadManagerShared.removeMostServicingBrokersForNamespace(serviceUnit.toString(), brokerCandidateCache, brokerToNamespaceToBundleRange); // After LoadManagerShared is finished applying the filter, put the results back into a multimap. for (final Map.Entry<Long, Set<ResourceUnit>> entry : availableBrokers.entrySet()) { final Long rank = entry.getKey(); final Set<ResourceUnit> resourceUnits = entry.getValue(); for (final ResourceUnit resourceUnit : resourceUnits) { if (brokerCandidateCache.contains(resourceUnit.getResourceId().replace("http://", ""))) { result.put(rank, resourceUnit); } } } return result; } }
From source file:com.palantir.atlasdb.keyvalue.partition.map.DynamicPartitionMapImpl.java
@Override public Multimap<ConsistentRingRangeRequest, KeyValueEndpoint> getServicesForRangeRead(String tableName, RangeRequest range) {/* w ww .java2 s.co m*/ if (range.isReverse()) { throw new UnsupportedOperationException(); } Multimap<ConsistentRingRangeRequest, KeyValueEndpoint> result = LinkedHashMultimap.create(); byte[] rangeStart = range.getStartInclusive(); if (range.getStartInclusive().length == 0) { rangeStart = RangeRequests.getFirstRowName(); } // Note that there is no wrapping around when traversing the circle with the key. // Ie. the range does not go over through "zero" of the ring. while (range.inRange(rangeStart)) { // Setup the consistent subrange byte[] rangeEnd = ring.higherKey(rangeStart); if (rangeEnd == null || !range.inRange(rangeEnd)) { rangeEnd = range.getEndExclusive(); } ConsistentRingRangeRequest crrr = ConsistentRingRangeRequest .of(range.getBuilder().startRowInclusive(rangeStart).endRowExclusive(rangeEnd).build()); Preconditions.checkState(!crrr.get().isEmptyRange()); // We have now the "consistent" subrange which means that // every service having the (inclusive) start row will also // have all the other rows belonging to this range. // No other services will have any of these rows. result.putAll(crrr, getServicesHavingRow(rangeStart, false)); // Proceed with next range rangeStart = ring.higherKey(rangeStart); // We are out of ranges to consider. if (rangeStart == null) { break; } } return result; }