trait Converters extends OptionConverters with TryConverters with EitherConverters with FutureConverters
Aggregates the various traits for converting from javascalautils -> Scala.
Example on usage:
import javascalautils.converters.j2s.Converters._ import javascalautils.{Some => JSome} val optionSome = asScalaOption(new JSome("Some is never None"))
Refer to the various methods on this object for further code examples.
- Alphabetic
- By Inheritance
- Converters
- FutureConverters
- EitherConverters
- TryConverters
- OptionConverters
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
asScalaEither[L, R](underlying: Either[L, R]): scala.util.Either[L, R]
Converts a javascalautils.Either to a scala.util.Either.
Converts a javascalautils.Either to a scala.util.Either.
import javascalautils.{ Either => JEither, Left => JLeft, Right => JRight } val eitherRight = asScalaEither(new JRight[String,String]("Left is not Right")) val eitherLeft = asScalaEither(new JLeft[String,String]("Left is not Right"))
- underlying
The type to be converted
- returns
The converted type
- Definition Classes
- EitherConverters
- Since
1.0
-
def
asScalaFailure[T](underlying: Failure[T]): scala.util.Failure[Nothing]
Converts a javascalautils.Failure to a scala.util.Failure.
Converts a javascalautils.Failure to a scala.util.Failure.
import javascalautils.{Try => JTry, Success => JSuccess, Failure => JFailure} val failure = asScalaFailure(new JFailure(new Exception("Error, terror")))
- underlying
The type to be converted
- returns
The converted type
- Definition Classes
- TryConverters
- Since
1.0
-
def
asScalaFuture[T](underlying: Future[T]): Future[T]
Converts a javascalautils.concurrent.Future to a scala.concurrent.Future.
Converts a javascalautils.concurrent.Future to a scala.concurrent.Future.
import javascalautils.concurrent.{ Future => JFuture } //just illustrating a Java Future by creating an already fulfilled one val future = asScalaFuture(JFuture.successful("The Future is here"))
- underlying
The type to be converted
- returns
The converted type
- Definition Classes
- FutureConverters
- Since
1.0
-
def
asScalaLeft[L, R](underlying: Left[L, R]): scala.util.Left[L, Nothing]
Converts a javascalautils.Left to a scala.util.Left.
Converts a javascalautils.Left to a scala.util.Left.
import javascalautils.{ Either => JEither, Left => JLeft, Right => JRight } val left = asScalaLeft(new JLeft[String,String]("Left is not Right"))
- underlying
The type to be converted
- returns
The converted type
- Definition Classes
- EitherConverters
- Since
1.0
-
def
asScalaNone[T](underlying: None[T]): scala.None.type
Converts a javascalautils.None to a scala.None.
Converts a javascalautils.None to a scala.None.
import javascalautils.{ None => JNone, Option => JOption, Some => JSome } val optionNone = asScalaOption(new JNone())
- underlying
The type to be converted
- returns
The converted type
- Definition Classes
- OptionConverters
- Since
1.0
-
def
asScalaOption[T](underlying: Option[T]): scala.Option[T]
Converts a javascalautils.Option to a scala.Option.
Converts a javascalautils.Option to a scala.Option.
import javascalautils.{ None => JNone, Option => JOption, Some => JSome } val optionNone = asScalaOption(new JNone()) val optionSome = asScalaOption(new JSome("Some is never None"))
- underlying
The type to be converted
- returns
The converted type
- Definition Classes
- OptionConverters
- Since
1.0
-
def
asScalaRight[L, R](underlying: Right[L, R]): scala.util.Right[Nothing, R]
Converts a javascalautils.Right to a scala.util.Right.
Converts a javascalautils.Right to a scala.util.Right.
import javascalautils.{ Either => JEither, Left => JLeft, Right => JRight } val right = asScalaRight(new JRight[String,String]("Left is not Right"))
- underlying
The type to be converted
- returns
The converted type
- Definition Classes
- EitherConverters
- Since
1.0
-
def
asScalaSome[T](underlying: Some[T]): scala.Some[T]
Converts a javascalautils.Some to a scala.Some.
Converts a javascalautils.Some to a scala.Some.
import javascalautils.{ None => JNone, Option => JOption, Some => JSome } val optionSome = asScalaOption(new JSome("Some is never None"))
- underlying
The type to be converted
- returns
The converted type
- Definition Classes
- OptionConverters
- Since
1.0
-
def
asScalaSuccess[T](underlying: Success[T]): scala.util.Success[T]
Converts a javascalautils.Success to a scala.util.Success.
Converts a javascalautils.Success to a scala.util.Success.
import javascalautils.{Try => JTry, Success => JSuccess, Failure => JFailure} val success = asScalaSuccess(new JSuccess("Success is never a Failure"))
- underlying
The type to be converted
- returns
The converted type
- Definition Classes
- TryConverters
- Since
1.0
-
def
asScalaTry[T](underlying: Try[T]): scala.util.Try[T]
Converts a javascalautils.Try to a scala.util.Try.
Converts a javascalautils.Try to a scala.util.Try.
import javascalautils.{Try => JTry, Success => JSuccess, Failure => JFailure} val trySuccess = asScalaTry(new JSuccess("Success is never a Failure")) val tryFailure = asScalaTry(new JFailure(new Exception("Error, terror")))
- underlying
The type to be converted
- returns
The converted type
- Definition Classes
- TryConverters
- Since
1.0
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native() @HotSpotIntrinsicCandidate()
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): scala.Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
final
def
notifyAll(): scala.Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(arg0: Long, arg1: Int): scala.Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): scala.Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
final
def
wait(): scala.Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
Deprecated Value Members
-
def
finalize(): scala.Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] ) @Deprecated
- Deprecated
Overview
This library provides the mechanisms to convert between types provided by javascalautils to their Scala equivalence and vice-versa.
One can either perform explicit conversions by using a specific converter method or do implicit conversions using the decorator pattern provided by Scalas implicit method declaration.
Explicit Conversion
This is the mechanism for performing the conversion by invoking a specific method taking the type you want to and converting it to its Scala or Java equivalence.
There's converters for Java -> Scala, javascalautils.converters.j2s.Converters as well as from Scala -> Java, javascalautils.converters.s2j.Converters. There's also an aggregate converter containing both of these javascalautils.converters.JavaScalaUtilConverters. Either import the converters you need:
or use the aggregate object composed of both above converters
import javascalautils.converters.JavaScalaUtilConverters._
After that it's a matter of using the right converter method to do the job.
E.g.
Refer to the aggregate object javascalautils.converters.JavaScalaUtilConverters for a list of all converter methods and examples on usage.
Implicit Conversion
This utilizes the implicit mechanism in Scala to decorate any given class with new methods.
More precisely this library provides asScala methods on all supported Java types and asJava methods on all supported Scala types.
This magic is enabled by having the right imports in scope.
Just as with the explicit converters the implicit ones are divided into Java -> Scala, javascalautils.converters.j2s.Implicits as well as from Scala -> Java, javascalautils.converters.s2j.Implicits.
Or one can choose to use the aggregate implicit javascalautils.converters.JavaScalaUtilImplicits.
It's again a matter of having the right imports in scope.
or use the aggregate object composed of both above implicits.
import javascalautils.converters.JavaScalaUtilImplicits._
Now your instances should be decorated with either a asScala or asJava method.
Full Documentation
Wiki
License
Copyright 2015 Peter Nerg
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and limitations under the License.