Java API for CamelServiceManager and CamelContextManager (usage of JavaAPI.Option)
This commit is contained in:
parent
353d01cf05
commit
77d5f39955
17 changed files with 188 additions and 126 deletions
|
|
@ -33,6 +33,7 @@ object JavaAPI {
|
|||
sealed abstract class Option[A] extends java.lang.Iterable[A] {
|
||||
def get: A
|
||||
def isDefined: Boolean
|
||||
def asScala: scala.Option[A]
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -44,11 +45,10 @@ object JavaAPI {
|
|||
final case class Some[A](v: A) extends Option[A] {
|
||||
import scala.collection.JavaConversions._
|
||||
|
||||
val sv = scala.Some(v)
|
||||
|
||||
def get = sv.get
|
||||
def iterator = sv.iterator
|
||||
def get = v
|
||||
def iterator = Iterator.single(v)
|
||||
def isDefined = true
|
||||
def asScala = scala.Some(v)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -60,11 +60,16 @@ object JavaAPI {
|
|||
import scala.collection.JavaConversions._
|
||||
|
||||
def get = throw new NoSuchElementException("None.get")
|
||||
def iterator = scala.None.iterator
|
||||
def iterator = Iterator.empty
|
||||
def isDefined = false
|
||||
def asScala = scala.None
|
||||
}
|
||||
|
||||
def some[A](v: A) = Some(v)
|
||||
def none[A] = None[A]
|
||||
|
||||
implicit def java2ScalaOption[A](o: Option[A]): scala.Option[A] = o.asScala
|
||||
implicit def scala2JavaOption[A](o: scala.Option[A]): Option[A] =
|
||||
if (o.isDefined) Some(o.get) else None[A]
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue