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 ma...@apache.org on 2020/02/27 16:20:33 UTC

[james-project] 12/14: JAMES-3009 remove factory method with java.util.List in History

This is an automated email from the ASF dual-hosted git repository.

matthieu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 610f268bfd6a721a38b4319a0336c922c5902036
Author: RĂ©mi KOWALSKI <rk...@linagora.com>
AuthorDate: Mon Dec 16 11:06:57 2019 +0100

    JAMES-3009 remove factory method with java.util.List in History
---
 .../james/eventsourcing/eventstore/History.scala   | 22 +++++++++++++---------
 .../task/eventsourcing/TaskAggregateTest.java      |  4 ++--
 2 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/event-sourcing/event-store-api/src/main/scala/org/apache/james/eventsourcing/eventstore/History.scala b/event-sourcing/event-store-api/src/main/scala/org/apache/james/eventsourcing/eventstore/History.scala
index 29d0132..8155056 100644
--- a/event-sourcing/event-store-api/src/main/scala/org/apache/james/eventsourcing/eventstore/History.scala
+++ b/event-sourcing/event-store-api/src/main/scala/org/apache/james/eventsourcing/eventstore/History.scala
@@ -1,4 +1,4 @@
-/** **************************************************************
+/****************************************************************
  * Licensed to the Apache Software Foundation (ASF) under one   *
  * or more contributor license agreements.  See the NOTICE file *
  * distributed with this work for additional information        *
@@ -7,7 +7,7 @@
  * "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                   *
+ *   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  *
@@ -15,29 +15,31 @@
  * KIND, either express or implied.  See the License for the    *
  * specific language governing permissions and limitations      *
  * under the License.                                           *
- * ***************************************************************/
+ ****************************************************************/
 package org.apache.james.eventsourcing.eventstore
 
 import org.apache.james.eventsourcing.{Event, EventId}
 
 import scala.annotation.varargs
-import scala.jdk.CollectionConverters._
 
 object History {
   def empty: History = new History(Nil)
 
   def of(events: List[Event]): History = new History(events)
-  def of(events: java.util.List[Event]): History = new History(events.asScala.toList)
 
   @varargs
   def of(events: Event*): History = of(events.toList)
 }
 
 final case class History private(events: List[Event]) {
-  if (hasEventIdDuplicates(events)) throw EventStoreFailedException("Event History contains duplicated EventId")
+  if (hasEventIdDuplicates(events)) {
+    throw EventStoreFailedException("Event History contains duplicated EventId")
+  }
 
   private def hasEventIdDuplicates(events: List[Event]) = {
-    val eventIdsNumber = events.map(event => event.eventId).toSet.size
+    val eventIdsNumber = events.map(event => event.eventId)
+      .toSet
+      .size
     eventIdsNumber != events.size
   }
 
@@ -45,8 +47,10 @@ final case class History private(events: List[Event]) {
     .map(event => event.eventId)
     .maxOption
 
-  def getEvents = events
+  def getEvents:List[Event] = events
 
-  def getNextEventId: EventId = getVersion.map(eventId => eventId.next).getOrElse(EventId.first)
+  def getNextEventId: EventId = getVersion
+    .map(eventId => eventId.next)
+    .getOrElse(EventId.first)
 
 }
\ No newline at end of file
diff --git a/server/task/task-memory/src/test/java/org/apache/james/task/eventsourcing/TaskAggregateTest.java b/server/task/task-memory/src/test/java/org/apache/james/task/eventsourcing/TaskAggregateTest.java
index 3892934..3e702a5 100644
--- a/server/task/task-memory/src/test/java/org/apache/james/task/eventsourcing/TaskAggregateTest.java
+++ b/server/task/task-memory/src/test/java/org/apache/james/task/eventsourcing/TaskAggregateTest.java
@@ -47,12 +47,12 @@ class TaskAggregateTest {
     static final Instant timestamp = Instant.parse("2018-11-13T12:00:55Z");
 
     History buildHistory(Function<EventId, Event>... events) {
-        return History.of(
+        return History.of(CollectionConverters.asScala(
             Streams.zip(
                     Stream.iterate(EventId.first(), EventId::next),
                     Arrays.stream(events),
                     (id, event) -> event.apply(id))
-                .collect(Guavate.toImmutableList()));
+                .collect(Guavate.toImmutableList())).toList());
     }
 
     @Test


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