/** * Parses a string with the default locale and returns the corresponding number * * @throws ParseException if number cannot be parsed */ public static double parseNumber(String number) throws ParseException { return parseNumber(number, Locale.ENGLISH); }
@Test public void parseString() throws ParseException { assertThat(ParsingUtils.parseNumber("23.12", Locale.ENGLISH)).isEqualTo(23.12); assertThat(ParsingUtils.parseNumber("12345.67", Locale.ENGLISH)).isEqualTo(12345.67); assertThat(ParsingUtils.parseNumber("12345,67", Locale.FRENCH)).isEqualTo(12345.67); } }
/** * Parses a string with the default locale and returns the corresponding number * * @throws ParseException if number cannot be parsed */ public static double parseNumber(String number) throws ParseException { return parseNumber(number, Locale.ENGLISH); }
/** * Parses a string with the default locale and returns the corresponding number * * @throws ParseException if number cannot be parsed */ public static double parseNumber(String number) throws ParseException { return parseNumber(number, Locale.getDefault()); }
private static Integer safeParseInt(String lineStr) { if (StringUtils.isBlank(lineStr)) { LOG.debug("Empty string to parse to int"); return null; } try { return (int) ParsingUtils.parseNumber(lineStr); } catch (ParseException ignore) { LOG.debug("Int parsing error", ignore); return null; } }
private static long getTimeAttributeInMS(String value) throws XMLStreamException { // hardcoded to Locale.ENGLISH see http://jira.codehaus.org/browse/SONAR-602 try { Double time = ParsingUtils.parseNumber(value, Locale.ENGLISH); return !Double.isNaN(time) ? (long) ParsingUtils.scaleValue(time * 1000, 3) : 0L; } catch (ParseException e) { throw new XMLStreamException(e); } }
private static long getTimeAttributeInMS(String value) throws XMLStreamException { // hardcoded to Locale.ENGLISH see http://jira.codehaus.org/browse/SONAR-602 try { Double time = ParsingUtils.parseNumber(value, Locale.ENGLISH); return !Double.isNaN(time) ? (long) ParsingUtils.scaleValue(time * 1000, 3) : 0L; } catch (ParseException e) { throw new XMLStreamException(e); } }
private long getTimeAttributeInMS(SMInputCursor testCaseCursor) throws XMLStreamException { // hardcoded to Locale.ENGLISH see http://jira.codehaus.org/browse/SONAR-602 try { Double time = ParsingUtils.parseNumber(testCaseCursor.getAttrValue("time"), Locale.ENGLISH); return !Double.isNaN(time) ? new Double(ParsingUtils.scaleValue(time * 1000, 3)).longValue() : 0L; } catch (ParseException e) { throw new XMLStreamException(e); } }
private long getTimeAttributeInMS(SMInputCursor testCaseCursor) throws XMLStreamException { // hardcoded to Locale.ENGLISH see http://jira.codehaus.org/browse/SONAR-602 try { Double time = ParsingUtils.parseNumber(testCaseCursor.getAttrValue("time"), Locale.ENGLISH); return !Double.isNaN(time) ? new Double(ParsingUtils.scaleValue(time * 1000, 3)).longValue() : 0L; } catch (ParseException e) { throw new XMLStreamException(e); } }
private long getTimeAttributeInMS(SMInputCursor testCaseCursor) throws XMLStreamException { // hardcoded to Locale.ENGLISH see http://jira.codehaus.org/browse/SONAR-602 try { Double time = ParsingUtils.parseNumber(testCaseCursor.getAttrValue("time"), Locale.ENGLISH); return !Double.isNaN(time) ? (long) ParsingUtils.scaleValue(time * 1000, 3) : 0L; } catch (ParseException e) { throw new XMLStreamException(e); } }
private long getTimeAttributeInMS(SMInputCursor testCaseCursor) throws XMLStreamException { // hardcoded to Locale.ENGLISH see http://jira.codehaus.org/browse/SONAR-602 try { Double time = ParsingUtils.parseNumber(testCaseCursor.getAttrValue("time"), Locale.ENGLISH); return !Double.isNaN(time) ? (long) ParsingUtils.scaleValue(time * 1000, 3) : 0L; } catch (ParseException e) { throw new XMLStreamException(e); } }
private static double parseTime(SMInputCursor testCaseCursor) throws XMLStreamException { double time; try { Double tmp = ParsingUtils.parseNumber(testCaseCursor.getAttrValue("time"), Locale.ENGLISH); time = ParsingUtils.scaleValue(tmp * 1000, 3); } catch (ParseException e) { throw new XMLStreamException(e); } return time; }
private static long getTimeAttributeInMS(SMInputCursor testCaseCursor) throws XMLStreamException { // hardcoded to Locale.ENGLISH see http://jira.codehaus.org/browse/SONAR-602 try { Double time = ParsingUtils.parseNumber(testCaseCursor.getAttrValue("time"), Locale.ENGLISH); return !Double.isNaN(time) ? (long) ParsingUtils.scaleValue(time * 1000, 3) : 0L; } catch (ParseException e) { throw new XMLStreamException(e); } }
private static double parseTime(SMInputCursor testCaseCursor) throws XMLStreamException { double time; try { Double tmp = ParsingUtils.parseNumber(testCaseCursor.getAttrValue("time"), Locale.ENGLISH); time = ParsingUtils.scaleValue(tmp * 1000, 3); } catch (ParseException e) { throw new XMLStreamException(e); } return time; }
private boolean canBeIncludedInFileMetrics(SMInputCursor metricsCursor) throws ParseException, XMLStreamException { while (metricsCursor.getNext() != null && isClass(metricsCursor)) { // skip class elements on 1.x xml format } return ParsingUtils.parseNumber(metricsCursor.getAttrValue("elements")) > 0; }
private static void collectFileData(SMInputCursor clazz, NewCoverage newCoverage) throws XMLStreamException { SMInputCursor line = clazz.childElementCursor("lines").advance().childElementCursor("line"); while (line.getNext() != null) { int lineId = Integer.parseInt(line.getAttrValue("number")); try { newCoverage.lineHits(lineId, (int) ParsingUtils.parseNumber(line.getAttrValue("hits"), Locale.ENGLISH)); } catch (ParseException e) { throw new IllegalStateException(e); } String isBranch = line.getAttrValue("branch"); String text = line.getAttrValue("condition-coverage"); if (StringUtils.equals(isBranch, "true") && StringUtils.isNotBlank(text)) { String[] conditions = StringUtils.split(StringUtils.substringBetween(text, "(", ")"), "/"); newCoverage.conditions(lineId, Integer.parseInt(conditions[1]), Integer.parseInt(conditions[0])); } } newCoverage.save(); }
private void saveHitsData(Resource resource, SMInputCursor lineCursor) throws ParseException, XMLStreamException { fileMeasuresBuilder.reset(); while (lineCursor.getNext() != null) { // skip class elements on format 2_3_2 if (isClass(lineCursor)) { continue; } final int lineId = Integer.parseInt(lineCursor.getAttrValue("num")); String count = lineCursor.getAttrValue("count"); if (StringUtils.isNotBlank(count)) { fileMeasuresBuilder.setHits(lineId, Integer.parseInt(count)); } else { int trueCount = (int) ParsingUtils.parseNumber(lineCursor.getAttrValue("truecount")); int falseCount = (int) ParsingUtils.parseNumber(lineCursor.getAttrValue("falsecount")); int coveredConditions = 0; if (trueCount > 0) { coveredConditions++; } if (falseCount > 0) { coveredConditions++; } fileMeasuresBuilder.setConditions(lineId, 2, coveredConditions); } } if (resource != null) { for (Measure measure : fileMeasuresBuilder.createMeasures()) { context.saveMeasure(resource, measure); } } }
private static void collectFileData(SMInputCursor clazz, ParsingResult parsingResult) throws XMLStreamException { SMInputCursor line = clazz.childElementCursor("lines").advance().childElementCursor("line"); while (line.getNext() != null) { int lineId = Integer.parseInt(line.getAttrValue("number")); boolean validLine = parsingResult.isValidLine(lineId); if (!validLine && parsingResult.fileExists()) { LOG.info("Hit on invalid line for file " + parsingResult.filename + " (line: " + lineId + "/" + parsingResult.inputFile.lines() + ")"); } try { int hits = (int) parseNumber(line.getAttrValue("hits"), ENGLISH); if (validLine) { parsingResult.coverage = parsingResult.coverage.lineHits(lineId, hits); } } catch (ParseException e) { throw MessageException.of("Unable to parse Cobertura report.", e); } String isBranch = line.getAttrValue("branch"); String text = line.getAttrValue("condition-coverage"); if (validLine && StringUtils.equals(isBranch, "true") && StringUtils.isNotBlank(text)) { String[] conditions = StringUtils.split(StringUtils.substringBetween(text, "(", ")"), "/"); parsingResult.coverage = parsingResult.coverage.conditions(lineId, Integer.parseInt(conditions[1]), Integer.parseInt(conditions[0])); } } }