[DEV] add filePos and many tools

This commit is contained in:
Edouard DUPIN 2022-05-11 00:51:20 +02:00
parent 05cbe51a47
commit 0483c2e661
6 changed files with 731 additions and 34 deletions

View File

@ -48,6 +48,14 @@ public record Dimension1f(
this.type = type;
}
public Dimension1f withSize(final float size) {
return new Dimension1f(size, this.type);
}
public Dimension1f withType(final Distance type) {
return new Dimension1f(this.size, type);
}
/**
* get the current dimension in pixel
* @return dimension in Pixel
@ -88,7 +96,7 @@ public record Dimension1f(
* @param config dimension configuration.
*/
public static Dimension1f valueOf(String config) {
Distance type = Distance.parseEndSmallString(config);
final Distance type = Distance.parseEndSmallString(config);
config = type.removeEndString(config);
if (type == Distance.UNKNOW) {
Log.critical("Can not parse dimension : '" + config + "'");

View File

@ -42,6 +42,14 @@ public record Dimension2f(
windowsSize = new Dimension2f(new Vector2f(200, 200), Distance.PIXEL);
}
public Dimension2f withSize(final Vector2f size) {
return new Dimension2f(size, this.type);
}
public Dimension2f withType(final Distance type) {
return new Dimension2f(this.size, type);
}
/**
* get the Windows diagonal size in the request unit
* @param type Unit type requested.
@ -200,7 +208,7 @@ public record Dimension2f(
}
public Vector2i getPixeli() {
Vector2f tmpSize = windowsSize.getPixel();
final Vector2f tmpSize = windowsSize.getPixel();
return getPixeli(new Vector2i((int) tmpSize.x(), (int) tmpSize.y()));
}
@ -241,7 +249,7 @@ public record Dimension2f(
* @param config dimension configuration.
*/
public static Dimension2f valueOf(String config) {
Distance type = Distance.parseEndSmallString(config);
final Distance type = Distance.parseEndSmallString(config);
config = type.removeEndString(config);
if (type == Distance.UNKNOW) {
Log.critical("Can not parse dimension : '" + config + "'");
@ -261,14 +269,14 @@ public record Dimension2f(
return get(getType()).toString() + getType().toSmallString();
}
public static Dimension2f valueOf(String contentX, String contentY) {
Distance typeX = Distance.parseEndSmallString(contentX);
public static Dimension2f valueOf(String contentX, final String contentY) {
final Distance typeX = Distance.parseEndSmallString(contentX);
contentX = typeX.removeEndString(contentX);
float tmpX = Float.valueOf(contentX);
final float tmpX = Float.valueOf(contentX);
Distance typeY = Distance.parseEndSmallString(contentY);
final Distance typeY = Distance.parseEndSmallString(contentY);
contentX = typeY.removeEndString(contentY);
float tmpY = Float.valueOf(contentY);
final float tmpY = Float.valueOf(contentY);
if (typeX != Distance.UNKNOW) {
return new Dimension2f(new Vector2f(tmpX, tmpY), typeX);

View File

@ -200,7 +200,7 @@ public record Dimension3f(
}
public Vector2i getPixeli() {
Vector3f tmpSize = windowsSize.getPixel();
final Vector3f tmpSize = windowsSize.getPixel();
return getPixeli(new Vector2i((int) tmpSize.x(), (int) tmpSize.y()));
}
@ -241,7 +241,7 @@ public record Dimension3f(
* @param config dimension configuration.
*/
public static Dimension3f valueOf(String config) {
Distance type = Distance.parseEndSmallString(config);
final Distance type = Distance.parseEndSmallString(config);
config = type.removeEndString(config);
if (type == Distance.UNKNOW) {
Log.critical("Can not parse dimension : '" + config + "'");
@ -253,6 +253,14 @@ public record Dimension3f(
return ret;
}
public Dimension3f withSize(final Vector3f size) {
return new Dimension3f(size, this.type);
}
public Dimension3f withType(final Distance type) {
return new Dimension3f(this.size, type);
}
/**
* string cast :
*/
@ -261,19 +269,19 @@ public record Dimension3f(
return get(getType()).toString() + getType().toSmallString();
}
public static Dimension3f valueOf(String contentX, String contentY, String contentZ) {
public static Dimension3f valueOf(String contentX, final String contentY, final String contentZ) {
Distance typeX = Distance.parseEndSmallString(contentX);
final Distance typeX = Distance.parseEndSmallString(contentX);
contentX = typeX.removeEndString(contentX);
float tmpX = Float.valueOf(contentX);
final float tmpX = Float.valueOf(contentX);
Distance typeY = Distance.parseEndSmallString(contentY);
final Distance typeY = Distance.parseEndSmallString(contentY);
contentX = typeY.removeEndString(contentY);
float tmpY = Float.valueOf(contentY);
final float tmpY = Float.valueOf(contentY);
Distance typeZ = Distance.parseEndSmallString(contentZ);
final Distance typeZ = Distance.parseEndSmallString(contentZ);
contentX = typeZ.removeEndString(contentZ);
float tmpZ = Float.valueOf(contentZ);
final float tmpZ = Float.valueOf(contentZ);
if (typeX != Distance.UNKNOW) {
return new Dimension3f(new Vector3f(tmpX, tmpY, tmpZ), typeX);

View File

@ -1,8 +1,160 @@
package org.atriasoft.etk;
import org.atriasoft.etk.internal.Log;
import org.atriasoft.etk.util.FilePos;
public class Tools {
/**
* add indentation of the string input.
* @param data String where the indentation is done.
* @param indent Number of tab to add at the string.
*/
public static void addIndent(final StringBuilder data, final int indent) {
if (!data.isEmpty()) {
data.append("\n");
}
for (int iii = 0; iii < indent; iii++) {
data.append("\t");
}
}
/**
* check if an element or attribute is availlable (not : !"#$%&'()*+,/;<=>?@[\]^`{|}~ \\n\\t\\r and for first char : not -.0123456789).
* @param val Value to check the conformity.
* @param firstChar True if the element check is the first char.
* @return true The value can be a part of attribute name
* @return false The value can NOT be a part of attribute name
*/
public static boolean checkAvaillable(final Character val, final boolean firstChar) {
if (val == '!' || val == '"' || val == '#' || val == '$' || val == '%' || val == '&' || val == '\'' || val == '(' || val == ')' || val == '*' || val == '+' || val == ',' || val == '/'
|| val == ';' || val == '<' || val == '=' || val == '>' || val == '?' || val == '@' || val == '[' || val == '\\' || val == ']' || val == '^' || val == '`' || val == '{' || val == '|'
|| val == '}' || val == '~' || val == ' ' || val == '\n' || val == '\t' || val == '\r') {
return false;
}
if (firstChar) {
if (val == '-' || val == '.' || (val >= '0' && val <= '9')) {
return false;
}
}
return true;
}
public static boolean checkNumber(final Character val, final boolean firstChar) {
if (val == '.' || (val >= '0' && val <= '9')) {
return true;
}
if (firstChar && val == '-') {
return true;
}
return false;
}
public static String cleanNumberList(final String data) {
return data.replaceAll("[ \t\n\r]", "").replaceAll(",", ";");
}
/**
* count the number of white char in the string from the specify position (stop at the first element that is not a white char)
* @param data Data to parse.
* @param pos Start position in the string.
* @param filePos new poistion of te file to add.
* @return number of white element.
*/
public static int countWhiteChar(final String data, final int pos, final FilePos filePos) {
filePos.clear();
int white = 0;
for (int iii = pos; iii < data.length(); iii++) {
filePos.check(data.charAt(iii));
if (!Tools.isWhiteChar(data.charAt(iii))) {
break;
}
white++;
}
filePos.decrement();
return white;
}
public static String createPosPointer(final String line, final int pos) {
final StringBuilder out = new StringBuilder();
int iii;
for (iii = 0; iii < pos && iii < line.length(); iii++) {
if (line.charAt(iii) == '\t') {
out.append("\t");
} else {
out.append(" ");
}
}
for (; iii < pos; iii++) {
out.append(" ");
}
out.append("^");
return out.toString();
}
// based on this: https://stackoverflow.com/questions/4052840/most-efficient-way-to-make-the-first-character-of-a-string-lower-case
public static String decapitalizeFirst(final String string) {
if (string == null || string.length() == 0) {
return string;
}
final char[] c = string.toCharArray();
c[0] = Character.toLowerCase(c[0]);
return new String(c);
}
/**
* Display the current element that is currently parse.
* @param val Char that is parsed.
* @param filePos Position of the char in the file.
*/
public static void drawElementParsed(final Character val, final FilePos filePos) {
// if (val == '\n') {
// Log.error(filePos + " parse '\\n'");
// } else if (val == '\t') {
// Log.error(filePos + " parse '\\t'");
// } else {
// Log.error(filePos + " parse '" + val + "'");
// }
}
public static String extractLine(final String data, final int pos) {
// search back : '\n'
int startPos = data.lastIndexOf('\n', pos);
if (startPos == pos) {
startPos = 0;
} else {
startPos++;
}
// search forward : '\n'
int stopPos = pos;
if (data.length() == pos) {
stopPos = pos;
} else if (data.charAt(pos) != '\n') {
stopPos = data.indexOf('\n', pos);
if (stopPos == pos) {
stopPos = data.length();
}
}
if (startPos == -1) {
startPos = 0;
} else if (startPos >= data.length()) {
return "";
}
if (stopPos == -1) {
return "";
}
if (stopPos >= data.length()) {
stopPos = data.length();
}
return data.substring(startPos, stopPos);
}
public static boolean isWhiteChar(final Character val) {
if (val == ' ' || val == '\t' || val == '\n' || val == '\r') {
return true;
}
return false;
}
/**
* get the next power 2 if the input
* @param value Value that we want the next power of 2
@ -20,5 +172,341 @@ public class Tools {
return val;
}
public static Boolean[] parseBooleanClassStringList(String data) {
data = Tools.cleanNumberList(data);
final String[] dataArray = data.split(";");
final Boolean[] out = new Boolean[dataArray.length];
int count = 0;
for (final String str : dataArray) {
out[count++] = Boolean.valueOf(str);
}
return out;
}
public static boolean[] parseBooleanStringList(String data) {
data = Tools.cleanNumberList(data);
final String[] dataArray = data.split(";");
final boolean[] out = new boolean[dataArray.length];
int count = 0;
for (final String str : dataArray) {
out[count++] = Boolean.parseBoolean(str);
}
return out;
}
public static Byte[] parseByteClassStringList(String data) {
data = Tools.cleanNumberList(data);
final String[] dataArray = data.split(";");
final Byte[] out = new Byte[dataArray.length];
int count = 0;
for (final String str : dataArray) {
out[count++] = Byte.parseByte(str);
}
return out;
}
public static byte[] parseByteStringList(String data) {
data = Tools.cleanNumberList(data);
final String[] dataArray = data.split(";");
final byte[] out = new byte[dataArray.length];
int count = 0;
for (final String str : dataArray) {
out[count++] = Byte.parseByte(str);
}
return out;
}
public static Double[] parseDoubleClassStringList(String data) {
data = Tools.cleanNumberList(data);
final String[] dataArray = data.split(";");
final Double[] out = new Double[dataArray.length];
int count = 0;
for (final String str : dataArray) {
out[count++] = Double.parseDouble(str);
}
return out;
}
public static double[] parseDoubleStringList(String data) {
data = Tools.cleanNumberList(data);
final String[] dataArray = data.split(";");
final double[] out = new double[dataArray.length];
int count = 0;
for (final String str : dataArray) {
out[count++] = Double.parseDouble(str);
}
return out;
}
public static Float[] parseFloatClassStringList(String data) {
data = Tools.cleanNumberList(data);
final String[] dataArray = data.split(";");
final Float[] out = new Float[dataArray.length];
int count = 0;
for (final String str : dataArray) {
out[count++] = Float.parseFloat(str);
}
return out;
}
public static float[] parseFloatStringList(String data) {
data = Tools.cleanNumberList(data);
final String[] dataArray = data.split(";");
final float[] out = new float[dataArray.length];
int count = 0;
for (final String str : dataArray) {
out[count++] = Float.parseFloat(str);
}
return out;
}
public static Integer[] parseIntegerClassStringList(String data) {
data = Tools.cleanNumberList(data);
final String[] dataArray = data.split(";");
final Integer[] out = new Integer[dataArray.length];
int count = 0;
for (final String str : dataArray) {
out[count++] = Integer.parseInt(str);
}
return out;
}
public static int[] parseIntegerStringList(String data) {
data = Tools.cleanNumberList(data);
final String[] dataArray = data.split(";");
final int[] out = new int[dataArray.length];
int count = 0;
for (final String str : dataArray) {
out[count++] = Integer.parseInt(str);
}
return out;
}
public static Long[] parseLongClassStringList(String data) {
data = Tools.cleanNumberList(data);
final String[] dataArray = data.split(";");
final Long[] out = new Long[dataArray.length];
int count = 0;
for (final String str : dataArray) {
out[count++] = Long.parseLong(str);
}
return out;
}
public static long[] parseLongStringList(String data) {
data = Tools.cleanNumberList(data);
final String[] dataArray = data.split(";");
final long[] out = new long[dataArray.length];
int count = 0;
for (final String str : dataArray) {
out[count++] = Long.parseLong(str);
}
return out;
}
public static Short[] parseShortClassStringList(String data) {
data = Tools.cleanNumberList(data);
final String[] dataArray = data.split(";");
final Short[] out = new Short[dataArray.length];
int count = 0;
for (final String str : dataArray) {
out[count++] = Short.parseShort(str);
}
return out;
}
public static short[] parseShortStringList(String data) {
data = Tools.cleanNumberList(data);
final String[] dataArray = data.split(";");
final short[] out = new short[dataArray.length];
int count = 0;
for (final String str : dataArray) {
out[count++] = Short.parseShort(str);
}
return out;
}
// transform the Text with :
// "&lt;" == "<"
// "&gt;" == ">"
// "&amp;" == "&"
// "&apos;" == "'"
// "&quot;" == """
public static String replaceSpecialChar(final String inval) {
String out = inval;
out = out.replace("&lt;", "<");
out = out.replace("&gt;", ">");
out = out.replace("&apos;", "'");
out = out.replace("&quot;", "\"");
out = out.replace("&amp;", "&");
//EXMLERROR("INNN '"<< inval << "' => '" << out << "'");
return out;
}
public static String replaceSpecialCharOut(final String inval) {
String out = inval;
out = out.replace("<", "&lt;");
out = out.replace(">", "&gt;");
out = out.replace("'", "&apos;");
out = out.replace("\"", "&quot;");
out = out.replace("&", "&amp;");
//EXMLERROR("OUTTT '"<< inval << "' => '" << out << "'");
return out;
}
public static String toString(final boolean[] data) {
final StringBuilder out = new StringBuilder();
for (int iii = 0; iii < data.length; iii++) {
if (iii != 0) {
out.append(";");
}
out.append(data[iii]);
}
return out.toString();
}
public static String toString(final Boolean[] data) {
final StringBuilder out = new StringBuilder();
for (int iii = 0; iii < data.length; iii++) {
if (iii != 0) {
out.append(";");
}
out.append(data[iii]);
}
return out.toString();
}
public static String toString(final byte[] data) {
final StringBuilder out = new StringBuilder();
for (int iii = 0; iii < data.length; iii++) {
if (iii != 0) {
out.append(";");
}
out.append(data[iii]);
}
return out.toString();
}
public static String toString(final Byte[] data) {
final StringBuilder out = new StringBuilder();
for (int iii = 0; iii < data.length; iii++) {
if (iii != 0) {
out.append(";");
}
out.append(data[iii]);
}
return out.toString();
}
public static String toString(final double[] data) {
final StringBuilder out = new StringBuilder();
for (int iii = 0; iii < data.length; iii++) {
if (iii != 0) {
out.append(";");
}
out.append(data[iii]);
}
return out.toString();
}
public static String toString(final Double[] data) {
final StringBuilder out = new StringBuilder();
for (int iii = 0; iii < data.length; iii++) {
if (iii != 0) {
out.append(";");
}
out.append(data[iii]);
}
return out.toString();
}
public static String toString(final float[] data) {
final StringBuilder out = new StringBuilder();
for (int iii = 0; iii < data.length; iii++) {
if (iii != 0) {
out.append(";");
}
out.append(data[iii]);
}
return out.toString();
}
public static String toString(final Float[] data) {
final StringBuilder out = new StringBuilder();
for (int iii = 0; iii < data.length; iii++) {
if (iii != 0) {
out.append(";");
}
out.append(data[iii]);
}
return out.toString();
}
public static String toString(final int[] data) {
final StringBuilder out = new StringBuilder();
for (int iii = 0; iii < data.length; iii++) {
if (iii != 0) {
out.append(";");
}
out.append(data[iii]);
}
return out.toString();
}
public static String toString(final Integer[] data) {
final StringBuilder out = new StringBuilder();
for (int iii = 0; iii < data.length; iii++) {
if (iii != 0) {
out.append(";");
}
out.append(data[iii]);
}
return out.toString();
}
public static String toString(final long[] data) {
final StringBuilder out = new StringBuilder();
for (int iii = 0; iii < data.length; iii++) {
if (iii != 0) {
out.append(";");
}
out.append(data[iii]);
}
return out.toString();
}
public static String toString(final Long[] data) {
final StringBuilder out = new StringBuilder();
for (int iii = 0; iii < data.length; iii++) {
if (iii != 0) {
out.append(";");
}
out.append(data[iii]);
}
return out.toString();
}
public static String toString(final short[] data) {
final StringBuilder out = new StringBuilder();
for (int iii = 0; iii < data.length; iii++) {
if (iii != 0) {
out.append(";");
}
out.append(data[iii]);
}
return out.toString();
}
public static String toString(final Short[] data) {
final StringBuilder out = new StringBuilder();
for (int iii = 0; iii < data.length; iii++) {
if (iii != 0) {
out.append(";");
}
out.append(data[iii]);
}
return out.toString();
}
private Tools() {}
}

View File

@ -35,7 +35,7 @@ public class Uri {
}
public static void addLibrary(final String libName, final Class<?> classHandle, String basePath) {
Log.info("Add library reference: lib={} ==> {} base path={}", libName, classHandle.getCanonicalName(), basePath);
Log.verbose("Add library reference: lib={} ==> {} base path={}", libName, classHandle.getCanonicalName(), basePath);
if (basePath == null || basePath.isEmpty()) {
basePath = "/";
}
@ -108,11 +108,11 @@ public class Uri {
}
public static InputStream getStream(final Uri uri) {
Log.warning("Load resource: {}", uri);
Log.verbose("Load resource: {}", uri);
String offsetGroup = "";
if (uri.group != null) {
if (uri.group.equals("FILE")) {
Log.warning("Load resource direct file: {}", uri);
Log.verbose("Load resource direct file: {}", uri);
try {
return new FileInputStream(new File(uri.getPath()));
} catch (final FileNotFoundException e) {
@ -121,30 +121,30 @@ public class Uri {
return null;
}
}
Log.warning(" find group: {}", uri.group);
Log.verbose(" find group: {}", uri.group);
final String ret = Uri.genericMap.get(uri.group);
if (ret != null) {
Log.warning(" ==> {}", ret);
Log.verbose(" ==> {}", ret);
offsetGroup = ret;
}
}
InputStream out = null;
if (Uri.applicationClass == null) {
Log.warning(" !! Application data class is not defined ...");
Log.verbose(" !! Application data class is not defined ...");
} else {
String tmpPath = Uri.applicationBasePath + offsetGroup + uri.path;
tmpPath = tmpPath.replace("//", "/");
Log.info("(appl) Try to load '{}' in {}", tmpPath, Uri.applicationClass.getCanonicalName());// + " ==> " + applicationClass.getProtectionDomain().getCodeSource().getLocation().getPath());
Log.verbose("(appl) Try to load '{}' in {}", tmpPath, Uri.applicationClass.getCanonicalName());// + " ==> " + applicationClass.getProtectionDomain().getCodeSource().getLocation().getPath());
final URL realFileName = Uri.applicationClass.getClassLoader().getResource(tmpPath);
if (realFileName != null) {
Log.info("(appl) >>> {}", realFileName.getFile());
Log.verbose("(appl) >>> {}", realFileName.getFile());
} else {
Log.info("(appl) ??? base folder: {}", Uri.applicationClass.getProtectionDomain().getCodeSource().getLocation().getPath() + Uri.applicationBasePath + offsetGroup + uri.path);
Log.verbose("(appl) ??? base folder: {}", Uri.applicationClass.getProtectionDomain().getCodeSource().getLocation().getPath() + Uri.applicationBasePath + offsetGroup + uri.path);
}
out = Uri.applicationClass.getResourceAsStream(tmpPath);
if (out == null) {
Log.info("(appl) ==> element does not exist ...");
Log.verbose("(appl) ==> element does not exist ...");
// try {
// Log.warning("elements: " + getResourceFiles(applicationClass, applicationBasePath + offsetGroup + "/*.*"));
// } catch (IOException e) {
@ -156,12 +156,12 @@ public class Uri {
if (out == null) {
// search in the libraries ...
if (uri.properties.get("lib") == null) {
Log.warning(" !! No library specified");
Log.verbose(" !! No library specified");
return null;
}
final LibraryElement libraryElement = Uri.libraries.get(uri.properties.get("lib"));
if (libraryElement == null) {
Log.warning(" Can not get element in library");
Log.verbose(" Can not get element in library");
return null;
}
// try {
@ -172,23 +172,23 @@ public class Uri {
// }
String tmpPath = libraryElement.basePath + offsetGroup + uri.path;
tmpPath = tmpPath.replace("//", "/");
Log.info("(lib) Try to load '{}' in {}", tmpPath, libraryElement.klass.getCanonicalName());
Log.verbose("(lib) Try to load '{}' in {}", tmpPath, libraryElement.klass.getCanonicalName());
final URL realFileName = libraryElement.klass.getClassLoader().getResource(tmpPath);
if (realFileName != null) {
Log.info("(lib) >>> {}", realFileName.getFile());
Log.verbose("(lib) >>> {}", realFileName.getFile());
} else {
Log.info("(lib) ??? base folder: {}", libraryElement.klass.getProtectionDomain().getCodeSource().getLocation().getPath() + libraryElement.basePath + offsetGroup + uri.path);
Log.verbose("(lib) ??? base folder: {}", libraryElement.klass.getProtectionDomain().getCodeSource().getLocation().getPath() + libraryElement.basePath + offsetGroup + uri.path);
}
out = libraryElement.klass.getResourceAsStream(tmpPath);
if (out == null) {
Log.info("(lib) ==> element does not exist ...");
Log.verbose("(lib) ==> element does not exist ...");
}
}
if (out == null) {
Log.error("Can not load resource: '" + uri + "'");
} else {
Log.warning(" =====> DATA LOADED <====== ");
Log.verbose(" =====> DATA LOADED <====== ");
}
return out;
}

View File

@ -0,0 +1,185 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package org.atriasoft.etk.util;
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
/**
* Position in the file of the original data.
*/
public class FilePos {
private int col; //!< source text colomn
private int line; //!< source Line colomn
/**
* default contructor (set line and col at 0)
*/
public FilePos() {
this.col = 0;
this.line = 0;
}
/**
* initialize constructor
* @param line Line in the file
* @param col Colomn in the file
*/
public FilePos(final int line, final int col) {
this.col = col;
this.line = line;
}
/**
* Addition operator
* @param obj Addition object..
* @return Reference on this
*/
public FilePos add(final FilePos obj) {
if (obj.line == 0) {
this.col += obj.col;
} else {
this.col = obj.col;
this.line += obj.line;
}
return this;
}
/**
* Colomn addition operator
* @param col Number of colomn to add
* @return Reference on this
*/
public FilePos add(final int col) {
this.col += col;
return this;
}
/**
* Check if the value is a new line and update internal property
* @param val Char value to check
* @return true We find a new line
* @return false We NOT find a new line
*/
public boolean check(final Character val) {
this.col++;
if (val == '\n') {
newLine();
return true;
}
return false;
}
/**
* Reset position at 0,0
*/
public void clear() {
this.col = 0;
this.line = 0;
}
@Override
public FilePos clone() {
final FilePos out = new FilePos();
out.col = this.col;
out.line = this.line;
return out;
}
/**
* Decrement the colomn position
* @return Reference on this
*/
public FilePos decrement() {
this.col--;
return this;
}
@Override
public boolean equals(final Object obj) {
if (obj == null) {
return false;
}
if (!(obj instanceof FilePos)) {
return false;
}
final FilePos other = (FilePos) obj;
return this.col == other.col && this.line == other.line;
}
/**
* Get the colomn position
* @return Colomn in number of utf8-char
*/
public int getCol() {
return this.col;
}
/**
* Get the line number position
* @return line ID (start at 0)
*/
public int getLine() {
return this.line;
}
@Override
public int hashCode() {
return super.hashCode() + this.line + this.col;
}
/**
* Increment the colomn position
* @return Reference on this
*/
public FilePos increment() {
this.col++;
return this;
}
/**
* Find a new line & reset colomn at 0
*/
public void newLine() {
this.col = 0;
this.line++;
}
/**
* Asignment operator
* @param obj Object to copy
* @return Reference on this
*/
public FilePos set(final FilePos obj) {
this.col = obj.col;
this.line = obj.line;
return this;
}
/**
* Setter of specific data
* @param line Line in the file
* @param col Colomn in the file
*/
public void set(final int line, final int col) {
this.col = col;
this.line = line;
}
@Override
public String toString() {
String out = "(l=";
out += this.line;
out += ",c=";
out += this.col;
out += ")";
return out;
}
}