Skip to content

Commit 2d12e86

Browse files
KuechAoxisto
authored andcommitted
Comparable version info
1 parent 205ee09 commit 2d12e86

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

Diff for: cpg-language-python/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/python/SystemInformation.kt

+19-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import de.fraunhofer.aisec.cpg.graph.OverlayNode
2929

3030
/** Represents the contents of `sys.version_info` which contains the Python version. */
3131
data class VersionInfo(var major: Long? = null, var minor: Long? = null, var micro: Long? = null) :
32-
OverlayNode() {
32+
OverlayNode(), Comparable<VersionInfo> {
3333
/**
3434
* Returns the version info as a tuple (major, minor, micro). The length of the tuple depends on
3535
* the information set, e.g., if only major version is set, then the list is 1 element long.
@@ -46,6 +46,24 @@ data class VersionInfo(var major: Long? = null, var minor: Long? = null, var mic
4646

4747
return list
4848
}
49+
50+
override fun compareTo(other: VersionInfo): Int {
51+
val thisMajor = this.major ?: -1
52+
val otherMajor = other.major ?: -1
53+
val thisMinor = this.minor ?: -1
54+
val otherMinor = other.minor ?: -1
55+
val thisMicro = this.micro ?: -1
56+
val otherMicro = other.micro ?: -1
57+
return if (thisMajor == otherMajor && thisMinor == otherMinor && thisMicro == otherMicro) {
58+
0
59+
} else if (
60+
thisMajor < otherMajor ||
61+
(thisMajor == otherMajor &&
62+
(thisMinor < otherMinor || thisMinor == otherMinor && thisMicro < otherMicro))
63+
) {
64+
-1
65+
} else 1
66+
}
4967
}
5068

5169
/**

0 commit comments

Comments
 (0)