From a90fb27d5d557945217496db5301f52fb0c9b902 Mon Sep 17 00:00:00 2001 From: fredrikr79 Date: Fri, 7 Nov 2025 11:14:27 +0100 Subject: [PATCH] scp2: task 1.1 --- .../src/main/scala/Transaction.scala | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/scala_project_2025/bank_system/src/main/scala/Transaction.scala b/scala_project_2025/bank_system/src/main/scala/Transaction.scala index d959748..5b20b52 100644 --- a/scala_project_2025/bank_system/src/main/scala/Transaction.scala +++ b/scala_project_2025/bank_system/src/main/scala/Transaction.scala @@ -1,24 +1,22 @@ +import java.util.concurrent.ConcurrentLinkedQueue +import scala.collection.JavaConverters._ + object TransactionStatus extends Enumeration { val SUCCESS, PENDING, FAILED = Value } class TransactionPool { + private val queue = new ConcurrentLinkedQueue[Transaction]() - // Remove and the transaction from the pool - def remove(t: Transaction): Boolean = ??? + def add(t: Transaction): Boolean = queue.offer(t) - // Return whether the queue is empty - def isEmpty: Boolean = ??? + def remove(t: Transaction): Boolean = queue.remove(t) - // Return the size of the pool - def size: Integer = ??? + def isEmpty: Boolean = queue.isEmpty - // Add new element to the back of the queue - def add(t: Transaction): Boolean = ??? - - // Return an iterator to allow you to iterate over the queue - def iterator: Iterator[Transaction] = ??? + def size: Integer = queue.size + def iterator: Iterator[Transaction] = queue.iterator.asScala } class Transaction(