/** * Scales a double value, taking into account 2 decimals */ public static double scaleValue(double value) { return scaleValue(value, 2); }
/** * 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); }
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 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; }
@Test public void scaleValue() { assertThat(ParsingUtils.scaleValue(23.3333333)).isEqualTo(23.33); assertThat(ParsingUtils.scaleValue(23.777777)).isEqualTo(23.78); assertThat(ParsingUtils.scaleValue(23.3333333, 0)).isEqualTo(23.0); assertThat(ParsingUtils.scaleValue(23.777777, 0)).isEqualTo(24.0); }
@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); } }
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; }
/** * Scales a double value, taking into account 2 decimals */ public static double scaleValue(double value) { return scaleValue(value, 2); }
/** * 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); }
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); } }
/** * Scales a double value, taking into account 2 decimals */ public static double scaleValue(double value) { return scaleValue(value, 2); }
/** * 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 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); } }
public double getDocumentedPublicApiDensity() { if (Double.doubleToRawLongBits(publicApi) == 0L) { return 100.0; } return ParsingUtils.scaleValue(documentedPublicApi / publicApi * 100, 2); } }
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(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); } }
public double getDocumentedPublicApiDensity() { if (Double.doubleToRawLongBits(publicApi) == 0L) { return 100.0; } return ParsingUtils.scaleValue(documentedPublicApi / publicApi * 100, 2); } }
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 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); } }