You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2019/01/08 08:00:35 UTC

[16/47] james-project git commit: MAILBOX-359 Use val to avoid too much class instanciations

MAILBOX-359 Use val to avoid too much class instanciations


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/6f8cb229
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/6f8cb229
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/6f8cb229

Branch: refs/heads/master
Commit: 6f8cb2291c5747105df6fc2689726f9da8a746bf
Parents: 0cdd567
Author: Benoit Tellier <bt...@linagora.com>
Authored: Tue Dec 25 15:59:19 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 8 14:39:38 2019 +0700

----------------------------------------------------------------------
 .../org/apache/james/event/json/EventSerializer.scala  | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/6f8cb229/mailbox/event/json/src/main/scala/org/apache/james/event/json/EventSerializer.scala
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/main/scala/org/apache/james/event/json/EventSerializer.scala b/mailbox/event/json/src/main/scala/org/apache/james/event/json/EventSerializer.scala
index 3628e37..6daf248 100644
--- a/mailbox/event/json/src/main/scala/org/apache/james/event/json/EventSerializer.scala
+++ b/mailbox/event/json/src/main/scala/org/apache/james/event/json/EventSerializer.scala
@@ -311,17 +311,16 @@ class JsonSerialize(mailboxIdFactory: MailboxId.Factory, messageIdFactory: Messa
     def fromJson(json: String): JsResult[Event] = Json.fromJson[Event](Json.parse(json))
   }
 
-  def toJson(event: JavaEvent): String = new EventSerializerPrivateWrapper().toJson(ScalaConverter.toScala(event))
-  def fromJson(json: String): JsResult[JavaEvent] = new EventSerializerPrivateWrapper().fromJson(json)
+  private val eventSerializerPrivateWrapper = new EventSerializerPrivateWrapper()
+  def toJson(event: JavaEvent): String = eventSerializerPrivateWrapper.toJson(ScalaConverter.toScala(event))
+  def fromJson(json: String): JsResult[JavaEvent] = eventSerializerPrivateWrapper.fromJson(json)
     .map(event => event.toJava)
 }
 
 class EventSerializer(mailboxIdFactory: MailboxId.Factory, messageIdFactory: MessageId.Factory) {
-  def toJson(event: JavaEvent): String = new JsonSerialize(mailboxIdFactory, messageIdFactory).toJson(event)
+  private val jsonSerialize = new JsonSerialize(mailboxIdFactory, messageIdFactory)
 
-  def fromJson(json: String): JsResult[JavaEvent] = {
-    new JsonSerialize(mailboxIdFactory, messageIdFactory)
-      .fromJson(json)
-  }
+  def toJson(event: JavaEvent): String = jsonSerialize.toJson(event)
+  def fromJson(json: String): JsResult[JavaEvent] = jsonSerialize.fromJson(json)
 }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org