Skip to content
Snippets Groups Projects
Verified Commit 52084366 authored by Timm Fitschen's avatar Timm Fitschen
Browse files

fix parsing of the unit

parent 32c737f9
No related branches found
No related tags found
1 merge request!13fix #131 and #134 (white spaces in query)
......@@ -70,8 +70,8 @@ public class POV implements EntityFilterInterface {
private String propertiesTable = null;
private String refIdsTable = null;
private final HashMap<String, String> statistics = new HashMap<>();
private Logger logger = LoggerFactory.getLogger(getClass());
private Stack<String> prefix = new Stack<>();
private final Logger logger = LoggerFactory.getLogger(getClass());
private final Stack<String> prefix = new Stack<>();
private Unit getUnit(final String s) throws ParserException {
return CaosDBSystemOfUnits.getUnit(s);
......@@ -116,7 +116,7 @@ public class POV implements EntityFilterInterface {
// try and parse as integer
try {
final Pattern dp = Pattern.compile("^(-?[0-9]++)([^(\\.[0-9])-][^-]*)?$");
final Pattern dp = Pattern.compile("^(-?[0-9]++)\\s*([^(\\.[0-9])-][^-]*)?$");
final Matcher m = dp.matcher(value);
if (!m.matches()) {
throw new NumberFormatException();
......@@ -133,7 +133,7 @@ public class POV implements EntityFilterInterface {
this.vDouble = (double) this.vInt;
} else {
try {
final Pattern dp = Pattern.compile("^(-?[0-9]+(?:\\.[0-9]+))([^-]*)$");
final Pattern dp = Pattern.compile("^(-?[0-9]+(?:\\.[0-9]+))\\s*([^-]*)$");
final Matcher m = dp.matcher(value);
if (!m.matches()) {
throw new NumberFormatException();
......@@ -142,7 +142,7 @@ public class POV implements EntityFilterInterface {
unitStr = m.group(2);
this.vDouble = Double.parseDouble(vDoubleStr);
if ((this.vDouble % 1) == 0) {
if (this.vDouble % 1 == 0) {
this.vInt = (int) Math.floor(this.vDouble);
}
} catch (final NumberFormatException e) {
......@@ -509,14 +509,16 @@ public class POV implements EntityFilterInterface {
return this.aggregate;
}
private String measurement(String m) {
private String measurement(final String m) {
return String.join("", prefix) + m;
}
@Override
public String getCacheKey() {
StringBuilder sb = new StringBuilder();
if (this.getAggregate() != null) sb.append(this.aggregate);
final StringBuilder sb = new StringBuilder();
if (this.getAggregate() != null) {
sb.append(this.aggregate);
}
sb.append(toString());
if (this.hasSubProperty()) {
sb.append(getSubProperty().getCacheKey());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment