dotty.tools.dotc.util.ReadOnlyMap.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scala3-compiler_3 Show documentation
Show all versions of scala3-compiler_3 Show documentation
scala3-compiler-bootstrapped
package dotty.tools
package dotc.util
/** A class for the reading part of mutable or immutable maps.
*/
abstract class ReadOnlyMap[Key, Value]:
def lookup(x: Key): Value | Null
def size: Int
def iterator: Iterator[(Key, Value)]
def keysIterator: Iterator[Key]
def valuesIterator: Iterator[Value]
def isEmpty: Boolean = size == 0
def get(key: Key): Option[Value] = lookup(key) match
case null => None
case v => Some(v.uncheckedNN)
def getOrElse(key: Key, value: => Value) = lookup(key) match
case null => value
case v => v.uncheckedNN
def contains(key: Key): Boolean = lookup(key) != null
def apply(key: Key): Value = lookup(key) match
case null => throw new NoSuchElementException(s"$key")
case v => v.uncheckedNN
def toArray: Array[(Key, Value)] =
val result = new Array[(Key, Value)](size)
var idx = 0
for pair <- iterator do
result(idx) = pair
idx += 1
result
def toSeq: Seq[(Key, Value)] = toArray.toSeq
© 2015 - 2025 Weber Informatics LLC | Privacy Policy