@ -121,7 +121,6 @@ public class PlotCommitList<L extends PlotLane> extends
final int nChildren = currCommit . getChildCount ( ) ;
final int nChildren = currCommit . getChildCount ( ) ;
if ( nChildren = = 0 ) {
if ( nChildren = = 0 ) {
currCommit . lane = nextFreeLane ( ) ;
currCommit . lane = nextFreeLane ( ) ;
activeLanes . add ( currCommit . lane ) ;
closeLane ( currCommit . lane ) ;
closeLane ( currCommit . lane ) ;
return ;
return ;
}
}
@ -135,7 +134,6 @@ public class PlotCommitList<L extends PlotLane> extends
// Hmmph. This child must be the first along this lane.
// Hmmph. This child must be the first along this lane.
//
//
c . lane = nextFreeLane ( ) ;
c . lane = nextFreeLane ( ) ;
activeLanes . add ( c . lane ) ;
}
}
for ( int r = index - 1 ; r > = 0 ; r - - ) {
for ( int r = index - 1 ; r > = 0 ; r - - ) {
final PlotCommit rObj = get ( r ) ;
final PlotCommit rObj = get ( r ) ;
@ -175,7 +173,6 @@ public class PlotCommitList<L extends PlotLane> extends
// not already positioned.
// not already positioned.
if ( c . lane = = null ) {
if ( c . lane = = null ) {
c . lane = nextFreeLane ( ) ;
c . lane = nextFreeLane ( ) ;
activeLanes . add ( c . lane ) ;
if ( reservedLane ! = null )
if ( reservedLane ! = null )
closeLane ( c . lane ) ;
closeLane ( c . lane ) ;
else
else
@ -192,7 +189,6 @@ public class PlotCommitList<L extends PlotLane> extends
closeLane ( reservedLane ) ;
closeLane ( reservedLane ) ;
currCommit . lane = nextFreeLane ( ) ;
currCommit . lane = nextFreeLane ( ) ;
activeLanes . add ( currCommit . lane ) ;
handleBlockedLanes ( index , currCommit , nChildren ) ;
handleBlockedLanes ( index , currCommit , nChildren ) ;
}
}
@ -218,32 +214,33 @@ public class PlotCommitList<L extends PlotLane> extends
if ( - - remaining = = 0 )
if ( - - remaining = = 0 )
break ;
break ;
}
}
addBlockedPosition ( blockedPositions , rObj ) ;
if ( rObj ! = null ) {
if ( rObj ! = null ) {
PlotLane lane = rObj . getLane ( ) ;
if ( lane ! = null )
blockedPositions . set ( lane . getPosition ( ) ) ;
rObj . addPassingLane ( commit . lane ) ;
rObj . addPassingLane ( commit . lane ) ;
}
}
}
}
// Now let's check whether we have to reposition the lane
// Now let's check whether we have to reposition the lane
if ( blockedPositions . get ( commit . lane . getPosition ( ) ) ) {
if ( blockedPositions . get ( commit . lane . getPosition ( ) ) ) {
int newPos = - 1 ;
int newPos = getFreePosition ( blockedPositions ) ;
for ( Integer pos : freePositions )
if ( ! blockedPositions . get ( pos . intValue ( ) ) ) {
newPos = pos . intValue ( ) ;
break ;
}
if ( newPos = = - 1 )
newPos = positionsAllocated + + ;
freePositions . add ( Integer . valueOf ( commit . lane . getPosition ( ) ) ) ;
freePositions . add ( Integer . valueOf ( commit . lane . getPosition ( ) ) ) ;
commit . lane . position = newPos ;
commit . lane . position = newPos ;
activeLanes . add ( commit . lane ) ;
activeLanes . add ( commit . lane ) ;
}
}
}
}
private static void addBlockedPosition ( BitSet blockedPositions ,
final PlotCommit rObj ) {
if ( rObj ! = null ) {
PlotLane lane = rObj . getLane ( ) ;
// Positions may be blocked by a commit on a lane.
if ( lane ! = null )
blockedPositions . set ( lane . getPosition ( ) ) ;
}
}
private void closeLane ( PlotLane lane ) {
private void closeLane ( PlotLane lane ) {
recycleLane ( ( L ) lane ) ;
if ( activeLanes . remove ( lane ) ) {
if ( activeLanes . remove ( lane ) ) {
recycleLane ( ( L ) lane ) ;
freePositions . add ( Integer . valueOf ( lane . getPosition ( ) ) ) ;
freePositions . add ( Integer . valueOf ( lane . getPosition ( ) ) ) ;
}
}
}
}
@ -255,15 +252,37 @@ public class PlotCommitList<L extends PlotLane> extends
}
}
private PlotLane nextFreeLane ( ) {
private PlotLane nextFreeLane ( ) {
return nextFreeLane ( null ) ;
}
private PlotLane nextFreeLane ( BitSet blockedPositions ) {
final PlotLane p = createLane ( ) ;
final PlotLane p = createLane ( ) ;
if ( freePositions . isEmpty ( ) ) {
p . position = getFreePosition ( blockedPositions ) ;
p . position = positionsAllocated + + ;
activeLanes . add ( p ) ;
return p ;
}
/ * *
* @param blockedPositions
* may be null
* @return a free lane position
* /
private int getFreePosition ( BitSet blockedPositions ) {
if ( freePositions . isEmpty ( ) )
return positionsAllocated + + ;
if ( blockedPositions ! = null ) {
for ( Integer pos : freePositions )
if ( ! blockedPositions . get ( pos . intValue ( ) ) ) {
freePositions . remove ( pos ) ;
return pos . intValue ( ) ;
}
return positionsAllocated + + ;
} else {
} else {
final Integer min = freePositions . first ( ) ;
final Integer min = freePositions . first ( ) ;
p . position = min . intValue ( ) ;
freePositions . remove ( min ) ;
freePositions . remove ( min ) ;
return min . intValue ( ) ;
}
}
return p ;
}
}
/ * *
/ * *