List of usage examples for com.google.common.collect Sets intersection
public static <E> SetView<E> intersection(final Set<E> set1, final Set<?> set2)
From source file:com.alibaba.jstorm.schedule.FollowerRunnable.java
private void setupBlobstore() throws Exception { BlobStore blobStore = data.getBlobStore(); StormClusterState clusterState = data.getStormClusterState(); Set<String> localSetOfKeys = Sets.newHashSet(blobStore.listKeys()); Set<String> allKeys = Sets.newHashSet(clusterState.active_keys()); Set<String> localAvailableActiveKeys = Sets.intersection(localSetOfKeys, allKeys); // keys on local but not on zk, we will delete it Set<String> keysToDelete = Sets.difference(localSetOfKeys, allKeys); LOG.debug("deleting keys not on zookeeper {}", keysToDelete); for (String key : keysToDelete) { blobStore.deleteBlob(key);// w w w . ja v a 2 s.com } LOG.debug("Creating list of key entries for blobstore inside zookeeper {} local {}", allKeys, localAvailableActiveKeys); for (String key : localAvailableActiveKeys) { int versionForKey = BlobStoreUtils.getVersionForKey(key, data.getNimbusHostPortInfo(), data.getConf()); clusterState.setup_blobstore(key, data.getNimbusHostPortInfo(), versionForKey); } }
From source file:com.zulily.omicron.scheduling.JobManager.java
/** * Updates the scheduled tasks and alert manager with any changes from the config or crontab * * @param configuration The more current global configuration instance * @param crontab The more current crontab *//*from w ww.j a va 2 s . c o m*/ public void updateConfiguration(final Configuration configuration, final Crontab crontab) { checkNotNull(configuration, "configuration"); checkNotNull(crontab, "crontab"); checkNotNull(alertManager, "alertManager"); this.alertManager.updateConfiguration(configuration); final HashSet<Job> result = Sets.newHashSet(); final HashSet<Job> jobUpdates = Sets.newHashSet(); for (final CrontabExpression crontabExpression : crontab.getCrontabExpressions()) { // If there are overrides in the crontab for this expression, get them and apply them final Configuration configurationOverride = crontab.getConfigurationOverrides() .get(crontabExpression.getLineNumber()); final Job job = new Job(crontabExpression, substituteVariables(crontabExpression.getCommand(), crontab.getVariables()), configurationOverride == null ? configuration : configurationOverride); jobUpdates.add(job); } // This is a view containing old scheduled tasks that have been removed or // reconfigured final Sets.SetView<Job> oldJobs = Sets.difference(jobSet, jobUpdates); info("CRON UPDATE: {0} tasks no longer scheduled or out of date", String.valueOf(oldJobs.size())); // This is a view of scheduled tasks that will not be updated by the cron reload final Sets.SetView<Job> existingJobs = Sets.intersection(jobSet, jobUpdates); info("CRON UPDATE: {0} tasks unchanged", String.valueOf(existingJobs.size())); // This is a view of scheduled tasks that are new or have been changed final Sets.SetView<Job> newJobs = Sets.difference(jobUpdates, jobSet); info("CRON UPDATE: {0} tasks are new or updated", String.valueOf(newJobs.size())); // Add all new tasks // keep references to old tasks that are still running // and transfer instances that haven't changed result.addAll(newJobs); for (final Job job : jobSet) { if (oldJobs.contains(job) && job.isRunning()) { job.setActive(false); result.add(job); retiredJobs.add(job); } if (existingJobs.contains(job)) { if (!job.isActive()) { // Did someone re-add a task that was running and then removed? // For whatever reason, it's now set to run again so just re-activate the instance info("CRON UPDATE: Reactivating {0}", job.toString()); job.setActive(true); } result.add(job); } } this.jobSet = result; }
From source file:bear.task.TaskDef.java
public boolean hasRole(Set<Role> roles) { return !Sets.intersection(this.roles, roles).isEmpty(); }
From source file:org.apache.cassandra.security.SSLFactory.java
private static String[] filterCipherSuites(String[] supported, String[] desired) { Set<String> des = Sets.newHashSet(desired); Set<String> toReturn = Sets.intersection(Sets.newHashSet(supported), des); if (des.size() > toReturn.size()) logger.warn("Filtering out {} as it isnt supported by the socket", StringUtils.join(Sets.difference(des, toReturn), ",")); return toReturn.toArray(new String[toReturn.size()]); }
From source file:com.wrmsr.wava.analyze.SwitchAnalysis.java
private static void analyze(Node node, ControlTransferAnalysis cfa, List<SwitchEntry> entries, Optional<Link> link) { node.accept(new Visitor<Void, Void>() { @Override//from w w w. j a v a 2 s .c o m protected Void visitNode(Node node, Void context) { for (int i = 0; i < node.getChildren().size(); ++i) { analyze(node.getChildren().get(i), cfa, entries, Optional.empty()); } return null; } @Override public Void visitBreakTable(BreakTable node, Void context) { analyze(node.getCondition(), cfa, entries, Optional.empty()); if (!link.isPresent() || !link.get().body.isEmpty()) { return null; } Map<Name, List<Integer>> caseValues = new HashMap<>(); caseValues.put(node.getDefaultTarget(), new ArrayList<>()); for (int i = 0; i < node.getTargets().size(); ++i) { Name target = node.getTargets().get(i); List<Integer> values = caseValues.get(target); if (values == null) { values = new ArrayList<>(); caseValues.put(target, values); } values.add(i); } Set<Name> cases = new HashSet<>(); cases.addAll(caseValues.keySet()); cases.add(node.getDefaultTarget()); Map<Name, CaseEntry> caseEntries = new LinkedHashMap<>(); Set<Name> remaining = new HashSet<>(cases); Set<Name> outliers = new HashSet<>(); Optional<Link> prev = Optional.empty(); Optional<Link> cur = link; while (!remaining.isEmpty() && cur.isPresent()) { Link curLink = cur.get(); Optional<Link> next = curLink.next; Name curName = curLink.label.getName(); if (!remaining.contains(curName)) { if (!prev.isPresent()) { return null; } Name prevName = prev.get().label.getName(); Set<Name> prevTargets = cfa.getTargetNames(prev.get().body.stream()); if (prevTargets.contains(curName)) { return null; } Set<Name> targets = cfa.getTargetNames(curLink.body.stream()); outliers.addAll(Sets.intersection(targets, remaining)); CaseEntry prevEntry = requireNonNull(caseEntries.get(prevName)); caseEntries.put(prevName, new CaseEntry(prevName, prevEntry.values, ImmutableList.<Node>builder() .add(new Label(curName, nodify(prevEntry.body))) .addAll(curLink.body).build())); } else { remaining.remove(curName); Set<Name> targets = cfa.getTargetNames(curLink.body.stream()); outliers.addAll(Sets.intersection(targets, remaining)); List<Integer> values = requireNonNull(caseValues.get(curLink.label.getName()), "all but default require int values"); checkState(!caseEntries.containsKey(curName)); caseEntries.put(curName, new CaseEntry(curLink.label.getName(), values, !remaining.isEmpty() ? next.map(l -> l.body).orElse(ImmutableList.of()) : ImmutableList.of())); } prev = Optional.of(curLink); cur = next; } if (!prev.isPresent() || !remaining.isEmpty() || !outliers.isEmpty()) { return null; } entries.add(new SwitchEntry(prev.get().label, node, ImmutableList.copyOf(caseEntries.values()))); return null; } @Override public Void visitLabel(Label node, Void context) { Label label = node; node.getBody().accept(new Visitor<Void, Void>() { @Override protected Void visitNode(Node node, Void context) { analyze(node, cfa, entries, Optional.empty()); return null; } @Override public Void visitBlock(Block node, Void context) { if (node.getChildren().isEmpty()) { return null; } Node first = listHead(node.getChildren()); List<Node> tail = listTail(node.getChildren()).collect(toImmutableList()); analyze(first, cfa, entries, Optional.of(new Link(label, tail, link))); for (Node child : tail) { analyze(child, cfa, entries, Optional.empty()); } return null; } @Override public Void visitBreakTable(BreakTable node, Void context) { analyze(node, cfa, entries, Optional.of(new Link(label, ImmutableList.of(), link))); return null; } @Override public Void visitLabel(Label node, Void context) { analyze(node, cfa, entries, Optional.of(new Link(label, ImmutableList.of(), link))); return null; } }, null); return null; } }, null); }
From source file:com.github.rinde.rinsim.cli.Menu.java
/** * Parses and executes the provided command-line arguments. * @param args The arguments to parse./*from w w w .j a v a 2s . c o m*/ * @return A string containing the help message, or {@link Optional#absent()} * if no help was requested. * @throws CliException If anything in the parsing or execution went wrong. */ public Optional<String> execute(String... args) { final PeekingIterator<String> it = Iterators.peekingIterator(Iterators.forArray(args)); final Set<Option> selectedOptions = newLinkedHashSet(); while (it.hasNext()) { final String arg = it.next(); final Optional<OptionParser> optParser = parseOption(arg); checkCommand(optParser.isPresent(), "Found unrecognized command: '%s'.", arg); checkAlreadySelected(!selectedOptions.contains(optParser.get().getOption()), optParser.get().getOption(), "Option is already selected: %s.", optParser.get().getOption()); if (groupMap.containsKey(optParser.get().getOption())) { // this option is part of a option group final SetView<Option> intersect = Sets.intersection(selectedOptions, newLinkedHashSet(groupMap.get(optParser.get().getOption()))); checkAlreadySelected(intersect.isEmpty(), optParser.get().getOption(), "An option from the same group as '%s' has already been selected: " + "'%s'.", optParser.get().getOption(), intersect); } selectedOptions.add(optParser.get().getOption()); if (optParser.get().getOption().isHelpOption()) { return Optional.of(printHelp()); } final List<String> arguments = newArrayList(); // if a non-option string is following the current option, it must be // the argument of the current option. while (it.hasNext() && !parseOption(it.peek()).isPresent()) { arguments.add(it.next()); } try { optParser.get().parse(arguments); } catch (IllegalArgumentException | IllegalStateException e) { throw new CliException(e.getMessage(), e, CauseType.HANDLER_FAILURE, optParser.get().getOption()); } } return Optional.absent(); }
From source file:org.fenixedu.academic.ui.struts.action.academicAdministration.executionCourseManagement.ExecutionCourseBean.java
public String getSourcePresentationName() { StringBuilder result = new StringBuilder(); if (getSourceExecutionCourse() != null) { result.append(getSourceExecutionCourse().getNameI18N().getContent()); final Set<DegreeCurricularPlan> plans; if (getDegree() != null) { plans = Sets.intersection(getDegree().getDegreeCurricularPlansSet(), Sets.newHashSet(getSourceExecutionCourse().getAssociatedDegreeCurricularPlans())); } else {// ww w.j a va 2 s. c o m plans = Sets.newHashSet(getSourceExecutionCourse().getAssociatedDegreeCurricularPlans()); } result.append(getDegreeCurricularPlansPresentationString(plans)); } return result.toString(); }
From source file:edu.udo.scaffoldhunter.model.dataimport.ImportProcess.java
/** * // w w w . j av a 2s. c o m * @return a multimap which contains for each import job the property * definitions which are already defined by a previous import job. */ public ImmutableMultimap<ImportJob, PropertyDefinition> getMergedPropeties() { ImmutableMultimap.Builder<ImportJob, PropertyDefinition> builder = ImmutableMultimap.builder(); Set<PropertyDefinition> allDefinitions = Sets.newHashSet(); Set<PropertyDefinition> definitionsFromJ = Sets.newHashSet(); for (ImportJob j : importJobs) { definitionsFromJ.clear(); for (SourcePropertyMapping m : j.getPropertyMappings().values()) { PropertyDefinition propDef = m.getPropertyDefiniton(); if (propDef != null) definitionsFromJ.add(m.getPropertyDefiniton()); } builder.putAll(j, Sets.intersection(allDefinitions, definitionsFromJ)); allDefinitions.addAll(definitionsFromJ); } return builder.build(); }
From source file:au.edu.uq.nmerge.mvd.KMPSearchState.java
/** * Split off a clone of ourselves intersecting with bs as its set of * versions. Should only be called after this.v.intersects(bs) has * returned true./*from w w w . ja v a2 s . c om*/ * * @param bs the set which must intersect with our versions. * @return a clone of everything we stand for. */ KMPSearchState<T> split(Set<Witness> bs) { final Sets.SetView<Witness> intersection = Sets.intersection(this.v, bs); Preconditions.checkArgument(!intersection.isEmpty()); return new KMPSearchState<T>(this, Sets.newHashSet(intersection)); }
From source file:npanday.resolver.NPandayDependencyResolution.java
private void addResolvedSpecialsToProjectDependencies(ArtifactResolutionResult result, Set<Artifact> dependencyArtifacts) { Set resolvedArtifacts = result.getArtifacts(); Sets.SetView intersection = Sets.intersection(resolvedArtifacts, artifactResolver.getCustomResolveCache()); for (Object ao : intersection) { Artifact a = (Artifact) ao;/*from ww w . j av a 2 s. c o m*/ if (!dependencyArtifacts.contains(a)) { getLogger() .info("NPANDAY-148-005: Adding custom resolved " + a + " to project.dependencyArtifacts"); dependencyArtifacts.add(a); } } }