scala/java interoperability, as deep as you want
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
project
scalafmt-config @ 3ad7033
scalaj-collection
scalaj-google-optional
.gitignore
.gitmodules use https instead of git for scalafmt-config submodule Nov 23, 2018
.travis.yml update travis yml and add checkFormatting alias Nov 23, 2018
LICENSE
README.md
RELEASE_NOTES.md
build.sbt
version.sbt

README.md

ScalaJ Converters Build Status Coverage Status

When JavaConverters is not enough...

If you work on a Java/Scala mixed project you can find yourself converting java collections and/or primitive wrappers to/from corresponding scala classes or vice versa. JavaConverters is your friend here, but it's not always good enough.

If you are tired of doing something like this

import scala.collection.JavaConverters._

def iTakeInt(i: Int) = { ... }

val something = someJavaListOfJavaIntegers.asScala.map(iTakeInt(_))

or this

import scala.collection.JavaConverters._

val something: mutable.Map[java.lang.Long, Buffer] = 
  someJavaMapOfJavaLongsToJavaLists.asScala.mapValues(_.asScala)

look no more!
Now you can do

import com.daodecode.scalaj.collection._

def iTakeInt(i: Int) = { ... }

val something = someJavaListOfJavaIntegers.deepAsScala.map(iTakeInt)

and

import com.daodecode.scalaj.collection._

val something: mutable.Map[Long, Buffer] = 
  someJavaMapOfJavaLongsToJavaLists.deepAsScala

ScalaJ Converters will go all the way down converting every nested collection or primitive type.
Of course you should be ready to pay some cost for all these conversions.

Import import com.daodecode.scalaj.collection._ aslo brings standard JavaConverters._ in scope, so you can use plain asJava/asScala if you don't have nested collections or collections of primitives.

Having scalaj-googloptional in classpath you can add guava Optionals to your funky data structures and convert between them and scala versions all the way down and back.

val foo: java.util.Set[Optional[java.lang.Double] = ...

import com.daodecode.scalaj.googleoptional._

val scalaFoo: mutable.Set[Option[Double]] = foo.deepAsScala

If you want you scala collections well-done immutable, you can do it as well

val boo: java.util.Set[Optional[java.util.List[java.lang.Double]] = ...

import com.daodecode.scalaj.googleoptional._
import com.daodecode.scalaj.collection.immutable._

val immutableScalaBoo: Set[Option[immutable.Seq[Double]]] = boo.deepAsScalaImmutable

Latest stable release

scalaj-collection

2.10 2.11 2.12
Maven Central Maven Central Maven Central

sbt

libraryDependencies += "com.daodecode" %% "scalaj-collection" % "0.2.0"

maven

set <scala.binary.version> property to scala version you need, like

<properties>
    <scala.binary.version>2.12</scala.binary.version>
</properties>

and then in dependencies add

<dependency>
    <groupId>com.daodecode</groupId>
    <artifactId>scalaj-collection_${scala.binary.version}</artifactId>
    <version>0.2.0</version>
</dependency>

scalaj-googleoptional

2.10 2.11 2.12
Maven Central Maven Central Maven Central

sbt

libraryDependencies += "com.daodecode" %% "scalaj-googleoptional" % "0.2.0"

maven

<properties>
    <scala.binary.version>2.12</scala.binary.version>
</properties>

and then in dependencies add

<dependency>
    <groupId>com.daodecode</groupId>
    <artifactId>scalaj-googleoptional_${scala.binary.version}</artifactId>
    <version>0.2.0</version>
</dependency>

Latest snapshot

First add sonatype snapshots repository to your settings

sbt

resolvers += Resolver.sonatypeRepo("snapshots")

maven

<repository>
    <id>snapshots-repo</id>
    <url>https://oss.sonatype.org/content/repositories/snapshots</url>
    <releases><enabled>false</enabled></releases>
    <snapshots><enabled>true</enabled></snapshots>
</repository>

then add snapshot as a dependency

scalaj-collection

sbt

libraryDependencies += "com.daodecode" %% "scalaj-collection" % "0.2.1-SNAPSHOT"

maven

<properties>
    <scala.binary.version>2.12</scala.binary.version>
</properties>

and then in dependencies add

<dependency>
    <groupId>com.daodecode</groupId>
    <artifactId>scalaj-collection_${scala.binary.version}</artifactId>
    <version>0.2.1-SNAPSHOT</version>
</dependency>

scalaj-googleoptional

sbt

libraryDependencies += "com.daodecode" %% "scalaj-googleoptional" % "0.2.1-SNAPSHOT"

maven

<properties>
    <scala.binary.version>2.12</scala.binary.version>
</properties>

and then in dependencies add

<dependency>
    <groupId>com.daodecode</groupId>
    <artifactId>scalaj-googleoptional_${scala.binary.version}</artifactId>
    <version>0.2.1-SNAPSHOT</version>
</dependency>

Related projects

https://github.com/softprops/guavapants

https://github.com/scalaj/scalaj-collection