blob: c9ff29e7f752aac70e17bee9fcd2a2a751f684f2 (
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
/**
* This class holds all info about paths, their FIDs, and their QIDs.
*/
class PathInfo() {
private val paths: MutableSet<Path> = 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<String>, 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<String>): 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<String>): 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<String>? {
return this.paths.find { x -> x.fid == fid }?.path
}
/**
* Retrieve all paths
*/
fun getAllPaths(): Set<Path> {
return this.paths.toSet()
}
}
|