private Collection<Collection<Object>> findCycles( Collection<ConflictId> conflictIds ) { Collection<Collection<Object>> cycles = new HashSet<Collection<Object>>(); Map<Object, Integer> stack = new HashMap<Object, Integer>( 128 ); Map<ConflictId, Object> visited = new IdentityHashMap<ConflictId, Object>( conflictIds.size() ); for ( ConflictId id : conflictIds ) { findCycles( id, visited, stack, cycles ); } return cycles; }
public DependencyNode transformGraph(DependencyNode node, DependencyGraphTransformationContext context) throws RepositoryException { List<?> sortedConflictIds = (List<?>) context.get(TransformationContextKeys.SORTED_CONFLICT_IDS); if (sortedConflictIds == null) { ConflictIdSorter sorter = new ConflictIdSorter(); sorter.transformGraph(node, context); sortedConflictIds = (List<?>) context.get(TransformationContextKeys.SORTED_CONFLICT_IDS); } Map<?, ?> conflictIds = (Map<?, ?>) context.get(TransformationContextKeys.CONFLICT_IDS); if (conflictIds == null) { throw new RepositoryException("conflict groups have not been identified"); } Map<DependencyNode, Integer> depths = new TreeMap<DependencyNode, Integer>(DependencyNodeComparator.INSTANCE); for (Object key : sortedConflictIds) { ConflictGroup group = new ConflictGroup(key); depths.clear(); selectVersion(node, null, 0, depths, group, conflictIds); updateNonSelectedVersions(group, conflictIds); } return node; }
buildConflitIdDAG( ids, node, id, 0, visited, conflictIds ); int cycles = topsortConflictIds( ids.values(), context );
processRoots( sorted, roots ); roots.add( nearest ); processRoots( sorted, roots ); if ( cycle ) cycles = findCycles( conflictIds );
private void buildConflitIdDAG( Map<Object, ConflictId> ids, DependencyNode node, ConflictId id, int depth, Map<DependencyNode, Object> visited, Map<?, ?> conflictIds ) { if ( visited.put( node, Boolean.TRUE ) != null ) { return; } depth++; for ( DependencyNode child : node.getChildren() ) { Object key = conflictIds.get( child ); ConflictId childId = ids.get( key ); if ( childId == null ) { childId = new ConflictId( key, depth ); ids.put( key, childId ); } else { childId.pullup( depth ); } if ( id != null ) { id.add( childId ); } buildConflitIdDAG( ids, child, childId, depth, visited, conflictIds ); } }
if ( sortedConflictIds == null ) ConflictIdSorter sorter = new ConflictIdSorter(); sorter.transformGraph( node, context );
buildConflitIdDAG( ids, node, id, 0, visited, conflictIds ); int cycles = topsortConflictIds( ids.values(), context );
processRoots( sorted, roots ); roots.add( nearest ); processRoots( sorted, roots ); if ( cycle ) cycles = findCycles( conflictIds );
private void buildConflitIdDAG( Map<Object, ConflictId> ids, DependencyNode node, ConflictId id, int depth, Map<DependencyNode, Object> visited, Map<?, ?> conflictIds ) { if ( visited.put( node, Boolean.TRUE ) != null ) { return; } depth++; for ( DependencyNode child : node.getChildren() ) { Object key = conflictIds.get( child ); ConflictId childId = ids.get( key ); if ( childId == null ) { childId = new ConflictId( key, depth ); ids.put( key, childId ); } else { childId.pullup( depth ); } if ( id != null ) { id.add( childId ); } buildConflitIdDAG( ids, child, childId, depth, visited, conflictIds ); } }
if ( sortedConflictIds == null ) ConflictIdSorter sorter = new ConflictIdSorter(); sorter.transformGraph( node, context );
private Collection<Collection<Object>> findCycles( Collection<ConflictId> conflictIds ) { Collection<Collection<Object>> cycles = new HashSet<Collection<Object>>(); Map<Object, Integer> stack = new HashMap<Object, Integer>( 128 ); Map<ConflictId, Object> visited = new IdentityHashMap<ConflictId, Object>( conflictIds.size() ); for ( ConflictId id : conflictIds ) { findCycles( id, visited, stack, cycles ); } return cycles; }
private void findCycles( ConflictId id, Map<ConflictId, Object> visited, Map<Object, Integer> stack, Collection<Collection<Object>> cycles ) { Integer depth = stack.put( id.key, stack.size() ); if ( depth != null ) { stack.put( id.key, depth ); Collection<Object> cycle = new HashSet<Object>(); for ( Map.Entry<Object, Integer> entry : stack.entrySet() ) { if ( entry.getValue() >= depth ) { cycle.add( entry.getKey() ); } } cycles.add( cycle ); } else { if ( visited.put( id, Boolean.TRUE ) == null ) { for ( ConflictId childId : id.children ) { findCycles( childId, visited, stack, cycles ); } } stack.remove( id.key ); } }
private void findCycles( ConflictId id, Map<ConflictId, Object> visited, Map<Object, Integer> stack, Collection<Collection<Object>> cycles ) { Integer depth = stack.put( id.key, stack.size() ); if ( depth != null ) { stack.put( id.key, depth ); Collection<Object> cycle = new HashSet<Object>(); for ( Map.Entry<Object, Integer> entry : stack.entrySet() ) { if ( entry.getValue() >= depth ) { cycle.add( entry.getKey() ); } } cycles.add( cycle ); } else { if ( visited.put( id, Boolean.TRUE ) == null ) { for ( ConflictId childId : id.children ) { findCycles( childId, visited, stack, cycles ); } } stack.remove( id.key ); } }