Package ch.usi.si.seart.treesitter
Class Point
- java.lang.Object
-
- ch.usi.si.seart.treesitter.Point
-
- All Implemented Interfaces:
Comparable<Point>
public class Point extends Object implements Comparable<Point>
Represents a two-dimensional point with row and column coordinates. Points are an alternative to byte ranges, and as such are used to represent more human-friendly positions of tree nodes within source code. Although node positions within files should never be negative, instances of this class can be created with negative row and column values for other purposes, such as denoting repositioning offsets.- Since:
- 1.0.0
- Author:
- Ozren Dabić
-
-
Constructor Summary
Constructors Constructor Description Point()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Pointadd(@NotNull Point other)Adds another point to this point, resulting in a new point with coordinates equal to the sum of the coordinates of this point and the other point.intcompareTo(@NotNull Point other)Compares this point with another point for positional order.booleanisOrigin()Checks if this point represents the origin, which is when both the row and the column are zero.Pointmultiply(int value)Multiplies the coordinates of this point by a scalar value, resulting in a new point with scaled coordinates.Pointsubtract(@NotNull Point other)Subtracts another point from this point, resulting in a new point with coordinates equal to the difference between the coordinates of this point and the other point.StringtoString()Returns a string representation of this point in the format:
-
-
-
Method Detail
-
toString
public String toString()
Returns a string representation of this point in the format:row:column
-
isOrigin
public boolean isOrigin()
Checks if this point represents the origin, which is when both the row and the column are zero. In byte range terms, this point also corresponds to zero.- Returns:
- true if this is an origin point, false otherwise
-
compareTo
public int compareTo(@NotNull @NotNull Point other)Compares this point with another point for positional order. Points are compared by their row coordinates first, and if those are equal they are then compared by their column coordinates.- Specified by:
compareToin interfaceComparable<Point>- Parameters:
other- the object to be compared- Returns:
- the row comparison result, or the column comparison result if the rows are equal
- Throws:
NullPointerException- if the other point is null- Since:
- 1.5.1
-
add
public Point add(@NotNull @NotNull Point other)
Adds another point to this point, resulting in a new point with coordinates equal to the sum of the coordinates of this point and the other point.- Parameters:
other- The point to be added to this point- Returns:
- A new point representing the sum of this point and the other point
- Throws:
NullPointerException- ifotheris null- Since:
- 1.5.1
-
subtract
public Point subtract(@NotNull @NotNull Point other)
Subtracts another point from this point, resulting in a new point with coordinates equal to the difference between the coordinates of this point and the other point.- Parameters:
other- The point to be subtracted from this point- Returns:
- A new point representing the difference between this point and the other point
- Throws:
NullPointerException- ifotheris null- Since:
- 1.5.1
-
multiply
public Point multiply(int value)
Multiplies the coordinates of this point by a scalar value, resulting in a new point with scaled coordinates.- Parameters:
value- The scalar value by which to multiply the coordinates of this point- Returns:
- A new point representing the scaled coordinates
- Since:
- 1.5.1
-
-