List of usage examples for java.lang Double doubleValue
@HotSpotIntrinsicCandidate public double doubleValue()
From source file:org.egov.works.web.actions.tender.TenderNegotiationAction.java
private double getTotalWorkOrderQuantity(final String negotiationNumber) { Object[] params = new Object[] { negotiationNumber, WorksConstants.CANCELLED_STATUS }; Double totalWorkOrderQty = (Double) getPersistenceService().findByNamedQuery("getTotalQuantityForWO", params);/*from ww w .j a v a2 s . com*/ params = new Object[] { negotiationNumber, WorksConstants.NEW }; final Double totalWorkOrderQtyForNew = (Double) getPersistenceService() .findByNamedQuery("getTotalQuantityForNewWO", params); if (totalWorkOrderQty != null && totalWorkOrderQtyForNew != null) totalWorkOrderQty = totalWorkOrderQty + totalWorkOrderQtyForNew; if (totalWorkOrderQty == null && totalWorkOrderQtyForNew != null) totalWorkOrderQty = totalWorkOrderQtyForNew; if (totalWorkOrderQty == null) return 0.0d; else return totalWorkOrderQty.doubleValue(); }
From source file:org.oscarehr.renal.web.RenalAction.java
public ActionForward getNextSteps(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {//from w w w . jav a 2 s . c o m String demographicNo = request.getParameter("demographicNo"); CkdScreener screener = new CkdScreener(); List<String> reasons = new ArrayList<String>(); boolean match = screener.screenDemographic(Integer.parseInt(demographicNo), reasons, null); String nextSteps = "N/A"; if (match) nextSteps = "Screen patient for CKD<br/>using eGFR, ACR, and BP"; //get tests List<Measurement> egfrs = measurementDao.findByType(Integer.parseInt(demographicNo), "EGFR"); List<Measurement> acrs = measurementDao.findByType(Integer.parseInt(demographicNo), "ACR"); Date latestEgfrDate = null; Double latestEgfr = null; Double aYearAgoEgfr = null; if (egfrs.size() > 0) { latestEgfr = Double.valueOf(egfrs.get(0).getDataField()); latestEgfrDate = egfrs.get(0).getDateObserved(); } Double latestAcr = null; if (acrs.size() > 0) { latestAcr = Double.valueOf(acrs.get(0).getDataField()); } if (latestEgfrDate != null) { Calendar cal = Calendar.getInstance(); cal.setTime(latestEgfrDate); cal.add(Calendar.MONTH, -12); Date aYearBefore = cal.getTime(); //do we have any egfrs from before this date? List<Measurement> tmp = measurementDao.findByTypeBefore(Integer.parseInt(demographicNo), "EGFR", aYearBefore); if (tmp.size() > 0) { Measurement m = tmp.get(0); aYearAgoEgfr = Double.valueOf(m.getDataField()); } } if ((latestEgfr != null && latestEgfr < 30) || (latestAcr != null && latestAcr >= 60)) { nextSteps = "<a href=\"javascript:void();\" onclick=\"window.open('" + request.getContextPath() + "/oscarEncounter/oscarConsultationRequest/ConsultationFormRequest.jsp?de=" + demographicNo + "&teamVar=','Consultation" + demographicNo + "','width=960,height=700');return false;\">Refer to Nephrology</a>"; } if ((latestAcr != null && latestAcr > 2.8 && latestAcr < 60) && (latestEgfr != null && latestEgfr > 30)) { nextSteps = "Check ACR/eGFR q6m for<br/> 2 years, and if stable, yearly"; } if ((latestAcr != null && latestAcr <= 2.8) && (latestEgfr != null && latestEgfr >= 30 && latestEgfr <= 59)) { nextSteps = "Check ACR/eGFR q6m for<br/> 2 years, and if stable, yearly"; } if ((latestAcr != null && latestAcr <= 2.8) && (latestEgfr != null && latestEgfr > 60)) { nextSteps = "Check ACR/eGFR yearly"; } if (latestEgfr != null && aYearAgoEgfr != null) { if ((aYearAgoEgfr.doubleValue() - latestEgfr.doubleValue()) > 20) { nextSteps = "Check ACR, and if drop pesistent, <a href=\"javascript:void();\" onclick=\"window.open('" + request.getContextPath() + "/oscarEncounter/oscarConsultationRequest/ConsultationFormRequest.jsp?de=" + demographicNo + "&teamVar=','Consultation" + demographicNo + "','width=960,height=700');return false;\">Refer to Nephrology</a>"; } } String str = "{'result':'" + StringEscapeUtils.escapeJavaScript(nextSteps) + "'}"; JSONObject jsonArray = (JSONObject) JSONSerializer.toJSON(str); response.setContentType("text/x-json"); try { jsonArray.write(response.getWriter()); } catch (IOException e) { MiscUtils.getLogger().error("Error", e); } return null; }
From source file:org.sakaiproject.tool.gradebook.business.impl.GradebookManagerHibernateImpl.java
private List convertPointsToLetterGrade(Assignment assignment, Gradebook gradebook, List assignRecordsFromDB) { Double pointPossible = assignment.getPointsPossible(); if (pointPossible.doubleValue() > 0) { List letterGradeList = new ArrayList(); LetterGradePercentMapping lgpm = getLetterGradePercentMapping(assignment.getGradebook()); for (int i = 0; i < assignRecordsFromDB.size(); i++) { AssignmentGradeRecord agr = (AssignmentGradeRecord) assignRecordsFromDB.get(i); if (agr != null) { agr.setDateRecorded(agr.getDateRecorded()); agr.setGraderId(agr.getGraderId()); }//from w w w . j av a 2 s . co m if (agr != null && agr.getPointsEarned() != null) { String letterGrade = lgpm .getGrade(calculateEquivalentPercent(pointPossible, agr.getPointsEarned())); agr.setLetterEarned(letterGrade); letterGradeList.add(agr); } else if (agr != null) { agr.setLetterEarned(null); letterGradeList.add(agr); } } return letterGradeList; } return null; }
From source file:mondrian.test.loader.MondrianFoodMartLoader.java
/** * String representation of the column in the result set, suitable for * inclusion in a SQL insert statement.<p/> * * The column in the result set is transformed according to the type in * the column parameter.<p/>/*from ww w .ja va 2 s .c om*/ * * Different DBMSs (and drivers) return different Java types for a given * column; {@link ClassCastException}s may occur. * * @param rs ResultSet row to process * @param column Column to process * @return String representation of column value */ private String columnValue(ResultSet rs, Column column) throws Exception { Object obj = rs.getObject(column.name); String columnType = column.typeName; if (obj == null) { return "NULL"; } /* * Output for an INTEGER column, handling Doubles and Integers * in the result set */ if (columnType.startsWith(Type.Integer.name)) { if (obj.getClass() == Double.class) { try { Double result = (Double) obj; return integerFormatter.format(result.doubleValue()); } catch (ClassCastException cce) { LOGGER.error("CCE: " + column.name + " to Long from: " + obj.getClass().getName() + " - " + obj.toString()); throw cce; } } else { try { int result = ((Number) obj).intValue(); return Integer.toString(result); } catch (ClassCastException cce) { LOGGER.error("CCE: " + column.name + " to Integer from: " + obj.getClass().getName() + " - " + obj.toString()); throw cce; } } /* * Output for an SMALLINT column, handling Integers * in the result set */ } else if (columnType.startsWith(Type.Smallint.name)) { if (obj instanceof Boolean) { return (Boolean) obj ? "1" : "0"; } else { try { Integer result = (Integer) obj; return result.toString(); } catch (ClassCastException cce) { LOGGER.error("CCE: " + column.name + " to Integer from: " + obj.getClass().getName() + " - " + obj.toString()); throw cce; } } /* * Output for an BIGINT column, handling Doubles and Longs * in the result set */ } else if (columnType.startsWith("BIGINT")) { if (obj.getClass() == Double.class) { try { Double result = (Double) obj; return integerFormatter.format(result.doubleValue()); } catch (ClassCastException cce) { LOGGER.error("CCE: " + column.name + " to Double from: " + obj.getClass().getName() + " - " + obj.toString()); throw cce; } } else { try { Long result = (Long) obj; return result.toString(); } catch (ClassCastException cce) { LOGGER.error("CCE: " + column.name + " to Long from: " + obj.getClass().getName() + " - " + obj.toString()); throw cce; } } /* * Output for a String, managing embedded quotes */ } else if (columnType.startsWith("VARCHAR")) { return embedQuotes((String) obj); /* * Output for a TIMESTAMP */ } else { if (columnType.startsWith("TIMESTAMP")) { Timestamp ts = (Timestamp) obj; // REVIEW jvs 26-Nov-2006: Is it safe to replace // these with dialect.quoteTimestampLiteral, etc? switch (dialect.getDatabaseProduct()) { case ORACLE: case LUCIDDB: case NEOVIEW: return "TIMESTAMP '" + ts + "'"; default: return "'" + ts + "'"; } //return "'" + ts + "'" ; /* * Output for a DATE */ } else if (columnType.startsWith("DATE")) { Date dt = (Date) obj; switch (dialect.getDatabaseProduct()) { case ORACLE: case LUCIDDB: case NEOVIEW: return "DATE '" + dateFormatter.format(dt) + "'"; default: return "'" + dateFormatter.format(dt) + "'"; } /* * Output for a FLOAT */ } else if (columnType.startsWith(Type.Real.name)) { Float result = (Float) obj; return result.toString(); /* * Output for a DECIMAL(length, places) */ } else if (columnType.startsWith("DECIMAL")) { final Matcher matcher = decimalDataTypeRegex.matcher(columnType); if (!matcher.matches()) { throw new Exception("Bad DECIMAL column type for " + columnType); } DecimalFormat formatter = new DecimalFormat(decimalFormat(matcher.group(1), matcher.group(2))); if (obj.getClass() == Double.class) { try { Double result = (Double) obj; return formatter.format(result.doubleValue()); } catch (ClassCastException cce) { LOGGER.error("CCE: " + column.name + " to Double from: " + obj.getClass().getName() + " - " + obj.toString()); throw cce; } } else { // should be (obj.getClass() == BigDecimal.class) try { BigDecimal result = (BigDecimal) obj; return formatter.format(result); } catch (ClassCastException cce) { LOGGER.error("CCE: " + column.name + " to BigDecimal from: " + obj.getClass().getName() + " - " + obj.toString()); throw cce; } } /* * Output for a BOOLEAN (Postgres) or BIT (other DBMSs) */ } else if (columnType.startsWith("BOOLEAN") || columnType.startsWith("BIT")) { Boolean result = (Boolean) obj; return result.toString(); /* * Output for a BOOLEAN - TINYINT(1) (MySQL) */ } else if (columnType.startsWith("TINYINT(1)")) { return (Boolean) obj ? "1" : "0"; } } throw new Exception("Unknown column type: " + columnType + " for column: " + column.name); }
From source file:org.sakaiproject.tool.gradebook.business.impl.GradebookManagerHibernateImpl.java
private double getTotalPointsInternal(Long gradebookId, Session session) { double totalPointsPossible = 0; Iterator assignmentPointsIter = session.createQuery( "select asn.pointsPossible from Assignment asn where asn.gradebook.id=:gbid and asn.removed=false and asn.notCounted=false and asn.ungraded=false") .setParameter("gbid", gradebookId).list().iterator(); while (assignmentPointsIter.hasNext()) { Double pointsPossible = (Double) assignmentPointsIter.next(); totalPointsPossible += pointsPossible.doubleValue(); }/*from w ww .j av a2 s . c o m*/ return totalPointsPossible; }
From source file:com.joliciel.jochre.graphics.ShapeImpl.java
double getBrightnessMeanBySector(String key, SectionBrightnessMeasurementMethod measurementMethod) { Map<SectionBrightnessMeasurementMethod, Double> methodToMeanMap = this.brightnessMeanBySectorMap.get(key); if (methodToMeanMap == null) { methodToMeanMap = new HashMap<Shape.SectionBrightnessMeasurementMethod, Double>(); this.brightnessMeanBySectorMap.put(key, methodToMeanMap); }/*from ww w. ja v a2 s . c o m*/ Double brightnessMeanBySectorObj = methodToMeanMap.get(measurementMethod); double brightnessMeanBySector = 0.0; if (brightnessMeanBySectorObj == null) { Mean mean = new Mean(); Map<SectionBrightnessMeasurementMethod, double[][]> brightnessByMethod = this.brightnessBySectorMap .get(key); double[][] brightnessGrid = brightnessByMethod.get(measurementMethod); for (int i = 0; i < brightnessGrid.length; i++) mean.incrementAll(brightnessGrid[i]); brightnessMeanBySector = mean.getResult(); methodToMeanMap.put(measurementMethod, brightnessMeanBySector); } else { brightnessMeanBySector = brightnessMeanBySectorObj.doubleValue(); } return brightnessMeanBySector; }
From source file:net.cbtltd.server.ReservationService.java
/** * Gets the deposit percentage required by a property manager (organization) on the specified date * * @param sqlSession the current SQL session. * @param reservation the reservation for which the deposit percentage is to be calculated. * @return the deposit percentage.// ww w . java 2 s. c o m */ public static final Double getDeposit(SqlSession sqlSession, Reservation reservation) { String temp = RelationService.value(sqlSession, Relation.PARTY_VALUE, reservation.getOrganizationid(), Party.Value.Payfull.name()); Integer payfull = temp == null ? 30 : Integer.valueOf(temp); temp = RelationService.value(sqlSession, Relation.PARTY_VALUE, reservation.getOrganizationid(), Party.Value.Payunit.name()); String unit = temp == null ? Unit.DAY : temp; if (Time.WEEK.name().equalsIgnoreCase(unit)) { payfull *= 7; } else if (Time.MONTH.name().equalsIgnoreCase(unit)) { payfull *= 30; } if (Time.getDuration(new Date(), reservation.getFromdate(), Time.DAY) <= payfull) { return 100.; } String type = RelationService.value(sqlSession, Relation.PARTY_VALUE, reservation.getOrganizationid(), Party.Value.DepositType.name()); if (type == null) { type = Party.DEPOSITS[1]; } temp = RelationService.value(sqlSession, Relation.PARTY_VALUE, reservation.getOrganizationid(), Party.Value.Deposit.name()); Double value = temp == null ? 0.0 : Double.valueOf(temp); // if (Party.DEPOSITS[0].equalsIgnoreCase(type)) {value = (value / 100.0) * reservation.getQuote();} // % Booking Value if (Party.DEPOSITS[1].equalsIgnoreCase(type)) { value = (value / 100.0) * reservation.getQuote() / reservation.getDuration(Time.DAY); } // % Daily Rate else if (Party.DEPOSITS[2].equalsIgnoreCase(type)) { ; } // Amount per Booking else if (Party.DEPOSITS[3].equalsIgnoreCase(type)) { value = value * reservation.getDuration(Time.DAY); } // Amount per Day else { value = (value / 100.0) * reservation.getQuote(); } // % Booking Value LOG.debug("" + type + " " + temp + " " + value + " " + reservation.getQuote() + " " + (value * 100.0 / reservation.getQuote()) + " " + reservation.getDuration(Time.DAY)); value = value * 100.0 / reservation.getQuote(); return value.doubleValue(); }
From source file:org.sakaiproject.tool.gradebook.business.impl.GradebookManagerHibernateImpl.java
private List convertPointsToPercentage(Assignment assignment, Gradebook gradebook, List assignRecordsFromDB) { Double pointPossible = assignment.getPointsPossible(); List percentageList = new ArrayList(); if (pointPossible.doubleValue() > 0) { for (int i = 0; i < assignRecordsFromDB.size(); i++) { AssignmentGradeRecord agr = (AssignmentGradeRecord) assignRecordsFromDB.get(i); if (agr != null) { agr.setDateRecorded(agr.getDateRecorded()); agr.setGraderId(agr.getGraderId()); }// w ww .j av a2s . c o m if (agr != null && agr.getPointsEarned() != null) { agr.setPercentEarned(calculateEquivalentPercent(pointPossible, agr.getPointsEarned())); percentageList.add(agr); } else if (agr != null) { agr.setPercentEarned(null); percentageList.add(agr); } } } return percentageList; }
From source file:org.sakaiproject.tool.gradebook.business.impl.GradebookManagerHibernateImpl.java
private double getTotalPointsEarnedInternal(final Long gradebookId, final String studentId, final Session session) { double totalPointsEarned = 0; Iterator scoresIter = session.createQuery( "select agr.pointsEarned from AssignmentGradeRecord agr, Assignment asn where agr.gradableObject=asn and agr.studentId=:student and asn.gradebook.id=:gbid and asn.removed=false and asn.notCounted=false and asn.ungraded=false and asn.pointsPossible > 0") .setParameter("student", studentId).setParameter("gbid", gradebookId).list().iterator(); while (scoresIter.hasNext()) { Double pointsEarned = (Double) scoresIter.next(); if (pointsEarned != null) { totalPointsEarned += pointsEarned.doubleValue(); }/* ww w. j a v a 2 s .c om*/ } if (log.isDebugEnabled()) log.debug( "getTotalPointsEarnedInternal for studentId=" + studentId + " returning " + totalPointsEarned); return totalPointsEarned; }
From source file:com.opengamma.financial.analytics.model.volatility.surface.HestonFourierIRFutureSurfaceFittingFunctionDeprecated.java
@Override public Set<ComputedValue> execute(final FunctionExecutionContext executionContext, final FunctionInputs inputs, final ComputationTarget target, final Set<ValueRequirement> desiredValues) { final Object objectSurfaceData = inputs.getValue(_surfaceRequirement); if (objectSurfaceData == null) { throw new OpenGammaRuntimeException("Could not get volatility surface data"); }/*ww w.jav a 2s.c o m*/ @SuppressWarnings("unchecked") final VolatilitySurfaceData<Double, Double> volatilitySurfaceData = (VolatilitySurfaceData<Double, Double>) objectSurfaceData; final Object objectFuturePriceData = inputs.getValue(_futurePriceRequirement); if (objectFuturePriceData == null) { throw new OpenGammaRuntimeException("Could not get futures price data"); } final NodalDoublesCurve futurePriceData = (NodalDoublesCurve) objectFuturePriceData; //assumes that the sorting is first x, then y if (volatilitySurfaceData.size() == 0) { throw new OpenGammaRuntimeException("Interest rate future option volatility surface definition name=" + _definitionName + " contains no data"); } final SortedSet<Double> x = volatilitySurfaceData.getUniqueXValues(); final DoubleArrayList fittedOptionExpiryList = new DoubleArrayList(); final DoubleArrayList futureDelayList = new DoubleArrayList(); final DoubleArrayList kappaList = new DoubleArrayList(); final DoubleArrayList thetaList = new DoubleArrayList(); final DoubleArrayList vol0List = new DoubleArrayList(); final DoubleArrayList omegaList = new DoubleArrayList(); final DoubleArrayList rhoList = new DoubleArrayList(); final DoubleArrayList chiSqList = new DoubleArrayList(); final Map<DoublesPair, DoubleMatrix2D> inverseJacobians = new HashMap<DoublesPair, DoubleMatrix2D>(); for (final Double t : x) { final List<ObjectsPair<Double, Double>> strip = volatilitySurfaceData.getYValuesForX(t); // FIXME This is bound to break. I changed x/t from an ordinal to an OG-Analytics Year, // via TimeCalculator.getTimeBetween(now, IRFutureOptionUtils.getTime(x,now)) where now is the valuationTime. See IRFutureOptionVolatilitySurfaceDataFunction final int n = strip.size(); final DoubleArrayList strikesList = new DoubleArrayList(n); final DoubleArrayList sigmaList = new DoubleArrayList(n); final DoubleArrayList errorsList = new DoubleArrayList(n); final Double futurePrice = futurePriceData.getYValue(t); if (strip.size() > 4 && futurePrice != null) { final double forward = 1 - futurePrice; for (final ObjectsPair<Double, Double> value : strip) { if (value.first != null && value.second != null) { strikesList.add(1 - value.first / 100); sigmaList.add(value.second); errorsList.add(ERROR); } } if (!strikesList.isEmpty()) { final double[] strikes = strikesList.toDoubleArray(); final double[] sigma = sigmaList.toDoubleArray(); final double[] errors = errorsList.toDoubleArray(); ArrayUtils.reverse(strikes); ArrayUtils.reverse(sigma); ArrayUtils.reverse(errors); final LeastSquareResultsWithTransform fittedResult = new HestonModelFitter(forward, strikes, t, sigma, errors, HESTON_FUNCTION).solve(HESTON_INITIAL_VALUES); final DoubleMatrix1D parameters = fittedResult.getModelParameters(); fittedOptionExpiryList.add(t); futureDelayList.add(0); kappaList.add(parameters.getEntry(0)); thetaList.add(parameters.getEntry(1)); vol0List.add(parameters.getEntry(2)); omegaList.add(parameters.getEntry(3)); rhoList.add(parameters.getEntry(4)); inverseJacobians.put(DoublesPair.of(t.doubleValue(), 0.), fittedResult.getModelParameterSensitivityToData()); chiSqList.add(fittedResult.getChiSq()); } } } if (fittedOptionExpiryList.size() < 5) { //don't have sufficient fits to construct a surface throw new OpenGammaRuntimeException( "Could not construct Heston parameter surfaces; have under 5 surface points"); } final double[] fittedOptionExpiry = fittedOptionExpiryList.toDoubleArray(); final double[] futureDelay = futureDelayList.toDoubleArray(); final double[] kappa = kappaList.toDoubleArray(); final double[] theta = thetaList.toDoubleArray(); final double[] vol0 = vol0List.toDoubleArray(); final double[] omega = omegaList.toDoubleArray(); final double[] rho = rhoList.toDoubleArray(); final InterpolatedDoublesSurface kappaSurface = InterpolatedDoublesSurface.from(fittedOptionExpiry, futureDelay, kappa, INTERPOLATOR, "Heston kappa surface"); final InterpolatedDoublesSurface thetaSurface = InterpolatedDoublesSurface.from(fittedOptionExpiry, futureDelay, theta, INTERPOLATOR, "Heston theta surface"); final InterpolatedDoublesSurface vol0Surface = InterpolatedDoublesSurface.from(fittedOptionExpiry, futureDelay, vol0, INTERPOLATOR, "Heston vol0 surface"); final InterpolatedDoublesSurface omegaSurface = InterpolatedDoublesSurface.from(fittedOptionExpiry, futureDelay, omega, INTERPOLATOR, "Heston omega surface"); final InterpolatedDoublesSurface rhoSurface = InterpolatedDoublesSurface.from(fittedOptionExpiry, futureDelay, rho, INTERPOLATOR, "Heston rho surface"); final HestonFittedSurfaces fittedSurfaces = new HestonFittedSurfaces(kappaSurface, thetaSurface, vol0Surface, omegaSurface, rhoSurface, inverseJacobians, _currency); return Sets.newHashSet(new ComputedValue(_resultSpecification, fittedSurfaces)); }