All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.scalaland.chimney.javacollections.JavaFactoryCompat.scala Maven / Gradle / Ivy

There is a newer version: 1.5.0
Show newest version
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