Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.anadix.html;

Representation of position of a character in document. It offers two variations: Either the position of a character or as a line, column pair. Please note that both representations at once are not supported.

Author(s):
tomason
Version:
$Id: $
 
 public class Position {
 	private final int characterNumber;
 	private final int lineNumber;
 	private final int columnNumber;

Constructor

Parameters:
characterNumber number of a character in document
 
 	public Position(int characterNumber) {
 		this(characterNumber, -1, -1);
 	}

Constructor

Parameters:
lineNumber number of line character is on
columnNumber number of column character is on
 
 	public Position(int lineNumberint columnNumber) {
 		this(-1, lineNumbercolumnNumber);
 	}
 
 	private Position(int characterNumberint lineNumberint columnNumber) {
 		this. = characterNumber;
 		this. = lineNumber;
 		this. = columnNumber;
 	}

Gets the character number from the beginning of the document

Returns:
character number or -1 if line, column pair is used
 
 	public int getCharacterNumber() {
 		return ;
 	}

Gets the line number

Returns:
line number or -1 if character number is used
 
 	public int getLineNumber() {
 		return ;
 	}

Gets the column number

Returns:
column number or -1 if character number is used
 
 	public int getColumnNumber() {
 		return ;
 	}

 
 	public int hashCode() {
 		final int prime = 2011;
 		int result = 1;
 		result = prime * result + ;
 		result = prime * result + ;
 		result = prime * result + ;
 		return result;
 	}

 
 	public boolean equals(Object obj) {
 		if (this == obj)
 			return true;
 		if (obj == null)
 			return false;
 		if (getClass() != obj.getClass())
 			return false;
 		Position other = (Positionobj;
 		if ( != other.characterNumber)
 			return false;
 		if ( != other.columnNumber)
 			return false;
 		if ( != other.lineNumber)
 			return false;
 		return true;
 	}

 
	public String toString() {
		if ( > 0) {
			return Integer.toString();
else {
			return String.format("[%s, %s]");
		}
	}
New to GrepCode? Check out our FAQ X