List of usage examples for java.util Collection retainAll
boolean retainAll(Collection<?> c);
From source file:org.b3mn.poem.handler.AccessHandler.java
@SuppressWarnings("unchecked") @FilterMethod(FilterName = "friend") public static Collection<String> filterByFriends(Identity subject, String params) throws Exception { // String typeQuery = ""; User user = new User(subject); Collection<String> modelUris = user.getModelUris(); // get all models of the user for (String friend : params.split(",")) { friend = removeSpaces(friend);/*from w ww.j a v a2s .c o m*/ Collection<String> friendModelUris = Persistance.getSession() .createSQLQuery( "SELECT access.object_name FROM access " + "WHERE access.subject_name=:friend_openId ") .setString("friend_openId", friend).list(); Persistance.commit(); modelUris.retainAll(friendModelUris); if (modelUris.size() == 0) break; } return modelUris; }
From source file:org.jactr.core.module.declarative.search.map.NumericTypeValueMap.java
public Collection<I> get(Object value) { Collection<I> rtn = lessThan(value); rtn.retainAll(greaterThan(value)); return rtn; }
From source file:edu.uci.ics.jung.visualization.util.PredicatedParallelEdgeIndexFunction.java
protected int getIndex(Graph<V, E> graph, E e, V v, V u) { Collection<E> commonEdgeSet = new HashSet<E>(graph.getIncidentEdges(u)); commonEdgeSet.retainAll(graph.getIncidentEdges(v)); for (Iterator<E> iterator = commonEdgeSet.iterator(); iterator.hasNext();) { E edge = iterator.next();/*from www . j a va 2s . c o m*/ Pair<V> ep = graph.getEndpoints(edge); V first = ep.getFirst(); V second = ep.getSecond(); // remove loops if (first.equals(second) == true) { iterator.remove(); } // remove edges in opposite direction if (first.equals(v) == false) { iterator.remove(); } } int count = 0; for (E other : commonEdgeSet) { if (e.equals(other) == false) { edge_index.put(other, count); count++; } } edge_index.put(e, count); return count; }
From source file:org.biopax.validator.rules.NextStepShareParticipantsRule.java
public void check(final Validation validation, PathwayStep step) { if (step.getNextStepOf().isEmpty()) return;/*from w w w .j a v a 2 s .c om*/ // get all the participants Collection<Entity> thisStepParticipants = getParticipants(step); // now find participants intersection with each previous step: for (PathwayStep prevStep : step.getNextStepOf()) { Collection<Entity> participants = getParticipants(prevStep); // first set becomes the intersection of the two: participants.retainAll(thisStepParticipants); if (participants.isEmpty()) { error(validation, step, "empty.participants.intersection", false, prevStep); } } }
From source file:com.hp.autonomy.frontend.find.core.fields.FieldsController.java
/** * Fetch the parametric fields of the given type along with their min and max values. *//* w ww . j a v a 2s . com*/ protected List<FieldAndValueDetails> fetchParametricFieldAndValueDetails(final R request, final FieldTypeParam fieldType, final Iterable<String> additionalFields) throws E { final Map<FieldTypeParam, List<TagName>> response = fieldsService.getFields(request, FieldTypeParam.Parametric, fieldType); final Collection<TagName> parametricFields = new ArrayList<>(response.get(FieldTypeParam.Parametric)); parametricFields.retainAll(response.get(fieldType)); for (final String field : additionalFields) { parametricFields.add(new TagName(field)); } final List<String> fieldNames = new LinkedList<>(); for (final TagName tagName : parametricFields) { fieldNames.add(tagName.getId()); } final P parametricRequest = parametricRequestBuilderFactory.getObject().setFieldNames(fieldNames) .setQueryRestrictions(createValueDetailsQueryRestrictions(request)).build(); final Map<TagName, ValueDetails> valueDetailsResponse = parametricValuesService .getValueDetails(parametricRequest); final List<FieldAndValueDetails> output = new LinkedList<>(); for (final TagName tagName : parametricFields) { final FieldAndValueDetails.Builder builder = new FieldAndValueDetails.Builder().setId(tagName.getId()) .setName(tagName.getName()); final ValueDetails valueDetails = valueDetailsResponse.get(tagName); if (valueDetails != null) { builder.setMax(valueDetails.getMax()).setMin(valueDetails.getMin()) .setTotalValues(valueDetails.getTotalValues()); } output.add(builder.build()); } return output; }
From source file:nl.strohalm.cyclos.services.sms.SmsMailingServiceSecurity.java
private void applySearchRestrictions(final SmsMailingQuery query) { // the search is allowed only for admins and brokers if (LoggedUser.isBroker()) { // Ensure that brokers only see mailings sent by himself query.setBroker((Member) LoggedUser.element()); Member member = fetchService.fetch(query.getMember(), Member.Relationships.BROKER); if (member != null && !LoggedUser.element().equals(member.getBroker())) { throw new PermissionDeniedException(); }/*from w w w .ja v a 2 s . c om*/ } else { // Ensure admins will only see groups he can manage final AdminGroup adminGroup = fetchService.fetch((AdminGroup) LoggedUser.group(), AdminGroup.Relationships.MANAGES_GROUPS); final Collection<MemberGroup> groups = query.getGroups(); if (CollectionUtils.isEmpty(groups)) { query.setGroups(adminGroup.getManagesGroups()); } else { groups.retainAll(adminGroup.getManagesGroups()); } } }
From source file:ubic.gemma.core.loader.association.phenotype.OmimDatabaseImporterCli.java
/** * return all common pubmed between an omimGeneId and a omimPhenotypeId * //w ww .j av a 2 s .c o m * @param omimGeneId * @param omimPhenotypeId * @param omimIdToPubmeds * @return */ private Collection<Long> findCommonPubmed(Long omimGeneId, Long omimPhenotypeId, Map<Long, Collection<Long>> omimIdToPubmeds) { Collection<Long> pubmedFromGeneId = omimIdToPubmeds.get(omimGeneId); Collection<Long> pubmedFromPhenotypeId = omimIdToPubmeds.get(omimPhenotypeId); if (pubmedFromGeneId != null && pubmedFromPhenotypeId != null) { Collection<Long> commonElements = new HashSet<>(pubmedFromGeneId); commonElements.retainAll(pubmedFromPhenotypeId); return commonElements; } return new HashSet<>(); }
From source file:com.hp.hpl.inkml.Ink.java
/** * Method to remove other traceData but retain them given in the parameter * //from ww w .ja v a2 s . c o m * @param traceDataList collection * @return boolean status * @see java.util.AbstractCollection#retainAll(java.util.Collection) */ public boolean retainAllTraceData(final Collection<TraceDataElement> traceDataList) { return traceDataList.retainAll(traceDataList); }
From source file:org.wso2.carbon.identity.application.authentication.framework.handler.provisioning.impl.DefaultProvisioningHandler.java
private Collection<String> getRolesToAdd(UserStoreManager userStoreManager, String[] newRoles) throws UserStoreException { Collection<String> addingRoles = new ArrayList<>(); Collections.addAll(addingRoles, newRoles); Collection<String> allExistingRoles = removeDomainFromNamesExcludeInternal( Arrays.asList(userStoreManager.getRoleNames())); addingRoles.retainAll(allExistingRoles); return addingRoles; }
From source file:com.google.code.facebook.graph.sna.applet.VertexCollapseDemo.java
public VertexCollapseDemo() { // create a simple graph for the demo graph = TestGraphs.getOneComponentGraph(); collapser = new GraphCollapser(graph); layout = new FRLayout(graph); Dimension preferredSize = new Dimension(400, 400); final VisualizationModel visualizationModel = new DefaultVisualizationModel(layout, preferredSize); vv = new VisualizationViewer(visualizationModel, preferredSize); vv.getRenderContext().setVertexShapeTransformer(new ClusterVertexShapeFunction()); final PredicatedParallelEdgeIndexFunction eif = PredicatedParallelEdgeIndexFunction.getInstance(); final Set exclusions = new HashSet(); eif.setPredicate(new Predicate() { public boolean evaluate(Object e) { return exclusions.contains(e); }// w ww .j a v a2s. c om }); vv.getRenderContext().setParallelEdgeIndexFunction(eif); vv.setBackground(Color.white); // add a listener for ToolTips vv.setVertexToolTipTransformer(new ToStringLabeller() { /* (non-Javadoc) * @see edu.uci.ics.jung.visualization.decorators.DefaultToolTipFunction#getToolTipText(java.lang.Object) */ @Override public String transform(Object v) { if (v instanceof Graph) { return ((Graph) v).getVertices().toString(); } return super.transform(v); } }); /** * the regular graph mouse for the normal view */ final DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse(); vv.setGraphMouse(graphMouse); Container content = getContentPane(); GraphZoomScrollPane gzsp = new GraphZoomScrollPane(vv); content.add(gzsp); JComboBox modeBox = graphMouse.getModeComboBox(); modeBox.addItemListener(graphMouse.getModeListener()); graphMouse.setMode(ModalGraphMouse.Mode.PICKING); final ScalingControl scaler = new CrossoverScalingControl(); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JButton collapse = new JButton("Collapse"); collapse.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Collection picked = new HashSet(vv.getPickedVertexState().getPicked()); if (picked.size() > 1) { Graph inGraph = layout.getGraph(); Graph clusterGraph = collapser.getClusterGraph(inGraph, picked); Graph g = collapser.collapse(layout.getGraph(), clusterGraph); double sumx = 0; double sumy = 0; for (Object v : picked) { Point2D p = (Point2D) layout.transform(v); sumx += p.getX(); sumy += p.getY(); } Point2D cp = new Point2D.Double(sumx / picked.size(), sumy / picked.size()); vv.getRenderContext().getParallelEdgeIndexFunction().reset(); layout.setGraph(g); layout.setLocation(clusterGraph, cp); vv.getPickedVertexState().clear(); vv.repaint(); } } }); JButton compressEdges = new JButton("Compress Edges"); compressEdges.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Collection picked = vv.getPickedVertexState().getPicked(); if (picked.size() == 2) { Pair pair = new Pair(picked); Graph graph = layout.getGraph(); Collection edges = new HashSet(graph.getIncidentEdges(pair.getFirst())); edges.retainAll(graph.getIncidentEdges(pair.getSecond())); exclusions.addAll(edges); vv.repaint(); } } }); JButton expandEdges = new JButton("Expand Edges"); expandEdges.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Collection picked = vv.getPickedVertexState().getPicked(); if (picked.size() == 2) { Pair pair = new Pair(picked); Graph graph = layout.getGraph(); Collection edges = new HashSet(graph.getIncidentEdges(pair.getFirst())); edges.retainAll(graph.getIncidentEdges(pair.getSecond())); exclusions.removeAll(edges); vv.repaint(); } } }); JButton expand = new JButton("Expand"); expand.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Collection picked = new HashSet(vv.getPickedVertexState().getPicked()); for (Object v : picked) { if (v instanceof Graph) { Graph g = collapser.expand(layout.getGraph(), (Graph) v); vv.getRenderContext().getParallelEdgeIndexFunction().reset(); layout.setGraph(g); } vv.getPickedVertexState().clear(); vv.repaint(); } } }); JButton reset = new JButton("Reset"); reset.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { layout.setGraph(graph); exclusions.clear(); vv.repaint(); } }); JButton help = new JButton("Help"); help.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog((JComponent) e.getSource(), instructions, "Help", JOptionPane.PLAIN_MESSAGE); } }); JPanel controls = new JPanel(); JPanel zoomControls = new JPanel(new GridLayout(2, 1)); zoomControls.setBorder(BorderFactory.createTitledBorder("Zoom")); zoomControls.add(plus); zoomControls.add(minus); controls.add(zoomControls); JPanel collapseControls = new JPanel(new GridLayout(3, 1)); collapseControls.setBorder(BorderFactory.createTitledBorder("Picked")); collapseControls.add(collapse); collapseControls.add(expand); collapseControls.add(compressEdges); collapseControls.add(expandEdges); collapseControls.add(reset); controls.add(collapseControls); controls.add(modeBox); controls.add(help); content.add(controls, BorderLayout.SOUTH); }