From 158c0e0ef40c16d9ae38a7fa70b10b893a80d7b3 Mon Sep 17 00:00:00 2001 From: Edoardo La Greca Date: Thu, 7 Aug 2025 16:29:16 +0200 Subject: turn FIDInfo into PathInfo --- src/main/kotlin/PathInfo.kt | 62 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/main/kotlin/PathInfo.kt (limited to 'src/main/kotlin/PathInfo.kt') diff --git a/src/main/kotlin/PathInfo.kt b/src/main/kotlin/PathInfo.kt new file mode 100644 index 0000000..c9ff29e --- /dev/null +++ b/src/main/kotlin/PathInfo.kt @@ -0,0 +1,62 @@ +/** + * This class holds all info about paths, their FIDs, and their QIDs. + */ +class PathInfo() { + private val paths: MutableSet = mutableSetOf() + + /** + * Information about a path. Each FID maps to one path but not all paths have FIDs (injective). On the other hand, + * one QID can be shared with different paths and FIDs. + * + * FIDs are optional because some R-messages only return QIDs for certain files (e.g. walk). + * + * @param path The path. + * @param fid The optional FID associated with the path. + * @param qid The QID associated with the path. + */ + data class Path(val path: List, val fid: UInt?, val qid: QID) + + /** + * Add a path. + */ + fun addPath(path: Path) { + this.paths.add(path) + } + + /** + * Find the FID associated with a path. + * + * @param path The path to find the FID of. + * @return The FID if [path] has an associated FID, or null otherwise. + */ + fun findFIDByPath(path: List): UInt? { + return this.paths.find { x -> x.path == path }?.fid + } + + /** + * Find the QID associated to a path. + * + * @param path The path to find the QID of. + * @return The QID if [path] could be found, or null otherwise. + */ + fun findQIDByPath(path: List): QID? { + return this.paths.find { x -> x.path == path }?.qid + } + + /** + * Find the path associated to a FID. + * + * @param fid The FID to find the path of. + * @return The path if [fid] could be found, or null otherwise. + */ + fun findPathByFID(fid: UInt): List? { + return this.paths.find { x -> x.fid == fid }?.path + } + + /** + * Retrieve all paths + */ + fun getAllPaths(): Set { + return this.paths.toSet() + } +} \ No newline at end of file -- cgit v1.2.3