Path
References[IoId("00000000-4edf-4b84-8cc9-4112a11949d4")]
public sealed class Path : IComparable<Path>, IEquatable<Path>, IStorable
Paths are used to identify twigs in data trees. Paths are ordered, immutable collections of non-negative integers.
Constructors
Path
#Create a new instance of TreePath based on a collection of indices.
Parameters:
| pathElements (IEnumerable<int>) | Indices that define this path. |
Fields
Properties
Indexers
Methods
AllUnique
#Check whether a collection of paths has any collisions.
Parameters:
| paths (IEnumerable<Path>) | Paths to test. |
Returns: True if all paths are unique.
AppendElement
#Create a new path by appending a new rule to this path.
Parameters:
| element (int) | Element to append. |
Returns: A new path.
CompareTo
#Compare this path to another one.
Parameters:
| other (Path) | Path to compare to. |
Returns: Sort order for these two paths.
Contains
#Test to see if this path contains the specified elements.
Parameters:
| elements (params int[]) | Elements to test. |
Returns: True if the path contains the specified elements, false if it doesn't.
CountElements
#Count the number of times this path contains elements in the given range.
CountElements
#Count the number of times this path contains the given element.
Parameters:
| value (int) | Value to test. |
Returns: Number of occurences of value.
EndsWith
#Test to see if this path ends with the specified elements.
Parameters:
| elements (params int[]) | Elements to test. |
Returns: True if the path ends with the specified elements, false if it doesn't.
Equals
#Test this path for equality with another path.
Parameters:
| obj (object) | Object to compare with. |
Returns: True if this path is equal to the other path.
Overrides: Object.Equals
Equals
#Implementation of the IEquatable interface for Path.
Parameters:
| other (Path) | Path to equate. |
Returns: True if this path is equatable with the given path.
EstimateNextPath
#Try and estimate the most sensible addition to a list of paths.
Parameters:
| paths (IEnumerable<Path>) | Collection of paths. |
Returns: Path that seems to be a sensible continuation of the collection.
EstimateNextPath
#Try and estimate the most sensible addition to a list of paths.
Parameters:
| paths (params Path[]) | Collection of paths. |
Returns: Path that seems to be a sensible continuation of the collection.
FindReplace
#Replace specific elements in this path with other elements.
FindReplace
#Replace specific elements in this path with other elements.
FormatPathLikeString
#Format a collection of strings as a path.
Parameters:
| elements (IEnumerable<string>) | Path elements to format. |
| pathOpenSymbol (string) | Text to use as an opening symbol. The recommended symbol is a curly opening brace. |
| pathCloseSymbol (string) | Text to use as a closing symbol. The recommended symbol is a curly closing brace. |
| pathSeparatorSymbol (string) | Text to use as a separator symbol. The recommended symbol is a semi-colon. |
Returns: Formatted string.
FormatPathLikeString
#Format a collection of strings as a path.
Parameters:
| elements (IEnumerable<string>) | Path elements to format. |
Returns: Formatted string.
GetHashCode
#Compute the hash code for this path.
Returns: The hash of this path.
Overrides: Object.GetHashCode
Increment
#Increment this path by one. The rightmost non-zero value is incremented, or, if all values are zero, the rightmost value is set to 1.
Returns: Incremented path.
Increment
#Increment this path by some constant. The rightmost non-zero value is incremented, or, if all values are zero, the rightmost value is set to 'amount'.
Parameters:
| amount (int) |
Returns: Incremented path.
IndexOf
#Finds the first occurance of a string of integers within the path.
IndexOf
#Finds the first occurance of a string of integers within the path.
Parameters:
| elements (params int[]) | Elements to test for. |
Returns: Index of first occurance, or -1 if the elements do not occur in the path.
MakeUnique
#Make sure the current path is unique amongst a collection of paths.
Parameters:
| paths (IEnumerable<Path>) | Paths to compare to. |
Returns: Path which resembles the current path as best as possible but which is unique within the set of given paths.
Offset
#Offset an element in this path
PadLeft
#Pad a pad on the leading edge until it reaches a certain length.
PadRight
#Pad a pad on the trailing edge until it reaches a certain length.
ParsePattern
#Try and parse a string that may represent some sort of path notation, yielding a view of each element and of the item.
Nothing is said about what the elements contain, so this reads the wildcards and expressions of path mapping as readily as it reads the whole numbers of a data path.
Parameters:
| text (string) | Text to parse. |
PrependElement
#Create a new path by prepending a new rule to this path.
Parameters:
| element (int) | Element to prepend. |
Returns: A new path.
RemoveElements
#Remove all elements that are between two extremes.
RemoveElements
#Remove all elements that have a specific value.
Parameters:
| value (int) | Value to remove. |
Returns: Path without specified elements or {0} if the path ends up being empty.
RemoveFirstElement
#Create a new path by removing the first element from this path.
Parameters:
| count (int = 1) |
Returns: A new path or null if this path only contains a single rule.
RemoveLastElement
#Create a new path by removing the last rule from this path.
Returns: A new path or null if this path only contains a single rule.
Replace
#Replace a specific element in this path with another.
ReplaceLastElement
#Replaces the last element in this path with a different value.
Parameters:
| newValue (int) | New value. |
Returns: Adjusted path.
StartsWith
#Test to see if this path starts with the specified elements.
Parameters:
| elements (params int[]) | Elements to test. |
Returns: True if the path starts with the specified elements, false if it doesn't.
SubPath
#Create a path that is a subset of this path.
SwapElements
#Create a new path by swapping two elements in this path.
ToArray
#Get a copy of the elements in this path.
Returns: An array containing all the elements in this path.
ToString
#Get the string representation of this path.
Returns: A string describing the path.
Overrides: Object.ToString
ToString
#Get the string representation of this path.
Parameters:
| pathOpenSymbol (string) | Symbol representing the path start. Curly open bracket is recommended for consistency. |
| pathCloseSymbol (string) | Symbol representing the path end. Curly close bracket is recommended for consistency. |
| pathSeparatorSymbol (string) | Symbol to be inserted in between path elements. Semi-colon is recommended for consistency. |
Returns: A string representation of this path.
Operators
| Operation | Result | Description | ||
|---|---|---|---|---|
| int | + | Path | Path | Prepend an item to a path. |
| Path | + | Path | Path | Combine two paths. |
| Path | + | int | Path | Append an item to a path. |
| Path | == | Path | bool | Compare two Path instances for equality. |
| Path | > | Path | bool | Test whether A is larger than B. |
| Path | >= | Path | bool | Test whether A is larger than or equal to B. |
| Path | != | Path | bool | Compare two Path instances for inequality. |
| Path | < | Path | bool | Test whether A is smaller than B. |
| Path | <= | Path | bool | Test whether A is smaller than or equal to B. |
| Path | * | int | Path | Multiply each index in this path by the given factor. |
Convertors
| Operation | Result | Description | ||
|---|---|---|---|---|
| implicit | Path | int[] | Convert a path to an integer array. | |
| implicit | (int a, int b, int c, int d, int e, int f) | Path | Create a path from a tuple with six elements. | |
| implicit | (int a, int b, int c, int d, int e) | Path | Create a path from a tuple with five elements. | |
| implicit | (int a, int b, int c, int d) | Path | Create a path from a tuple with four elements. | |
| implicit | (int a, int b, int c) | Path | Create a path from a tuple with three elements. | |
| implicit | (int a, int b) | Path | Create a path from a tuple with two elements. | |
| implicit | int | Path | Create a path from a single integer. | |