List of usage examples for java.lang Integer doubleValue
public double doubleValue()
From source file:msi.gaml.operators.Maths.java
@operator(value = { "^" }, can_be_const = true, category = { IOperatorCategory.ARITHMETIC }) @doc(value = "Returns the value (always a float) of the left operand raised to the power of the right operand.") public static Double pow(final Integer a, final Double b) { return pow(a.doubleValue(), b); }
From source file:com.aurel.track.item.PrintItemDetailsBL.java
/** * The big difference relative to other FlatHistoryBean of RENDER_TYPE=ACTUAL_VALUES is that * some of HistoryEntries of FlatHistoryBean have oldValue set which means special handling in jsp: * either rendering a image or create a link for attachment * @param attachmentBeans//from ww w. j a v a 2 s. c o m * @param locale * @return */ private static List<FlatHistoryBean> loadAttachmentFlatHistoryBeans(List<TAttachmentBean> attachmentBeans, Map<Integer, TWorkItemBean> workItemBeansMap, Locale locale, boolean withChildren) { List<FlatHistoryBean> flatValueList = new ArrayList<FlatHistoryBean>(); Integer stretchPercent = null; Integer maxWidth = null; Integer maxHeight = null; Properties properties = loadConfigFromFile(); stretchPercent = getConfigByName(properties, "stretchPercent", 100); maxWidth = getConfigByName(properties, "maxWidth", 500); maxHeight = getConfigByName(properties, "maxHeight", 500); if (attachmentBeans != null) { for (TAttachmentBean attachmentBean : attachmentBeans) { FlatHistoryBean flatHistoryBean = new FlatHistoryBean(); List<HistoryEntry> historyEntries = new ArrayList<HistoryEntry>(); flatHistoryBean.setHistoryEntries(historyEntries); flatHistoryBean.setChangedByName(attachmentBean.getChangedByName()); flatHistoryBean.setPersonID(attachmentBean.getChangedBy()); flatHistoryBean.setLastEdit(attachmentBean.getLastEdit()); flatHistoryBean.setType(HistoryBean.HISTORY_TYPE.ATTACHMENT); flatHistoryBean.setIconName("attachment.png"); HistoryLoaderBL.addWorkItemToFlatHistoryBean(flatHistoryBean, workItemBeansMap, attachmentBean.getWorkItem(), FlatHistoryBean.RENDER_TYPE.ACTUAL_VALUES); flatHistoryBean.setWorkItemID(attachmentBean.getWorkItem()); HistoryEntry historyEntry = new HistoryEntry(); /*render the attachmnet download: historyEntry.fieldLabel -> Name historyEntry.newValue -> the fileName historyEntry.oldValue -> attachmentID: the value is used in the URL */ historyEntry.setFieldLabel( LocalizeUtil.getLocalizedTextFromApplicationResources("common.lbl.name", locale)); historyEntry.setNewValue(attachmentBean.getFileName()); historyEntry.setOldValue(attachmentBean.getObjectID().toString()); historyEntries.add(historyEntry); if (!withChildren) { historyEntry = new HistoryEntry(); historyEntry.setFieldLabel( LocalizeUtil.getLocalizedTextFromApplicationResources("common.lbl.size", locale)); historyEntry.setNewValue(TAttachmentBean.getFileSizeString(attachmentBean.getSize())); historyEntries.add(historyEntry); String description = attachmentBean.getDescription(); if (description != null && !"".equals(description)) { historyEntry = new HistoryEntry(); historyEntry.setFieldLabel(LocalizeUtil .getLocalizedTextFromApplicationResources("common.lbl.description", locale)); historyEntry.setNewValue(description); historyEntries.add(historyEntry); } } boolean isImage = AttachBL.isImage(attachmentBean); if (isImage) { /*render the image: historyEntry.fieldLabel -> null historyEntry.newValue -> image width (in pixels) historyEntry.oldValue -> attachmentID: used in the URL */ TAttachmentBean attachmentBeanPopulated = AttachBL.loadAttachment(attachmentBean.getObjectID(), attachmentBean.getWorkItem(), true); String fileNameOnDisk = attachmentBeanPopulated.getFullFileNameOnDisk(); File f = new File(fileNameOnDisk); BufferedImage image; Integer originalWidth = null; Integer originalHeight = null; try { image = ImageIO.read(f); originalWidth = image.getWidth(); originalHeight = image.getHeight(); } catch (IOException e) { LOGGER.warn("Reading the image failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } if (fileNameOnDisk != null && !"".equals(fileNameOnDisk)) { historyEntry = new HistoryEntry(); if (originalWidth != null && originalHeight != null) { Integer calculatedWidth = Integer .valueOf(originalWidth.intValue() * stretchPercent / 100); Integer calculatedHeight = Integer .valueOf(originalHeight.intValue() * stretchPercent / 100); if (calculatedWidth.intValue() > maxWidth.intValue() && calculatedHeight.intValue() > maxHeight.intValue()) { double widthScale = calculatedWidth.doubleValue() / maxWidth.doubleValue(); double heightScale = calculatedHeight.doubleValue() / maxHeight.doubleValue(); if (widthScale > heightScale) { calculatedWidth = maxWidth; } else { calculatedWidth = Integer.valueOf((int) (calculatedWidth.doubleValue() * maxHeight.doubleValue() / calculatedHeight.doubleValue())); } } else { if (calculatedWidth.intValue() > maxWidth.intValue()) { calculatedWidth = maxWidth; } else { if (calculatedHeight.intValue() > maxHeight.intValue()) { calculatedWidth = Integer.valueOf((int) (calculatedWidth.doubleValue() * maxHeight.doubleValue() / calculatedHeight.doubleValue())); } } } historyEntry.setNewValue(calculatedWidth.toString()); } historyEntry.setOldValue(attachmentBean.getObjectID().toString()); historyEntries.add(historyEntry); } } flatValueList.add(flatHistoryBean); } } return flatValueList; }
From source file:msi.gaml.operators.Maths.java
/** * The Class Units./*ww w . j av a2 s .c o m*/ */ @operator(value = { "^" }, can_be_const = true, category = { IOperatorCategory.ARITHMETIC }) @doc(value = "Returns the value (always a float) of the left operand raised to the power of the right operand.", masterDoc = true, usages = { @usage("if the right-hand operand is equal to 0, returns 1"), @usage("if it is equal to 1, returns the left-hand operand."), @usage(value = "Various examples of power", examples = { @example(value = "2 ^ 3", equals = "8.0"), @example(value = "4.0^2", equals = "16.0", isTestOnly = true), @example(value = "4.0^0.5", equals = "2.0", isTestOnly = true), @example(value = "8^0", equals = "1.0", isTestOnly = true), @example(value = "8.0^0", equals = "1.0", isTestOnly = true), @example(value = "8^1", equals = "8.0", isTestOnly = true), @example(value = "8.0^1", equals = "8.0", isTestOnly = true), @example(value = "8^1.0", equals = "8.0", isTestOnly = true), @example(value = "8.0^1.0", equals = "8.0", isTestOnly = true), @example(value = "2^0.5", equals = "sqrt(2)", isTestOnly = true), @example(value = "16.81^0.5", equals = "sqrt(16.81)", isTestOnly = true), @example(value = "assert (10^(-9) = 0) equals: false;", isTestOnly = true), }) }, see = { "*", "sqrt" }) public static Double pow(final Integer a, final Integer b) { return pow(a.doubleValue(), b.doubleValue()); }
From source file:com.topsec.tsm.common.message.CommandHandlerUtil.java
public static Serializable handleLogStatProgress(Serializable obj, LogReportTaskService logReportTaskService) { Map<String, Object> progress = (Map<String, Object>) obj; Integer id = (Integer) progress.get("id"); Integer percent = (Integer) progress.get("percent"); ReportTask task = logReportTaskService.getTaskWithoutResult(id); if (task != null) { if (task.getProgress() == null || !task.getProgress().equals(percent)) { task.setProgress(percent.doubleValue()); logReportTaskService.refreshTask(task); }// w ww . j av a2 s . c o m } else { logger.warn("{}?!", id); } return null; }
From source file:org.neo4j.nlp.examples.sentiment.main.java
private static Map<String, Double> test(Integer testCount) throws IOException { Integer negativeError = 0; Integer positiveError = 0;//ww w . java2 s . co m Integer totalCount = 0; Integer negativeStep = 0; Integer positiveStep = 0; Integer allStep = 0; List<String> negativeText = readLargerTextFile(negativeSentimentDirectory); List<String> positiveText = readLargerTextFile(positiveSentimentDirectory); for (int i = 1; i < testCount * 2; i++) { if (i % 2 == 0) { int result = testOnText(negativeText.get(NEGATIVE_RANDOMIZED_INDEX.pop()), "negative") ? 0 : 1; totalCount += result; negativeError += result; negativeStep += 1; // Status update System.out.println("Negative: " + (1.0 - (negativeError.doubleValue() / negativeStep))); } else { int result = testOnText(positiveText.get(POSITIVE_RANDOMIZED_INDEX.pop()), "positive") ? 0 : 1; totalCount += result; positiveError += result; positiveStep += 1; // Status update System.out.println("Positive: " + (1.0 - (positiveError.doubleValue() / positiveStep))); } allStep += 1; // Status update System.out.println( "All: " + (1.0 - ((negativeError.doubleValue() + positiveError.doubleValue()) / allStep))); } Map<String, Double> errorMap = new HashMap<>(); errorMap.put("negative", 1.0 - (negativeError.doubleValue() / testCount.doubleValue())); errorMap.put("positive", 1.0 - (positiveError.doubleValue() / testCount.doubleValue())); errorMap.put("all", 1.0 - (totalCount.doubleValue() / (testCount.doubleValue() * 2))); // Return success ratio return errorMap; }
From source file:msi.gaml.operators.Maths.java
@operator(value = IKeyword.DIVIDE, can_be_const = true, category = { IOperatorCategory.ARITHMETIC }) @doc(value = "Returns a float, equal to the division of the left-hand operand by the rigth-hand operand.", see = "*") public static Double opDivide(final Double a, final Integer b) throws GamaRuntimeException { if (b == 0) { throw GamaRuntimeException.error("Division by zero"); }//from ww w . j a va 2s. com return a / b.doubleValue(); }
From source file:msi.gaml.operators.Maths.java
@operator(value = IKeyword.DIVIDE, can_be_const = true, category = { IOperatorCategory.ARITHMETIC }) @doc(value = "Returns a float, equal to the division of the left-hand operand by the rigth-hand operand.", see = "*") public static Double opDivide(final Integer a, final Double b) throws GamaRuntimeException { if (b.equals(0.0)) { throw GamaRuntimeException.error("Division by zero"); }/*from w w w . ja v a 2s.co m*/ return a.doubleValue() / b.doubleValue(); }
From source file:msi.gaml.operators.Maths.java
@operator(value = IKeyword.DIVIDE, can_be_const = true, category = { IOperatorCategory.ARITHMETIC }) @doc(value = "Returns the division of the two operands.", masterDoc = true, usages = { @usage(value = "if both operands are numbers (float or int), performs a normal arithmetic division and returns a float.", examples = { @example(value = "3 / 5.0", equals = "0.6") }) }, special_cases = "if the right-hand operand is equal to zero, raises a \"Division by zero\" exception", see = { IKeyword.PLUS, IKeyword.MINUS, IKeyword.MULTIPLY }) public static Double opDivide(final Integer a, final Integer b) throws GamaRuntimeException { if (b == 0) { throw GamaRuntimeException.error("Division by zero"); }/*from w ww .j a va 2 s . c o m*/ return Double.valueOf(a.doubleValue() / b.doubleValue()); }
From source file:no.imr.stox.functions.acoustic.PgNapesIO.java
public static void export(String cruise, String country, String callSignal, String path, String fileName, List<DistanceBO> distances, String species, Double intDist, Double pchThick) { // Atle: implement! Integer acoCat = PgNapesEchoConvert.getAcoCatFromPgNapesSpecies(species); BufferedWriter bWriter1 = null; BufferedWriter bWriter2 = null; try {/* w ww . j av a 2 s .com*/ String fil1 = path + "/" + fileName + "_Acoustic.txt"; String fil2 = path + "/" + fileName + "_AcousticValues.txt"; bWriter1 = new BufferedWriter(new FileWriter(fil1)); bWriter2 = new BufferedWriter(new FileWriter(fil2)); bWriter1.write("Country" + "" + "\t" + "Vessel" + "" + "\t" + "Cruise" + "" + "\t" + "Log" + "" + "\t"); bWriter1.write("Year" + "" + "\t" + "Month" + "" + "\t" + "Day" + "" + "\t" + "Hour" + "" + "\t"); bWriter1.write("Min" + "" + "\t" + "AcLat" + "" + "\t" + "AcLon" + "" + "\t" + "Logint" + "" + "\t"); bWriter1.write("Frequency" + "" + "\t" + "Sv_threshold"); bWriter1.newLine(); bWriter2.write("Country" + "" + "\t" + "Vessel" + "" + "\t" + "Cruise" + "" + "\t" + "Log" + "" + "\t"); bWriter2.write("Year" + "" + "\t" + "Month" + "" + "\t" + "Day" + "" + "\t" + "Species" + "" + "\t"); bWriter2.write("ChUppDepth" + "" + "\t" + "ChLowDepth" + "" + "\t" + "SA"); bWriter2.newLine(); Boolean isEnd = true; //Vertical Resolution/new channel thickness from filter Double totintdist = 0.0; Integer countdist = 0; Double sa50ch[] = new Double[1001]; //sa pr intdist Double saout[] = new Double[1001]; //sa accumulated over 5 nm. Output to files for (int g = 0; g < sa50ch.length; g++) { sa50ch[g] = 0.0; saout[g] = 0.0; } String hout1[] = new String[14]; // Sheet1: header info from first intdist in 5 nm dist for (int h = 0; h < hout1.length; h++) { hout1[h] = null; } String hout2[] = new String[8]; // Sheet2: header info from first intdist in 5 nm dist for (int h = 0; h < hout2.length; h++) { hout2[h] = null; } Resolution rr = new Resolution(); //GO THROUGH ALL OBSERVATIONS IN SELECTED DATASETT ONE OBS AT THE TIME Integer nobs = distances.size(); for (int line = 0; line < nobs; line++) { DistanceBO dist = distances.get(line); for (FrequencyBO f : dist.getFrequencies()) { FrequencyBO frequency = f; //PS! What if threshold change within a 5 nm ?? Use first value OK??? String threshold = Double.toString(frequency.getThreshold()); //String helpNumPel = Integer.toString(freq.getNum_pel_ch()); Date d = dist.getStart_time(); String helpymd = IMRdate.formatDate(d, "yyyyMMdd"); String year = helpymd.substring(0, 4); String month = helpymd.substring(4, 6); String day = helpymd.substring(6, 8); String helphms = IMRdate.formatDate(d, "HHmmss"); String hour = helphms.substring(0, 2); String min = helphms.substring(2, 4); // String Log = df.format(dist.getLog_start()/*LogFloor*/); String log = Conversion.formatDoubletoDecimalString(dist.getLog_start().doubleValue(), "0.0"); //Check if this is the end of the integrator distance (using the filter value rr.setIntDist(Math.max(intDist, dist.getIntegrator_dist())); rr.setLog(Conversion.safeStringtoDouble(log)); isEnd = rr.getIsEnd(); String acLat = Conversion.formatDoubletoDecimalString(dist.getLat_start(), "0.000"); String acLon = Conversion.formatDoubletoDecimalString(dist.getLon_start(), "0.000"); Double helppct = dist.getPel_ch_thickness(); Integer helppctR = (int) Math.round(helppct); //Number of ch per 50 meter ch Double vertRes = null; if (pchThick != null && pchThick > dist.getPel_ch_thickness()) { vertRes = pchThick; } else { vertRes = dist.getPel_ch_thickness(); } Double ww = vertRes / helppct; Integer helpnchch = ww.intValue(); //Number of 50 meter channels Integer q = frequency.getNum_pel_ch(); Integer ww1 = frequency.getNum_pel_ch() % helpnchch; Integer ww2 = (frequency.getNum_pel_ch() / helpnchch); Integer helpnch = ww2.intValue(); if (ww1 > 0) { helpnch = helpnch + 1; } if (helpnch > sa50ch[0]) { sa50ch[0] = helpnch.doubleValue(); } // SUM UP P SA VALUES FOR THIS OBSERVATION IN 50 meter CHANNELS List<SABO> salist = frequency.getSa(); for (Integer ch = 1; ch <= frequency.getNum_pel_ch(); ch++) { if (ch <= frequency.getNum_pel_ch()) { //Double saval = 0.0; for (Integer i = 0; i < salist.size(); i++) { //storage.getSaByFrequencyChannelTypeAcousticCategory(freq, "P", f.getId_acoustic_category()); SABO elm = salist.get(i); if (elm.getAcoustic_category() == null || elm.getCh() == null || elm.getCh_type() == null || !elm.getCh().equals(ch) || !elm.getCh_type().equals("P") || !elm.getAcoustic_category().equalsIgnoreCase(acoCat.toString())) { continue; } Double ch50a = (ch * helppctR.doubleValue()) % vertRes; Double ch50b = (ch * helppctR.doubleValue()) / vertRes; Integer ch50c = ch50b.intValue(); if (ch50a > 0) { ch50c = ch50c + 1; } sa50ch[ch50c] = elm.getSa() + sa50ch[ch50c]; sa50ch[1000] = elm.getSa() + sa50ch[1000]; break; } } } //IF START OF A NEW 5 NM DISTANCE KEEP HEADING VALUES if (isEnd.equals(true)) { hout1[0] = country; hout1[1] = callSignal; hout1[2] = cruise; hout1[3] = log; hout1[4] = year; hout1[5] = month; hout1[6] = day; hout1[7] = hour; hout1[8] = min; hout1[9] = acLat; hout1[10] = acLon; //hout1[11] = Logint; hout1[12] = frequency.getFreq().toString(); hout1[13] = threshold; hout2[0] = country; hout2[1] = callSignal; hout2[2] = cruise; hout2[3] = log; hout2[4] = year; hout2[5] = month; hout2[6] = day; hout2[7] = species; } //KEEP SA-VALUES FROM THIS INTEGRATOR DISTANCE if (sa50ch[0] > saout[0]) { saout[0] = sa50ch[0]; } for (int k = 1; k < saout.length; k++) { saout[k] = saout[k] + sa50ch[k]; } //Count number of intdist + totaldist countdist = countdist + 1; totintdist = totintdist + dist.getIntegrator_dist(); boolean okIntDist = false; //Check if distance from previous output distance is not to large due to holes in data: boolean okPrevDist = false; if ((rr.getEndLog() != null) && (rr.getIntDist() != null)) { if ((rr.getLog() - rr.getEndLog()) - 0.05 <= rr.getIntDist()) { okPrevDist = true; } else { okPrevDist = false; } } else { okPrevDist = true; } //Check if sum of distances is correct + check if stoplog minus startlog is equal to sum of distances if (rr.getIntDist() == null) { okIntDist = true; } else { if ((((rr.getIntDist() - 0.05) < totintdist) && (totintdist < (rr.getIntDist() + 0.05))) && okPrevDist) { okIntDist = true; } } //PRINT TO FILES if (okIntDist && isEnd) { for (int k = 1; k < saout.length; k++) { saout[k] = saout[k] / countdist; } //Sheet file 1: hout1[11] = Conversion.formatDoubletoDecimalString(totintdist, "0.0"); for (Integer elm = 0; elm < 14; elm++) { if (hout1[elm] != null) { bWriter1.write(hout1[elm] + "" + "\t"); } else { bWriter1.write(" " + "" + "\t"); } } bWriter1.newLine(); //Sheet file 2: for (Integer elm = 0; elm < saout[0].intValue(); elm++) { for (Integer e = 0; e < 8; e++) { bWriter2.write(hout2[e] + "" + "\t"); } bWriter2.write((elm * vertRes) + "" + "\t"); bWriter2.write(((elm * vertRes) + vertRes) + "" + "\t"); String sa = String.format(Locale.UK, "%11.5f", (saout[elm + 1])); bWriter2.write(sa + "" + "\t"); bWriter2.newLine(); } } else { for (int k = 1; k < sa50ch.length; k++) { sa50ch[k] = 0.0; } } if (isEnd.equals(true)) { for (int g = 0; g < sa50ch.length; g++) { sa50ch[g] = 0.0; saout[g] = 0.0; } //Total sa all channels, this variable is not used, test only sa50ch[1000] = 0.0; //Max number of 50 meter channels in 5 nm distance sa50ch[0] = 0.0; countdist = 0; totintdist = 0.0; } } // Have to look up by frequency here in future. } bWriter1.close(); bWriter2.close(); } catch (IOException ex) { throw new UncheckedIOException(ex); } }
From source file:org.squale.squalecommon.enterpriselayer.facade.quality.MeasureFacade.java
/** * Creation d'une mesure de type Bubble pour un projet * // ww w . ja va 2 s.c o m * @param pProjectId Id du projet * @param pAuditId Id de l'audit * @throws JrafEnterpriseException en cas de pb Hibernate * @return chart Scatterplot de l'Audit * @throws JrafEnterpriseException si pb Hibernate */ public static Object[] getProjectBubble(Long pProjectId, Long pAuditId) throws JrafEnterpriseException { // Rcupration des valeurs int i = 0; Collection measures = new ArrayList(0); MeasureDAOImpl measureDAO = MeasureDAOImpl.getInstance(); // Session Hibernate ISession session = null; Object[] result = null; try { // rcupration d'une session session = PERSISTENTPROVIDER.getSession(); // On rcupre la configuration du scatterplot pour ce projet et cet audit AuditDisplayConfBO auditConf = AuditDisplayConfDAOImpl.getInstance().findConfigurationWhere(session, pProjectId, pAuditId, "bubble"); if (null != auditConf) { BubbleConfBO bubble = (BubbleConfBO) auditConf.getDisplayConf(); String[] tre = { bubble.getXTre(), bubble.getYTre() }; // rcupration des mesures distinctes rattaches l'audit et au projet measures = MeasureDAOImpl.getInstance().findDistinct(session, pProjectId.longValue(), pAuditId.longValue(), tre); // recuperation des 2 tableaux evgs, vgs contenant les mesures double[] xMeasures = new double[measures.size()]; double[] yMeasures = new double[measures.size()]; double[] total = new double[measures.size()]; Iterator it = measures.iterator(); // Constantes pour la rcuprations des valeurs dans le tableau des rsultats remonts de la base final int VG_ID = 0; final int EVG_ID = 1; final int TOTAL_ID = 2; while (it.hasNext()) { Object[] res = (Object[]) it.next(); // on ajoute ses valeurs Integer vg = (Integer) res[VG_ID]; yMeasures[i] = vg.doubleValue(); Integer evg = (Integer) res[EVG_ID]; xMeasures[i] = evg.doubleValue(); Integer tt = (Integer) res[TOTAL_ID]; total[i] = tt.doubleValue(); i++; } // Positions des axes Long horizontal = new Long(bubble.getHorizontalAxisPos()); Long vertical = new Long(bubble.getVerticalAxisPos()); // construction des paramtres de la srie String displayedXTre = bubble.getXTre().substring(bubble.getXTre().lastIndexOf(".") + 1); String displayedYTre = bubble.getYTre().substring(bubble.getYTre().lastIndexOf(".") + 1); String measuresKinds = "(" + displayedXTre + "," + displayedYTre + ",total)"; result = new Object[] { horizontal, vertical, measuresKinds, yMeasures, xMeasures, total, yMeasures, xMeasures, total, tre }; } } catch (Exception e) { FacadeHelper.convertException(e, MeasureFacade.class.getName() + ".getMeasures"); } finally { FacadeHelper.closeSession(session, MeasureFacade.class.getName() + ".getMeasures"); } return result; }