/** * Return a string representation of this CatalogType handle * * @param catalog_item * @return */ public static String debug(CatalogType catalog_item) { Map<String, Object> m = new ListOrderedMap<String, Object>(); for (String field : CollectionUtils.union(catalog_item.getFields(), catalog_item.getChildFields())) { String val_str = null; if (catalog_item.getChildFields().contains(field)) { val_str = CatalogUtil.debug(catalog_item.getChildren(field)); } else { Object val = catalog_item.getField(field); if (val != null) { val_str = val.toString(); } else { val_str = "null"; } } m.put(field, val_str); } // FOR return (catalog_item.fullName() + "\n" + StringUtil.formatMaps(m)); }
/** * Load the tuples for the given table name * @param tableName */ protected void generateTableData(String tableName) { LOG.info("*** START " + tableName); final AbstractTableGenerator generator = this.generators.get(tableName); assert (generator != null); // Generate Data final VoltTable volt_table = generator.getVoltTable(); while (generator.hasMore()) { generator.generateBatch(); this.loadVoltTable(generator.getTableName(), volt_table); volt_table.clearRowData(); } // WHILE // Mark as finished generator.markAsFinished(); this.finished.add(tableName); LOG.info(String.format("*** FINISH %s - %d tuples - [%d / %d]", tableName, this.getTableTupleCount(tableName), this.finished.size(), this.generators.size())); if (debug.val) { LOG.debug("Remaining Tables: " + CollectionUtils.subtract(this.generators.keySet(), this.finished)); } }
/** * Add an additional Map to the composite. * * @param map the Map to be added to the composite * @throws IllegalArgumentException if there is a key collision and there is no * MapMutator set to handle it. */ public synchronized void addComposited(Map<? extends K, ? extends V> map) throws IllegalArgumentException { for (int i = composite.length - 1; i >= 0; --i) { Collection<K> intersect = (Collection<K>) CollectionUtils.intersection(this.composite[i].keySet(), map.keySet()); if (intersect.size() != 0) { if (this.mutator == null) { throw new IllegalArgumentException("Key collision adding Map to CompositeMap"); } else { this.mutator.resolveCollision(this, this.composite[i], map, intersect); } } } Map[] temp = new Map[this.composite.length + 1]; System.arraycopy(this.composite, 0, temp, 0, this.composite.length); temp[temp.length - 1] = map; this.composite = temp; }
/** * Add a Set to this composite * * @param c Must implement Set * @throws IllegalArgumentException if c does not implement java.util.Set * or if a SetMutator is set, but fails to resolve a collision * @throws UnsupportedOperationException if there is no SetMutator set, or * a CollectionMutator is set instead of a SetMutator * @see org.apache.commons.collections15.collection.CompositeCollection.CollectionMutator * @see SetMutator */ public synchronized void addComposited(Collection<? extends E> c) { if (!(c instanceof Set)) { throw new IllegalArgumentException("Collections added must implement java.util.Set"); } for (Iterator i = this.getCollections().iterator(); i.hasNext();) { Set set = (Set) i.next(); Collection intersects = CollectionUtils.intersection(set, c); if (intersects.size() > 0) { if (this.mutator == null) { throw new UnsupportedOperationException("Collision adding composited collection with no SetMutator set"); } else if (!(this.mutator instanceof SetMutator)) { throw new UnsupportedOperationException("Collision adding composited collection to a CompositeSet with a CollectionMutator instead of a SetMutator"); } ((SetMutator) this.mutator).resolveCollision(this, set, (Set) c, intersects); if (CollectionUtils.intersection(set, c).size() > 0) { throw new IllegalArgumentException("Attempt to add illegal entry unresolved by SetMutator.resolveCollision()"); } } } super.addComposited((Collection<E>[]) new Collection[]{c}); }
public void find() { specs = new LinkedHashSet<SubstitutionSubtreeSpecification>(); Set<ExtendedNode> textTreeNodes = AbstractNodeUtils.treeToLinkedHashSet(textTree.getTree()); CollectionUtils.filter(textTreeNodes, textNodePredicate); if (textTreeNodes.isEmpty()) return; Set<ExtendedNode> hypothesisTreeNodes = AbstractNodeUtils.treeToLinkedHashSet(hypothesisTree.getTree()); CollectionUtils.filter(hypothesisTreeNodes, hypothesisNodePredicate); if (hypothesisTreeNodes.isEmpty()) return; for (ExtendedNode textNode: textTreeNodes) { for (ExtendedNode hypothesisNode: hypothesisTreeNodes) { specs.add(new SubstitutionSubtreeSpecification( description, textNode, hypothesisNode)); } } }
public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } ImmutableSortedSetHierarchyNode<T> that = (ImmutableSortedSetHierarchyNode<T>) o; if (!CollectionUtils.isEqualCollection(children, that.children)) { return false; } if (contents != null ? !contents.equals(that.contents) : that.contents != null) { return false; } if (parent != null ? !parent.equals(that.parent) : that.parent != null) { return false; } return true; }
/** * 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.) * * @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; }
public VertexPartition<V,E> transform(Graph<V,E> g) { Set<Pair<V>> vertex_pairs = getEquivalentPairs(g); Set<Set<V>> rv = new HashSet<Set<V>>(); Map<V, Set<V>> intermediate = new HashMap<V, Set<V>>(); for (Pair<V> p : vertex_pairs) { Set<V> res = intermediate.get(p.getFirst()); if (res == null) res = intermediate.get(p.getSecond()); if (res == null) // we haven't seen this one before res = new HashSet<V>(); res.add(p.getFirst()); res.add(p.getSecond()); intermediate.put(p.getFirst(), res); intermediate.put(p.getSecond(), res); } rv.addAll(intermediate.values()); // pick up the vertices which don't appear in intermediate; they are // singletons (equivalence classes of size 1) Collection<V> singletons = CollectionUtils.subtract(g.getVertices(), intermediate.keySet()); for (V v : singletons) { Set<V> v_set = Collections.singleton(v); intermediate.put(v, v_set); rv.add(v_set); } return new VertexPartition<V, E>(g, intermediate, rv); }
/** * @see edu.uci.ics.jung.graph.Tree#getChildEdges(java.lang.Object) */ public Collection<E> getChildEdges(V vertex) { if (!containsVertex(vertex)) return null; List<E> edges = vertex_data.get(vertex).child_edges; return edges == null ? Collections.<E>emptySet() : CollectionUtils.unmodifiableCollection(edges); }
/** * Returns an ordered list of {@code vertex}'s child vertices. * If there is no child in position i, then the list will contain * {@code null} in position i. If {@code vertex} has no children * then the empty set will be returned. * @see edu.uci.ics.jung.graph.Tree#getChildren(java.lang.Object) */ public Collection<V> getChildren(V vertex) { if (!containsVertex(vertex)) return null; List<E> edges = vertex_data.get(vertex).child_edges; if (edges == null) return Collections.emptySet(); Collection<V> children = new ArrayList<V>(order); for (E edge : edges) children.add(this.getOpposite(vertex, edge)); return CollectionUtils.unmodifiableCollection(children); }
private void removeRedundantEdges(Graph graph, final Set<Long> substitutionsMade) { CollectionUtils.filter(graph.getGraphEdges(), new Predicate<GraphEdge>() { public boolean evaluate(GraphEdge graphEdge) { return !(substitutionsMade.contains(graphEdge.getSource()) && substitutionsMade.contains(graphEdge.getTarget())); } }); }
private Map<Macro, Collection<Set<Long>>> removeRedundantNodes(Graph graph, final Set<Long> substitutionsMade) { // this is a variable which indicates that a macro can be inserted. It cannot be inserted when one of it's node ids has // already been removed. Map<Macro, Collection<Set<Long>>> canBeSubstituted = new HashMap<Macro, Collection<Set<Long>>>(); for (final Macro macro : macrosToBeSubstitutedIn) { final Set<Set<Long>> nodeIDsToSubstitute = macro.getNodeIdsInMacro(); for (Set<Long> macroIds : nodeIDsToSubstitute) { if (!CollectionUtils.containsAny(macroIds, substitutionsMade)) { if (CollectionUtils.isSubCollection(macroIds, graph.getNodeIdsToNode().keySet())) { if (!canBeSubstituted.containsKey(macro)) { canBeSubstituted.put(macro, new ArrayList<Set<Long>>()); } canBeSubstituted.get(macro).add(macroIds); substitutionsMade.addAll(macroIds); graph.removeNodesFromGraph(macroIds); } } } System.out.println("Graph node size is now " + graph.getGraphNodes().size()); } return canBeSubstituted; }
@Override public boolean equals(Object obj){ ExplanationGraph eg ; if (obj instanceof ExplanationGraph){ eg = (ExplanationGraph) obj; } else { return false; } if (!CollectionUtils.isEqualCollection(eg.getVertices(), this.getVertices())) return false; if (!CollectionUtils.isEqualCollection(eg.getEdges(), this.getEdges())) return false; return true; }
/** * Removes the unused fields. * * @param classNode * the class node */ public static void removeUnusedFields(final ClassNode classNode) { final Set<FieldNode> usedFields = new HashSet<>(); collectUsedFields(classNode, usedFields); final Collection<FieldNode> unusedFields = CollectionUtils.subtract(classNode.fields, usedFields); classNode.fields.removeAll(unusedFields); correctConstructors(classNode); }
/** * Returns true if there is a conflict between the two transactions for the * given list of tableIds based on their tracking sets. * @param partition * @param tableIds * @param ts0 * @param tsTracking0 * @param ts1 * @param tsTracking1 * @return */ protected boolean hasTupleConflict(int partition, int tableIds[], AbstractTransaction ts0, VoltTable tsTracking0, AbstractTransaction ts1, VoltTable tsTracking1) { // Check whether the first transaction accessed the same tuple by the second txn Set<Integer> tupleIds0 = new HashSet<Integer>(); Set<Integer> tupleIds1 = new HashSet<Integer>(); if (trace.val) LOG.trace("\n"+ StringUtil.columns(ts0+"\n"+VoltTableUtil.format(tsTracking0), ts1+"\n"+VoltTableUtil.format(tsTracking1))); for (int tableId : tableIds) { Table targetTbl = catalogContext.getTableById(tableId); // Skip if we know that the other transaction hasn't done anything // to the table at this partition. if (ts0.isTableReadOrWritten(partition, targetTbl) == false) { continue; } tupleIds0.clear(); this.getTupleIds(targetTbl.getName(), tsTracking0, tupleIds0); tupleIds1.clear(); this.getTupleIds(targetTbl.getName(), tsTracking1, tupleIds1); if (debug.val) { Map<String, Object> m = new LinkedHashMap<String, Object>(); m.put(targetTbl.getName() + " TRACKING SETS", null); m.put(ts0.toString(), tupleIds0); m.put(ts1.toString(), tupleIds1); LOG.debug(StringUtil.formatMaps(m)); } if (CollectionUtils.containsAny(tupleIds0, tupleIds1)) { if (debug.val) LOG.debug(String.format("Found conflict in %s between %s and %s", targetTbl, ts0, ts1)); return (true); } } // FOR return (false); }
@Override public PartitionSet getWritePartitions(EstimationThresholds t) { return new PartitionSet(CollectionUtils.subtract(this.partitions, this.readonly)); }
/** * Calculate whether two Procedures have WRITE-WRITE conflicts * @param proc0 * @param proc1 * @return * @throws Exception */ protected Collection<Conflict> checkWriteWriteConflict(Procedure proc0, Procedure proc1) throws Exception { ProcedureInfo pInfo0 = this.procedures.get(proc0); assert(pInfo0 != null); ProcedureInfo pInfo1 = this.procedures.get(proc1); assert(pInfo1 != null); Set<Conflict> conflicts = new HashSet<Conflict>(); // Write-Write Conflicts // Any INSERT or DELETE is always a conflict // For UPDATE, we will check whether their columns intersect for (Statement stmt0 : pInfo0.writeQueries) { if (this.ignoredStatements.contains(stmt0)) continue; Collection<Table> tables0 = CatalogUtil.getReferencedTables(stmt0); QueryType type0 = QueryType.get(stmt0.getQuerytype()); Collection<Column> cols0 = CatalogUtil.getReferencedColumns(stmt0); boolean alwaysConflicting0 = this.alwaysWriteConflicting(stmt0, type0, tables0, cols0); for (Statement stmt1 : pInfo1.writeQueries) { if (this.ignoredStatements.contains(stmt1)) continue; Collection<Table> tables1 = CatalogUtil.getReferencedTables(stmt1); QueryType type1 = QueryType.get(stmt1.getQuerytype()); Collection<Column> cols1 = CatalogUtil.getReferencedColumns(stmt1); boolean alwaysConflicting1 = this.alwaysWriteConflicting(stmt1, type1, tables1, cols1); Collection<Table> intersectTables = CollectionUtils.intersection(tables0, tables1); if (debug.val) LOG.debug(String.format("WW %s <-> %s - Intersection Tables %s", stmt0.fullName(), stmt1.fullName(), intersectTables)); if (intersectTables.isEmpty()) continue; // If both queries are INSERTs, then this is always a conflict since // there might be a global constraint... if (type0 == QueryType.INSERT && type1 == QueryType.INSERT) { // 2013-07-24 // This fails for John's INSERT INTO...SELECT queries. // We need to decide whether we should have a new query type or not... // assert(intersectTables.size() == 1) : // String.format("There are %d intersection tables when we expected only 1: %s <-> %s", // intersectTables.size(), stmt0.fullName(), stmt1.fullName()); alwaysConflicting1 = true; } Collection<Column> intersectColumns = CollectionUtils.intersection(cols0, cols1); if (debug.val) LOG.debug(String.format("WW %s <-> %s - Intersection Columns %s", stmt0.fullName(), stmt1.fullName(), intersectColumns)); if (alwaysConflicting0 == false && alwaysConflicting1 == false && intersectColumns.isEmpty()) continue; Conflict c = new Conflict(stmt0, stmt1, intersectTables, (alwaysConflicting0 || alwaysConflicting1)); conflicts.add(c); } // FOR (proc1) } // FOR (proc0) return (conflicts); }
/** * Grab the constructor for the given target class with the provided input parameters. * This method will first try to find an exact match for the parameters, and if that * fails then it will be smart and try to find one with the input parameters super classes. * @param <T> * @param target_class * @param params * @return */ @SuppressWarnings("unchecked") public static <T> Constructor<T> getConstructor(Class<T> target_class, Class<?>... params) { NoSuchMethodException error = null; try { return (target_class.getConstructor(params)); } catch (NoSuchMethodException ex) { // The first time we get this it can be ignored // We'll try to be nice and find a match for them error = ex; } assert (error != null); if (debug.val) { LOG.debug("TARGET CLASS: " + target_class); LOG.debug("TARGET PARAMS: " + Arrays.toString(params)); } final int num_params = (params != null ? params.length : 0); List<Class<?>> paramSuper[] = (List<Class<?>>[]) new List[num_params]; for (int i = 0; i < num_params; i++) { paramSuper[i] = ClassUtil.getSuperClasses(params[i]); if (debug.val) LOG.debug(" SUPER[" + params[i].getSimpleName() + "] => " + paramSuper[i]); } // FOR for (Constructor<?> c : target_class.getConstructors()) { Class<?> cTypes[] = c.getParameterTypes(); if (debug.val) { LOG.debug("CANDIDATE: " + c); LOG.debug("CANDIDATE PARAMS: " + Arrays.toString(cTypes)); } if (params.length != cTypes.length) continue; for (int i = 0; i < num_params; i++) { List<Class<?>> cSuper = ClassUtil.getSuperClasses(cTypes[i]); if (debug.val) LOG.debug(" SUPER[" + cTypes[i].getSimpleName() + "] => " + cSuper); if (CollectionUtils.intersection(paramSuper[i], cSuper).isEmpty() == false) { return ((Constructor<T>) c); } } // FOR (param) } // FOR (constructors) throw new RuntimeException("Failed to retrieve constructor for " + target_class.getSimpleName(), error); }
/** * * @param <T> * @param target_class * @param params * @return */ @SuppressWarnings("unchecked") public static <T> Constructor<T> getConstructor(Class<T> target_class, Class<?>...params) { NoSuchMethodException error = null; try { return (target_class.getConstructor(params)); } catch (NoSuchMethodException ex) { // The first time we get this it can be ignored // We'll try to be nice and find a match for them error = ex; } assert(error != null); if (LOG.isDebugEnabled()) { LOG.debug("TARGET CLASS: " + target_class); LOG.debug("TARGET PARAMS: " + Arrays.toString(params)); } List<Class<?>> paramSuper[] = (List<Class<?>>[])new List[params.length]; for (int i = 0; i < params.length; i++) { paramSuper[i] = ClassUtil.getSuperClasses(params[i]); if (LOG.isDebugEnabled()) LOG.debug(" SUPER[" + params[i].getSimpleName() + "] => " + paramSuper[i]); } // FOR for (Constructor<?> c : target_class.getConstructors()) { Class<?> cTypes[] = c.getParameterTypes(); if (LOG.isDebugEnabled()) { LOG.debug("CANDIDATE: " + c); LOG.debug("CANDIDATE PARAMS: " + Arrays.toString(cTypes)); } if (params.length != cTypes.length) continue; for (int i = 0; i < params.length; i++) { List<Class<?>> cSuper = ClassUtil.getSuperClasses(cTypes[i]); if (LOG.isDebugEnabled()) LOG.debug(" SUPER[" + cTypes[i].getSimpleName() + "] => " + cSuper); if (CollectionUtils.intersection(paramSuper[i], cSuper).isEmpty() == false) { return ((Constructor<T>)c); } } // FOR (param) } // FOR (constructors) throw new RuntimeException("Failed to retrieve constructor for " + target_class.getSimpleName(), error); }
/** * @see edu.uci.ics.jung.graph.Hypergraph#getEdges() */ public Collection<E> getEdges() { return CollectionUtils.unmodifiableCollection(edge_vpairs.keySet()); }
/** * @see edu.uci.ics.jung.graph.Hypergraph#getVertices() */ public Collection<V> getVertices() { return CollectionUtils.unmodifiableCollection(vertex_data.keySet()); }