io.scalaland.chimney.javacollections.JavaFactoryCompat.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of chimney-java-collections_3 Show documentation
Show all versions of chimney-java-collections_3 Show documentation
Integrations with selected Java collections
package io.scalaland.chimney.javacollections
import scala.collection.compat.*
import scala.collection.mutable
import scala.language.implicitConversions
private[javacollections] trait JavaFactoryCompat {
implicit def convertJavaFactoryToScalaFactory[A, CC](javaFactory: JavaFactory[A, CC]): Factory[A, CC] =
new FactoryImpl(javaFactory)
implicit def provideScalaFactoryFromJavaFactory[A, CC](implicit javaFactory: JavaFactory[A, CC]): Factory[A, CC] =
new FactoryImpl(javaFactory)
final private class FactoryImpl[A, CC](javaFactory: JavaFactory[A, CC]) extends scala.collection.Factory[A, CC] {
override def fromSpecific(it: IterableOnce[A]): CC = javaFactory.fromSpecific(it)
override def newBuilder: mutable.Builder[A, CC] = new mutable.Builder[A, CC] {
private var inner = javaFactory.newBuilder
override def clear(): Unit = inner = javaFactory.newBuilder
override def result(): CC = inner.result()
override def addOne(elem: A): this.type = { inner.addOne(elem); this }
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy