Monday, 15 September 2014

Instantiate scala.Int in Java -



Instantiate scala.Int in Java -

i'm writing persistence layer securesocial plugin of play 2 framework. found illustration @ https://github.com/play-modules/modules.playframework.org/blob/master/app/models/ss/mpooauth2info.java:

package models.ss; import models.abstractmodel; import securesocial.core.java.oauth2info; import javax.persistence.entity; @entity public class mpooauth2info extends abstractmodel { public string accesstoken; public string tokentype; public integer expiresin; public string refreshtoken; public mpooauth2info() { // no-op } public mpooauth2info(oauth2info oauth2info) { this.accesstoken = oauth2info.accesstoken; this.tokentype = oauth2info.tokentype; this.expiresin = oauth2info.expiresin; this.refreshtoken = oauth2info.refreshtoken; } public oauth2info tooauth2info() { oauth2info oauth2info = new oauth2info(); oauth2info.accesstoken = this.accesstoken; oauth2info.tokentype = this.tokentype; oauth2info.expiresin = this.expiresin; oauth2info.refreshtoken = this.refreshtoken; homecoming oauth2info; } }

but api changed can't utilize securesocial.core.java.oauth2info. securesocial written scala , class java front-end. decided utilize scala straight where:

case class oauth2info(accesstoken: string, tokentype: option[string] = none, expiresin: option[int] = none, refreshtoken: option[string] = none)

my result:

package models.security.securesocial; import models.abstractmodel; import scala.option; import securesocial.core.*; import javax.persistence.entity; /** * persistence wrapper securesocial's {@link } class. * * @author steve chaloner (steve@objectify.be) */ @entity public class mpooauth2info extends abstractmodel { public string accesstoken; public string tokentype; public integer expiresin; public string refreshtoken; public mpooauth2info(){ // no-op } public mpooauth2info(oauth2info oauth2info){ this.accesstoken = oauth2info.accesstoken(); this.tokentype = oauth2info.tokentype().get(); this.expiresin = scala.int.unbox(oauth2info.expiresin().get()); this.refreshtoken = oauth2info.refreshtoken().get(); } public oauth2info tooauth2info(){ homecoming new oauth2info(accesstoken, option.apply(tokentype), option.apply(some_transformation(expiresin)), option.apply(refreshtoken)); } }

but have problems convertation of scala.int to/from java.lang.integer types. convert scala.int java.lang.integer used scala.int.unbox(). connect way? , don't know how convert java.lang.integer scala.int: in code typed pseudo code some_transformation(). right implementation of some_transformation?

thank you

scala.int.unbox(new java.lang.integer(3)) gives int = 3

scala.int.box(3) gives integer = 3

java scala playframework-2.0 scala-java-interop securesocial

No comments:

Post a Comment