List of usage examples for java.util Set remove
boolean remove(Object o);
From source file:bayesGame.ui.painter.AndNodePainter.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("AND node with more than 2 parents not yet implemented"); }//from w ww . j a v a 2 s. 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; } } Color whiteColor = Color.WHITE; 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, falseColor, Color.BLACK); NodePainter.squarePainter(g, 0, YSize, XSize, Y_Size, falseColor, 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; }
From source file:Main.java
/** * Internal function to realize the mathematical combination of given * values. This method creates the next sub-tree by iterating over values * given by parameter set./*from w w w .j a va 2 s .c om*/ * * @param <E> * the type of the given and returned values * @param set * the possible values for next iteration * @param combination * the current path of the abstract combination tree * @param combinations * overall combinations */ private static <E extends Object> void combination(Set<E> set, Set<E> combination, Set<Set<E>> combinations) { for (E value : set) { Set<E> combination_ = new HashSet<E>(); combination_.addAll(combination); combination_.add(value); combinations.add(combination_); Set<E> set_ = new HashSet<E>(); set_.addAll(set); long size = set_.size(); set_.remove(value); if (set_.size() == size) { for (E v : set_) { if (v.equals(value)) { set_.remove(v); break; } } } if (!set_.isEmpty()) { combination(set_, combination_, combinations); } } }
From source file:Main.java
public static <T> boolean hasCycle(Collection<T> vertices, Function<T, Collection<T>> neighborExtractor) { Map<T, Collection<T>> parents = vertices.stream().collect(toMap(identity(), v -> new ArrayList<T>())); vertices.forEach(// w w w . ja v a 2 s. co m v -> nullSafeCollection(neighborExtractor.apply(v)).forEach(child -> parents.get(child).add(v))); Set<T> roots = vertices.stream().filter(v -> parents.get(v).isEmpty()).collect(Collectors.toSet()); while (!roots.isEmpty()) { T root = roots.iterator().next(); roots.remove(root); parents.remove(root); nullSafeCollection(neighborExtractor.apply(root)).forEach(child -> { parents.get(child).remove(root); if (parents.get(child).isEmpty()) { roots.add(child); } }); } return !parents.isEmpty(); }
From source file:es.emergya.ui.base.plugins.PluginEventHandler.java
/** * Deregistra a observer para no volverle a avisar cuando observable se * modifique/* w ww. jav a 2s. com*/ * * @param observer * @param observable */ public static synchronized void deregister(PluginListener observer, PluginListener observable) { Set<PluginListener> observers = getObservables(observable); if (observers == null) observers = new HashSet<PluginListener>(); observers.remove(observer); observables.put(observable, observers); }
From source file:zipkin.sparkstreaming.job.ZipkinSparkStreamingConfiguration.java
/** * This assumes everything is in the uber-jar except perhaps the adjusters (which are themselves * self-contained jars)./* w w w . j a va2 s . c o m*/ */ static List<String> pathToJars(Class<?> entryPoint, List<Adjuster> adjusters) { Set<String> jars = new LinkedHashSet<>(); jars.add(pathToJar(entryPoint)); for (Adjuster adjuster : adjusters) { jars.add(pathToJar(adjuster.getClass())); } jars.remove(null); return jars.isEmpty() ? null : new ArrayList<>(jars); }
From source file:com.hp.autonomy.aci.content.printfields.PrintFields.java
/** * Parser for a printfields string./*from w w w .j ava 2 s .c om*/ * * @param printFields A valid IDOL printfields * @return A parsed {@code PrintFields} */ public static PrintFields parse(final String printFields) { Validate.notNull(printFields, "PrintFields must not be null"); final Set<String> printFieldsSet = new LinkedHashSet<String>(Arrays.asList(SEPARATORS.split(printFields))); printFieldsSet.remove(""); return new PrintFields(printFieldsSet); }
From source file:edu.uci.ics.jung.algorithms.metrics.TriadicCensus.java
/** * Returns an array whose ith element (for i in [1,16]) is the number of * occurrences of the corresponding triad type in <code>g</code>. * (The 0th element is not meaningful; this array is effectively 1-based.) * /*from w ww .j av a2 s . c o m*/ * @param g */ public static <V, E> long[] getCounts(DirectedGraph<V, E> g) { long[] count = new long[MAX_TRIADS]; List<V> id = new ArrayList<V>(g.getVertices()); // apply algorithm to each edge, one at at time for (int i_v = 0; i_v < g.getVertexCount(); i_v++) { V v = id.get(i_v); for (V u : g.getNeighbors(v)) { int triType = -1; if (id.indexOf(u) <= i_v) continue; Set<V> neighbors = new HashSet<V>(CollectionUtils.union(g.getNeighbors(u), g.getNeighbors(v))); neighbors.remove(u); neighbors.remove(v); if (g.isSuccessor(v, u) && g.isSuccessor(u, v)) { triType = 3; } else { triType = 2; } count[triType] += g.getVertexCount() - neighbors.size() - 2; for (V w : neighbors) { if (shouldCount(g, id, u, v, w)) { count[triType(triCode(g, u, v, w))]++; } } } } int sum = 0; for (int i = 2; i <= 16; i++) { sum += count[i]; } int n = g.getVertexCount(); count[1] = n * (n - 1) * (n - 2) / 6 - sum; return count; }
From source file:de.unisb.cs.st.javalanche.mutation.util.AddMutations.java
private static Set<Integer> getOpcodeReplacements(int operator) { Set<Integer> result = new HashSet<Integer>(); int[] replaceOperators = getReplaceOperators(operator); for (int i : replaceOperators) { result.add(i);/*from w ww. j a v a2 s . c om*/ } result.remove(operator); Integer alreadyUsedReplacement = ReplaceMap.getReplaceMap().get(operator); result.remove(alreadyUsedReplacement); return result; }
From source file:au.org.ala.delta.intkey.model.FormattingUtils.java
/** * Formats the values set for an integer character as a string. It is * assumed the values for the integer character have already been processed * such that they are in the range minimumValue - 1 to maximumValue + 1. * /*from ww w .jav a 2 s. c o m*/ * @param integerValues * the values set for the integer character * @param minimumValue * the character's minimum value * @param maximumValue * the character's maximum value * @return the integer character's values formatted as a string. */ public static String formatIntegerValuesAsString(Set<Integer> integerValues, int minimumValue, int maximumValue) { Set<Integer> valuesCopy = new HashSet<Integer>(integerValues); List<String> stringParts = new ArrayList<String>(); if (integerValues.contains(minimumValue - 1)) { stringParts.add(Integer.toString(minimumValue - 1)); } valuesCopy.remove(minimumValue - 1); valuesCopy.remove(maximumValue + 1); if (!valuesCopy.isEmpty()) { List<Integer> valuesCopyAsList = new ArrayList<Integer>(valuesCopy); Collections.sort(valuesCopyAsList); stringParts.add(Utils.formatIntegersAsListOfRanges(valuesCopyAsList, "/", "-")); } if (integerValues.contains(maximumValue + 1)) { stringParts.add(Integer.toString(maximumValue + 1)); } return StringUtils.join(stringParts, "/"); }
From source file:net.sf.json.AbstractJSON.java
/** * Removes a reference for cycle detection check. *//*w w w. j av a2 s . c o m*/ protected static void removeInstance(Object instance) { Set set = getCycleSet(); set.remove(instance); if (set.size() == 0) { cycleSet.remove(); } }