diff --git a/src/main/kotlin/com/amazon/ionelement/api/IonUtils.kt b/src/main/kotlin/com/amazon/ionelement/api/IonUtils.kt index 3b36d94..81a101a 100644 --- a/src/main/kotlin/com/amazon/ionelement/api/IonUtils.kt +++ b/src/main/kotlin/com/amazon/ionelement/api/IonUtils.kt @@ -42,6 +42,8 @@ public fun IonElement.toIonValue(factory: ValueFactory): IonValue { * Bridge function that converts from the mutable [IonValue] to an [AnyElement]. * * New code that does not need to integrate with uses of the mutable DOM should not use this. + * + * This will fail for IonDatagram if the IonDatagram does not contain exactly one user value. */ public fun IonValue.toIonElement(): AnyElement = this.system.newReader(this).use { reader -> diff --git a/src/main/kotlin/com/amazon/ionelement/impl/IonElementLoaderImpl.kt b/src/main/kotlin/com/amazon/ionelement/impl/IonElementLoaderImpl.kt index e45e1f0..e19ae34 100644 --- a/src/main/kotlin/com/amazon/ionelement/impl/IonElementLoaderImpl.kt +++ b/src/main/kotlin/com/amazon/ionelement/impl/IonElementLoaderImpl.kt @@ -101,7 +101,6 @@ internal class IonElementLoaderImpl(private val options: IonElementLoaderOptions return handleReaderException(ionReader) { loadCurrentElementRecursively(ionReader) } } - private fun loadCurrentElementRecursively(ionReader: IonReader): AnyElement { val valueType = requireNotNull(ionReader.type) { "The IonReader was not positioned at an element." } diff --git a/src/main/kotlin/com/amazon/ionelement/impl/collections/extensions.kt b/src/main/kotlin/com/amazon/ionelement/impl/collections/extensions.kt index 829bad5..dc73c60 100644 --- a/src/main/kotlin/com/amazon/ionelement/impl/collections/extensions.kt +++ b/src/main/kotlin/com/amazon/ionelement/impl/collections/extensions.kt @@ -75,15 +75,6 @@ internal fun List.toImmutableListUnsafe(): ImmutableList { return ImmutableListAdapter(this) } -/** - * Creates a [ImmutableList] for [this] without making a defensive copy. - * Only call this method if you are sure that [this] cannot leak anywhere it could be mutated. - */ -internal fun List.toImmutableListUnsafeAllowModification(): ImmutableList { - if (this is ImmutableList) return this - return ImmutableListAdapter(this) -} - /** * Creates a [ImmutableList] for [this] without making a defensive copy. * Only call this method if you are sure that [this] cannot leak anywhere it could be mutated. @@ -94,85 +85,3 @@ internal fun Array.toImmutableListUnsafe(): ImmutableList { // even further but using only a single wrapper layer, if we created such a thing. return ImmutableListAdapter(asList()) } - - -internal interface SometimesMutableList { - fun add(element: E): Boolean - fun seal(): ImmutableList -} - -internal class SometimesMutableListImpl private constructor( - private val impl: MutableList -) : SometimesMutableList, ImmutableList, List by impl { - constructor(): this(mutableListOf()) - - private var isClosed = false - - override fun add(element: E): Boolean { - if (isClosed) throw UnsupportedOperationException("Attempting to add $element") - impl.add(element) - return true - } - - override fun seal(): ImmutableList { - // check(!isClosed) { "Trying to seal an already sealed list" } - isClosed = true - return this - } - - override fun subList(fromIndex: Int, toIndex: Int): ImmutableList = ImmutableListAdapter(impl.subList(fromIndex, toIndex)) - - override fun equals(other: Any?): Boolean = impl.equals(other) - override fun hashCode(): Int = impl.hashCode() - override fun toString(): String = impl.toString() -} - -internal class SealableList : SometimesMutableList, ImmutableList, ArrayList() { - - private var isClosed = false - - override fun add(element: E): Boolean { - if (isClosed) throw UnsupportedOperationException() - super.add(element) - return true - } - - override fun seal(): ImmutableList { - isClosed = true - return this - } - - override fun subList(fromIndex: Int, toIndex: Int): Nothing { - TODO("Not supported due to conflicting interfaces") - } - - // override fun subList(fromIndex: Int, toIndex: Int): List = ImmutableListAdapter(subList(fromIndex, toIndex)) -} - -internal class SealableList2 : SometimesMutableList, ArrayList() { - - private var isClosed = false - - override fun add(element: E): Boolean { - if (isClosed) throw UnsupportedOperationException() - super.add(element) - return true - } - - override fun seal(): ImmutableList { - isClosed = true - return Immutable() - } - - fun immutable(): ImmutableList = Immutable() - - override fun subList(fromIndex: Int, toIndex: Int): Nothing { - TODO("Not supported due to conflicting interfaces") - } - - internal inner class Immutable: ImmutableList, List by this { - override fun subList(fromIndex: Int, toIndex: Int): ImmutableList = ImmutableListAdapter(subList(fromIndex, toIndex)) - } - - // override fun subList(fromIndex: Int, toIndex: Int): List = ImmutableListAdapter(subList(fromIndex, toIndex)) -} diff --git a/src/test/kotlin/com/amazon/ionelement/IonElementLoaderTests.kt b/src/test/kotlin/com/amazon/ionelement/IonElementLoaderTests.kt index e69b25c..ef2ffb9 100644 --- a/src/test/kotlin/com/amazon/ionelement/IonElementLoaderTests.kt +++ b/src/test/kotlin/com/amazon/ionelement/IonElementLoaderTests.kt @@ -50,24 +50,6 @@ class IonElementLoaderTests { assertEquals(tc.expectedElement, parsedIonElement) } - @Test - fun kotlinIddiomaticTest() { - - - val parsedIonValue = ION.loader.load("[null.struct, false]") - val parsedIonElement = loadAllElements("[null.struct, false]", INCLUDE_LOCATION_META) - - // Text generated from both should match - // assertEquals(convertToString(parsedIonValue), parsedIonElement.toString()) - - // Converting from IonElement to IonValue results in an IonValue that is equivalent to the parsed IonValue - assertEquals(parsedIonElement.map { it.toIonValue(ION) }, parsedIonValue.toList()) - - // Converting from IonValue to IonElement should result in an IonElement that is equivalent to the - // parsed IonElement - // assertEquals(parsedIonValue.toIonElement(), parsedIonElement) - } - companion object { @JvmStatic @Suppress("unused")