public PackedQuadCell nextCell(boolean descend){
  final int level=getLevel();
  final int shift=getShiftForLevel(level);
  if ((!descend && isEnd(level,shift)) || isEnd(maxLevels,getShiftForLevel(maxLevels))) {
    return null;
  }
  long newTerm;
  final boolean isLeaf=(term & 0x1L) == 0x1L;
  if ((descend && !isLeaf && (level != maxLevels)) || level == 0) {
    newTerm=((term >>> 1) + 0x1L) << 1;
  }
 else {
    newTerm=term + (0x1L << shift);
    if (((term >>> shift) & 0x3L) == 0x3L) {
      newTerm=((newTerm >>> 1) - (Long.numberOfTrailingZeros(newTerm >>> shift) >>> 1)) << 1;
    }
  }
  return new PackedQuadCell(newTerm);
}

public PackedQuadCell nextCell ( boolean descend ) { final int level = getLevel ( ) ; final int shift = getShiftForLevel ( level ) ; if ( ( ! descend && isEnd ( level , shift ) ) || isEnd ( maxLevels , getShiftForLevel ( maxLevels ) ) ) { return null ; } long newTerm ; final boolean isLeaf = ( term & 0x1L ) == 0x1L ; if ( ( descend && ! isLeaf && ( level != maxLevels ) ) || level == 0 ) { newTerm = ( ( term > > > 1 ) + 0x1L ) << 1 ; } else { newTerm = term + ( 0x1L << shift ) ; if ( ( ( term > > > shift ) & 0x3L ) == 0x3L ) { newTerm = ( ( newTerm > > > 1 ) - ( Long . numberOfTrailingZeros ( newTerm > > > shift ) > > > 1 ) ) << 1 ; } } return new PackedQuadCell ( newTerm ) ; }
get the next cell in the tree without using recursion . descend parameter requests traversal to the child nodes , setting this to false will step to the next sibling . note : this complies with lexicographical ordering , once you ' ve moved to the next sibling there is no backtracking .
