}
protected Cigar refactorNDNtoN(final Cigar originalCigar) {
final Cigar refactoredCigar = new Cigar();
final int cigarLength = originalCigar.numCigarElements();
for(int i = 0; i < cigarLength; i++){
final CigarElement element = originalCigar.getCigarElement(i);
if(element.getOperator() == CigarOperator.N && thereAreAtLeast2MoreElements(i,cigarLength)){
final CigarElement nextElement = originalCigar.getCigarElement(i+1);
final CigarElement nextNextElement = originalCigar.getCigarElement(i+2);
// if it is N-D-N replace with N (with the total length) otherwise just add the first N.
if(nextElement.getOperator() == CigarOperator.D && nextNextElement.getOperator() == CigarOperator.N){
final int threeElementsLength = element.getLength() + nextElement.getLength() + nextNextElement.getLength();
final CigarElement refactoredElement = new CigarElement(threeElementsLength,CigarOperator.N);
refactoredCigar.add(refactoredElement);
i += 2; //skip the elements that were refactored
}
else
refactoredCigar.add(element); // add only the first N
}
else
refactoredCigar.add(element); // add any non-N element
}
return refactoredCigar;
}