private static Set<String> getTasksForHostsNowInactive(Map<String, String> previousAssignments, Map<String, ServiceKeyValue> hosts) { SetView<String> inactiveHosts = Sets.difference(new HashSet<>(previousAssignments.values()), hosts.keySet()); Set<String> removedTaskIds = new HashSet<>(); for (Entry<String, String> assignment : previousAssignments.entrySet()) { if (inactiveHosts.contains(assignment.getValue())) { removedTaskIds.add(assignment.getKey()); } } return removedTaskIds; }
Sets.difference(ASTHelpers.enumValues(switchType), handledCases); if (!setDifference.isEmpty()) { if (setDifference.contains("UNRECOGNIZED") && setDifference.size() == 1) {
Sets.difference(ASTHelpers.enumValues(switchType), handledCases); if (!setDifference.isEmpty()) { if (setDifference.contains("UNRECOGNIZED") && setDifference.size() == 1) {
/** * If there are direct type matches between the inner func and the outer func, then remove all * other outer funcs except the ones with direct matches. * * @param prevFuncs The list of candidate inner functions * @param nextFuncs The list of candidate outer functions * @return count of items removed */ private int reduceByDirectTypes(List<ResolvedFunction> prevFuncs, List<ResolvedFunction> nextFuncs) { int progressed = 0; // Rule 1: If there are direct type matches, remove extraneous next funcs Set<Class<?>> outputs = getOutputs(prevFuncs); Set<Class<?>> inputs = getInputs(nextFuncs); Sets.SetView<Class<?>> directMatches = Sets.intersection(inputs, outputs); if (directMatches.size() > 0) { List<ResolvedFunction> toremove = new ArrayList<>(); for (ResolvedFunction nextFunc : nextFuncs) { if (!directMatches.contains(nextFunc.getArgType())) { logger.debug("removing next func: " + nextFunc + " because its input types are not satisfied by an previous func"); toremove.add(nextFunc); progressed++; } } nextFuncs.removeAll(toremove); } return progressed; }
private ImmutableSet<TypeElement> findMissingModules( ChildFactoryMethodEdge edge, BindingGraph graph) { ImmutableSet<TypeElement> factoryMethodParameters = subgraphFactoryMethodParameters(edge, graph); ComponentNode child = (ComponentNode) graph.network().incidentNodes(edge).target(); SetView<TypeElement> modulesOwnedByChild = ownedModules(child, graph); return graph.bindings().stream() // bindings owned by child .filter(binding -> binding.componentPath().equals(child.componentPath())) // that require a module instance .filter(binding -> binding.requiresModuleInstance()) .map(binding -> binding.contributingModule().get()) .distinct() // module owned by child .filter(module -> modulesOwnedByChild.contains(module)) // module not in the method parameters .filter(module -> !factoryMethodParameters.contains(module)) // module doesn't have an accessible no-arg constructor .filter(moduleType -> !componentCanMakeNewInstances(moduleType)) .collect(toImmutableSet()); }
/** * calculates map intersection by doing an intersection on key sets and accumulating the keys * @param m1 first operand * @param m2 second operand * @param <K> map key type * @param <V> map value type * @return map intersection */ public static <K, V> Multimap<K, V> multimapIntersection(Multimap<K, V> m1, Multimap<K, V> m2){ Multimap<K, V> intersection = HashMultimap.create(); Sets.SetView<K> keyIntersection = Sets.intersection(m1.keySet(), m2.keySet()); Stream.concat(m1.entries().stream(), m2.entries().stream()) .filter(e -> keyIntersection.contains(e.getKey())) .forEach(e -> intersection.put(e.getKey(), e.getValue())); return intersection; }
@Test public void testListDomainChildren() { skipIfNotDomainAdmin(); Set<Domain> domains = domainAdminClient.getDomainClient().listDomains(); Domain root = findRootOfVisibleTree(domains); if (domains.size() > 1) { assertTrue(root.hasChild()); } Set<Domain> children = domainAdminClient.getDomainClient() .listDomainChildren(parentDomainId(root.getId()).isRecursive(true)); assertEquals(domains.size() - 1, children.size()); assertTrue(Sets.difference(domains, children).contains(root)); }
@Test public void testListDomainChildren() { skipIfNotDomainAdmin(); Set<Domain> domains = domainAdminClient.getDomainClient().listDomains(); Domain root = findRootOfVisibleTree(domains); if (domains.size() > 1) { assertTrue(root.hasChild()); } Set<Domain> children = domainAdminClient.getDomainClient() .listDomainChildren(parentDomainId(root.getId()).isRecursive(true)); assertEquals(domains.size() - 1, children.size()); assertTrue(Sets.difference(domains, children).contains(root)); }