Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-3529 - Make DataTypePath comparable

ghizard5125814a3e80
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/DataTypePath.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/DataTypePath.java
index 796229c28b..e3885144af 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/DataTypePath.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/DataTypePath.java
@@ -15,11 +15,13 @@
*/
package ghidra.program.model.data;
+import java.util.Objects;
+
/**
* Object to hold a category path and a datatype name. They are held separately so that
* the datatype name can contain a categoryPath delimiter ("/") character.
*/
-public class DataTypePath {
+public class DataTypePath implements Comparable<DataTypePath> {
private final CategoryPath categoryPath;
private final String dataTypeName;
@@ -43,8 +45,8 @@ public class DataTypePath {
if (dataTypeName == null || categoryPath == null) {
throw new IllegalArgumentException("null not allowed for categoryPath or datatypeName");
}
- this.categoryPath = categoryPath;
- this.dataTypeName = dataTypeName;
+ this.categoryPath = Objects.requireNonNull(categoryPath, "Category path cannot be null");
+ this.dataTypeName = Objects.requireNonNull(dataTypeName, "Data type name cannot be null");
}
/**
@@ -125,6 +127,15 @@ public class DataTypePath {
return true;
}
+ @Override
+ public int compareTo(DataTypePath other) {
+ int result = categoryPath.compareTo(other.categoryPath);
+ if (result == 0) {
+ result = dataTypeName.compareTo(other.dataTypeName);
+ }
+ return result;
+ }
+
@Override
public String toString() {
return getPath();