private void insertCOMMarkerSegment(COMMarkerSegment newGuy){
  int lastCOM=findMarkerSegmentPosition(COMMarkerSegment.class,false);
  boolean hasJFIF=(findMarkerSegment(JFIFMarkerSegment.class,true) != null);
  int firstAdobe=findMarkerSegmentPosition(AdobeMarkerSegment.class,true);
  if (lastCOM != -1) {
    markerSequence.add(lastCOM + 1,newGuy);
  }
 else   if (hasJFIF) {
    markerSequence.add(1,newGuy);
  }
 else   if (firstAdobe != -1) {
    markerSequence.add(firstAdobe + 1,newGuy);
  }
 else {
    markerSequence.add(0,newGuy);
  }
}

private void insertCOMMarkerSegment ( COMMarkerSegment newGuy ) { int lastCOM = findMarkerSegmentPosition ( COMMarkerSegment . class , false ) ; boolean hasJFIF = ( findMarkerSegment ( JFIFMarkerSegment . class , true ) != null ) ; int firstAdobe = findMarkerSegmentPosition ( AdobeMarkerSegment . class , true ) ; if ( lastCOM != - 1 ) { markerSequence . add ( lastCOM + 1 , newGuy ) ; } else if ( hasJFIF ) { markerSequence . add ( 1 , newGuy ) ; } else if ( firstAdobe != - 1 ) { markerSequence . add ( firstAdobe + 1 , newGuy ) ; } else { markerSequence . add ( 0 , newGuy ) ; } }
insert a new com marker segment into an appropriate place in the marker sequence , as follows : if there already exist com marker segments , the new one is inserted after the last one . if there are no com segments , the new com segment is inserted after the jfif segment , if there is one . if there is no jfif segment , the new com segment is inserted after the adobe marker segment , if there is one . if there is no adobe segment , the new com segment is inserted at the beginning of the sequence .
