private Number valueToNum(Object o) { if (o instanceof Number) { return (Number) o; } else if (o instanceof String) { String val = (String)o; return Util.parseStringNumber(val, Double.NaN); } else { return Double.NaN; } }
/** * @param indexKey the indexKey to set */ public void setIndex(String indexKey) { this.indexKey = Util.parseStringNumber(indexKey, -1); }
public void configure(Properties configuration) { logger.debug("Configuration: " + configuration); port = jrds.Util.parseStringNumber((String) configuration.getProperty("jmx.port"), port).intValue(); propFileName = configuration.getProperty("propertiesFile", propFileName); }
public void configure(Properties configuration) { logger.debug("Configuration: " + configuration); host = configuration.getProperty("jetty.host"); port = jrds.Util.parseStringNumber(configuration.getProperty("jetty.port"), port).intValue(); propFileName = configuration.getProperty("propertiesFile", propFileName); webRoot = configuration.getProperty("webRoot", webRoot); }
protected Map<String, Number> parseLines(List<String> lines) { Map<String, Number> retValue = new HashMap<String, Number>(lines.size()); for(String l: lines) { String[] kvp = l.split(":"); if(kvp.length != 2) continue; Double value = Util.parseStringNumber(kvp[1].trim(), Double.NaN); retValue.put(kvp[0].trim(), value); } Number uptimeNumber = retValue.remove("Uptime"); if(uptimeNumber != null) { setUptime(uptimeNumber.longValue()); } return retValue; }
@Override public void configureStore(PropertiesManager pm, Properties props) { super.configureStore(pm, props); String host = props.getProperty("host", "localhost"); String portStr = props.getProperty("port", "2003"); int port = Util.parseStringNumber(portStr, new Integer(2003)); String prefix = props.getProperty("prefix", ""); cnx = new GraphiteConnection(host, port, prefix); }
protected Map<String, Number> parseLines(List<String> lines) { Map<String, Number> retValue = new HashMap<String, Number>(lines.size()); for(String l: lines) { String[] kvp = l.split(":"); if(kvp.length != 2) continue; if("Scoreboard".equals(kvp[0].trim())) { parseScoreboard(kvp[1].trim(), retValue); } else { Double value = Util.parseStringNumber(kvp[1].trim(), Double.NaN); retValue.put(kvp[0].trim(), value); } } Number uptimeNumber = retValue.remove("Uptime"); if(uptimeNumber != null) setUptime(uptimeNumber.longValue()); return retValue; }
@Override public Map<String, Number> parseRs(ResultSet rs) throws SQLException { Map<String, Number> retValues = new HashMap<String, Number>(getPd().getSize()); Set<String> toCollect = getPd().getCollectMapping().keySet(); for(Map<String, Object> m: parseRsVerticaly(rs, false)) { for(Map.Entry<String, Object> e: m.entrySet()) { Double d = Double.NaN; // We only keep the data in data stores list if(toCollect.contains(e.getKey())) { if(e.getValue() instanceof String) d = Util.parseStringNumber((String) e.getValue(), Double.NaN).doubleValue(); retValues.put(e.getKey(), d); } } } return retValues; } }
@Override public Map<String, Number> getNewSampleValuesConnected(LdapConnection cnx) { uptime = findUptime(cnx); if(uptime < 0) { return null; } Set<String> collected = getCollectMapping().keySet(); Map<String, Set<String>> requestInfo = buildRequestInfo(getCollectMapping().keySet()); Map<String, Object> foundValues = doMultiSearch(cnx, requestInfo); Map<String, Number> retValues = new HashMap<String, Number>(); for(Map.Entry<String, Object> e: foundValues.entrySet()) { if(collected.contains(e.getKey())) { double val = jrds.Util.parseStringNumber(e.getValue().toString(), Double.NaN).doubleValue(); retValues.put(e.getKey(), val); } } return retValues; }
private ArcDef getArchDef(JrdsElement archiveElement) { String cfName = archiveElement.getElementbyName("consolFun").getTextContent(); ConsolFun consolFun = null; if(cfName != null && !"".equals(cfName.trim())) { consolFun = ConsolFun.valueOf(cfName.trim().toUpperCase()); } double xff = Util.parseStringNumber(archiveElement.getElementbyName("xff").getTextContent(), Double.NaN); int steps = Util.parseStringNumber(archiveElement.getElementbyName("steps").getTextContent(), 0); int rows = Util.parseStringNumber(archiveElement.getElementbyName("rows").getTextContent(), 0); return new ArcDef(consolFun, xff, steps, rows); }
private Target makeSnmpTarget(HttpServletRequest request) throws UnknownHostException { String hostname = request.getParameter("host"); String community = request.getParameter("discoverSnmpCommunity"); if(community == null) { community = "public"; } int port = jrds.Util.parseStringNumber(request.getParameter("discoverSnmpPort"), 161); IpAddress addr = new UdpAddress(InetAddress.getByName(hostname), port); Target hosttarget = new CommunityTarget(addr, new OctetString(community)); hosttarget.setVersion(SnmpConstants.version2c); return hosttarget; }
private double parseRangeArg(String rangeArg, Graph g) { if(rangeArg == null) return Double.NaN; Matcher m = rangePattern.matcher(rangeArg); jrds.GraphNode node = g.getNode(); if(m.matches() && node != null) { String valueString = m.group(1); Number value = jrds.Util.parseStringNumber(valueString, Double.NaN); String suffixString = m.group(3); if(!"".equals(suffixString)) { try { SiPrefix suffix = SiPrefix.valueOf(suffixString); return suffix.evaluate(value.doubleValue(), node.getGraphDesc().isSiUnit()); } catch (java.lang.IllegalArgumentException e) { logger.info("Illegal SI suffix " + suffixString); } } else return value.doubleValue(); } return Double.NaN; }
private MBeanServerConnection connect(String hostname, HttpServletRequest request) { this.hostname = hostname; String protocolName = request.getParameter("discoverJmxProtocol"); if(protocolName != null && !protocolName.trim().isEmpty()) { cnx.setProtocol(JmxProtocol.valueOf(protocolName.trim())); } Integer port = jrds.Util.parseStringNumber(request.getParameter("discoverJmxPort"), 0); if(port != 0) { cnx.setPort(port); } cnx.setUser(request.getParameter("discoverJmxUser")); cnx.setPassword(request.getParameter("discoverJmxPassword")); if(cnx.startConnection()) { return cnx.getConnection().connection; } else { return null; } }
@Override public void run() { HostsList hl = Configuration.get().getHostsList(); try { for(Timer t: hl.getTimers()) { t.lockCollect(); } Thread.sleep(jrds.Util.parseStringNumber(arg, 1) * 1000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } for(Timer t: hl.getTimers()) { t.releaseCollect(); } logger.info("collect restarted"); } };
@Test public void testParseStringNumber2() { double n = Util.parseStringNumber(null, Double.NaN); Assert.assertTrue(Double.isNaN(n)); }
@Test public void testParseStringNumber3() { double n = Util.parseStringNumber("a", Double.NaN); Assert.assertTrue(Double.isNaN(n)); }
@Test public void testParseStringNumber5() { int n = Util.parseStringNumber("1", 2); Assert.assertEquals(1, n); }
@Test public void testParseStringNumber7() { double n = Util.parseStringNumber("1.33427403132E11", 1.0d); Assert.assertEquals(1.33427403132E11, n, 1e-10); }
@Test public void testParseStringNumber1() { double n = Util.parseStringNumber("1", Double.NaN); Assert.assertEquals(1.0, n, 0.001); }
@Test public void testParseStringNumber6() { double n = Util.parseStringNumber("1", 2.0d); Assert.assertEquals(1.0, n, 0.001); }