summaryrefslogtreecommitdiff
path: root/src/main/kotlin/FIDInfo.kt
blob: dbbc945659ef0ff6afbdaf971d9c3e1fcf0d1d27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
 * This class holds all info about File IDs (FIDs).
 */
class FIDInfo() {
    private val inUse: MutableSet<FID> = mutableSetOf()

    /**
     * A single FID.
     *
     * @param fid The actual FID value.
     * @param path The path of the FID, represented as successive path name elements.
     * @param qid The QID associated with the FID.
     */
    data class FID(val fid: UInt, val path: List<String>, val qid: QID)

    /**
     * Add a FID with the associated file path and QID.
     */
    fun addFID(fid: FID) {
        this.inUse.add(fid)
    }

    /**
     * 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<String>? {
        return this.inUse.find { x -> x.fid == fid }?.path
    }

    /**
     * Find the FID associated to 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<String>): UInt? {
        return this.inUse.find { x -> x.path == path }?.fid
    }
}