private static int countDuplicates(StackTraceElement[] currentStack,StackTraceElement[] parentStack){
  int duplicates=0;
  int parentIndex=parentStack.length;
  for (int i=currentStack.length; --i >= 0 && --parentIndex >= 0; ) {
    StackTraceElement parentFrame=parentStack[parentIndex];
    if (parentFrame.equals(currentStack[i])) {
      duplicates++;
    }
 else {
      break;
    }
  }
  return duplicates;
}

private static int countDuplicates ( StackTraceElement [ ] currentStack , StackTraceElement [ ] parentStack ) { int duplicates = 0 ; int parentIndex = parentStack . length ; for ( int i = currentStack . length ; -- i >= 0 && -- parentIndex >= 0 ; ) { StackTraceElement parentFrame = parentStack [ parentIndex ] ; if ( parentFrame . equals ( currentStack [ i ] ) ) { duplicates ++ ; } else { break ; } } return duplicates ; }
count the number of duplicate stack frames , starting from the end of the stack .
