This is an automated email from the ASF dual-hosted git repository. btellier pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 76934c9dd29955efeb2c08a3c11973be7399738c Author: Benoit Tellier <[email protected]> AuthorDate: Wed Nov 18 18:36:11 2020 +0700 [Refactoring] Apply some standards scala idioms - Use AnyVal to limit allocations - Avoid inner nested class definitions - Use case objects --- .../org/apache/james/jmap/core/Capability.scala | 2 +- .../scala/org/apache/james/jmap/core/Session.scala | 4 +-- .../scala/org/apache/james/jmap/mail/Email.scala | 12 ++++---- .../org/apache/james/jmap/mail/EmailBodyPart.scala | 12 ++++---- .../apache/james/jmap/mail/EmailBodyValue.scala | 4 +-- .../james/jmap/method/MailboxGetMethod.scala | 36 +++++++++++----------- .../jmap/method/VacationResponseSetMethod.scala | 4 +-- .../james/jmap/vacation/VacationResponse.scala | 6 ++-- 8 files changed, 40 insertions(+), 40 deletions(-) diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/core/Capability.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/core/Capability.scala index 1cebf30..8ec9dfd 100644 --- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/core/Capability.scala +++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/core/Capability.scala @@ -94,7 +94,7 @@ case class MaxMailboxesPerEmail(value: Option[UnsignedInt]) case class MaxMailboxDepth(value: Option[UnsignedInt]) case class MaxSizeMailboxName(value: UnsignedInt) case class MaxSizeAttachmentsPerEmail(value: UnsignedInt) -case class MayCreateTopLevelMailbox(value: Boolean) +case class MayCreateTopLevelMailbox(value: Boolean) extends AnyVal final case class MailCapabilityProperties(maxMailboxesPerEmail: MaxMailboxesPerEmail, maxMailboxDepth: MaxMailboxDepth, diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/core/Session.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/core/Session.scala index 00d6708..1e86baf 100644 --- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/core/Session.scala +++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/core/Session.scala @@ -32,8 +32,8 @@ import org.apache.james.jmap.core.CapabilityIdentifier.CapabilityIdentifier import org.apache.james.jmap.core.Id.Id import org.apache.james.jmap.core.State.{INSTANCE, State} -case class IsPersonal(value: Boolean) -case class IsReadOnly(value: Boolean) +case class IsPersonal(value: Boolean) extends AnyVal +case class IsReadOnly(value: Boolean) extends AnyVal object AccountId { def from(username: Username): Either[IllegalArgumentException, AccountId] = { diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/Email.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/Email.scala index 23fd436..aa75e4e 100644 --- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/Email.scala +++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/Email.scala @@ -562,18 +562,18 @@ object EmailFastViewReader { val logger: Logger = LoggerFactory.getLogger(classOf[EmailFastViewReader]) } +private sealed trait FastViewResult + +private case class FastViewAvailable(id: MessageId, fastView: MessageFastViewPrecomputedProperties) extends FastViewResult + +private case class FastViewUnavailable(id: MessageId) extends FastViewResult + private class EmailFastViewReader @Inject()(messageIdManager: MessageIdManager, messageFastViewProjection: MessageFastViewProjection, zoneIdProvider: ZoneIdProvider, fullViewFactory: EmailFullViewFactory) extends EmailViewReader[EmailView] { private val fullReader: GenericEmailViewReader[EmailFullView] = new GenericEmailViewReader[EmailFullView](messageIdManager, FULL_CONTENT, fullViewFactory) - private sealed trait FastViewResult - - private case class FastViewAvailable(id: MessageId, fastView: MessageFastViewPrecomputedProperties) extends FastViewResult - - private case class FastViewUnavailable(id: MessageId) extends FastViewResult - override def read[T >: EmailView](ids: Seq[MessageId], request: EmailGetRequest, mailboxSession: MailboxSession): SFlux[T] = { SMono.fromPublisher(messageFastViewProjection.retrieve(ids.asJava)) .map(_.asScala.toMap) diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/EmailBodyPart.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/EmailBodyPart.scala index 631fcb5..c5eb21f 100644 --- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/EmailBodyPart.scala +++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/EmailBodyPart.scala @@ -166,16 +166,16 @@ object Name { }.map(Name(_)) } -case class Name(value: String) -case class Type(value: String) -case class Charset(value: String) +case class Name(value: String) extends AnyVal +case class Type(value: String) extends AnyVal +case class Charset(value: String) extends AnyVal object Disposition { val ATTACHMENT = Disposition("attachment") val INLINE = Disposition("inline") } -case class Disposition(value: String) +case class Disposition(value: String) extends AnyVal object Languages { def of(entity: Entity): Option[Languages] = @@ -190,9 +190,9 @@ case class Languages(value: List[Language]) { def asField: Field = new RawField("Content-Language", value.map(_.value).mkString(", ")) } -case class Language(value: String) +case class Language(value: String) extends AnyVal -case class Location(value: String) { +case class Location(value: String) extends AnyVal { def asField: Field = new RawField("Content-Location", value) } diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/EmailBodyValue.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/EmailBodyValue.scala index efff66a..f026308 100644 --- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/EmailBodyValue.scala +++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/EmailBodyValue.scala @@ -24,8 +24,8 @@ import java.nio.{ByteBuffer, CharBuffer} import org.apache.james.jmap.mail.EmailGetRequest.{MaxBodyValueBytes, ZERO} -case class IsEncodingProblem(value: Boolean) -case class IsTruncated(value: Boolean) +case class IsEncodingProblem(value: Boolean) extends AnyVal +case class IsTruncated(value: Boolean) extends AnyVal case class EmailBodyValue(value: String, isEncodingProblem: IsEncodingProblem, diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxGetMethod.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxGetMethod.scala index a7adf77..cd036cb 100644 --- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxGetMethod.scala +++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxGetMethod.scala @@ -42,6 +42,24 @@ import reactor.core.scheduler.Schedulers import scala.jdk.CollectionConverters._ import scala.util.Try +object MailboxGetResults { + def merge(result1: MailboxGetResults, result2: MailboxGetResults): MailboxGetResults = result1.merge(result2) + def empty(): MailboxGetResults = MailboxGetResults(Set.empty, NotFound(Set.empty)) + def found(mailbox: Mailbox): MailboxGetResults = MailboxGetResults(Set(mailbox), NotFound(Set.empty)) + def notFound(mailboxId: UnparsedMailboxId): MailboxGetResults = MailboxGetResults(Set.empty, NotFound(Set(mailboxId))) + def notFound(mailboxId: MailboxId): MailboxGetResults = MailboxGetResults(Set.empty, NotFound(Set(MailboxGet.asUnparsed(mailboxId)))) +} + +case class MailboxGetResults(mailboxes: Set[Mailbox], notFound: NotFound) { + def merge(other: MailboxGetResults): MailboxGetResults = MailboxGetResults(this.mailboxes ++ other.mailboxes, this.notFound.merge(other.notFound)) + + def asResponse(accountId: AccountId): MailboxGetResponse = MailboxGetResponse( + accountId = accountId, + state = INSTANCE, + list = mailboxes.toList.sortBy(_.sortOrder), + notFound = notFound) +} + class MailboxGetMethod @Inject() (serializer: MailboxSerializer, mailboxManager: MailboxManager, subscriptionManager: SubscriptionManager, @@ -53,24 +71,6 @@ class MailboxGetMethod @Inject() (serializer: MailboxSerializer, override val methodName: MethodName = MethodName("Mailbox/get") override val requiredCapabilities: Set[CapabilityIdentifier] = Set(JMAP_CORE, JMAP_MAIL) - object MailboxGetResults { - def merge(result1: MailboxGetResults, result2: MailboxGetResults): MailboxGetResults = result1.merge(result2) - def empty(): MailboxGetResults = MailboxGetResults(Set.empty, NotFound(Set.empty)) - def found(mailbox: Mailbox): MailboxGetResults = MailboxGetResults(Set(mailbox), NotFound(Set.empty)) - def notFound(mailboxId: UnparsedMailboxId): MailboxGetResults = MailboxGetResults(Set.empty, NotFound(Set(mailboxId))) - def notFound(mailboxId: MailboxId): MailboxGetResults = MailboxGetResults(Set.empty, NotFound(Set(MailboxGet.asUnparsed(mailboxId)))) - } - - case class MailboxGetResults(mailboxes: Set[Mailbox], notFound: NotFound) { - def merge(other: MailboxGetResults): MailboxGetResults = MailboxGetResults(this.mailboxes ++ other.mailboxes, this.notFound.merge(other.notFound)) - - def asResponse(accountId: AccountId): MailboxGetResponse = MailboxGetResponse( - accountId = accountId, - state = INSTANCE, - list = mailboxes.toList.sortBy(_.sortOrder), - notFound = notFound) - } - override def doProcess(capabilities: Set[CapabilityIdentifier], invocation: InvocationWithContext, mailboxSession: MailboxSession, request: MailboxGetRequest): SMono[InvocationWithContext] = { val requestedProperties: Properties = request.properties.getOrElse(Mailbox.allProperties) (requestedProperties -- Mailbox.allProperties match { diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/VacationResponseSetMethod.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/VacationResponseSetMethod.scala index 46b9bf5..ce0dd34 100644 --- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/VacationResponseSetMethod.scala +++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/VacationResponseSetMethod.scala @@ -49,7 +49,7 @@ sealed trait VacationResponseUpdateResult { def asVacationResponseUpdateResults = VacationResponseUpdateResults(updated, notUpdated) } -case class VacationResponseUpdateSuccess() extends VacationResponseUpdateResult { +case object VacationResponseUpdateSuccess extends VacationResponseUpdateResult { override def updated: Map[String, VacationResponseUpdateResponse] = Map(VACATION_RESPONSE_PATCH_OBJECT_KEY -> VacationResponseUpdateResponse(JsObject(Seq()))) override def notUpdated: Map[String, VacationResponseSetError] = Map() @@ -101,7 +101,7 @@ class VacationResponseSetMethod @Inject()(vacationRepository: VacationRepository private def update(validatedPatch: VacationPatch, mailboxSession: MailboxSession): SMono[VacationResponseUpdateResult] = SMono.fromPublisher( vacationRepository.modifyVacation(toVacationAccountId(mailboxSession), validatedPatch)) - .`then`(SMono.just(VacationResponseUpdateSuccess())) + .`then`(SMono.just(VacationResponseUpdateSuccess)) private def toVacationAccountId(mailboxSession: MailboxSession): AccountId = { AccountId.fromUsername(mailboxSession.getUser) diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/vacation/VacationResponse.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/vacation/VacationResponse.scala index c1c44d5..26cb067 100644 --- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/vacation/VacationResponse.scala +++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/vacation/VacationResponse.scala @@ -31,11 +31,11 @@ import scala.compat.java8.OptionConverters._ case class VacationResponseId() -case class IsEnabled(value: Boolean) +case class IsEnabled(value: Boolean) extends AnyVal case class FromDate(value: UTCDate) case class ToDate(value: UTCDate) -case class TextBody(value: String) -case class HtmlBody(value: String) +case class TextBody(value: String) extends AnyVal +case class HtmlBody(value: String) extends AnyVal object VacationResponse { val VACATION_RESPONSE_ID: Id = "singleton" --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
