All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.couchbase.client.scala.kv.MutationState.scala Maven / Gradle / Ivy

There is a newer version: 1.7.5
Show newest version
package com.couchbase.client.scala.kv

import com.couchbase.client.core.api.shared.CoreMutationState
import com.couchbase.client.core.msg.kv.MutationToken
import scala.jdk.CollectionConverters._

/** Represents the tokens from one or more mutations. */
case class MutationState(tokens: Seq[MutationToken]) {

  /** Add the token from a [[MutationResult]], if it's present, to this.
    *
    * @return a copy of this, for chaining
    */
  def add(mutationResult: MutationResult): MutationState = {
    mutationResult.mutationToken match {
      case Some(mt) => copy(tokens :+ mt)
      case _        => this
    }
  }

  /** Add the tokens from another MutationState to this.
    *
    * @return a copy of this, for chaining
    */
  def add(mutationState: MutationState): MutationState = {
    copy(tokens ++ mutationState.tokens)
  }

  private[scala] def toCore = new CoreMutationState(tokens.asJava)
}

object MutationState {

  /** Create a new MutationState representing all the tokens from the provided [[MutationResult]]s. */
  def from(result: MutationResult*): MutationState = {
    MutationState(result.map(_.mutationToken).filter(_.isDefined).map(_.get))
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy