aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/Server/Clients.scala
diff options
context:
space:
mode:
authorJoel Kronqvist <joel.kronqvist@iki.fi>2024-11-07 21:00:04 +0200
committerJoel Kronqvist <joel.kronqvist@iki.fi>2024-11-07 21:00:04 +0200
commit891b6f877ba848a3f78851a757734ebd1f066798 (patch)
tree849d4f9bac3b3e83f84b6319d7148f93f5a44c06 /src/main/scala/Server/Clients.scala
parentfdaec6534eb7ee902c75be3e4b732b6970abd859 (diff)
downloadscalevalapokalypsi-891b6f877ba848a3f78851a757734ebd1f066798.tar.gz
scalevalapokalypsi-891b6f877ba848a3f78851a757734ebd1f066798.zip
Added comments for documentation and reformatted old ones
Diffstat (limited to 'src/main/scala/Server/Clients.scala')
-rw-r--r--src/main/scala/Server/Clients.scala44
1 files changed, 24 insertions, 20 deletions
diff --git a/src/main/scala/Server/Clients.scala b/src/main/scala/Server/Clients.scala
index 24a245c..786a09a 100644
--- a/src/main/scala/Server/Clients.scala
+++ b/src/main/scala/Server/Clients.scala
@@ -6,11 +6,11 @@ class Clients(maxClients: Int):
private val clients: Array[Option[Client]] = Array.fill(maxClients)(None)
/** Adds `client` to this collection of clients.
- *
- * @param client the Client to add
- * @return true if there was room for the client
- * i.e. fewer clients than `maxClients`, false otherwise
- */
+ *
+ * @param client the Client to add
+ * @return true if there was room for the client
+ * i.e. fewer clients than `maxClients`, false otherwise
+ */
def addClient(client: Client): Boolean =
val i = this.clients.indexOf(None)
if i == -1 then
@@ -20,9 +20,9 @@ class Clients(maxClients: Int):
true
/** Returns all the clients.
- *
- * @return an iterable of all the clients
- */
+ *
+ * @return an iterable of all the clients
+ */
def allClients: Iterable[Client] = clients.toVector.flatten
/** Applies the function `f` to all the clients for its side effects. */
@@ -36,17 +36,21 @@ class Clients(maxClients: Int):
*/
def forall(f: Client => Boolean): Boolean = this.clients.flatten.forall(f)
+ /** Gets the names of all the clients stored by this object.
+ *
+ * @return the names of the clients
+ */
def names: Vector[String] = this.clients.flatten.flatMap(_.getName).toVector
def isEmpty: Boolean = this.clients.flatten.isEmpty
/** Applies the function `f` to all the clients for its side effects
- * and removes all the clients for which `f([client])` returns false.
- * This is useful for doing IO with the client and removing clients
- * with stale sockets.
- *
- * @param f the function to apply to all the clients and filter them with
- */
+ * and removes all the clients for which `f([client])` returns false.
+ * This is useful for doing IO with the client and removing clients
+ * with stale sockets.
+ *
+ * @param f the function to apply to all the clients and filter them with
+ */
def removeNonSatisfying(f: Client => Boolean): Unit =
for i <- this.clients.indices do
this.clients(i) match
@@ -60,11 +64,11 @@ class Clients(maxClients: Int):
this.removeNonSatisfying(_.isIntactProtocolWise)
/** Applies the function f to all clients for its side effects.
- * If the function throws an exception, the client is removed.
- * Probably a more concise alternative to `removeNonSatisfying`,
- * but might catch exceptions unintentionally.
- *
- * @param f the function to apply for its side effects to each client
- */
+ * If the function throws an exception, the client is removed.
+ * Probably a more concise alternative to `removeNonSatisfying`,
+ * but might catch exceptions unintentionally.
+ *
+ * @param f the function to apply for its side effects to each client
+ */
def mapAndRemove(f: Client => Unit): Unit =
this.removeNonSatisfying(c => Try(f(c)).isSuccess)