List of usage examples for com.google.common.collect Sets filter
@GwtIncompatible("NavigableSet") @SuppressWarnings("unchecked") @CheckReturnValue public static <E> NavigableSet<E> filter(NavigableSet<E> unfiltered, Predicate<? super E> predicate)
From source file:org.zanata.model.HProject.java
/** * Immutable set of maintainers for this project. * * To change maintainers, use other methods in this class. * * @see {@link #addMaintainer(HPerson)}//from www .j a va 2 s. c om * @see {@link #removeMaintainer(HPerson)} */ @Transient public ImmutableSet<HPerson> getMaintainers() { Set<HProjectMember> maintainerMembers = Sets.filter(members, HProjectMember.IS_MAINTAINER); Collection<HPerson> maintainers = Collections2.transform(maintainerMembers, HProjectMember.TO_PERSON); return ImmutableSet.<HPerson>copyOf(maintainers); }
From source file:org.eclipse.papyrus.uml.diagram.activity.activitygroup.utils.Utils.java
/** * Same as {@link EcoreUtil#filterDescendants(Collection)} * // ww w.j a v a2s . c o m * @param all * @return */ public static Set<EObject> filterDescendants(Set<EObject> all) { return Sets.filter(all, new DescendantsFilter(all)); }
From source file:com.google.devtools.build.skyframe.InMemoryMemoizingEvaluator.java
@Override public void deleteDirty(long versionAgeLimit) { Preconditions.checkArgument(versionAgeLimit >= 0); final Version threshold = IntVersion.of(lastGraphVersion.getVal() - versionAgeLimit); valuesToDelete.addAll(Sets.filter(progressReceiver.getUnenqueuedDirtyKeys(), new Predicate<SkyKey>() { @Override/*from w w w . j a v a 2 s . c o m*/ public boolean apply(SkyKey skyKey) { NodeEntry entry = graph.get(null, Reason.OTHER, skyKey); Preconditions.checkNotNull(entry, skyKey); Preconditions.checkState(entry.isDirty(), skyKey); return entry.getVersion().atMost(threshold); } })); }
From source file:edu.udo.scaffoldhunter.model.util.Scaffolds.java
private static int[] fillMap(Map<Scaffold, List<Integer>> map, Scaffold scaffold, ConfigMapping mapping, final PropertyDefinition propertyDefinition, boolean cumulative) { int[] dist = new int[mapping.getIntervals().size()]; { // determine Distribution for current Scaffold Predicate<Molecule> propertyNotNull = new Predicate<Molecule>() { @Override//from w ww . jav a2 s .c o m public boolean apply(Molecule input) { return input.getNumPropertyValue(propertyDefinition) != null; } }; Set<Molecule> current = Sets.filter(scaffold.getMolecules(), propertyNotNull); int i = mapping.getIntervals().size() - 1; for (Interval interval : Iterables.limit(Lists.reverse(mapping.getIntervals()), mapping.getIntervals().size() - 1)) { Set<Molecule> filtered = Sets.filter(current, new LesserOrEqual(propertyDefinition, interval.getLowerBound())); dist[i--] = current.size() - filtered.size(); current = filtered; } dist[0] = current.size(); } /* * determine distributions for children recursively and add them in the * cumulative case */ for (Scaffold child : scaffold.getChildren()) { int[] childDistribution = fillMap(map, child, mapping, propertyDefinition, cumulative); if (cumulative) { for (int i = 0; i < dist.length; ++i) dist[i] += childDistribution[i]; } } map.put(scaffold, Ints.asList(dist)); return dist; }
From source file:easycare.web.user.NewUserForm.java
private Set<Role> filterRoles(RoleService roleService, SessionSecurityService securityService) { if (isEmpty(userRoles)) { return newHashSet(); }//from www .j a v a 2 s . c om Set<Role> userViewableRoles = roleService.findUserViewableRoles(securityService.getCurrentUserDetails()); return Sets.filter(userViewableRoles, new Predicate<Role>() { @Override public boolean apply(Role role) { return userRoles.contains(role.getName().name()); } }); }
From source file:com.facebook.buck.core.util.graph.Dot.java
/** Writes out the graph in dot format to the given output */ public void writeOutput(Appendable output) throws IOException { // Sorting the edges to have deterministic output and be able to test this. ImmutableSet.Builder<String> builder = ImmutableSet.builder(); output.append("digraph ").append(graphName).append(" {"); output.append(System.lineSeparator()); if (bfsSorted) { for (T root : ImmutableSortedSet.copyOf(graph.getNodesWithNoIncomingEdges())) { new AbstractBreadthFirstTraversal<T>(root) { @Override/*from ww w. j a v a2s . co m*/ public Iterable<T> visit(T node) { if (!shouldContainNode.test(node)) { return ImmutableSet.of(); } builder.add(printNode(node, nodeToName, nodeToTypeName, nodeToAttributes)); ImmutableSortedSet<T> nodes = ImmutableSortedSet .copyOf(Sets.filter(graph.getOutgoingNodesFor(node), shouldContainNode::test)); for (T sink : nodes) { builder.add(printEdge(node, sink, nodeToName)); } return nodes; } }.start(); } } else { ImmutableSortedSet.Builder<String> sortedSetBuilder = ImmutableSortedSet.naturalOrder(); new AbstractBottomUpTraversal<T, RuntimeException>(graph) { @Override public void visit(T node) { if (!shouldContainNode.test(node)) { return; } sortedSetBuilder.add(printNode(node, nodeToName, nodeToTypeName, nodeToAttributes)); for (T sink : Sets.filter(graph.getOutgoingNodesFor(node), shouldContainNode::test)) { sortedSetBuilder.add(printEdge(node, sink, nodeToName)); } } }.traverse(); builder.addAll(sortedSetBuilder.build()); } for (String line : builder.build()) { output.append(line); } output.append("}"); output.append(System.lineSeparator()); }
From source file:org.loadui.testfx.service.finder.impl.NodeFinderImpl.java
private Set<Node> nodesImpl(List<Window> windows, Function<Node, Set<Node>> toResultNodesFunction) { Set<Node> resultNodes = transformToResultNodes(windows, toResultNodesFunction); assertNodesFound(resultNodes, ERROR_NO_NODES_FOUND); Set<Node> visibleNodes = Sets.filter(resultNodes, isNodeVisiblePredicate()); assertNodesVisible(visibleNodes, ERROR_NO_VISIBLE_NODES_FOUND); return visibleNodes; }
From source file:com.android.tools.idea.structure.gradle.ModuleDependenciesPanel.java
public ModuleDependenciesPanel(@NotNull Project project, @NotNull String modulePath) { super(new BorderLayout()); myModulePath = modulePath;// w ww. j av a 2 s . com myProject = project; myModel = new ModuleDependenciesTableModel(); myGradleSettingsFile = GradleSettingsFile.get(myProject); Module module = GradleUtil.findModuleByGradlePath(myProject, modulePath); myGradleBuildFile = module != null ? GradleBuildFile.get(module) : null; if (myGradleBuildFile != null) { List<BuildFileStatement> dependencies = myGradleBuildFile.getDependencies(); for (BuildFileStatement dependency : dependencies) { myModel.addItem(new ModuleDependenciesTableItem(dependency)); } } else { LOG.warn("Unable to find Gradle build file for module " + myModulePath); } myModel.resetModified(); myEntryTable = new JBTable(myModel); TableRowSorter<ModuleDependenciesTableModel> sorter = new TableRowSorter<ModuleDependenciesTableModel>( myModel); sorter.setRowFilter(myModel.getFilter()); myEntryTable.setRowSorter(sorter); myEntryTable.setShowGrid(false); myEntryTable.setDragEnabled(false); myEntryTable.setIntercellSpacing(new Dimension(0, 0)); myEntryTable.setDefaultRenderer(ModuleDependenciesTableItem.class, new TableItemRenderer()); if (myGradleBuildFile == null) { return; } final boolean isAndroid = myGradleBuildFile.hasAndroidPlugin(); List<Dependency.Scope> scopes = Lists .newArrayList(Sets.filter(EnumSet.allOf(Dependency.Scope.class), new Predicate<Dependency.Scope>() { @Override public boolean apply(Dependency.Scope input) { return isAndroid ? input.isAndroidScope() : input.isJavaScope(); } })); ComboBoxModel boxModel = new CollectionComboBoxModel(scopes, null); JComboBox scopeEditor = new ComboBox(boxModel); myEntryTable.setDefaultEditor(Dependency.Scope.class, new DefaultCellEditor(scopeEditor)); myEntryTable.setDefaultRenderer(Dependency.Scope.class, new ComboBoxTableRenderer<Dependency.Scope>(Dependency.Scope.values()) { @Override protected String getTextFor(@NotNull final Dependency.Scope value) { return value.getDisplayName(); } }); myEntryTable.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); new SpeedSearchBase<JBTable>(myEntryTable) { @Override public int getSelectedIndex() { return myEntryTable.getSelectedRow(); } @Override protected int convertIndexToModel(int viewIndex) { return myEntryTable.convertRowIndexToModel(viewIndex); } @Override @NotNull public Object[] getAllElements() { return myModel.getItems().toArray(); } @Override @NotNull public String getElementText(Object element) { return getCellAppearance((ModuleDependenciesTableItem) element).getText(); } @Override public void selectElement(@NotNull Object element, @NotNull String selectedText) { final int count = myModel.getRowCount(); for (int row = 0; row < count; row++) { if (element.equals(myModel.getItemAt(row))) { final int viewRow = myEntryTable.convertRowIndexToView(row); myEntryTable.getSelectionModel().setSelectionInterval(viewRow, viewRow); TableUtil.scrollSelectionToVisible(myEntryTable); break; } } } }; TableColumn column = myEntryTable.getTableHeader().getColumnModel() .getColumn(ModuleDependenciesTableModel.SCOPE_COLUMN); column.setResizable(false); column.setMaxWidth(SCOPE_COLUMN_WIDTH); column.setMinWidth(SCOPE_COLUMN_WIDTH); add(createTableWithButtons(), BorderLayout.CENTER); if (myEntryTable.getRowCount() > 0) { myEntryTable.getSelectionModel().setSelectionInterval(0, 0); } DefaultActionGroup actionGroup = new DefaultActionGroup(); actionGroup.add(myRemoveButton); PopupHandler.installPopupHandler(myEntryTable, actionGroup, ActionPlaces.UNKNOWN, ActionManager.getInstance()); }
From source file:co.cask.cdap.common.lang.ProgramResources.java
/** * Returns a Set of resources name that are visible through the cdap-api module as well as Hadoop classes. * This includes all classes+resources in cdap-api plus all classes+resources that cdap-api * depends on (for example, sl4j, guava, gson, etc). */// w w w.j a v a2s .c om private static Set<String> createBaseResources() throws IOException { // Everything should be traceable in the same ClassLoader of this class, which is the CDAP system ClassLoader ClassLoader classLoader = ProgramResources.class.getClassLoader(); // Gather resources information for cdap-api classes Set<ClassPath.ClassInfo> apiResources = getResources(getClassPath(classLoader, Application.class), CDAP_API_PACKAGES, Sets.<ClassPath.ClassInfo>newHashSet()); // Trace dependencies for cdap-api classes Set<String> result = findClassDependencies(classLoader, Iterables.transform(apiResources, CLASS_INFO_TO_CLASS_NAME), Sets.<String>newHashSet()); // Gather resources for javax.ws.rs classes. They are not traceable from the api classes. getResources(getClassPath(classLoader, Path.class), JAVAX_WS_RS_PACKAGES, CLASS_INFO_TO_RESOURCE_NAME, result); // Gather Hadoop classes. getResources(ClassPath.from(classLoader, JAR_ONLY_URI), HADOOP_PACKAGES, CLASS_INFO_TO_RESOURCE_NAME, result); // Excludes HBase classes return ImmutableSet.copyOf(Sets.filter(result, new Predicate<String>() { @Override public boolean apply(String input) { return !input.startsWith(HBASE_PACKAGE_PREFIX); } })); }
From source file:com.facebook.buck.graph.MutableDirectedGraph.java
public ImmutableSet<ImmutableSet<T>> findCycles() { Set<Set<T>> cycles = Sets.filter(tarjan(), new Predicate<Set<T>>() { @Override/*from ww w . j a v a2 s . c o m*/ public boolean apply(@Nullable Set<T> stronglyConnectedComponent) { return stronglyConnectedComponent.size() > 1; } }); Iterable<ImmutableSet<T>> immutableCycles = Iterables.transform(cycles, new Function<Set<T>, ImmutableSet<T>>() { @Override public ImmutableSet<T> apply(Set<T> cycle) { return ImmutableSet.copyOf(cycle); } }); // Tarjan's algorithm (as pseudo-coded on Wikipedia) does not appear to account for single-node // cycles. Therefore, we must check for them exclusively. ImmutableSet.Builder<ImmutableSet<T>> builder = ImmutableSet.builder(); builder.addAll(immutableCycles); for (T node : nodes) { if (containsEdge(node, node)) { builder.add(ImmutableSet.of(node)); } } return builder.build(); }