@Nullable private static Transferable merge(@NotNull KillRingTransferable newData,@NotNull KillRingTransferable oldData) throws IOException, UnsupportedFlavorException {
  if (!oldData.isReadyToCombine() || !newData.isReadyToCombine()) {
    return null;
  }
  Document document=newData.getDocument();
  if (document == null || document != oldData.getDocument()) {
    return null;
  }
  Object newDataText=newData.getTransferData(DataFlavor.stringFlavor);
  Object oldDataText=oldData.getTransferData(DataFlavor.stringFlavor);
  if (newDataText == null || oldDataText == null) {
    return null;
  }
  if (oldData.isCut()) {
    if (newData.getStartOffset() == oldData.getStartOffset()) {
      return new KillRingTransferable(oldDataText.toString() + newDataText,document,oldData.getStartOffset(),newData.getEndOffset(),newData.isCut());
    }
  }
  if (newData.getStartOffset() == oldData.getEndOffset()) {
    return new KillRingTransferable(oldDataText.toString() + newDataText,document,oldData.getStartOffset(),newData.getEndOffset(),false);
  }
  if (newData.getEndOffset() == oldData.getStartOffset()) {
    return new KillRingTransferable(newDataText.toString() + oldDataText,document,newData.getStartOffset(),oldData.getEndOffset(),false);
  }
  return null;
}

@ Nullable private static Transferable merge ( @ NotNull KillRingTransferable newData , @ NotNull KillRingTransferable oldData ) throws IOException , UnsupportedFlavorException { if ( ! oldData . isReadyToCombine ( ) || ! newData . isReadyToCombine ( ) ) { return null ; } Document document = newData . getDocument ( ) ; if ( document == null || document != oldData . getDocument ( ) ) { return null ; } Object newDataText = newData . getTransferData ( DataFlavor . stringFlavor ) ; Object oldDataText = oldData . getTransferData ( DataFlavor . stringFlavor ) ; if ( newDataText == null || oldDataText == null ) { return null ; } if ( oldData . isCut ( ) ) { if ( newData . getStartOffset ( ) == oldData . getStartOffset ( ) ) { return new KillRingTransferable ( oldDataText . toString ( ) + newDataText , document , oldData . getStartOffset ( ) , newData . getEndOffset ( ) , newData . isCut ( ) ) ; } } if ( newData . getStartOffset ( ) == oldData . getEndOffset ( ) ) { return new KillRingTransferable ( oldDataText . toString ( ) + newDataText , document , oldData . getStartOffset ( ) , newData . getEndOffset ( ) , false ) ; } if ( newData . getEndOffset ( ) == oldData . getStartOffset ( ) ) { return new KillRingTransferable ( newDataText . toString ( ) + oldDataText , document , newData . getStartOffset ( ) , oldData . getEndOffset ( ) , false ) ; } return null ; }
merges given new data with the given old one and returns merge result in case of success .
