List of usage examples for com.google.common.collect Multimap put
boolean put(@Nullable K key, @Nullable V value);
From source file:grakn.core.graql.reasoner.rule.RuleUtils.java
/** * @param rules to be stratified (ordered) * @return stream of rules ordered in terms of priority (high priority first) *///from w w w. j av a2 s. c o m public static Stream<InferenceRule> stratifyRules(Set<InferenceRule> rules) { if (rules.stream().allMatch(r -> r.getBody().isPositive())) { return rules.stream().sorted(Comparator.comparing(r -> -r.resolutionPriority())); } Multimap<Type, InferenceRule> typeMap = HashMultimap.create(); rules.forEach(r -> r.getRule().thenTypes().flatMap(Type::sups).forEach(t -> typeMap.put(t, r))); HashMultimap<Type, Type> typeGraph = persistedTypeSubGraph(rules); List<Set<Type>> scc = new TarjanSCC<>(typeGraph).getSCC(); return Lists.reverse(scc).stream().flatMap(strata -> strata.stream().flatMap(t -> typeMap.get(t).stream()) .sorted(Comparator.comparing(r -> -r.resolutionPriority()))); }
From source file:com.addthis.basis.util.MultidictUtil.java
/** * parse a parameter and add it to the map * * @param str parameter in key=value format * @param map map to which the parameter should be added * @return reference to the map for convenience */// w ww . j a va 2s . com public static Multimap<String, String> parseParam(String str, Multimap<String, String> map) { if (LessStrings.isEmpty(str)) { return map; } int sep = str.indexOf('='); if (sep < 0) { // no delimiter, put null value map.put(urlDecode(str), null); } else if (sep == 0) { // no key, discard } else if (sep < str.length() - 1) { // has map.put(urlDecode(str.substring(0, sep)), urlDecode(str.substring(sep + 1))); } else { // empty value map.put(urlDecode(str.substring(0, sep)), ""); } return map; }
From source file:org.eclipse.elk.layered.intermediate.SplineSelfLoopPreProcessor.java
/** * Creates a set of all connected components. If there are ports with no edge, they will form a * component of size 1. If there are edges connecting ports not in the list of ports, this will * result in unpredictable behavior./*from w w w .j a v a 2s.c o m*/ * * @param loopEdges The edges connecting the ports. They may not connect any ports not in the list * of ports! * @param node The node we are currently working on. * @return A set of sets. Every single set represents a connected component. */ private static List<ConnectedSelfLoopComponent> findAllConnectedComponents(final Set<LEdge> loopEdges, final LNode node) { final List<ConnectedSelfLoopComponent> components = Lists.newArrayList(); final Multimap<LPort, LEdge> portToEdge = LinkedListMultimap.create(); for (final LEdge edge : loopEdges) { portToEdge.put(edge.getSource(), edge); portToEdge.put(edge.getTarget(), edge); } while (!portToEdge.isEmpty()) { components.add(findAConnectedComponent(portToEdge, node, node.getProperty(LayoutOptions.PORT_CONSTRAINTS).isOrderFixed())); } return components; }
From source file:org.eclipse.elk.alg.layered.intermediate.SplineSelfLoopPreProcessor.java
/** * Creates a set of all connected components. If there are ports with no edge, they will form a * component of size 1. If there are edges connecting ports not in the list of ports, this will * result in unpredictable behavior./* www . j a v a2 s. co m*/ * * @param loopEdges The edges connecting the ports. They may not connect any ports not in the list * of ports! * @param node The node we are currently working on. * @return A set of sets. Every single set represents a connected component. */ private static List<ConnectedSelfLoopComponent> findAllConnectedComponents(final Set<LEdge> loopEdges, final LNode node) { final List<ConnectedSelfLoopComponent> components = Lists.newArrayList(); final Multimap<LPort, LEdge> portToEdge = LinkedListMultimap.create(); for (final LEdge edge : loopEdges) { portToEdge.put(edge.getSource(), edge); portToEdge.put(edge.getTarget(), edge); } while (!portToEdge.isEmpty()) { components.add(findAConnectedComponent(portToEdge, node, node.getProperty(LayeredOptions.PORT_CONSTRAINTS).isOrderFixed())); } return components; }
From source file:de.cau.cs.kieler.klay.layered.intermediate.SplineSelfLoopPreProcessor.java
/** * Creates a set of all connected components. If there are ports with no edge, they will form a * component of size 1. If there are edges connecting ports not in the list of ports, this will * result in unpredictable behavior./*from ww w . j av a 2 s . c o m*/ * * @param loopEdges The edges connecting the ports. They may not connect any ports not in the list * of ports! * @param node The node we are currently working on. * @return A set of sets. Every single set represents a connected component. */ private static List<ConnectedSelfLoopComponent> findAllConnectedComponents(final Set<LEdge> loopEdges, final LNode node) { final List<ConnectedSelfLoopComponent> components = Lists.newArrayList(); final Multimap<LPort, LEdge> portToEdge = ArrayListMultimap.create(); for (final LEdge edge : loopEdges) { portToEdge.put(edge.getSource(), edge); portToEdge.put(edge.getTarget(), edge); } while (!portToEdge.isEmpty()) { components.add(findAConnectedComponent(portToEdge, node, node.getProperty(LayoutOptions.PORT_CONSTRAINTS).isOrderFixed())); } return components; }
From source file:toughasnails.api.HealthHelper.java
/**Returns true if successful*/ public static boolean addActiveHearts(EntityPlayer player, int hearts) { IAttributeInstance maxHealthInstance = player.getAttributeMap() .getAttributeInstance(SharedMonsterAttributes.MAX_HEALTH); AttributeModifier modifier = maxHealthInstance.getModifier(HealthHelper.LIFEBLOOD_HEALTH_MODIFIER_ID); float newHealth = player.getMaxHealth() + (hearts * 2); double existingHearts = modifier != null ? modifier.getAmount() : 0.0D; if (newHealth <= heartProvider.getMaxHearts() * 2F && newHealth > 0.0F) { Multimap<String, AttributeModifier> multimap = HashMultimap.<String, AttributeModifier>create(); modifier = new AttributeModifier(HealthHelper.LIFEBLOOD_HEALTH_MODIFIER_ID, "Lifeblood Health Modifier", existingHearts + hearts * 2, 0); multimap.put(SharedMonsterAttributes.MAX_HEALTH.getName(), modifier); player.getAttributeMap().applyAttributeModifiers(multimap); return true; }/*from ww w.j a va 2 s . c o m*/ return false; }
From source file:org.sonar.ce.taskprocessor.CeTaskProcessorRepositoryImpl.java
private static Multimap<String, CeTaskProcessor> buildPermissiveCeTaskProcessorIndex( CeTaskProcessor[] taskProcessors) { Multimap<String, CeTaskProcessor> permissiveIndex = ArrayListMultimap.create(taskProcessors.length, 1); for (CeTaskProcessor taskProcessor : taskProcessors) { for (String ceTaskType : taskProcessor.getHandledCeTaskTypes()) { permissiveIndex.put(ceTaskType, taskProcessor); }//from ww w. ja v a2 s . c om } return permissiveIndex; }
From source file:ps3joiner.Main.java
/** * @return a MultiMap where each key is the Path to a whole file, and the values are the partial files, sorted by name *//*from www . j a v a 2s . co m*/ public static ImmutableMultimap<Path, Path> findFilesToJoin(final Path path) throws IOException { final Map<Path, Path> splitToWholeFileMapping = new HashMap<>(); final SplitFilesVisitor visitor = new SplitFilesVisitor(); Files.walkFileTree(path, visitor); final List<Path> foundPaths = visitor.foundPaths(); for (final Path foundPath : foundPaths) { final Path originalFilePath = findOriginalFileFromSplitFile(foundPath); splitToWholeFileMapping.put(foundPath, originalFilePath); } final Multimap<Path, Path> multimap = TreeMultimap.create(); for (final Entry<Path, Path> entry : splitToWholeFileMapping.entrySet()) { final Path splitFilePath = entry.getKey(); final Path wholeFilePath = entry.getValue(); multimap.put(wholeFilePath, splitFilePath); } return ImmutableMultimap.copyOf(multimap); }
From source file:org.jclouds.chef.predicates.CookbookVersionPredicates.java
/** * Note that the default recipe of a cookbook is its name. Otherwise, you * prefix the recipe with the name of the cookbook. ex. {@code apache2} will * be the default recipe where {@code apache2::mod_proxy} is a specific one * in the cookbook./*from w w w .j av a 2 s.c om*/ * * @param recipes * names of the recipes. * @return true if the cookbook version contains a recipe in the list. */ public static Predicate<CookbookVersion> containsRecipes(String... recipes) { checkNotNull(recipes, "recipes must be defined"); final Multimap<String, String> search = LinkedListMultimap.create(); for (String recipe : recipes) { if (recipe.indexOf("::") != -1) { Iterable<String> nameRecipe = Splitter.on("::").split(recipe); search.put(get(nameRecipe, 0), get(nameRecipe, 1) + ".rb"); } else { search.put(recipe, "default.rb"); } } return new Predicate<CookbookVersion>() { @Override public boolean apply(final CookbookVersion cookbookVersion) { return search.containsKey(cookbookVersion.getCookbookName()) && any(search.get(cookbookVersion.getCookbookName()), new Predicate<String>() { @Override public boolean apply(final String recipeName) { return any(cookbookVersion.getRecipes(), new Predicate<Resource>() { @Override public boolean apply(Resource resource) { return resource.getName().equals(recipeName); } }); } }); } @Override public String toString() { return "containsRecipes(" + search + ")"; } }; }
From source file:org.dslforge.xtext.common.scoping.BasicTextMultimapBasedScope.java
public static IScope createScope(IScope parent, Iterable<IEObjectDescription> descriptions, boolean ignoreCase, List<URI> uris) { availableResourceURs = uris;//from w w w .ja v a2 s .c o m Multimap<QualifiedName, IEObjectDescription> map = null; for (IEObjectDescription description : descriptions) { if (map == null) map = LinkedHashMultimap.create(5, 2); if (ignoreCase) map.put(description.getName().toLowerCase(), description); else map.put(description.getName(), description); } if (map == null || map.isEmpty()) { return parent; } return new BasicTextMultimapBasedScope(parent, map, ignoreCase); }