GP-3529 - Make DataTypePath comparable

This commit is contained in:
ghizard 2023-06-09 11:19:39 -04:00
parent bc0bcbe985
commit 5125814a3e

View file

@ -15,11 +15,13 @@
*/ */
package ghidra.program.model.data; 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 * 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. * the datatype name can contain a categoryPath delimiter ("/") character.
*/ */
public class DataTypePath { public class DataTypePath implements Comparable<DataTypePath> {
private final CategoryPath categoryPath; private final CategoryPath categoryPath;
private final String dataTypeName; private final String dataTypeName;
@ -43,8 +45,8 @@ public class DataTypePath {
if (dataTypeName == null || categoryPath == null) { if (dataTypeName == null || categoryPath == null) {
throw new IllegalArgumentException("null not allowed for categoryPath or datatypeName"); throw new IllegalArgumentException("null not allowed for categoryPath or datatypeName");
} }
this.categoryPath = categoryPath; this.categoryPath = Objects.requireNonNull(categoryPath, "Category path cannot be null");
this.dataTypeName = dataTypeName; this.dataTypeName = Objects.requireNonNull(dataTypeName, "Data type name cannot be null");
} }
/** /**
@ -125,6 +127,15 @@ public class DataTypePath {
return true; 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 @Override
public String toString() { public String toString() {
return getPath(); return getPath();