Package ghidra.program.model.data
Class CategoryPath
- java.lang.Object
-
- ghidra.program.model.data.CategoryPath
-
- All Implemented Interfaces:
java.lang.Comparable<CategoryPath>
public class CategoryPath extends java.lang.Object implements java.lang.Comparable<CategoryPath>
A category path is the full path to a particular data type
-
-
Field Summary
Fields Modifier and Type Field Description static char
DELIMITER_CHAR
static java.lang.String
DELIMITER_STRING
static java.lang.String
ESCAPED_DELIMITER_STRING
static CategoryPath
ROOT
-
Constructor Summary
Constructors Constructor Description CategoryPath(CategoryPath parent, java.lang.String... subPathElements)
Construct a CategoryPath from a parent and a hierarchical array of strings where each string is the name of a category in the category path.CategoryPath(CategoryPath parent, java.util.List<java.lang.String> subPathElements)
Construct a CategoryPath from a parent and a hierarchical list of strings where each string is the name of a category in the category path.CategoryPath(java.lang.String path)
Creates a category path given a forward-slash-delimited string (e.g.,"/aa/bb"
).
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String[]
asArray()
Returns a hierarchical array of names of the categories in the category path, starting with the name just below theROOT
category.java.util.List<java.lang.String>
asList()
Returns a hierarchical list of names of the categories in the category path, starting with the name just below theROOT
category.int
compareTo(CategoryPath other)
boolean
equals(java.lang.Object obj)
static java.lang.String
escapeString(java.lang.String nonEscapedString)
Converts a non-escaped String into an escaped string suitable for being passed in as a component of a single category path string to the constructor that takes a single escaped category path string.java.lang.String
getName()
Return the terminating name of this category path.CategoryPath
getParent()
Return the parent category path.java.lang.String
getPath()
Return theString
representation of this category path including the category name, where components are delimited with a forward slash.java.lang.String[]
getPathElements()
Returns array of names in category path.int
hashCode()
boolean
isAncestorOrSelf(CategoryPath candidateAncestorPath)
Tests if the specified categoryPath is the same as, or an ancestor of, this category path.boolean
isRoot()
Determine if this category path corresponds to the root categoryjava.lang.String
toString()
static java.lang.String
unescapeString(java.lang.String escapedString)
Converts an escaped String suitable for being passed in as a component of a single category path string into an non-escaped string.
-
-
-
Field Detail
-
DELIMITER_CHAR
public static final char DELIMITER_CHAR
- See Also:
- Constant Field Values
-
DELIMITER_STRING
public static final java.lang.String DELIMITER_STRING
- See Also:
- Constant Field Values
-
ESCAPED_DELIMITER_STRING
public static final java.lang.String ESCAPED_DELIMITER_STRING
- See Also:
- Constant Field Values
-
ROOT
public static final CategoryPath ROOT
-
-
Constructor Detail
-
CategoryPath
public CategoryPath(CategoryPath parent, java.lang.String... subPathElements)
Construct a CategoryPath from a parent and a hierarchical array of strings where each string is the name of a category in the category path.- Parameters:
parent
- the parent CategoryPath. ChooseROOT
if needed.subPathElements
- the array of names of sub-categories of the parent.- Throws:
java.lang.IllegalArgumentException
- if the given array is null or empty.
-
CategoryPath
public CategoryPath(CategoryPath parent, java.util.List<java.lang.String> subPathElements)
Construct a CategoryPath from a parent and a hierarchical list of strings where each string is the name of a category in the category path.- Parameters:
parent
- the parent CategoryPath. ChooseROOT
if needed.subPathElements
- the hierarchical array of sub-categories of the parent.- Throws:
java.lang.IllegalArgumentException
- if the given list is null or empty.
-
CategoryPath
public CategoryPath(java.lang.String path)
Creates a category path given a forward-slash-delimited string (e.g.,"/aa/bb"
). If an individual path component has one or more '/' characters in it, then it can be escaped using theescapeString(String)
utility method. TheunescapeString(String)
method can be used to unescape an individual component.Refrain from using this constructor in production code, and instead use one of the other constructors that does not require escaping. Situations where using this constructor is OK is in simple cases where a literal is passed in, such as in testing methods or in scripts.
- Parameters:
path
- category path string, delimited with '/' characters where individual components may have '/' characters escaped. Must start with the '/' character.
-
-
Method Detail
-
escapeString
public static java.lang.String escapeString(java.lang.String nonEscapedString)
Converts a non-escaped String into an escaped string suitable for being passed in as a component of a single category path string to the constructor that takes a single escaped category path string. The user is responsible for constructing the single category path string from the escaped components.- Parameters:
nonEscapedString
- String that might need escaping for characters used for delimiting- Returns:
- escaped String
- See Also:
unescapeString(String)
-
unescapeString
public static java.lang.String unescapeString(java.lang.String escapedString)
Converts an escaped String suitable for being passed in as a component of a single category path string into an non-escaped string.- Parameters:
escapedString
- String that might need unescaping for characters used for delimiting- Returns:
- non-escaped String
- See Also:
escapeString(String)
-
isRoot
public boolean isRoot()
Determine if this category path corresponds to the root category- Returns:
- true if this is a root category path
-
getParent
public CategoryPath getParent()
Return the parent category path.- Returns:
- the parent
-
getName
public java.lang.String getName()
Return the terminating name of this category path.- Returns:
- the name
-
getPath
public java.lang.String getPath()
Return theString
representation of this category path including the category name, where components are delimited with a forward slash. Any component that contains a forward slash will be have the forward slash characters escaped.- Returns:
- the full category path
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
isAncestorOrSelf
public boolean isAncestorOrSelf(CategoryPath candidateAncestorPath)
Tests if the specified categoryPath is the same as, or an ancestor of, this category path.- Parameters:
candidateAncestorPath
- the category path to be checked.- Returns:
- true if the given path is the same as, or an ancestor of, this category path.
-
getPathElements
public java.lang.String[] getPathElements()
Returns array of names in category path.- Returns:
- array of names
-
compareTo
public int compareTo(CategoryPath other)
- Specified by:
compareTo
in interfacejava.lang.Comparable<CategoryPath>
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
asList
public java.util.List<java.lang.String> asList()
Returns a hierarchical list of names of the categories in the category path, starting with the name just below theROOT
category.- Returns:
- a hierarchical list of names of the category in the category path.
-
asArray
public java.lang.String[] asArray()
Returns a hierarchical array of names of the categories in the category path, starting with the name just below theROOT
category.- Returns:
- a hierarchical array of names of the categories in the category path.
-
-