本文整理汇总了Java中org.apache.commons.collections15.CollectionUtils类的典型用法代码示例。如果您正苦于以下问题:Java CollectionUtils类的具体用法?Java CollectionUtils怎么用?Java CollectionUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CollectionUtils类属于org.apache.commons.collections15包,在下文中一共展示了CollectionUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: debug
import org.apache.commons.collections15.CollectionUtils; //导入依赖的package包/类
/**
* 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));
}
示例2: generateTableData
import org.apache.commons.collections15.CollectionUtils; //导入依赖的package包/类
/**
* 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));
}
}
示例3: addComposited
import org.apache.commons.collections15.CollectionUtils; //导入依赖的package包/类
/**
* 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;
}
示例4: addComposited
import org.apache.commons.collections15.CollectionUtils; //导入依赖的package包/类
/**
* 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});
}
示例5: find
import org.apache.commons.collections15.CollectionUtils; //导入依赖的package包/类
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));
}
}
}
示例6: equals
import org.apache.commons.collections15.CollectionUtils; //导入依赖的package包/类
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;
}
示例7: getCounts
import org.apache.commons.collections15.CollectionUtils; //导入依赖的package包/类
/**
* 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;
}
示例8: transform
import org.apache.commons.collections15.CollectionUtils; //导入依赖的package包/类
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);
}
示例9: getChildEdges
import org.apache.commons.collections15.CollectionUtils; //导入依赖的package包/类
/**
* @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);
}
示例10: getChildren
import org.apache.commons.collections15.CollectionUtils; //导入依赖的package包/类
/**
* 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);
}
示例11: removeRedundantEdges
import org.apache.commons.collections15.CollectionUtils; //导入依赖的package包/类
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()));
}
});
}
示例12: removeRedundantNodes
import org.apache.commons.collections15.CollectionUtils; //导入依赖的package包/类
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;
}
示例13: equals
import org.apache.commons.collections15.CollectionUtils; //导入依赖的package包/类
@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;
}
示例14: removeUnusedFields
import org.apache.commons.collections15.CollectionUtils; //导入依赖的package包/类
/**
* 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);
}
示例15: hasTupleConflict
import org.apache.commons.collections15.CollectionUtils; //导入依赖的package包/类
/**
* 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);
}