comparison src/name/blackcap/clipman/Pasteboard.kt @ 18:96cc73ae2904

Make it more fail-safe.
author David Barts <n5jrn@me.com>
date Tue, 21 Jan 2020 16:39:02 -0800
parents 9dd58db4d15a
children 8aa2dfac27eb
comparison
equal deleted inserted replaced
17:9dd58db4d15a 18:96cc73ae2904
82 put(HTML_FLAVOR, item.html.toByteArray(CHARSET) as Any) 82 put(HTML_FLAVOR, item.html.toByteArray(CHARSET) as Any)
83 } 83 }
84 is RTF -> { 84 is RTF -> {
85 put(DataFlavor.stringFlavor, item.plain as Any) 85 put(DataFlavor.stringFlavor, item.plain as Any)
86 if (item.html != null) { 86 if (item.html != null) {
87 put(HTML_FLAVOR, item.html?.toByteArray(CHARSET) as Any) 87 put(HTML_FLAVOR, item.html!!.toByteArray(CHARSET) as Any)
88 } 88 }
89 } 89 }
90 } 90 }
91 } 91 }
92 _data.keys.asIterable().run { 92 _data.keys.asIterable().run {
101 override fun getTransferDataFlavors(): Array<DataFlavor> = flavors 101 override fun getTransferDataFlavors(): Array<DataFlavor> = flavors
102 override fun isDataFlavorSupported(flavor: DataFlavor) = _data.containsKey(flavor) 102 override fun isDataFlavorSupported(flavor: DataFlavor) = _data.containsKey(flavor)
103 override fun lostOwnership(clipboard: Clipboard, contents: Transferable) {} 103 override fun lostOwnership(clipboard: Clipboard, contents: Transferable) {}
104 } 104 }
105 105
106 /**
107 * Compare this PasteboardItem with another object.
108 * @param other object
109 * @return true iff this item's type and native content match the other's
110 */
106 override operator fun equals(other: Any?): Boolean { 111 override operator fun equals(other: Any?): Boolean {
107 return when (this) { 112 return when (this) {
108 is Plain -> (other is Plain) && (this.plain == other.plain) 113 is Plain -> (other is Plain) && (this.plain == other.plain)
109 is HTML -> (other is HTML) && (this.html == other.html) 114 is HTML -> (other is HTML) && (this.html == other.html)
110 is RTF -> (other is RTF) && (this.rtf contentEquals other.rtf) 115 is RTF -> (other is RTF) && (this.rtf contentEquals other.rtf)