List of usage examples for com.google.common.collect Multimap get
Collection<V> get(@Nullable K key);
From source file:com.facebook.buck.apple.XctoolRunTestsStep.java
private static void formatXctoolFilterParams(TestSelectorList testSelectorList, Multimap<String, TestDescription> testTargetsToDescriptions, ImmutableList.Builder<String> filterParamsBuilder) { for (String testTarget : testTargetsToDescriptions.keySet()) { StringBuilder sb = new StringBuilder(); boolean matched = false; for (TestDescription testDescription : testTargetsToDescriptions.get(testTarget)) { if (!testSelectorList.isIncluded(testDescription)) { continue; }// w w w .j a v a 2 s . com if (!matched) { matched = true; sb.append(testTarget); sb.append(':'); } else { sb.append(','); } sb.append(testDescription.getClassName()); sb.append('/'); sb.append(testDescription.getMethodName()); } if (matched) { filterParamsBuilder.add("-only"); filterParamsBuilder.add(sb.toString()); } } }
From source file:com.zimbra.cs.mailbox.acl.AclPushTask.java
public static synchronized void doWork() { if (!supported) return;//from w w w . java 2 s. c om ZimbraLog.misc.debug("Starting pending ACL push"); Multimap<Integer, List<Integer>> currentItemIdsProcessed = ArrayListMultimap.create(); try { Date now = new Date(); Multimap<Integer, Integer> mboxIdToItemIds = DbPendingAclPush.getEntries(now); for (int mboxId : mboxIdToItemIds.keySet()) { Mailbox mbox; List<Integer> itemsProcessed = new ArrayList<Integer>(); try { mbox = MailboxManager.getInstance().getMailboxById(mboxId); } catch (ServiceException e) { ZimbraLog.misc.info("Exception occurred while getting mailbox for id %s during ACL push", mboxId, e); continue; } Collection<Integer> itemIds = mboxIdToItemIds.get(mboxId); MailItem[] items = null; try { items = mbox.getItemById(null, itemIds, MailItem.Type.UNKNOWN); } catch (MailServiceException.NoSuchItemException e) { // one or more folders no longer exist if (itemIds.size() > 1) { List<MailItem> itemList = new ArrayList<MailItem>(); for (int itemId : itemIds) { try { itemList.add(mbox.getItemById(null, itemId, MailItem.Type.UNKNOWN)); } catch (MailServiceException.NoSuchItemException ignored) { } } items = itemList.toArray(new MailItem[itemList.size()]); } } Account account = mbox.getAccount(); String[] existingSharedItems = account.getSharedItem(); Set<String> updatedSharedItems = new HashSet<String>(); for (String sharedItem : existingSharedItems) { ShareInfoData shareData = AclPushSerializer.deserialize(sharedItem); if (!itemIds.contains(shareData.getItemId())) { updatedSharedItems.add(sharedItem); } } if (items != null) { for (MailItem item : items) { if (item == null) { continue; } // for now push the Folder grants to LDAP if (!(item instanceof Folder)) { continue; } ACL acl = item.getACL(); if (acl == null) { continue; } for (ACL.Grant grant : acl.getGrants()) { updatedSharedItems.add(AclPushSerializer.serialize(item, grant)); } itemsProcessed.add(item.getId()); currentItemIdsProcessed.put(mboxId, itemsProcessed); } } account.setSharedItem(updatedSharedItems.toArray(new String[updatedSharedItems.size()])); } // for DbPendingAclPush.deleteEntries(now); } catch (ServiceException e) { ZimbraLog.misc.warn("Error during ACL push task", e); } catch (Throwable t) { //don't let exceptions kill the timer try { // We ran into runtime exception, so we want to delete records from ACL // table for processed records. deleteDbAclEntryForProcessedItems(currentItemIdsProcessed); } catch (ServiceException e) { ZimbraLog.misc.warn("Error during ACL push task and deleting ACL push entry."); } ZimbraLog.misc.warn("Error during ACL push task", t); } ZimbraLog.misc.debug("Finished pending ACL push"); }
From source file:com.android.tools.idea.editors.theme.attributes.AttributesGrouper.java
@NotNull private static List<TableLabel> generateLabelsForGroup(final List<EditedStyleItem> source, final List<EditedStyleItem> sink) { // A TreeMap is used to ensure the keys are sorted in alphabetical order // ArrayLists are used for values to ensure that they stay in the same order they came in Multimap<String, EditedStyleItem> classes = Multimaps.newListMultimap( new TreeMap<String, Collection<EditedStyleItem>>(), new Supplier<List<EditedStyleItem>>() { @Override// www . j ava2 s . c o m public List<EditedStyleItem> get() { return new ArrayList<EditedStyleItem>(); } }); for (EditedStyleItem item : source) { String group = item.getAttrGroup(); classes.put(group, item); } final List<TableLabel> labels = new ArrayList<TableLabel>(); int offset = 0; sink.clear(); for (String group : classes.keySet()) { final int size = classes.get(group).size(); sink.addAll(classes.get(group)); if (size != 0) { labels.add(new TableLabel(group, offset)); } offset += size; } return labels; }
From source file:org.opentripplanner.routing.edgetype.TripPattern.java
/** * Patterns do not have unique IDs in GTFS, so we make some by concatenating agency id, route id, and an integer. * We impose our assumption that all trips in the same pattern are on the same route. * This only works if the Collection of TripPattern includes every TripPattern for the agency. *//* w w w. j a v a 2 s . c o m*/ public static void generateUniqueIds(Collection<TripPattern> tripPatterns) { Multimap<Route, TripPattern> patternsForRoute = HashMultimap.create(); for (TripPattern pattern : tripPatterns) { AgencyAndId routeId = pattern.route.getId(); patternsForRoute.put(pattern.route, pattern); int count = patternsForRoute.get(pattern.route).size(); // OBA library uses underscore as separator, we're moving toward colon. String id = String.format("%s:%s:%02d", routeId.getAgencyId(), routeId.getId(), count); pattern.code = (id); } }
From source file:org.apache.samza.execution.OperatorSpecGraphAnalyzer.java
/** * Creates a function that retrieves the next {@link OperatorSpec}s of any given {@link OperatorSpec} in the specified * {@code operatorSpecGraph}./* ww w . j a va 2 s . c om*/ * * Calling the returned function with any {@link SendToTableOperatorSpec} will return a collection of all * {@link StreamTableJoinOperatorSpec}s that reference the same table as the specified * {@link SendToTableOperatorSpec}, as if they were actually connected. */ private static Function<OperatorSpec, Iterable<OperatorSpec>> getCustomGetNextOpSpecs( Iterable<InputOperatorSpec> inputOpSpecs) { // Traverse operatorSpecGraph to create mapping between every SendToTableOperatorSpec and all // StreamTableJoinOperatorSpecs referencing the same table. TableJoinVisitor tableJoinVisitor = new TableJoinVisitor(); for (InputOperatorSpec inputOpSpec : inputOpSpecs) { traverse(inputOpSpec, tableJoinVisitor, opSpec -> opSpec.getRegisteredOperatorSpecs()); } Multimap<SendToTableOperatorSpec, StreamTableJoinOperatorSpec> sendToTableOpSpecToStreamTableJoinOpSpecs = tableJoinVisitor .getSendToTableOpSpecToStreamTableJoinOpSpecs(); return operatorSpec -> { // If this is a SendToTableOperatorSpec, return all StreamTableJoinSpecs referencing the same table. // For all other types of operator specs, return the next registered operator specs. if (operatorSpec instanceof SendToTableOperatorSpec) { SendToTableOperatorSpec sendToTableOperatorSpec = (SendToTableOperatorSpec) operatorSpec; return Collections.unmodifiableCollection( sendToTableOpSpecToStreamTableJoinOpSpecs.get(sendToTableOperatorSpec)); } return operatorSpec.getRegisteredOperatorSpecs(); }; }
From source file:com.ardor3d.scenegraph.AbstractBufferData.java
private static void handleVBODelete(final Renderer deleter, final Multimap<Object, Integer> idMap) { Object currentGLRef = null;/*from w w w . j a v a 2 s .co m*/ // Grab the current context, if any. if (deleter != null && ContextManager.getCurrentContext() != null) { currentGLRef = ContextManager.getCurrentContext().getGlContextRep(); } // For each affected context... for (final Object glref : idMap.keySet()) { // If we have a deleter and the context is current, immediately delete if (deleter != null && glref.equals(currentGLRef)) { deleter.deleteVBOs(idMap.get(glref)); } // Otherwise, add a delete request to that context's render task queue. else { GameTaskQueueManager.getManager(ContextManager.getContextForRef(glref)) .render(new RendererCallable<Void>() { public Void call() throws Exception { getRenderer().deleteVBOs(idMap.get(glref)); return null; } }); } } }
From source file:com.android.tools.idea.rendering.LayoutlibCallbackImpl.java
@Nullable private static List<String> dfs(String from, Set<String> visiting, Multimap<String, String> includeMap) { visiting.add(from);/*from ww w . ja v a2 s . c o m*/ Collection<String> includes = includeMap.get(from); if (includes != null && includes.size() > 0) { for (String include : includes) { if (visiting.contains(include)) { List<String> list = Lists.newLinkedList(); list.add(include); list.add(from); return list; } List<String> chain = dfs(include, visiting, includeMap); if (chain != null) { chain.add(from); return chain; } } } visiting.remove(from); return null; }
From source file:org.apache.shindig.gadgets.http.HttpResponse.java
/** * Tries to find a valid date from the input headers. * * @return The value of the date header, in milliseconds, or -1 if no Date could be determined. *//*from w ww .j av a 2 s.c o m*/ private static long getAndUpdateDate(Multimap<String, String> headers) { // Validate the Date header. Must conform to the HTTP date format. long timestamp = -1; long currentTime = getTimeSource().currentTimeMillis(); Collection<String> dates = headers.get("Date"); if (!dates.isEmpty()) { Date d = DateUtil.parseRfc1123Date(dates.iterator().next()); if (d != null) { timestamp = d.getTime(); if (Math.abs(currentTime - timestamp) > responseDateDriftLimit) { // Do not trust the date from response if it is too old (server time out of sync) timestamp = -1; } } } if (timestamp == -1) { timestamp = currentTime; headers.replaceValues("Date", ImmutableList.of(DateUtil.formatRfc1123Date(timestamp))); } return timestamp; }
From source file:org.opendaylight.controller.netconf.confignetconfconnector.mapping.config.Config.java
public static Map<String, Map<String, Collection<ObjectName>>> getMappedInstances( Set<ObjectName> instancesToMap, Map<String, Map<String, ModuleConfig>> configs) { Multimap<String, ObjectName> moduleToInstances = mapInstancesToModules(instancesToMap); Map<String, Map<String, Collection<ObjectName>>> retVal = Maps.newLinkedHashMap(); for (Entry<String, Map<String, ModuleConfig>> namespaceToModuleToConfigEntry : configs.entrySet()) { Map<String, Collection<ObjectName>> innerRetVal = Maps.newHashMap(); for (Entry<String, ModuleConfig> mbeEntry : namespaceToModuleToConfigEntry.getValue().entrySet()) { String moduleName = mbeEntry.getKey(); Collection<ObjectName> instances = moduleToInstances.get(moduleName); // TODO, this code does not support same module names from different namespaces // Namespace should be present in ObjectName if (instances == null) { continue; }// w w w . j a va 2 s .c o m innerRetVal.put(moduleName, instances); } retVal.put(namespaceToModuleToConfigEntry.getKey(), innerRetVal); } return retVal; }
From source file:com.facebook.buck.apple.project_generator.WorkspaceAndProjectGenerator.java
private static Function<BuildTarget, PBXTarget> getTargetNodeToPBXTargetTransformFunction( final Multimap<BuildTarget, PBXTarget> buildTargetToTarget, final boolean buildWithBuck) { return input -> { ImmutableList<PBXTarget> targets = ImmutableList.copyOf(buildTargetToTarget.get(input)); if (targets.size() == 1) { return targets.get(0); }//from w w w.j a v a 2s. co m // The only reason why a build target would map to more than one project target is if // there are two project targets: one is the usual one, the other is a target that just // shells out to Buck. Preconditions.checkState(targets.size() == 2); PBXTarget first = targets.get(0); PBXTarget second = targets.get(1); Preconditions.checkState(first.getName().endsWith(ProjectGenerator.BUILD_WITH_BUCK_POSTFIX) ^ second.getName().endsWith(ProjectGenerator.BUILD_WITH_BUCK_POSTFIX)); PBXTarget buildWithBuckTarget; PBXTarget buildWithXcodeTarget; if (first.getName().endsWith(ProjectGenerator.BUILD_WITH_BUCK_POSTFIX)) { buildWithBuckTarget = first; buildWithXcodeTarget = second; } else { buildWithXcodeTarget = first; buildWithBuckTarget = second; } return buildWithBuck ? buildWithBuckTarget : buildWithXcodeTarget; }; }