summaryrefslogtreecommitdiff
path: root/examples/scala-js/javalib/src/main/scala/java/util/concurrent/atomic/AtomicLong.scala
diff options
context:
space:
mode:
Diffstat (limited to 'examples/scala-js/javalib/src/main/scala/java/util/concurrent/atomic/AtomicLong.scala')
-rw-r--r--examples/scala-js/javalib/src/main/scala/java/util/concurrent/atomic/AtomicLong.scala61
1 files changed, 61 insertions, 0 deletions
diff --git a/examples/scala-js/javalib/src/main/scala/java/util/concurrent/atomic/AtomicLong.scala b/examples/scala-js/javalib/src/main/scala/java/util/concurrent/atomic/AtomicLong.scala
new file mode 100644
index 0000000..5bfecf2
--- /dev/null
+++ b/examples/scala-js/javalib/src/main/scala/java/util/concurrent/atomic/AtomicLong.scala
@@ -0,0 +1,61 @@
+package java.util.concurrent.atomic
+
+class AtomicLong(private[this] var value: Long) extends Number with Serializable {
+ def this() = this(0L)
+
+ final def get(): Long = value
+
+ final def set(newValue: Long): Unit =
+ value = newValue
+
+ final def lazySet(newValue: Long): Unit =
+ set(newValue)
+
+ final def getAndSet(newValue: Long): Long = {
+ val old = value
+ value = newValue
+ old
+ }
+
+ final def compareAndSet(expect: Long, update: Long): Boolean = {
+ if (expect != value) false else {
+ value = update
+ true
+ }
+ }
+
+ final def weakCompareAndSet(expect: Long, update: Long): Boolean =
+ compareAndSet(expect, update)
+
+ final def getAndIncrement(): Long =
+ getAndAdd(1L)
+
+ final def getAndDecrement(): Long =
+ getAndAdd(-1L)
+
+ @inline final def getAndAdd(delta: Long): Long = {
+ val old = value
+ value = old + delta
+ old
+ }
+
+ final def incrementAndGet(): Long =
+ addAndGet(1L)
+
+ final def decrementAndGet(): Long =
+ addAndGet(-1L)
+
+ @inline final def addAndGet(delta: Long): Long = {
+ val newValue = value + delta
+ value = newValue
+ newValue
+ }
+
+ override def toString(): String =
+ value.toString()
+
+ def intValue(): Int = value.toInt
+ def longValue(): Long = value
+ def floatValue(): Float = value.toFloat
+ def doubleValue(): Double = value.toDouble
+}