-
Notifications
You must be signed in to change notification settings - Fork 84
Description
I noticed that there is a whole bunch of case classes copied between com.ing.baker.runtime.scaladsl and com.ing.baker.runtime.javadsl.
The only difference seems to be the use of Scala's Option vs Java's Optional.
You could get rid of that by adding a companion object to every case class with a fromJava (or differently named) method which takes Optional arguments but constructs the Scala class with an Option. The corresponding Java getter method could convert back to an Optional.
Example:
/**
* Event describing the fact that an event was received for a process.
*
* @param timeStamp The time that the event was received
* @param recipeName The name of the recipe that interaction is part of
* @param recipeId The recipe id
* @param recipeInstanceId The id of the process
* @param correlationId The (optional) correlation id of the event
* @param event The event
*/
case class EventReceived(timeStamp: Long,
recipeName: String,
recipeId: String,
recipeInstanceId: String,
correlationId: Option[String],
event: EventInstance) extends BakerEvent with common.EventReceived {
def getTimeStamp: Long = timeStamp
def getRecipeName: String = recipeName
def getRecipeId: String = recipeId
def getRecipeInstanceId: String = recipeInstanceId
def getCorrelationId: Optional[String] = Optional.ofNullable(correlationId.orNull)
def getEvent: EventInstance = event
}
object EventReceived {
def fromJava(timeStamp: Long,
recipeName: String,
recipeId: String,
recipeInstanceId: String,
correlationId: Optional[String],
event: EventInstance
) = new EventReceived(
timeStamp,
recipeName,
recipeId,
recipeInstanceId,
if (correlationId.isPresent) Some(correlationId.get) else None,
event: EventInstance
)
}
The same thing would also work the other way round.
This approach would have a minor performance impact for converting back and forth between Option and Optional, but I would assume this is negligible under real-life scenarios.
If this is desirable, I could create a corresponding PR.
Let me know what you think!