List of usage examples for java.lang Long doubleValue
public double doubleValue()
From source file:com.github.rvesse.github.pr.stats.collectors.LongStatsCollector.java
@Override public void collect(GitHubClient client, Long item) { if (item == null) throw new IllegalArgumentException("item cannot be null"); this.items.add(item); this.freq.incrementValue(item.longValue(), 1); this.stats.addValue(item.doubleValue()); }
From source file:org.sonar.api.utils.Duration.java
/** * Return the duration in text, by using the given hours in day parameter to process hours. * <br>//from w w w . j a va 2 s. com * Duration.decode("1d 1h", 8).encode(8) will return "1d 1h" * Duration.decode("2d", 8).encode(16) will return "1d" */ public String encode(int hoursInDay) { int days = ((Double) ((double) durationInMinutes / hoursInDay / MINUTES_IN_ONE_HOUR)).intValue(); Long remainingDuration = durationInMinutes - (days * hoursInDay * MINUTES_IN_ONE_HOUR); int hours = ((Double) (remainingDuration.doubleValue() / MINUTES_IN_ONE_HOUR)).intValue(); remainingDuration = remainingDuration - (hours * MINUTES_IN_ONE_HOUR); int minutes = remainingDuration.intValue(); StringBuilder stringBuilder = new StringBuilder(); if (days > 0) { stringBuilder.append(days); stringBuilder.append(DAY); } if (hours > 0) { stringBuilder.append(hours); stringBuilder.append(HOUR); } if (minutes > 0) { stringBuilder.append(minutes); stringBuilder.append(MINUTE); } return stringBuilder.length() == 0 ? ("0" + MINUTE) : stringBuilder.toString(); }
From source file:Servlets.ServletMonitora.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String opcao = request.getParameter("opcao"); StringBuffer sb = new StringBuffer(); JSONParser parser = new JSONParser(); JSONObject produto = null;// w w w . j a va 2 s .c om GerenciarProduto gerenciarProduto = new GerenciarProduto(); switch (opcao) { case "cadastrar": try { BufferedReader reader = request.getReader(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line); } } catch (Exception e) { e.printStackTrace(); } try { produto = (JSONObject) parser.parse(sb.toString()); } catch (ParseException e) { e.printStackTrace(); } try { String nomeProduto = (String) produto.get("name"); String descricaoProduto = (String) produto.get("description"); String imagemProduto = (String) produto.get("image"); Long l = new Long((long) produto.get("price")); double precoProdutoModificado = l.doubleValue(); Integer codigoVendedor = (Integer) request.getSession().getAttribute("codigoVendedor"); //criando conexao gerenciarProduto.criarConexao(); gerenciarProduto.adicionarProduto(nomeProduto, precoProdutoModificado, imagemProduto, descricaoProduto, codigoVendedor); gerenciarProduto.fecharConexao(); } catch (Exception e) { e.printStackTrace(); } break; case "atualizar": try { BufferedReader reader = request.getReader(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line); } } catch (Exception e) { e.printStackTrace(); } try { produto = (JSONObject) parser.parse(sb.toString()); } catch (ParseException e) { e.printStackTrace(); } try { Long longID = new Long((long) produto.get("id")); int id = longID.intValue(); String nomeProduto = (String) produto.get("name"); String descricaoProduto = (String) produto.get("description"); String imagemProduto = (String) produto.get("image"); Long l = new Long((long) produto.get("price")); double precoProdutoModificado = l.doubleValue(); Integer codigoVendedor = (Integer) request.getSession().getAttribute("codigoVendedor"); //criando conexao gerenciarProduto.criarConexao(); gerenciarProduto.atualizarProduto(id, nomeProduto, precoProdutoModificado, imagemProduto, descricaoProduto, codigoVendedor); gerenciarProduto.fecharConexao(); } catch (Exception e) { e.printStackTrace(); } break; case "deletar": try { BufferedReader reader = request.getReader(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line); } } catch (Exception e) { e.printStackTrace(); } try { produto = (JSONObject) parser.parse(sb.toString()); } catch (ParseException e) { e.printStackTrace(); } try { Long longID = new Long((long) produto.get("id")); int id = longID.intValue(); //criando conexao gerenciarProduto.criarConexao(); gerenciarProduto.deletarProduto(id); gerenciarProduto.fecharConexao(); } catch (Exception e) { e.printStackTrace(); } break; } }
From source file:org.raml.yagi.framework.grammar.rule.RangeValueRule.java
private boolean validate(Node node) { if (node instanceof IntegerNode) { Long value = ((IntegerNode) node).getValue(); return range.containsLong(value); } else if (node instanceof FloatingNode) { BigDecimal value = ((FloatingNode) node).getValue(); return range.containsDouble(value.doubleValue()); } else if (node instanceof SimpleTypeNode) { try {// ww w . ja v a 2s . c o m long parseLong = Long.parseLong(((StringNode) node).getValue()); return range.containsLong(parseLong); } catch (NumberFormatException ex) { return false; } } else { return false; } }
From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFJDoubleEditor.java
public boolean isEditValid() { final String S_ProcName = "isEditValid"; if (!hasValue()) { setValue(null);//from w w w. j a v a 2 s . com return (true); } boolean retval = super.isEditValid(); if (retval) { try { commitEdit(); } catch (ParseException e) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Field is not valid - " + e.getMessage(), e); } Object obj = getValue(); if (obj == null) { retval = false; } else if (obj instanceof Float) { Float f = (Float) obj; Double v = new Double(f.doubleValue()); if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) { retval = false; } } else if (obj instanceof Double) { Double v = (Double) obj; if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) { retval = false; } } else if (obj instanceof Short) { Short s = (Short) obj; Double v = new Double(s.doubleValue()); if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) { retval = false; } } else if (obj instanceof Integer) { Integer i = (Integer) obj; Double v = new Double(i.doubleValue()); if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) { retval = false; } } else if (obj instanceof Long) { Long l = (Long) obj; Double v = new Double(l.doubleValue()); if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) { retval = false; } } else if (obj instanceof BigDecimal) { BigDecimal b = (BigDecimal) obj; Double v = new Double(b.toString()); if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) { retval = false; } } else if (obj instanceof Number) { Number n = (Number) obj; Double v = new Double(n.toString()); if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) { retval = false; } } else { throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName, "EditedValue", obj, "Short, Integer, Long, BigDecimal, Float, Double or Number"); } } return (retval); }
From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFJDoubleEditor.java
public Double getDoubleValue() { final String S_ProcName = "getDoubleValue"; Double retval;//from w ww . jav a 2 s . co m String text = getText(); if ((text == null) || (text.length() <= 0)) { retval = null; } else { if (!isEditValid()) { throw CFLib.getDefaultExceptionFactory().newInvalidArgumentException(getClass(), S_ProcName, "Field is not valid"); } try { commitEdit(); } catch (ParseException e) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Field is not valid - " + e.getMessage(), e); } Object obj = getValue(); if (obj == null) { retval = null; } else if (obj instanceof Float) { Float f = (Float) obj; Double v = new Double(f.doubleValue()); if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, minValue, maxValue); } retval = v; } else if (obj instanceof Double) { Double v = (Double) obj; if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, minValue, maxValue); } retval = v; } else if (obj instanceof Short) { Short s = (Short) obj; Double v = new Double(s.doubleValue()); if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, minValue, maxValue); } retval = v; } else if (obj instanceof Integer) { Integer i = (Integer) obj; Double v = new Double(i.doubleValue()); if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, minValue, maxValue); } retval = v; } else if (obj instanceof Long) { Long l = (Long) obj; Double v = new Double(l.doubleValue()); if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, minValue, maxValue); } retval = v; } else if (obj instanceof BigDecimal) { BigDecimal b = (BigDecimal) obj; Double v = new Double(b.toString()); if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, minValue, maxValue); } retval = v; } else if (obj instanceof Number) { Number n = (Number) obj; Double v = new Double(n.toString()); if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, minValue, maxValue); } retval = v; } else { throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName, "EditedValue", obj, "Short, Integer, Long, BigDecimal or Number"); } } return (retval); }
From source file:com.googlecode.jchav.chart.Chart.java
/** * @param value the upper bound on the y-axis. *///from w w w.ja va2s . com public void setMaxY(Long value) { // Force the range on the chart, if set, plus 10% to allow // a bit of white space at the top of the chart so the marker point // isn't off the chart: chart.getCategoryPlot().getRangeAxis().setUpperBound(value.doubleValue() * 1.1); }
From source file:it.geosolutions.unredd.stats.impl.StatsRunner.java
protected void outputStats(Map<MultiKey, List<Result>> results) { boolean rangeAlreadyLogged = false; for (MultiKey classes : results.keySet()) { StringBuilder sb = new StringBuilder(); //= append all classes for (Object o : classes.getKeys()) { // LOGGER.info("Adding class " + o); sb.append(o).append(cfg.getOutput().getSeparator()); }//from ww w . ja v a 2s . c o m //= append stats in the requested order List<Result> resultList = results.get(classes); int statsnum = statsIndexes.size() + (countIndex != null ? 1 : 0); // LOGGER.info(statsnum + " stats requested"); // prefill outval List<Double> outval = new ArrayList<Double>(statsnum); for (int i = 0; i < statsnum; i++) { outval.add(Double.NaN); } // fill count stat if (countIndex != null) { // COUNT is not a real stat: set it by hand Long l = resultList.get(0).getNumAccepted(); outval.set(countIndex, l.doubleValue()); } // fill computed stats for (Result result : resultList) { // LOGGER.info(result); Integer idx = statsIndexes.get(result.getStatistic()); if (idx == null) { if (LOGGER.isDebugEnabled()) { if (result.getStatistic() != Statistic.RANGE || !rangeAlreadyLogged) { // display range warning only once LOGGER.debug("Encountered stat not requested (" + result.getStatistic().name() + "): " + result); } rangeAlreadyLogged = result.getStatistic() == Statistic.RANGE; } // log continue; } // else // LOGGER.info("Adding " + result.getStatistic()); outval.set(idx, result.getValue()); } //= put stats in output line for (Iterator<Double> it = outval.iterator(); it.hasNext();) { Double val = it.next(); if (!Double.isNaN(val)) sb.append(val); else sb.append(cfg.getOutput().getNanValue()); if (it.hasNext()) sb.append(cfg.getOutput().getSeparator()); } output(sb); } closeOutputFile(); CSVConverter.convertFromCSV(cfg); }
From source file:org.opennms.features.newts.converter.eventd.EventdStresser.java
private static int sendTraps(final SnmpTrapBuilder builder, PoolingConnection pool, long beginMillis, int initialEventCount) throws IllegalStateException, InterruptedException, SQLException { m_sleepMillis = 0;//from ww w . j a v a2s . c o m int totalTrapsSent = 0; System.out.println("Sending " + m_trapCount + " traps in " + m_batchCount + " batches with a batch interval of " + m_batchDelay.toString() + " seconds..."); for (int i = 1; i <= m_batchCount; i++) { Long batchBegin = Calendar.getInstance().getTimeInMillis(); Double currentRate = 0.0; Integer batchTrapsSent = 0; Long batchElapsedMillis = 0L; System.out.println("Sending batch " + i + " of " + Integer.valueOf(m_batchCount) + " batches of " + m_batchSize.intValue() + " traps at the rate of " + m_trapRate.toString() + " traps/sec..."); System.out.println( "Estimated time to send: " + m_batchSize.doubleValue() / m_trapRate.doubleValue() + " seconds"); while (batchTrapsSent.intValue() < m_batchSize.intValue()) { if (currentRate <= m_trapRate || batchElapsedMillis == 0) { batchTrapsSent += sendTrap(builder); } else { Thread.sleep(1); m_sleepMillis++; } batchElapsedMillis = Calendar.getInstance().getTimeInMillis() - batchBegin; currentRate = batchTrapsSent.doubleValue() / batchElapsedMillis.doubleValue() * 1000.0; if (batchElapsedMillis % 1000 == 0) { System.out.print("."); } } System.out.println(); totalTrapsSent += batchTrapsSent; System.out.println(" Actual time to send: " + (batchElapsedMillis / 1000.0 + " seconds")); System.out.println("Elapsed Time (secs): " + ((System.currentTimeMillis() - beginMillis) / 1000L)); System.out.println(" Traps sent: " + Integer.valueOf(totalTrapsSent).toString()); Integer currentEventCount = getEventCount(pool) - initialEventCount; System.out.println("Current Event count: " + currentEventCount.toString()); System.out.println(); Thread.sleep(m_batchDelay.longValue() * 1000L); m_sleepMillis += m_batchDelay.longValue() * 1000L; } int remainingTraps = m_trapCount - totalTrapsSent; System.out.println("Sending batch remainder of " + remainingTraps + " traps..."); Long batchBegin = Calendar.getInstance().getTimeInMillis(); Double currentRate = 0.0; Long batchTrapsSent = 0L; Long elapsedMillis = 0L; while (batchTrapsSent.intValue() < remainingTraps) { if (currentRate <= m_trapRate || elapsedMillis == 0) { batchTrapsSent += sendTrap(builder); } else { Thread.sleep(1); m_sleepMillis++; } elapsedMillis = Calendar.getInstance().getTimeInMillis() - batchBegin; currentRate = batchTrapsSent.doubleValue() / elapsedMillis.doubleValue() * 1000.0; } totalTrapsSent += batchTrapsSent; System.out.println("Elapsed Time (secs): " + ((System.currentTimeMillis() - beginMillis) / 1000L)); System.out.println(" Traps sent: " + Integer.valueOf(totalTrapsSent).toString()); Integer currentEventCount = getEventCount(pool) - initialEventCount; System.out.println("Current Event count: " + currentEventCount.toString()); return totalTrapsSent; }
From source file:test.PBEncryptLink.java
/** * Given a course and user value, insert them in the context string, add the * current time and encrypt using the currently initialized blowfish Cipher * object. Note that the String is converted to an arry of bytes and treated * as ISO8859_1 -- reasonable in our environment. The result is returned as * a Base64 String./* www . j a v a2 s. c om*/ * * @param courseName * @param user_id * @param log * @return String in Base64 representing the encrypted data. * @throws IllegalBlockSizeException * Is this possible in Blowfish? * @throws BadPaddingException * Shouldn't see this since default is used. */ public String encryptContextString(String courseName, String user_id, Logger log) throws IllegalBlockSizeException, BadPaddingException { Long curTime = new Long(Calendar.getInstance().getTimeInMillis()); long rndTime = Math.round(curTime.doubleValue() / 60000); if (log != null) { log.info("Default date and time " + (Calendar.getInstance()).toString()); } Cipher cipher = getBlowfishCipher(); String value = "login=" + user_id + (courseName != null ? ("&course=" + courseName) : "") + "&time=" + rndTime; if (log != null) { log.info("string before encrypting=" + value.toLowerCase()); } byte[] bArray = stringTo_iso8859_1_Bytes(value.toLowerCase()); byte[] encryptedData = cipher.doFinal(bArray); byte[] bBase64Array = Base64.encodeBase64(encryptedData); String base64String = iso8859_1_BytesToString(bBase64Array); return base64String; }