- java.lang.Object
-
- com.googlecode.lanterna.TerminalPosition
-
- All Implemented Interfaces:
java.lang.Comparable<TerminalPosition>
public class TerminalPosition extends java.lang.Object implements java.lang.Comparable<TerminalPosition>
A 2-d position in 'terminal space'. Please note that the coordinates are 0-indexed, meaning 0x0 is the top left corner of the terminal. This object is immutable so you cannot change it after it has been created. Instead, you can easily create modified 'clones' by using the 'with' methods.
-
-
Field Summary
Fields Modifier and Type Field Description private int
column
static TerminalPosition
OFFSET_1x1
Constant for the 1x1 position (one offset in both directions from top-left)private int
row
static TerminalPosition
TOP_LEFT_CORNER
Constant for the top-left corner (0x0)
-
Constructor Summary
Constructors Constructor Description TerminalPosition(int column, int row)
Creates a new TerminalPosition object, which represents a location on the screen.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TerminalPosition
abs()
int
compareTo(TerminalPosition o)
TerminalPosition
divide(TerminalPosition denominator)
boolean
equals(int columnIndex, int rowIndex)
boolean
equals(java.lang.Object obj)
int
getColumn()
Returns the index of the column this position is representing, zero indexed (the first column has index 0).int
getRow()
Returns the index of the row this position is representing, zero indexed (the first row has index 0)int
hashCode()
TerminalPosition
max(TerminalPosition position)
TerminalPosition
min(TerminalPosition position)
TerminalPosition
minus(TerminalPosition position)
TerminalPosition
multiply(TerminalPosition position)
TerminalPosition
plus(TerminalPosition position)
java.lang.String
toString()
TerminalPosition
with(TerminalPosition position)
Returns itself if it is equal to the supplied position, otherwise the supplied position.TerminalPosition
withColumn(int column)
Creates a new TerminalPosition object representing a position with the same row index as this but with a supplied column index.TerminalPosition
withRelative(int deltaColumn, int deltaRow)
Creates a new TerminalPosition object that is 'translated' by an amount of rows and columns specified by the two parameters.TerminalPosition
withRelative(TerminalPosition translate)
Creates a new TerminalPosition object that is 'translated' by an amount of rows and columns specified by another TerminalPosition.TerminalPosition
withRelativeColumn(int delta)
Creates a new TerminalPosition object representing a position on the same row, but with a column offset by a supplied value.TerminalPosition
withRelativeRow(int delta)
Creates a new TerminalPosition object representing a position on the same column, but with a row offset by a supplied value.TerminalPosition
withRow(int row)
Creates a new TerminalPosition object representing a position with the same column index as this but with a supplied row index.
-
-
-
Field Detail
-
TOP_LEFT_CORNER
public static final TerminalPosition TOP_LEFT_CORNER
Constant for the top-left corner (0x0)
-
OFFSET_1x1
public static final TerminalPosition OFFSET_1x1
Constant for the 1x1 position (one offset in both directions from top-left)
-
row
private final int row
-
column
private final int column
-
-
Constructor Detail
-
TerminalPosition
public TerminalPosition(int column, int row)
Creates a new TerminalPosition object, which represents a location on the screen. There is no check to verify that the position you specified is within the size of the current terminal and you can specify negative positions as well.- Parameters:
column
- Column of the location, or the "x" coordinate, zero indexed (the first column is 0)row
- Row of the location, or the "y" coordinate, zero indexed (the first row is 0)
-
-
Method Detail
-
getColumn
public int getColumn()
Returns the index of the column this position is representing, zero indexed (the first column has index 0).- Returns:
- Index of the column this position has
-
getRow
public int getRow()
Returns the index of the row this position is representing, zero indexed (the first row has index 0)- Returns:
- Index of the row this position has
-
withRow
public TerminalPosition withRow(int row)
Creates a new TerminalPosition object representing a position with the same column index as this but with a supplied row index.- Parameters:
row
- Index of the row for the new position- Returns:
- A TerminalPosition object with the same column as this but with a specified row index
-
withColumn
public TerminalPosition withColumn(int column)
Creates a new TerminalPosition object representing a position with the same row index as this but with a supplied column index.- Parameters:
column
- Index of the column for the new position- Returns:
- A TerminalPosition object with the same row as this but with a specified column index
-
withRelativeColumn
public TerminalPosition withRelativeColumn(int delta)
Creates a new TerminalPosition object representing a position on the same row, but with a column offset by a supplied value. Calling this method with delta 0 will return this, calling it with a positive delta will return a terminal position delta number of columns to the right and for negative numbers the same to the left.- Parameters:
delta
- Column offset- Returns:
- New terminal position based off this one but with an applied offset
-
withRelativeRow
public TerminalPosition withRelativeRow(int delta)
Creates a new TerminalPosition object representing a position on the same column, but with a row offset by a supplied value. Calling this method with delta 0 will return this, calling it with a positive delta will return a terminal position delta number of rows to the down and for negative numbers the same up.- Parameters:
delta
- Row offset- Returns:
- New terminal position based off this one but with an applied offset
-
withRelative
public TerminalPosition withRelative(TerminalPosition translate)
Creates a new TerminalPosition object that is 'translated' by an amount of rows and columns specified by another TerminalPosition. Same as callingwithRelativeRow(translate.getRow()).withRelativeColumn(translate.getColumn())
- Parameters:
translate
- How many columns and rows to translate- Returns:
- New TerminalPosition that is the result of the original with added translation
-
withRelative
public TerminalPosition withRelative(int deltaColumn, int deltaRow)
Creates a new TerminalPosition object that is 'translated' by an amount of rows and columns specified by the two parameters. Same as callingwithRelativeRow(deltaRow).withRelativeColumn(deltaColumn)
- Parameters:
deltaColumn
- How many columns to move from the current position in the new TerminalPositiondeltaRow
- How many rows to move from the current position in the new TerminalPosition- Returns:
- New TerminalPosition that is the result of the original position with added translation
-
with
public TerminalPosition with(TerminalPosition position)
Returns itself if it is equal to the supplied position, otherwise the supplied position. You can use this if you have a position field which is frequently recalculated but often resolves to the same; it will keep the same object in memory instead of swapping it out every cycle.- Parameters:
position
- Position you want to return- Returns:
- Itself if this position equals the position passed in, otherwise the position passed in
-
plus
public TerminalPosition plus(TerminalPosition position)
-
minus
public TerminalPosition minus(TerminalPosition position)
-
multiply
public TerminalPosition multiply(TerminalPosition position)
-
divide
public TerminalPosition divide(TerminalPosition denominator)
-
abs
public TerminalPosition abs()
-
min
public TerminalPosition min(TerminalPosition position)
-
max
public TerminalPosition max(TerminalPosition position)
-
compareTo
public int compareTo(TerminalPosition o)
- Specified by:
compareTo
in interfacejava.lang.Comparable<TerminalPosition>
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(int columnIndex, int rowIndex)
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
-