List of usage examples for java.util TreeSet add
public boolean add(E e)
From source file:org.opendatakit.security.server.SecurityServiceUtil.java
/** * Given a collection of users, ensure that each user is a registered user (creating a registered * user if one doesn't exist) and assign those users to the granted authority. * <p>/*from w ww. j a v a 2s .c o m*/ * The collection is assumed to be exhaustive. If there are other e-mails already assigned to the * granted authority, they will be removed so that exactly the passed-in set of users are assigned * to the authority, no more, no less. * </p> * * @param users * @param auth * @param cc * @throws DatastoreFailureException */ private static void setUsersOfGrantedAuthority(Map<UserSecurityInfo, String> pkMap, GrantedAuthority auth, CallingContext cc) throws DatastoreFailureException { Set<GrantedAuthority> badGrants = new TreeSet<GrantedAuthority>(); GrantedAuthorityName name = mapName(auth, badGrants); if (name != null) { // build the set of uriUsers for this granted authority... TreeSet<String> desiredMembers = new TreeSet<String>(); for (Map.Entry<UserSecurityInfo, String> u : pkMap.entrySet()) { UserSecurityInfo info = u.getKey(); String uriUser = u.getValue(); if (info.getAssignedUserGroups().contains(name)) { desiredMembers.add(uriUser); } } // assert that the authority has exactly this set of uriUsers (no more, no // less) try { UserGrantedAuthority.assertGrantedAuthorityMembers(auth, desiredMembers, cc); } catch (ODKDatastoreException e) { e.printStackTrace(); throw new DatastoreFailureException("Incomplete security update", e); } } else { try { removeBadGrantedAuthorities(badGrants, cc); } catch (ODKDatastoreException e) { e.printStackTrace(); throw new DatastoreFailureException("Incomplete security update", e); } } }
From source file:org.openmrs.module.distrotools.AbstractOrderedDescriptorTest.java
@Test public void compareTo() { TreeSet<TestDescriptor> tree = new TreeSet<TestDescriptor>(); tree.add(descriptor3); tree.add(descriptor2);//from w w w . j av a 2 s.co m tree.add(descriptor1); Assert.assertThat(tree, contains(descriptor1, descriptor2, descriptor3)); }
From source file:com.opendoorlogistics.core.utils.strings.Strings.java
public static TreeSet<String> stdTreeSet(Iterable<String> iterable) { TreeSet<String> ret = new TreeSet<>(); if (iterable != null) { for (String s : iterable) { if (s != null) { String std = std(s); if (std.length() > 0) { ret.add(std(s)); }// w w w . ja va 2 s. com } } } return ret; }
From source file:com.smoketurner.notification.application.riak.CursorObjectTest.java
@Test public void testCursorSorting() { final CursorObject c2 = new CursorObject("test-notifications", 1L); final CursorObject c3 = new CursorObject("test-notifications", 2L); final TreeSet<CursorObject> cursors = Sets.newTreeSet(); cursors.add(cursor); cursors.add(c2);// w ww. j a v a 2 s .c om cursors.add(c3); assertThat(cursors).containsExactly(cursor, c3, c2); }
From source file:com.cyanogenmod.eleven.ui.fragments.RecentFragment.java
@Override protected void updateMenuIds(TreeSet<Integer> set) { set.add(FragmentMenuItems.REMOVE_FROM_RECENT); }
From source file:DecorateMutationsSNP.java
/** * This function returns the set of leaves in the ARG that are reachable from a node give in input * @param root integer value representing the ID of the node in the arg * @param arg object of the class PopulationARG * @see PopulationARG// www . j a va 2s .c o m * @see Node * @return the set of integer values representing the leaves in the ARG that are reachable from a node give in input (root) */ public static TreeSet<Integer> computeLeaves(int root, PopulationARG arg) { TreeSet<Integer> leaves = new TreeSet<Integer>(); Queue<Integer> q = new LinkedList<Integer>(); boolean visited[] = new boolean[arg.getNodeSet().size()]; /*System.out.println("ID Population = "+arg.getId_pop()); System.out.println("Population Kind = "+arg.getKind()); System.out.println("Extant units = "+arg.getExtantUnits()); System.out.println("Node set size = "+arg.getNodeSet().size());*/ for (int i = 0; i < visited.length; i++) { visited[i] = false; } //System.out.println("Root = "+root); //If root is a leaf I have to add just that leaf in leaves, no reason to do the visit if (root >= 0 && root < arg.getExtantUnits()) { leaves.add(new Integer(root)); } //Else bfv to search for all the leaves of the subtree with root root else { visited[root] = true; q.add(new Integer(root)); while (!q.isEmpty()) { // remove a labeled vertex from the queue int w = ((Integer) q.remove()).intValue(); // mark unreached vertices adjacent from w Iterator<Integer> it_edges = arg.getGraphEdges().keySet().iterator(); while (it_edges.hasNext()) { Integer keyE = it_edges.next(); Edge e = arg.getGraphEdges().get(keyE); //if I have found an edge with w has father if (e.getId_fath() == w) { int u = e.getId_son(); //System.out.println("Visiting edge "+w+"-"+u); if (!visited[u]) { q.add(new Integer(u)); visited[u] = true; //System.out.println("Visiting node :"+u); if (u >= 0 && u < arg.getExtantUnits()) { //System.out.println("u is a leaf :"+u); //u is a leaf node leaves.add(u); } } } //end if w is a father of the edge } //for all edge..select the one that has w has father and take u as son } //end while } // end else root is not a leaf return leaves; }
From source file:net.spfbl.core.Reverse.java
public static ArrayList<String> getMXSet(String host) throws NamingException { TreeMap<Integer, TreeSet<String>> mxMap = new TreeMap<Integer, TreeSet<String>>(); Attributes atributes = Server.getAttributesDNS(host, new String[] { "MX" }); if (atributes == null || atributes.size() == 0) { atributes = Server.getAttributesDNS(host, new String[] { "CNAME" }); Attribute attribute = atributes.get("CNAME"); if (attribute != null) { String cname = (String) attribute.get(0); return getMXSet(cname); }//from www. java2 s .c om } else { Attribute attribute = atributes.get("MX"); if (attribute != null) { for (int index = 0; index < attribute.size(); index++) { try { String mx = (String) attribute.get(index); int space = mx.indexOf(' '); String value = mx.substring(0, space); int priority = Integer.parseInt(value); mx = mx.substring(space + 1); int last = mx.length() - 1; TreeSet<String> mxSet = mxMap.get(priority); if (mxSet == null) { mxSet = new TreeSet<String>(); mxMap.put(priority, mxSet); } if (Subnet.isValidIP(mx.substring(0, last))) { mxSet.add(Subnet.normalizeIP(mx.substring(0, last))); } else if (Domain.isHostname(mx)) { mxSet.add(Domain.normalizeHostname(mx, true)); } } catch (NumberFormatException ex) { } } } } ArrayList<String> mxList = new ArrayList<String>(); if (mxMap.isEmpty()) { // https://tools.ietf.org/html/rfc5321#section-5 mxList.add(Domain.normalizeHostname(host, true)); } else { for (int priority : mxMap.keySet()) { TreeSet<String> mxSet = mxMap.get(priority); for (String mx : mxSet) { if (!mxList.contains(mx)) { mxList.add(mx); } } } } return mxList; }
From source file:edu.umass.cs.protocoltask.examples.ExampleNode.java
protected PingPongProtocolTask reliableSend(int id) { TreeSet<Integer> nodes = new TreeSet<Integer>(); nodes.add(id); PingPongProtocolTask task = new PingPongProtocolTask(this.myID, nodes, 1); log.info("Node" + myID + " spawning reliableSend protocol task"); this.protocolExecutor.spawn(task); return task;// w w w . jav a 2 s . c o m }
From source file:net.spfbl.core.Client.java
public static TreeSet<Client> getClientSet(String domain) { TreeSet<Client> clientSet = new TreeSet<Client>(); for (Client client : getSet()) { if (client.isDomain(domain)) { clientSet.add(client); }//from w w w .j av a 2 s .c o m } return clientSet; }
From source file:net.spfbl.core.Client.java
public static TreeSet<Client> getAdministratorSet() { TreeSet<Client> clientSet = new TreeSet<Client>(); for (Client client : getSet()) { if (client.isAdministrator()) { clientSet.add(client); }//from ww w . j a v a 2 s .c om } return clientSet; }