List of usage examples for java.util HashSet remove
public boolean remove(Object o)
From source file:com.googlecode.eyesfree.brailleback.FocusFinder.java
public static AccessibilityNodeInfoCompat findFirstFocusableDescendant(AccessibilityNodeInfoCompat root, Context context) {// w ww .j a va 2 s . c om // null guard and shortcut for leaf nodes. if (root == null || root.getChildCount() <= 0) { return null; } HashSet<AccessibilityNodeInfoCompat> seenNodes = new HashSet<AccessibilityNodeInfoCompat>(); seenNodes.add(root); try { return findFirstFocusableDescendantInternal(root, context, seenNodes); } finally { seenNodes.remove(root); // Not owned by us. AccessibilityNodeInfoUtils.recycleNodes(seenNodes); } }
From source file:org.apache.oodt.cas.cli.CmdLineUtility.java
/** * Checks for required options which are not set and returns the ones it * finds.//w ww .j a v a2 s. c o m * * @param cmdLineArgs * The {@link CmdLineArgs} which will be check for required * options. * @return The required {@link CmdLineOption}s not specified. */ public static Set<CmdLineOption> check(CmdLineArgs cmdLineArgs) { Set<CmdLineOption> requiredOptions = determineRequired(cmdLineArgs.getSpecifiedAction(), cmdLineArgs.getSupportedOptions()); HashSet<CmdLineOption> requiredOptionsNotSet = new HashSet<CmdLineOption>(requiredOptions); for (CmdLineOptionInstance specifiedOption : cmdLineArgs.getSpecifiedOptions()) { requiredOptionsNotSet.remove(specifiedOption.getOption()); } return requiredOptionsNotSet; }
From source file:com.sencko.basketball.stats.advanced.FIBAJsonParser.java
static void analyzeGame(Game game) { HashSet[] playersInGameTeam = { new HashSet<String>(5), new HashSet<String>(5) }; HashSet[] playersInRest = { new HashSet<String>(5), new HashSet<String>(5) }; HashMap[][] plusMinusPlayers = { { new HashMap<String, Integer>(), new HashMap<String, Integer>() }, { new HashMap<String, Integer>(), new HashMap<String, Integer>() } }; for (int i = game.getPbp().size() - 1; i >= 0; i--) { Event event = game.getPbp().get(i); if (EventType.sub.equals(event.getTyp())) { HashSet<String> teamSet = playersInGameTeam[event.getTno() - 1]; HashSet<String> restSet = playersInRest[event.getTno() - 1]; String actor = event.getActor().toString(); if (teamSet.contains(actor)) { teamSet.remove(actor); restSet.add(actor);//w ww. j a va 2s.co m } else { teamSet.add(actor); if (restSet.contains(actor)) { restSet.remove(actor); } else { //add plus minus on bench HashMap<String, Integer> bench = plusMinusPlayers[event.getTno() - 1][1]; int change = (event.getTno() == 1) ? (event.getS1() - event.getS2()) : (event.getS2() - event.getS1()); bench.put(actor, change); } } // System.out.println(Arrays.toString(playersInGameTeam)); } else if (i != game.getPbp().size() - 1) { Event previousEvent = game.getPbp().get(i + 1); int change = 0; if (previousEvent.getS1() != event.getS1()) { change += event.getS1() - previousEvent.getS1(); } if (previousEvent.getS2() != event.getS2()) { change -= event.getS2() - previousEvent.getS2(); } for (int j = 0; j < 2; j++) { HashSet<String> teamSet = playersInGameTeam[j]; for (String player : teamSet) { HashMap<String, Integer> prev = plusMinusPlayers[j][0]; Integer previous = prev.get(player); if (previous == null) { previous = 0; } previous = previous + change; prev.put(player, previous); } HashSet<String> restSet = playersInRest[j]; for (String player : restSet) { HashMap<String, Integer> prev = plusMinusPlayers[j][1]; Integer previous = prev.get(player); if (previous == null) { previous = 0; } previous = previous + change; prev.put(player, previous); } change = -change; } } } // System.out.println(Arrays.deepToString(plusMinusPlayers)); for (int i = 0; i < 2; i++) { HashMap<String, Integer> board = plusMinusPlayers[i][0]; HashMap<String, Integer> bench = plusMinusPlayers[i][1]; int checkSum = 0; for (String name : board.keySet()) { int plusS = board.get(name); int plusB = bench.get(name); int total = plusS - plusB; System.out.printf("%20s\t%4d\t%4d\t%4d\n", name, plusS, plusB, total); checkSum += total; } System.out.println(checkSum + "----------------------------------------"); } }
From source file:com.facebook.TestUtils.java
private static boolean areEqual(final JSONObject expected, final JSONObject actual) { // JSONObject.equals does not do an order-independent comparison, so let's roll our own :( if (expected == actual) { return true; }/*from w w w . ja v a 2s. c om*/ if ((expected == null) || (actual == null)) { return false; } final Iterator<String> expectedKeysIterator = expected.keys(); final HashSet<String> expectedKeys = new HashSet<String>(); while (expectedKeysIterator.hasNext()) { expectedKeys.add(expectedKeysIterator.next()); } final Iterator<String> actualKeysIterator = actual.keys(); while (actualKeysIterator.hasNext()) { final String key = actualKeysIterator.next(); if (!areEqual(expected.opt(key), actual.opt(key))) { return false; } expectedKeys.remove(key); } return expectedKeys.size() == 0; }
From source file:com.velonuboso.made.core.common.Helper.java
/** * Modification by rhgarcia from the implementation of M. Jessup * at StackOverflow./*from w w w . j a va 2s. c om*/ * http://stackoverflow.com/users/294738/m-jessup */ public static ArrayList<Class> topologicalOrder(ArrayList<Class> classes) throws Exception { Node[] allNodes = new Node[classes.size()]; HashMap<String, Node> nodes = new HashMap<String, Node>(); for (int i = 0; i < classes.size(); i++) { Class c = classes.get(i); Node n = new Node(c); allNodes[i] = n; nodes.put(c.getSimpleName(), n); } for (int i = 0; i < allNodes.length; i++) { Node n = allNodes[i]; Class c = n.getC(); Archetype a = (Archetype) c.getConstructors()[0].newInstance(); ArrayList<Class> dependencies = a.getDependencies(); for (int j = 0; j < dependencies.size(); j++) { Class dep = dependencies.get(j); Node nAux = nodes.get(dep.getSimpleName()); if (nAux != null) { nAux.addEdge(n); } } } //L <- Empty list that will contain the sorted elements ArrayList<Node> L = new ArrayList<Node>(); //S <- Set of all nodes with no incoming edges HashSet<Node> S = new HashSet<Node>(); for (Node n : allNodes) { if (n.inEdges.size() == 0) { S.add(n); } } //while S is non-empty do while (!S.isEmpty()) { //remove a node n from S Node n = S.iterator().next(); S.remove(n); //insert n into L L.add(n); //for each node m with an edge e from n to m do for (Iterator<Edge> it = n.outEdges.iterator(); it.hasNext();) { //remove edge e from the graph Edge e = it.next(); Node m = e.to; it.remove();//Remove edge from n m.inEdges.remove(e);//Remove edge from m //if m has no other incoming edges then insert m into S if (m.inEdges.isEmpty()) { S.add(m); } } } //Check to see if all edges are removed boolean cycle = false; for (Node n : allNodes) { if (!n.inEdges.isEmpty()) { cycle = true; break; } } if (cycle) { throw new Exception("Cycle present, topological sort not possible"); } System.out.println("Topological Sort: " + Arrays.toString(L.toArray())); ArrayList<Class> ret = new ArrayList<Class>(); for (Node n : L) { ret.add(n.getC()); } return ret; }
From source file:com.battlelancer.seriesguide.util.TraktTools.java
private static void applyEpisodeFlagChanges(Context context, List<TvShow> remoteShows, HashSet<Integer> localShows, String episodeFlagColumn, boolean clearExistingFlags) { HashSet<Integer> skippedShows = new HashSet<>(localShows); // loop through shows on trakt, update the ones existing locally for (TvShow tvShow : remoteShows) { if (tvShow == null || tvShow.tvdb_id == null || !localShows.contains(tvShow.tvdb_id)) { // does not match, skip continue; }/*ww w .ja v a2s .c o m*/ applyEpisodeFlagChanges(context, tvShow, episodeFlagColumn, clearExistingFlags); skippedShows.remove(tvShow.tvdb_id); } // clear flags on all shows not synced if (clearExistingFlags && skippedShows.size() > 0) { clearFlagsOfShow(context, episodeFlagColumn, skippedShows); } }
From source file:com.act.reachables.Network.java
public static JSONObject get(MongoDB db, Set<Node> nodes, Set<Edge> edges, HashMap<Long, Long> parentIds, HashMap<Long, Edge> toParentEdges) throws JSONException { // init the json object with structure: // {//from w w w . ja v a2 s. com // "name": "nodeid" // "children": [ // { "name": "childnodeid", toparentedge: {}, nodedata:.. }, ... // ] // } HashMap<Long, Node> nodeById = new HashMap<>(); for (Node n : nodes) nodeById.put(n.id, n); HashMap<Long, JSONObject> nodeObjs = new HashMap<>(); // un-deconstruct tree... for (Long nid : parentIds.keySet()) { JSONObject nObj = JSONHelper.nodeObj(db, nodeById.get(nid)); nObj.put("name", nid); if (toParentEdges.get(nid) != null) { JSONObject eObj = JSONHelper.edgeObj(toParentEdges.get(nid), null /* no ordering reqd for referencing nodeMapping */); nObj.put("edge_up", eObj); } else { } nodeObjs.put(nid, nObj); } // now that we know that each node has an associated obj // link the objects together into the tree structure // put each object inside its parent HashSet<Long> unAssignedToParent = new HashSet<>(parentIds.keySet()); for (Long nid : parentIds.keySet()) { JSONObject child = nodeObjs.get(nid); // append child to "children" key within parent JSONObject parent = nodeObjs.get(parentIds.get(nid)); if (parent != null) { parent.append("children", child); unAssignedToParent.remove(nid); } else { } } // outputting a single tree makes front end processing easier // we can always remove the root in the front end and get the forest again // if many trees remain, assuming they indicate a disjoint forest, // add then as child to a proxy root. // if only one tree then return it JSONObject json; if (unAssignedToParent.size() == 0) { json = null; throw new RuntimeException("All nodeMapping have parents! Where is the root? Abort."); } else if (unAssignedToParent.size() == 1) { json = unAssignedToParent.toArray(new JSONObject[0])[0]; // return the only element in the set } else { json = new JSONObject(); for (Long cid : unAssignedToParent) { json.put("name", "root"); json.append("children", nodeObjs.get(cid)); } } return json; }
From source file:amie.keys.CombinationsExplorationNew.java
public static HashSet<HashSet<Integer>> buidPropertyGraphNew(int property) { HashSet<HashSet<Integer>> propertyPowerSets = new HashSet<>(); for (HashSet<Integer> nonKeyInt : nonKeysInt) { if (nonKeyInt.contains(property)) { HashSet<Integer> remainingSet = new HashSet<>(nonKeyInt); remainingSet.addAll(nonKeyInt); remainingSet.remove(property); propertyPowerSets.addAll(powerSet(remainingSet)); }/*from w w w .j av a2s. c o m*/ } return propertyPowerSets; }
From source file:amie.keys.CombinationsExplorationNew.java
public static HashSet<HashSet<Integer>> simplifyHashNonKeySet(HashSet<HashSet<Integer>> nonKeySet) { HashSet<HashSet<Integer>> newnonKeySet = new HashSet<HashSet<Integer>>(); newnonKeySet.addAll(nonKeySet);/* w ww.j a v a 2 s . com*/ for (HashSet set : nonKeySet) { for (HashSet set2 : nonKeySet) { if (set2 != set && set2.containsAll(set)) { newnonKeySet.remove(set); break; } } } return newnonKeySet; }
From source file:org.ng200.openolympus.controller.contest.ContestTaskRemovalController.java
@PreAuthorize(SecurityExpressionConstants.IS_ADMIN) @CacheEvict(value = "contests", key = "#contest.id") @RequestMapping(value = "/api/contest/{contest}/removeTask", method = RequestMethod.DELETE) public void removeTask(@PathVariable(value = "contest") final Contest contest, @RequestParam(value = "task") final Task task, final Model model) { Assertions.resourceExists(contest);/*from w w w .j av a 2s.c om*/ Assertions.resourceExists(task); HashSet<Task> tasks = new HashSet<>(contest.getTasks()); if (tasks.contains(task)) { tasks.remove(task); contest.setTasks(tasks); this.contestService.saveContest(contest); } }