-
Notifications
You must be signed in to change notification settings - Fork 56
Class Position
Ori Roth edited this page Apr 2, 2017
·
3 revisions
public final class Position implements Comparable<Position>, Serializable, Checkable {
/*
* Forge (1)
*/
Position(int line, int column);
/*
* Type (11)
*/
final int line;
final int column;
void invariant();
String toString();
boolean equals(Object o);
boolean equals(Position p);
int hashCode();
int compareTo(Position p);
boolean before(Position p);
Position nextColumn();
Position nextLine();
}
Code
// SSDLPedia
package il.ac.technion.cs.ssdl.parsing;
import static il.ac.technion.cs.ssdl.utils.DBC.nonnegative;
import il.ac.technion.cs.ssdl.stereotypes.Immutable;
import il.ac.technion.cs.ssdl.stereotypes.Instantiable;
import il.ac.technion.cs.ssdl.utils.DBC.Checkable;
import java.io.Serializable;
/**
* An immutable class to model a position in a text file, including a column and
* line number.
*
* Author: Yossi Gil @since 13/06/2007
*/
@Immutable @Instantiable public final class Position implements Comparable<Position>, Serializable, Checkable {
/**
* The line of this position. First line is 0.
*/
public final int line;
/**
* The column of this position. First column is 0.
*/
public final int column;
@Override public void invariant() {
nonnegative(line);
nonnegative(column);
}
@Override public String toString() {
return "(" + line + ":" + column + ")";
}
/**
* Create a new instance
*
* line a non-negative integer specifying the line of this position
* column non-negative integer specifying the column of this position
*/
public Position(final int line, final int column) {
this.line = line;
this.column = column;
}
@Override public boolean equals(final Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
return equals((Position) o);
}
/**
* Determine whether two positions are the same
*
* p a position to compare with
* Return: true iff both positions are the same
*/
public boolean equals(final Position p) {
if (p == null)
return false;
return column == p.column && line == p.line;
}
@Override public int hashCode() {
return line ^ column >>> 1;
}
@Override public int compareTo(final Position p) {
return line != p.line ? line - p.line : column - p.column;
}
/**
* Total Inspector: Determine whether one position occurs before another.
*
* p a position to compare with
* Return: true iff this position occurs prior to
* p
*/
public boolean before(final Position p) {
return compareTo(p) < 0;
}
/**
* Compute the next position
*
* Return: a new Position object, representing the next character
* position.
*/
public Position nextColumn() {
return new Position(line, column + 1);
}
/**
* Compute the position of the next line
*
* Return: a new Position object, representing the first character
* in the next line.
*/
public Position nextLine() {
return new Position(line + 1, 0);
}
private static final long serialVersionUID = -9094620074260625651L;
}
Metric | Value | Acronym | Explanation |
---|---|---|---|
LOC | 108 | Lines Of Code | Total number of lines in the code |
SCC | 24 | SemiColons Count | Total number of semicolon tokens found in the code. |
NOT | 362 | Number Of Tokens | Comments, whitespace and text which cannot be made into a token not included. |
VCC | 2195 | Visible Characters Count | The total number of non-white (i.e., not space, tab, newline, carriage return, form feed) characters. |
CCC | 1246 | Code Characters Count | Total number of non-white characters in tokens. White space characters in string and character literals are not counted. |
UIC | 34 | Unique Identifiers Count | The number of different identifiers found in the code |
WHC | 3 | Weighted Horizontal Complexity | A heuritistic on horizontal complexity |
Statistic | Value |
---|---|
Average token length | 3.4 |
Tokens/line | 3.4 |
Visible characters/line | 20 |
Code characters/line | 12 |
Semicolons/tokens | 6% |
Comment text percentage | 43% |
Token Kind Occurrences | |
---|---|
KEYWORD | 69 |
OPERATOR | 27 |
LITERAL | 9 |
ID | 120 |
PUNCTUATION | 137 |
COMMENT | 9 |
OTHER | 200 |