List of usage examples for org.apache.commons.collections15 CollectionUtils union
public static <E> Collection<E> union(final Collection<? extends E> a, final Collection<? extends E> b)
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 w w .ja v a 2 s .com * @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:org.bigwiv.blastgraph.io.GraphIOUtils.java
/** * Returns a graph which consists of the union of the two input graphs. * Assumes that both graphs are of a type that can accept the vertices and * edges found in both graphs. The resultant graph contains all constraints * that are common to both graphs.//from w w w . j a va 2s .c o m */ public static BlastGraph<HitVertex, ValueEdge> union(BlastGraph<HitVertex, ValueEdge> g1, BlastGraph<HitVertex, ValueEdge> g2) { BlastGraph<HitVertex, ValueEdge> g = new BlastGraph<HitVertex, ValueEdge>(); for (HitVertex hv : CollectionUtils.union(g1.getVertices(), g2.getVertices())) { g.addVertex(hv); } for (ValueEdge ve : g1.getEdges()) { g.addEdge(ve, g1.getEndpoints(ve)); } for (ValueEdge ve : g2.getEdges()) { g.addEdge(ve, g2.getEndpoints(ve)); } return g; }
From source file:org.openanzo.client.RealtimeUpdateManager.java
/** * Finds all the tracker patterns that match the provided statements. * /* ww w.j a va 2 s . co m*/ * Implementation: * * Trackers are stored as quads in a quad store, allowing the find operation to be use to find the matching trackers. * * Nodes in a tracker pattern may be the special "ANY_URI", indicating the node in the quad is a wildcard. * * The matching trackers are found as follows: * * <pre> * (INTERSECTION * (UNION trackers-with-matching-subject trackers-with-wildcard-subject) * (UNION trackers-with-matching-predicate trackers-with-wildcard-predicate) * (UNION trackers-with-matching-object trackers-with-wildcard-object) * (UNION trackers-with-matching-namedGraphUri trackers-with-wildcard-namedGraphUri)) * </pre> * * @param statement * The statement find matching tracker patterns for. * @return The tracker patterns matching the provided statement. */ protected Collection<Statement> findMatchingPatterns(Statement statement) { Collection<Statement> subjectExactMatches = quadStore.find(statement.getSubject(), null, null, (URI[]) null); Collection<Statement> subjectWildcardMatches = quadStore.find(Constants.ANY_URI, null, null, (URI[]) null); // UNION exact and wildcard matches of the statements subject Collection<Statement> subjectMatches = CollectionUtils.union(subjectExactMatches, subjectWildcardMatches); Collection<Statement> predicateExactMatches = quadStore.find(null, statement.getPredicate(), null, (URI[]) null); Collection<Statement> predicateWildcardMatches = quadStore.find(null, Constants.ANY_URI, null, (URI[]) null); // UNION exact and wildcard matches of the statements predicate Collection<Statement> predicateMatches = CollectionUtils.union(predicateExactMatches, predicateWildcardMatches); Collection<Statement> objectExactMatches = quadStore.find(null, null, statement.getObject(), (URI[]) null); Collection<Statement> objectWildcardMatches = quadStore.find(null, null, Constants.ANY_URI, (URI[]) null); // UNION exact and wildcard matches of the statements object Collection<Statement> objectMatches = CollectionUtils.union(objectExactMatches, objectWildcardMatches); Collection<Statement> namedGraphExactMatches = quadStore.find(null, null, null, statement.getNamedGraphUri()); Collection<Statement> namedGraphWildcardMatches = quadStore.find(null, null, null, Constants.ANY_URI); // UNION exact and wildcard matches of the statements namedGraphUri Collection<Statement> namedGraphMatches = CollectionUtils.union(namedGraphExactMatches, namedGraphWildcardMatches); // INTERSECTION of the unions Collection<Statement> intersection = CollectionUtils.intersection(CollectionUtils.intersection( CollectionUtils.intersection(subjectMatches, predicateMatches), objectMatches), namedGraphMatches); return intersection; }