List of usage examples for java.util Set remove
boolean remove(Object o);
From source file:Main.java
public static void removeFromFavorites(final Context context, long movieId) { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); Set<String> set = sp.getStringSet(PREF_FAVORED_MOVIES, null); if (set == null) set = new HashSet<>(); set.remove(String.valueOf(movieId)); sp.edit().putStringSet(PREF_FAVORED_MOVIES, set).apply(); }
From source file:Main.java
public static void compareList(List<? extends Object> origin, List<? extends Object> current, List<Object> added, List<Object> removed) { if (origin == null) { if (current != null) { added.addAll(current);/*from w w w . j av a2 s. c o m*/ } return; } if (current == null) { if (origin != null) { removed.addAll(origin); } return; } Set<Object> originSet = new HashSet<Object>(origin); for (Object eachValue : current) { if (!originSet.remove(eachValue)) { added.add(eachValue); } } removed.addAll(originSet); }
From source file:Main.java
public static long remove(Set set) { long start, stop, result = 0; for (int i = 0; i < 100; i++) { start = System.nanoTime(); set.remove(set.size() - 1 - i); stop = System.nanoTime(); result += stop - start;//from w ww. j a va 2 s .c om } return result / 100; }
From source file:melnorme.utilbox.tests.CommonTestExt.java
protected static <V> void checkSetContains(Set<V> set, V expectedValue) { assertTrue(set.remove(expectedValue)); }
From source file:Main.java
/** * Bestimmt die Differenz zweier Mengen. * //from w ww . ja v a 2s . co m * @param <T> * der Typ der Mengen. * @param set1 * die Menge von der abgezogen wird. * @param set2 * die Elemente dieser Liste werden abgezogen. * @return die Mengendifferenz. */ public static <T> Set<T> difference(final Set<T> set1, final Set<T> set2) { final Set<T> result = new HashSet<T>(set1); for (final T e : set2) { result.remove(e); } return result; }
From source file:edu.cornell.mannlib.vitro.webapp.utils.logging.ToString.java
/** Show the sub-graphs, except for the base graph. */ private static String subGraphsToString(Collection<Graph> subGraphs, Graph baseGraph) { Set<Graph> set = new HashSet<>(subGraphs); set.remove(baseGraph); return setOfGraphsToString(set); }
From source file:Main.java
/** * Answer a set containing all elements that are both in source and in query * Delete these elements from source Creation date: (13.10.2002 16:23:00) * /*from w ww . ja v a 2 s .co m*/ * @return java.util.Set * @param source * java.util.Set * @param elements * java.util.Collection */ public static Set extractFrom(Set source, Collection query) { Set answer = new HashSet(); Iterator i = query.iterator(); while (i.hasNext()) { Object o = i.next(); if (source.remove(o)) { answer.add(o); } } return answer; }
From source file:Main.java
public static <T> Set<T> removeSorted(Set<T> set, T element) { final int size = set.size(); if (size == 0 || (size == 1 && set.contains(element))) { return ImmutableSet.of(); } else {/*w w w . ja va 2 s . co m*/ set.remove(element); } return set; }
From source file:com.tealcube.minecraft.bukkit.mythicdrops.utils.ChatColorUtil.java
public static ChatColor getRandomChatColorWithoutColors(ChatColor... colors) { Set<ChatColor> colors1 = Sets.newHashSet(ChatColor.values()); for (ChatColor c : colors) { if (colors1.contains(c)) { colors1.remove(c); }//from ww w . ja va2 s.c o m } return getRandomChatColorFromSet(colors1); }
From source file:bayesGame.ui.painter.OrNodePainter.java
public static Image paintPercentage(Color gridColor, Color falseColor, int size, int squaresize, BayesNode node, Fraction parentNode1Probability, Fraction parentNode2Probability) { BufferedImage img = new BufferedImage(size, size, BufferedImage.TYPE_INT_RGB); Graphics g = img.getGraphics(); NodePainter.graphicBackgroundPainter(g, 0, 0, size, size); // get non-zero truth table entries from the node List<Map<Object, Boolean>> nonZeroEntries = node.getNonZeroProbabilities(); // get the identities of its parents by taking the first map and querying it // for KeySet, subtracting the object representing the node itself Set<Object> nodeParents = nonZeroEntries.get(0).keySet(); nodeParents.remove(node.type); if (nodeParents.size() > 2) { throw new IllegalArgumentException("OR node with more than 2 parents not yet implemented"); }/*from w w w . j ava 2s. co m*/ Object[] nodeParentsArray = nodeParents.toArray(); Object parent1 = nodeParentsArray[0]; Object parent2 = nodeParentsArray[1]; // for each map, check the truth table entry it corresponds to and color // those appropriately boolean p1true_p2true = false; boolean p1true_p2false = false; boolean p1false_p2true = false; boolean p1false_p2false = false; for (Map<Object, Boolean> map : nonZeroEntries) { Boolean parent1truth = map.get(parent1); Boolean parent2truth = map.get(parent2); if (parent1truth && parent2truth) { p1true_p2true = true; } else if (parent1truth && !parent2truth) { p1true_p2false = true; } else if (!parent1truth && parent2truth) { p1false_p2true = true; } else if (!parent1truth && !parent2truth) { p1false_p2false = true; } } int XSize = parentNode1Probability.multiply(size).intValue(); int X_Size = size - XSize; int YSize = parentNode2Probability.multiply(size).intValue(); int Y_Size = size - YSize; if (p1true_p2true) { NodePainter.squarePainter(g, 0, 0, XSize, YSize, gridColor, Color.BLACK); } else { NodePainter.squarePainter(g, 0, 0, XSize, YSize, NodePainter.RECTANGLE_BOX_BACKGROUND_COLOR, Color.BLACK); } NodePainter.squarePainter(g, XSize, 0, X_Size, YSize, gridColor, Color.BLACK); NodePainter.squarePainter(g, 0, YSize, XSize, Y_Size, gridColor, Color.BLACK); if (p1false_p2false) { NodePainter.squarePainter(g, XSize, YSize, X_Size, Y_Size, falseColor, Color.BLACK); } else { NodePainter.squarePainter(g, XSize, YSize, X_Size, Y_Size, NodePainter.RECTANGLE_BOX_BACKGROUND_COLOR, Color.BLACK); } return img; }