![JAR search and dependency download from the Maven repository](/logo.png)
panda.el.parse.NumberParse Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of panda-core Show documentation
Show all versions of panda-core Show documentation
Panda Core is the core module of Panda Framework, it contains commonly used utility classes similar to apache-commons.
package panda.el.parse;
import panda.el.ELException;
/**
* Number parse
*/
public class NumberParse implements Parse {
@Override
public Object fetchItem(CharQueue exp) {
StringBuilder sb = new StringBuilder();
switch (exp.peek()) {
case '.':
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
boolean hasPoint = exp.peek() == '.';
sb.append(exp.poll());
while (!exp.isEmpty()) {
switch (exp.peek()) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
sb.append(exp.poll());
break;
case '.':
if (hasPoint) {
throw new ELException("表达式错误,请查看是否有多个'.'!");
}
hasPoint = true;
sb.append(exp.poll());
break;
case 'l':
case 'L':
sb.append(exp.poll());
return Long.parseLong(sb.toString());
case 'f':
case 'F':
sb.append(exp.poll());
return Float.parseFloat(sb.toString());
case 'd':
case 'D':
sb.append(exp.poll());
return Double.parseDouble(sb.toString());
default:
if (hasPoint) {
return Double.parseDouble(sb.toString());
}
return Integer.parseInt(sb.toString());
}
}
if (hasPoint) {
return Double.parseDouble(sb.toString());
}
return Integer.parseInt(sb.toString());
}
return NULL;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy