
com.google.protobuf.UnmodifiableCollections.kt Maven / Gradle / Ivy
package com.google.protobuf.kotlin
/** Wraps an [Iterator] and makes it unmodifiable even from Java. */
internal class UnmodifiableIterator(delegate: Iterator) : Iterator by delegate
/** Wraps a [ListIterator] and makes it unmodifiable even from Java. */
internal class UnmodifiableListIterator(
delegate: ListIterator
) : ListIterator by delegate
/** Wraps a [Collection] and makes it unmodifiable even from Java. */
internal open class UnmodifiableCollection(
private val delegate: Collection
) : Collection by delegate {
override fun iterator(): Iterator = UnmodifiableIterator(delegate.iterator())
}
/** Wraps a [Set] and makes it unmodifiable even from Java. */
internal class UnmodifiableSet(
delegate: Collection
) : UnmodifiableCollection(delegate), Set
/** Wraps a [Map.Entry] and makes it unmodifiable even from Java. */
internal class UnmodifiableMapEntry(delegate: Map.Entry) : Map.Entry by delegate
/** Wraps a [Set] of map entries and makes it unmodifiable even from Java. */
internal class UnmodifiableMapEntries(
private val delegate: Set>
) : UnmodifiableCollection>(delegate), Set> {
// Is this overkill? Probably.
override fun iterator(): Iterator> {
val itr = delegate.iterator()
return object : Iterator> by itr {
override fun next(): Map.Entry = UnmodifiableMapEntry(itr.next())
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy