From cdc81b5dae623de006946ec83ce0ab7a4b2e4922 Mon Sep 17 00:00:00 2001 From: kjappvaffel <45148718+kjappvaffel@users.noreply.github.com> Date: Fri, 11 Nov 2022 15:48:55 +0100 Subject: [PATCH] task 1.1. first try --- project_tasks/src/main/scala/Transaction.scala | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/project_tasks/src/main/scala/Transaction.scala b/project_tasks/src/main/scala/Transaction.scala index 3f13c1d..34f71fe 100644 --- a/project_tasks/src/main/scala/Transaction.scala +++ b/project_tasks/src/main/scala/Transaction.scala @@ -1,5 +1,6 @@ import exceptions._ import scala.collection.mutable +import scala.collection.mutable._ object TransactionStatus extends Enumeration { val SUCCESS, PENDING, FAILED = Value @@ -10,21 +11,21 @@ class TransactionQueue { // TODO // project task 1.1 // Add datastructure to contain the transactions - + var queue: Queue[Transaction] = Queue() // Remove and return the first element from the queue - def pop: Transaction = ??? + def pop: Transaction = {queue.synchronized(queue.dequeue())} // Return whether the queue is empty - def isEmpty: Boolean = ??? + def isEmpty: Boolean = {queue.synchronized(queue.isEmpty())} // Add new element to the back of the queue - def push(t: Transaction): Unit = ??? + def push(t: Transaction): Unit = {queue.synchronized(queue.push(t))} // Return the first element from the queue without removing it - def peek: Transaction = ??? + def peek: Transaction = {queue.synchronized(queue.front())} // Return an iterator to allow you to iterate over the queue - def iterator: Iterator[Transaction] = ??? + def iterator: Iterator[Transaction] = {queue.synchronized(queue.iterator())} } class Transaction(val transactionsQueue: TransactionQueue,