add flag crdt constants (#24208)

* add flag crdt constants

* add scaladoc
This commit is contained in:
Nafer Sanabria 2018-01-09 04:39:06 -05:00 committed by Patrik Nordwall
parent 7c94bc7df4
commit 804dc4b6ba
6 changed files with 27 additions and 15 deletions

View file

@ -7,12 +7,24 @@ object Flag {
/**
* `Flag` that is initialized to `false`.
*/
val empty = new Flag(false)
def apply(): Flag = empty
val empty: Flag = new Flag(false)
/**
* `Flag` that is initialized to `false`.
*/
val Disabled: Flag = empty
/**
* `Flag` that is initialized to `true`.
*/
val Enabled: Flag = new Flag(true)
def apply(): Flag = Disabled
/**
* Java API: `Flag` that is initialized to `false`.
*/
def create(): Flag = empty
def create(): Flag = Disabled
// unapply from case class
}
@ -30,7 +42,7 @@ final case class Flag(enabled: Boolean) extends ReplicatedData with ReplicatedDa
def switchOn: Flag =
if (enabled) this
else Flag(true)
else Flag.Enabled
override def merge(that: Flag): Flag =
if (that.enabled) that

View file

@ -484,7 +484,7 @@ class ReplicatedDataSerializer(val system: ExtendedActorSystem)
flagFromProto(rd.Flag.parseFrom(bytes))
def flagFromProto(flag: rd.Flag): Flag =
Flag(flag.getEnabled)
if (flag.getEnabled) Flag.Enabled else Flag.Disabled
def lwwRegisterToProto(lwwRegister: LWWRegister[_]): rd.LWWRegister =
rd.LWWRegister.newBuilder().