Transferable (@NotNull Transferable content) { try { String clipString = getStringContent(content); if (clipString == null) { return content; } if (content instanceof KillRingTransferable killRingContent) { if (killRingContent.isReadyToCombine() && !myData.isEmpty()) { Transferable prev = myData.get(0); if (prev instanceof KillRingTransferable) { Transferable merged = merge(killRingContent, (KillRingTransferable)prev); if (merged != null) { myData.set(0, merged); return merged; } } } if (killRingContent.isReadyToCombine()) { addToTheTopOfTheStack(killRingContent); return killRingContent; } } CaretStateTransferableData caretData = CaretStateTransferableData.getFrom(content); Iterator<Transferable> it = myData.iterator(); while (it.hasNext()) { Transferable old = it.next(); if (clipString.equals(getStringContent(old)) && CaretStateTransferableData.areEquivalent(caretData, CaretStateTransferableData.getFrom(old))) { it.remove(); myData.add(0, content); return content; } } addToTheTopOfTheStack(content); } catch (UnsupportedFlavorException | IOException ignore) { } return content; }