List of usage examples for com.google.common.collect HashMultimap create
public static <K, V> HashMultimap<K, V> create()
From source file:com.google.cloud.dataflow.sdk.options.PipelineOptionsReflector.java
/** * Extract pipeline options and their respective getter methods from a series of * {@link Method methods}. A single pipeline option may appear in many methods. * * @return A mapping of option name to the input methods which declare it. *//*from w w w . j av a 2 s.c o m*/ static Multimap<String, Method> getPropertyNamesToGetters(Iterable<Method> methods) { Multimap<String, Method> propertyNamesToGetters = HashMultimap.create(); for (Method method : methods) { String methodName = method.getName(); if ((!methodName.startsWith("get") && !methodName.startsWith("is")) || method.getParameterTypes().length != 0 || method.getReturnType() == void.class) { continue; } String propertyName = Introspector .decapitalize(methodName.startsWith("is") ? methodName.substring(2) : methodName.substring(3)); propertyNamesToGetters.put(propertyName, method); } return propertyNamesToGetters; }
From source file:com.google.caliper.runner.worker.targetinfo.TargetInfoFromWorkerFactory.java
@Override public TargetInfo getTargetInfo() { SetMultimap<BenchmarkClassModel, Target> models = HashMultimap.create(); Map<Target, Host> hosts = new HashMap<>(); try {/*ww w . j a va 2 s . c o m*/ for (Target target : targets) { TargetInfoLogMessage logMessage = targetInfoComponentBuilder.get().target(target).build() .workerRunner().runWorker(); models.put(logMessage.model(), target); hosts.put(target, new Host.Builder().addAllProperties(logMessage.deviceProperties()).build()); } } catch (ProxyWorkerException e) { if (e.exceptionType().equals(UserCodeException.class.getName())) { throw new UserCodeException(e.message(), e); } else if (e.exceptionType().equals(InvalidBenchmarkException.class.getName())) { throw new InvalidBenchmarkException(e.message(), e); } throw e; } if (models.keySet().size() > 1) { throw new InvalidConfigurationException( "Different targets produced different models of the benchmark class. Please ensure " + "that the classpaths used for each type of target contain equivalent versions of " + "the benchmark class."); } return TargetInfo.create(Iterables.getOnlyElement(models.keySet()), hosts); }
From source file:edu.umd.cs.psl.model.atom.memory.MemoryAtom.java
@Override public boolean registerGroundKernel(GroundKernel f) { checkAccess();/*from w w w .j a v a2 s .c o m*/ if (dependentKernels == null) dependentKernels = HashMultimap.create(); return dependentKernels.put(f.getKernel(), f); }
From source file:org.artifactory.search.deployable.VersionUnitSearcher.java
@Override public ItemSearchResults<VersionUnitSearchResult> doSearch(VersionUnitSearchControls controls) { RepoPath pathToSearch = controls.getPathToSearchWithin(); Repo repo = getRepoService().repositoryByKey(pathToSearch.getRepoKey()); if (repo == null) { return new ItemSearchResults<>(Lists.<VersionUnitSearchResult>newArrayList()); }/* w ww.j a v a 2s . c o m*/ VfsQuery repoQuery = createQuery(controls).setSingleRepoKey(pathToSearch.getRepoKey()) .addPathFilter(pathToSearch.getPath()).addPathFilters(VfsQuery.ALL_PATH_VALUE) .expectedResult(VfsQueryResultType.FILE); VfsQueryResult queryResult = repoQuery.execute(getLimit(controls)); Multimap<ModuleInfo, RepoPath> moduleInfoToRepoPaths = HashMultimap.create(); for (VfsQueryRow row : queryResult.getAllRows()) { ItemInfo item = row.getItem(); ModuleInfo moduleInfo = repo.getItemModuleInfo(item.getRelPath()); if (moduleInfo.isValid()) { ModuleInfo stripped = stripModuleInfoFromUnnecessaryData(moduleInfo); moduleInfoToRepoPaths.put(stripped, item.getRepoPath()); } } Set<VersionUnitSearchResult> results = getVersionUnitResults(moduleInfoToRepoPaths); return new ItemSearchResults<>(Lists.newArrayList(results), queryResult.getCount()); }
From source file:org.openhab.binding.networkupstools.internal.NetworkUpsToolsBinding.java
/** * @{inheritDoc}/*from w ww. j av a 2 s . c o m*/ */ @Override protected void execute() { Multimap<String, ItemDefinition> items = HashMultimap.create(); for (NetworkUpsToolsBindingProvider provider : providers) { for (String itemName : provider.getItemNames()) { String name = provider.getUps(itemName); Class<? extends Item> itemType = provider.getItemType(itemName); String property = provider.getProperty(itemName); items.put(name, new ItemDefinition(itemName, itemType, property)); } } for (String name : items.keySet()) { NutConfig nut = upses.get(name); if (nut == null) { logger.error("No configuration for UPS with name: '{}'", name); continue; } Client client = null; try { client = new Client(nut.host, nut.port, nut.login, nut.pass); Device device = client.getDevice(nut.device); for (ItemDefinition definition : items.get(name)) { Variable variable = device.getVariable(definition.property); String value = variable.getValue(); Class<? extends Item> itemType = definition.itemType; String itemName = definition.itemName; // Change to a state State state = null; if (itemType.isAssignableFrom(StringItem.class)) { state = StringType.valueOf(value); } else if (itemType.isAssignableFrom(NumberItem.class)) { state = DecimalType.valueOf(value); } else if (itemType.isAssignableFrom(SwitchItem.class)) { state = OnOffType.valueOf(value); } if (state != null) { eventPublisher.postUpdate(itemName, state); } else { logger.error( "'{}' couldn't be parsed to a State. Valid State-Types are String, Number and Switch", variable.toString()); } } } catch (Exception ex) { logger.error("Nut processing error", ex); } finally { if (client != null) { client.disconnect(); } } } }
From source file:com.zimbra.cs.account.accesscontrol.ACLUtil.java
private static Multimap<Right, Entry> getGrantedRights(Account grantee, Set<String> fetchAttrs) throws ServiceException { SearchGrants search = new SearchGrants(grantee.getProvisioning(), EnumSet.of(TargetType.account), RightBearer.Grantee.getGrantee(grantee, false).getIdAndGroupIds()); search.addFetchAttribute(fetchAttrs); Set<SearchGrants.GrantsOnTarget> results = search.doSearch().getResults(); Multimap<Right, Entry> map = HashMultimap.create(); for (SearchGrants.GrantsOnTarget grants : results) { ZimbraACL acl = grants.getAcl(); for (ZimbraACE ace : acl.getAllACEs()) { if (ace.getGrantee().equals(grantee.getId())) { map.put(ace.getRight(), grants.getTargetEntry()); }//from ww w . j a v a2 s. c o m } } return map; }
From source file:com.zimbra.cs.service.admin.ExportAndDeleteItems.java
@Override public Element handle(Element requst, Map<String, Object> context) throws ServiceException { ZimbraSoapContext zsc = getZimbraSoapContext(context); checkRight(zsc, context, null, AdminRight.PR_SYSTEM_ADMIN_ONLY); // Parse request. ExportAndDeleteItemsRequest req = JaxbUtil.elementToJaxb(requst); ExportAndDeleteMailboxSpec mailbox = req.getMailbox(); if (mailbox == null) { throw ServiceException.INVALID_REQUEST("empty mbox id", null); }/*from ww w .java 2 s . c om*/ Mailbox mbox = MailboxManager.getInstance().getMailboxById(mailbox.getId()); Multimap<Integer, Integer> idRevs = HashMultimap.create(); for (ExportAndDeleteItemSpec item : mailbox.getItems()) { idRevs.put(item.getId(), item.getVersion()); } String dirPath = req.getExportDir(); String prefix = req.getExportFilenamePrefix(); // Lock the mailbox, to make sure that another thread doesn't modify the items we're exporting/deleting. mbox.lock.lock(); try { DbConnection conn = null; try { conn = DbPool.getConnection(); if (dirPath != null) { File exportDir = new File(dirPath); if (!exportDir.isDirectory()) { DbPool.quietClose(conn); throw ServiceException.INVALID_REQUEST(dirPath + " is not a directory", null); } String filePath = makePath(dirPath, DbMailItem.TABLE_MAIL_ITEM, prefix); export(conn, mbox, DbMailItem.TABLE_MAIL_ITEM, "id", idRevs, filePath); filePath = makePath(dirPath, DbMailItem.TABLE_MAIL_ITEM_DUMPSTER, prefix); export(conn, mbox, DbMailItem.TABLE_MAIL_ITEM_DUMPSTER, "id", idRevs, filePath); filePath = makePath(dirPath, DbMailItem.TABLE_REVISION, prefix); export(conn, mbox, DbMailItem.TABLE_REVISION, "item_id", idRevs, filePath); filePath = makePath(dirPath, DbMailItem.TABLE_REVISION_DUMPSTER, prefix); export(conn, mbox, DbMailItem.TABLE_REVISION_DUMPSTER, "item_id", idRevs, filePath); filePath = makePath(dirPath, DbMailItem.TABLE_APPOINTMENT, prefix); export(conn, mbox, DbMailItem.TABLE_APPOINTMENT, "item_id", idRevs, filePath); filePath = makePath(dirPath, DbMailItem.TABLE_APPOINTMENT_DUMPSTER, prefix); export(conn, mbox, DbMailItem.TABLE_APPOINTMENT_DUMPSTER, "item_id", idRevs, filePath); } // delete item from mail_item and revision table for (Integer itemId : idRevs.keySet()) { Collection<Integer> revs = idRevs.get(itemId); for (int rev : revs) { if (rev == 0) { // delete all revisions to make sure we delete all blobs List<MailItem> list = null; try { list = mbox.getAllRevisions(null, itemId, MailItem.Type.UNKNOWN); } catch (NoSuchItemException ex) { // exception happens when we try to delete a mail_item which is already in mail_item_dumpster continue; } for (MailItem item : list) { if (item.getType() == MailItem.Type.DOCUMENT) { mbox.purgeRevision(null, itemId, item.getVersion(), false); } } mbox.delete(null, itemId, MailItem.Type.UNKNOWN, null); break; } else if (!revs.contains(0)) { try { mbox.purgeRevision(null, itemId, rev, false); } catch (NoSuchItemException ex) { // exception happens when we try to delete a revision which is already in revision_dumpster continue; } } } } // Delete items from mail_item_dumpster & revision_dumpster tables just // incase moved to dumpster tables DbBlobConsistency.delete(conn, mbox, idRevs); } finally { conn.commit(); DbPool.quietClose(conn); } } finally { mbox.lock.release(); } return zsc.createElement(AdminConstants.EXPORT_AND_DELETE_ITEMS_RESPONSE); }
From source file:org.terasology.workstation.ui.UIAvailableStationRecipesDisplay.java
public void update() { // TODO: Naive approach by comparing all the possible recipes to those currently displayed Multimap<String, String> recipes = HashMultimap.create(); for (Map.Entry<String, CraftingStationRecipe> craftInHandRecipe : registry.getCraftingRecipes(stationType) .entrySet()) {/* w ww . j ava2s .com*/ String recipeId = craftInHandRecipe.getKey(); CraftingStationRecipe recipe = craftInHandRecipe.getValue(); List<CraftingStationRecipe.CraftingStationResult> results = recipe.getMatchingRecipeResults(station, componentFromSlot, componentSlotCount, toolFromSlot, toolSlotCount); if (results != null) { for (CraftingStationRecipe.CraftingStationResult result : results) { String resultId = result.getResultId(); recipes.put(recipeId, resultId); } } } if (!recipes.equals(displayedRecipes)) { reloadRecipes(); } super.update(); }
From source file:org.robotninjas.commandbus.AnnotatedHandlerFinder.java
/** * {@inheritDoc}// w w w .j ava 2s. co m * <p/> * This implementation finds all methods marked with a {@link Execute} annotation. */ @Override public Multimap<Class<?>, EventHandler> findAllHandlers(Class<?> clazz) { Multimap<Class<?>, EventHandler> methodsInListener = HashMultimap.create(); for (Method method : getAnnotatedMethods(clazz)) { Class<?>[] parameterTypes = method.getParameterTypes(); Class<?> eventType = parameterTypes[0]; EventHandler handler = makeHandler(clazz, method); methodsInListener.put(eventType, handler); } return methodsInListener; }
From source file:com.facebook.buck.core.util.graph.MutableDirectedGraph.java
/** Creates a new graph with no nodes or edges. */ public MutableDirectedGraph() { this(new HashSet<T>(), HashMultimap.create(), HashMultimap.create()); }