List of usage examples for java.lang Double doubleValue
@HotSpotIntrinsicCandidate public double doubleValue()
From source file:com.aerohive.nms.web.config.lbs.services.HmFolderServiceImpl.java
private double getDistanceMetric(Double distance, LengthUnit unit) { if (null == distance) { return 0; }//from ww w .j av a 2 s .c om if (null == unit) { return distance.doubleValue(); } if (LengthUnit.FEET == unit) { return distance * HmFolder.FEET_TO_METERS; } else { return distance.doubleValue(); } }
From source file:eionet.gdem.conversion.excel.writer.ExcelConversionHandler.java
@Override public void addCell(String type, String str_value, String style_name) { HSSFSheet _sheet = wb.getSheetAt(currentSheet); HSSFRow _row = _sheet.getRow(currentRow); HSSFCell _cell = _row.createCell((currentCell)); Double number_value = null; Boolean boolean_value = null; boolean isNumber = false; boolean isBoolean = false; if (type == null) { type = (String) getDefaultParams("data_type"); }/* w w w . j a va2 s . c o m*/ if (type != null) { if (type.equals("float") || type.equals("number")) { if (str_value != null) { try { number_value = new Double(str_value); isNumber = true; } catch (Exception e) { // the value is not number, it will be inserted as a string // System.out.println(e.toString()); } } else { isNumber = true; } } else if (type.equals("boolean")) { if (str_value != null) { try { boolean_value = new Boolean(str_value); isBoolean = true; } catch (Exception e) { // the value is not boolean, it will be inserted as a string // System.out.println(e.toString()); } } else { isBoolean = true; } } else if (type.equals("date")) { if (str_value != null) { try { // cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("yyyymmdd")); /* * * The way how to handle user defined formats not supported right now HSSFDataFormat format = * wb.createDataFormat(); HSSFCellStyle style = wb.createCellStyle(); * style.setDataFormat(format.getFormat("yyyymmdd")); _cell.setCellStyle(style); */ // cellStyle.setDataFormat(new HSSFDataFormat("yyyymmdd")); /* * try{ l_value=Long.parseLong(value); System.out.println(String.valueOf(l_value)); isLong=true; } * catch(Exception e){ System.out.println(e.toString()); } */ /* * if (isLong){ Date d = new Date(); _cell.setCellStyle(cellStyle); //_cell.setCellValue(d); * _cell.setCellValue(value); //System.out.println(d.toString()); isDate=true; } else * _cell.setCellValue(value); */ // System.out.println("hh"); } catch (Exception e) { System.out.println(e.toString()); } } } } if (isNumber) { if (number_value != null) { _cell.setCellValue(number_value.doubleValue()); } _cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); } else if (isBoolean) { if (boolean_value != null) { _cell.setCellValue(boolean_value.booleanValue()); } _cell.setCellType(HSSFCell.CELL_TYPE_BOOLEAN); } else { _cell.setCellType(HSSFCell.CELL_TYPE_STRING); // _cell.setEncoding(HSSFCell.ENCODING_UTF_16 );// _cell.setCellValue(str_value); } short idx = -1; if (style_name != null) { idx = getStyleIdxByName(style_name, ExcelStyleIF.STYLE_FAMILY_TABLE_CELL); } if (idx < 0) { Short short_idx = (Short) getDefaultParams("style"); if (short_idx != null) { idx = short_idx.shortValue(); } } if (idx > -1) { _cell.setCellStyle(wb.getCellStyleAt(idx)); } // calculates the col with according to the first row if (currentRow == 0 && idx > -1) { short colStyleWidth = 0; HSSFCellStyle style = wb.getCellStyleAt(idx); int f_i = style.getFontIndex(); HSSFFont font = wb.getFontAt((short) f_i); // character size short size = font.getFontHeightInPoints(); if (columns.size() > currentCell) { RowColumnDefinition column = columns.get(currentCell); String column_style_name = column.getStyleName() == null ? "" : column.getStyleName(); ExcelStyleIF definedStyle = getStyleByName(column_style_name, ExcelStyleIF.STYLE_FAMILY_TABLE_CELL); if (definedStyle != null) { colStyleWidth = definedStyle.getColumnWidth(); } } short width = (short) (_sheet.getDefaultColumnWidth() * size * 25); if (colStyleWidth > 0) { width = colStyleWidth; } else if (str_value.length() > 0) { width = (short) (str_value.length() * size * 50); } _sheet.setColumnWidth(currentCell, width); } currentCell = _cell.getColumnIndex() + 1; // System.out.println("Cell" + currentCell+ "-" + value); }
From source file:com.aerohive.nms.web.config.lbs.services.HmFolderServiceImpl.java
private void setFolderImageSize(HmFolder folder) throws Exception { String backgroundImage = folder.getBackground(); if (StringUtils.isEmpty(backgroundImage)) { // no background image attached Double sizeX = folder.getMetricWidth(); Double sizeY = folder.getMetricHeight(); if (null != sizeX && null != sizeY && sizeX.doubleValue() > 0 && sizeY.doubleValue() > 0) { folder.setImageWidth(sizeX.intValue()); folder.setImageHeight(sizeY.intValue()); } else {// w w w .j a va2 s .c o m folder.setImageWidth(0); folder.setImageHeight(0); } } else { // background image attached HmImageMetadata o = imageRep.findByImageNameAndOwnerId(backgroundImage, folder.getOwnerId()); if (null != o) { folder.setImageWidth(o.getImageWidth()); folder.setImageHeight(o.getImageHeight()); logger.info("Set " + folder.getName() + " background image Height : " + o.getImageHeight() + " Width : " + o.getImageWidth()); // calculate metric height if metric width assigned if (null != folder.getMetricWidth()) { folder.setMetricHeight( folder.getMetricWidth() * folder.getImageHeight() / folder.getImageWidth()); } else { folder.setMetricHeight(null); } } else { folder.setImageWidth(0); folder.setImageHeight(0); folder.setMetricWidth(null); folder.setMetricHeight(null); folder.setBackground(null); logger.error("Set " + folder.getName() + " background image Height and width to 0, as no image metadata found with image: " + backgroundImage); } } }
From source file:org.energy_home.jemma.ah.internal.greenathome.GreenathomeAppliance.java
public Hashtable getInfo(IAppliance peerAppliance) throws ApplianceException, ServiceClusterException { int availability = 0; int state = 0; int status = 0; boolean isStateChangable = false; String locationPid = null;/* w w w. j a va 2 s . c o m*/ String categoryPid = null; Hashtable props = new Hashtable(); props.put("type", peerAppliance.getDescriptor().getType()); props.put("pid", peerAppliance.getPid()); props.put("id", peerAppliance.getPid()); // Pid or id? synchronized (lockGatH) { OnOffServer onOffServer = null; onOffServer = (OnOffServer) greenathomeEndPoint.getPeerServiceCluster(peerAppliance.getPid(), OnOffServer.class.getName()); if (onOffServer != null) { isStateChangable = true; availability = ((IServiceCluster) onOffServer).getEndPoint().isAvailable() ? 2 : 0; boolean onOff = false; try { onOff = onOffServer.getOnOff(onOffCommandContext); if (onOff) state = On; else state = Off; } catch (Exception e) { // availability = 0; state = Unknown; } } /* * if (readApplianceStatus) { ApplianceControlServer * applianceControlServer = (ApplianceControlServer) * greenathomeEndPoint.getPeerServiceCluster( * peerAppliance.getPid(), ApplianceControlServer.class.getName()); * if (applianceControlServer != null) { isStateChangable = true; * availability = ((IServiceCluster) * applianceControlServer).getEndPoint().isAvailable() ? 2 : 0; * * int applianceStatus = 0; * * try { applianceStatus = * applianceControlServer.getApplianceStatus(null); * * if (logEnabled) log.debug("applianceStatus is " + * applianceStatus); * * if (applianceStatus < 0x03) { state = Off; } else { state = On; } * } catch (Exception e) { state = Unknown; // availability = 0; } } * } */ ThermostatServer thermostatServer = (ThermostatServer) greenathomeEndPoint .getPeerServiceCluster(peerAppliance.getPid(), ThermostatServer.class.getName()); if (thermostatServer != null) { isStateChangable = true; availability = ((IServiceCluster) thermostatServer).getEndPoint().isAvailable() ? 2 : 0; } RelativeHumidityMeasurementServer humidityServer = (RelativeHumidityMeasurementServer) greenathomeEndPoint .getPeerServiceCluster(peerAppliance.getPid(), RelativeHumidityMeasurementServer.class.getName()); if (humidityServer != null) { isStateChangable = true; availability = ((IServiceCluster) humidityServer).getEndPoint().isAvailable() ? 2 : 0; } // handle Smart Info and Smart Plugs SimpleMeteringServer simpleMeteringServer = (SimpleMeteringServer) greenathomeEndPoint .getPeerServiceCluster(peerAppliance.getPid(), SimpleMeteringServer.class.getName()); if (onOffServer == null && simpleMeteringServer != null) { availability = ((IServiceCluster) simpleMeteringServer).getEndPoint().isAvailable() ? 2 : 0; } ConfigServer configServer = (ConfigServer) greenathomeEndPoint .getPeerServiceCluster(peerAppliance.getPid(), ConfigServer.class.getName()); if (configServer != null) { locationPid = configServer.getLocationPid(null); if (locationPid != null) { ILocation location = this.getLocation(locationPid); if (location != null) props.put("location", location); } categoryPid = configServer.getCategoryPid(null); if (categoryPid != null) { ICategory category = this.getCategory(categoryPid); if (category != null) props.put("category", category); } try { props.put("name", configServer.getName(null)); } catch (Exception e) { props.put("name", peerAppliance.getPid()); } try { props.put("icon", configServer.getIconName(null)); } catch (Exception e) { props.put("icon", "lampadina.png"); } } else return null; props.put("device_state_avail", new Boolean(isStateChangable)); props.put("device_state", new Integer(state)); props.put("availability", new Integer(availability)); props.put("device_status", new Integer(status)); String value = ""; if (!peerAppliance.getDescriptor().getType().equals(SMARTINFO_APP_TYPE)) { if (thermostatServer != null) { float localTemperature = (float) (thermostatServer.getLocalTemperature(maxAgeContext) / 100.0); value = localTemperature + "^C"; if (humidityServer != null) { float humididy = (float) (humidityServer.getMeasuredValue(maxAgeContext) / 100.0); value += " " + humididy + "%"; } } else { if (!useReportingOnSimpleMetering) { try { double power = this.readPower(peerAppliance); value = OutputPower.format(power / 1000.0); } catch (Exception e) { value = "na"; } } else { Double istantaneousDemand = (Double) istantaneousDemands.get(peerAppliance.getPid()); if (istantaneousDemand != null) { value = OutputPower.format(istantaneousDemand.doubleValue() / 1000.0); } } } } props.put("device_value", value); // if (location != null) { // props.put("location", location); // } // // if (category != null) { // props.put("category", category); // } } return props; }
From source file:org.egov.ptis.domain.service.property.PropertyExternalService.java
private PropertyTaxDetails getPropertyTaxDetails(final BasicProperty basicProperty, String category) { final PropertyTaxDetails propertyTaxDetails = new PropertyTaxDetails(); final ErrorDetails errorDetails = new ErrorDetails(); if (null != basicProperty) { final String assessmentNo = basicProperty.getUpicNo(); if (!basicProperty.isActive()) { errorDetails.setErrorCode(PROPERTY_DEACTIVATE_ERR_CODE); errorDetails.setErrorMessage(PROPERTY_DEACTIVATE_ERR_MSG); propertyTaxDetails.setErrorDetails(errorDetails); } else {//from www . j ava 2 s .c o m final Set<PropertyStatusValues> statusValues = basicProperty.getPropertyStatusValuesSet(); if (null != statusValues && !statusValues.isEmpty()) for (final PropertyStatusValues statusValue : statusValues) if (statusValue.getPropertyStatus().getStatusCode() == MARK_DEACTIVE) { errorDetails.setErrorCode(PROPERTY_MARK_DEACTIVATE_ERR_CODE); errorDetails.setErrorMessage(PROPERTY_MARK_DEACTIVATE_ERR_MSG); } } final Property property = basicProperty.getProperty(); ptDemandDAO.getDemandCollMap(property); if (!StringUtils.isBlank(category)) { String propType = property.getPropertyDetail().getPropertyTypeMaster().getCode(); if (CATEGORY_TYPE_PROPERTY_TAX.equals(category)) { if (propType.equals(OWNERSHIP_TYPE_VAC_LAND)) { errorDetails.setErrorCode(THIRD_PARTY_ERR_CODE_PROPERTY_TAX_ASSESSMENT_NOT_FOUND); errorDetails.setErrorMessage(THIRD_PARTY_ERR_MSG_PROPERTY_TAX_ASSESSMENT_NOT_FOUND); propertyTaxDetails.setErrorDetails(errorDetails); return propertyTaxDetails; } } else if (CATEGORY_TYPE_VACANTLAND_TAX.equals(category)) { if (!propType.equals(OWNERSHIP_TYPE_VAC_LAND)) { errorDetails.setErrorCode(THIRD_PARTY_ERR_CODE_VACANTLAND_ASSESSMENT_NOT_FOUND); errorDetails.setErrorMessage(THIRD_PARTY_ERR_MSG_VACANTLAND_ASSESSMENT_NOT_FOUND); propertyTaxDetails.setErrorDetails(errorDetails); return propertyTaxDetails; } } else { errorDetails.setErrorCode(THIRD_PARTY_ERR_CODE_WRONG_CATEGORY); errorDetails.setErrorMessage(THIRD_PARTY_ERR_MSG_WRONG_CATEGORY); propertyTaxDetails.setErrorDetails(errorDetails); return propertyTaxDetails; } } final List<PropertyOwnerInfo> propOwnerInfos = property.getBasicProperty().getPropertyOwnerInfo(); propertyTaxDetails.setOwnerDetails(new ArrayList<OwnerDetails>(0)); OwnerDetails ow; for (int i = 0; i < propOwnerInfos.size(); i++) { final PropertyOwnerInfo propOwnerInfo = propOwnerInfos.get(i); final String ownerName = propOwnerInfo.getOwner().getName(); if (null != ownerName && ownerName.trim().length() != 0) { ow = new OwnerDetails(); ow.setOwnerName(ownerName); ow.setMobileNo(propOwnerInfo.getOwner().getMobileNumber()); propertyTaxDetails.getOwnerDetails().add(ow); } } propertyTaxDetails.setPropertyAddress(property.getBasicProperty().getAddress().toString()); propertyTaxDetails.setAssessmentNo(property.getBasicProperty().getUpicNo()); propertyTaxDetails.setOldAssessmentNo(property.getBasicProperty().getOldMuncipalNum()); propertyTaxDetails.setLocalityName(property.getBasicProperty().getPropertyID().getLocality().getName()); propertyTaxBillable.setBasicProperty(basicProperty); propertyTaxBillable.setLevyPenalty(Boolean.TRUE); Map<Installment, PenaltyAndRebate> calculatedPenalty = propertyTaxBillable.getCalculatedPenalty(); final List<Object> list = ptDemandDAO.getPropertyTaxDetails(assessmentNo); if (!list.isEmpty()) propertyTaxDetails.setTaxDetails(new ArrayList<RestPropertyTaxDetails>(0)); else { return propertyTaxDetails; } String loopInstallment = ""; RestPropertyTaxDetails arrearDetails = null; BigDecimal total = BigDecimal.ZERO; for (final Object record : list) { final Object[] data = (Object[]) record; final String taxType = (String) data[0]; final String installment = (String) data[1]; final Double dmd = (Double) data[2]; final Double col = (Double) data[3]; final BigDecimal demand = BigDecimal.valueOf(dmd.doubleValue()); final BigDecimal collection = BigDecimal.valueOf(col.doubleValue()); if (loopInstallment.isEmpty()) { loopInstallment = installment; arrearDetails = new RestPropertyTaxDetails(); arrearDetails.setInstallment(installment); } if (loopInstallment.equals(installment)) { if (DEMANDRSN_CODE_PENALTY_FINES.equalsIgnoreCase(taxType)) arrearDetails.setPenalty(demand.subtract(collection)); else if (DEMANDRSN_CODE_CHQ_BOUNCE_PENALTY.equalsIgnoreCase(taxType)) arrearDetails.setChqBouncePenalty(demand.subtract(collection)); else total = total.add(demand.subtract(collection)); } else { arrearDetails.setTaxAmount(total); arrearDetails.setTotalAmount(total.add(arrearDetails.getChqBouncePenalty())); propertyTaxDetails.getTaxDetails().add(arrearDetails); loopInstallment = installment; arrearDetails = new RestPropertyTaxDetails(); arrearDetails.setInstallment(installment); total = BigDecimal.ZERO; if (DEMANDRSN_CODE_PENALTY_FINES.equalsIgnoreCase(taxType)) arrearDetails.setPenalty(demand.subtract(collection)); else if (DEMANDRSN_CODE_CHQ_BOUNCE_PENALTY.equalsIgnoreCase(taxType)) arrearDetails.setChqBouncePenalty(demand.subtract(collection)); else total = total.add(demand.subtract(collection)); } } if (arrearDetails != null) { arrearDetails.setTaxAmount(total); arrearDetails.setTotalAmount(total.add(arrearDetails.getChqBouncePenalty())); propertyTaxDetails.getTaxDetails().add(arrearDetails); } Set<Installment> keySet = calculatedPenalty.keySet(); // for all years data for (RestPropertyTaxDetails details : propertyTaxDetails.getTaxDetails()) { // loop trough the penalty for (Installment inst : keySet) { if (inst.getDescription().equalsIgnoreCase(details.getInstallment())) { details.setPenalty(calculatedPenalty.get(inst).getPenalty()); details.setRebate(calculatedPenalty.get(inst).getRebate()); details.setTotalAmount( details.getTotalAmount().add(calculatedPenalty.get(inst).getPenalty())); if (details.getRebate() != null) { details.setTotalAmount(details.getTotalAmount().subtract(details.getRebate())); } break; } } } } return propertyTaxDetails; }
From source file:org.sakaiproject.component.gradebook.GradebookServiceHibernateImpl.java
@SuppressWarnings({ "rawtypes", "unchecked" }) private double getTotalPointsInternal(final Gradebook gradebook, final List categories, final String studentId, List<AssignmentGradeRecord> studentGradeRecs, List<Assignment> countedAssigns, boolean literalTotal) { int gbGradeType = gradebook.getGrade_type(); if (gbGradeType != GradebookService.GRADE_TYPE_POINTS && gbGradeType != GradebookService.GRADE_TYPE_PERCENTAGE) { if (log.isInfoEnabled()) log.error("Wrong grade type in GradebookCalculationImpl.getTotalPointsInternal"); return -1; }/*w w w. java2 s. com*/ if (studentGradeRecs == null || countedAssigns == null) { if (log.isDebugEnabled()) log.debug("Returning 0 from getTotalPointsInternal " + "since studentGradeRecs or countedAssigns was null"); return 0; } double totalPointsPossible = 0; HashSet<Assignment> countedSet = new HashSet<Assignment>(countedAssigns); // we need to filter this list to identify only "counted" grade recs List<AssignmentGradeRecord> countedGradeRecs = new ArrayList<AssignmentGradeRecord>(); for (AssignmentGradeRecord gradeRec : studentGradeRecs) { Assignment assign = gradeRec.getAssignment(); boolean extraCredit = assign.isExtraCredit(); if (gradebook.getCategory_type() != GradebookService.CATEGORY_TYPE_NO_CATEGORY && assign.getCategory() != null && assign.getCategory().isExtraCredit()) extraCredit = true; if (assign.isCounted() && !assign.getUngraded() && !assign.isRemoved() && countedSet.contains(assign) && assign.getPointsPossible() != null && assign.getPointsPossible() > 0 && !gradeRec.getDroppedFromGrade() && !extraCredit) { countedGradeRecs.add(gradeRec); } } Set assignmentsTaken = new HashSet(); Set categoryTaken = new HashSet(); for (AssignmentGradeRecord gradeRec : countedGradeRecs) { if (gradeRec.getPointsEarned() != null && !gradeRec.getPointsEarned().equals("")) { Double pointsEarned = new Double(gradeRec.getPointsEarned()); Assignment go = gradeRec.getAssignment(); if (pointsEarned != null) { if (gradebook.getCategory_type() == GradebookService.CATEGORY_TYPE_NO_CATEGORY) { assignmentsTaken.add(go.getId()); } else if ((gradebook.getCategory_type() == GradebookService.CATEGORY_TYPE_ONLY_CATEGORY || gradebook.getCategory_type() == GradebookService.CATEGORY_TYPE_WEIGHTED_CATEGORY) && go != null && categories != null) { // assignmentsTaken.add(go.getId()); // } // else if(gradebook.getCategory_type() == GradebookService.CATEGORY_TYPE_WEIGHTED_CATEGORY && go != null && categories != null) // { for (int i = 0; i < categories.size(); i++) { Category cate = (Category) categories.get(i); if (cate != null && !cate.isRemoved() && go.getCategory() != null && cate.getId().equals(go.getCategory().getId()) && ((cate.isExtraCredit() != null && !cate.isExtraCredit()) || cate.isExtraCredit() == null)) { assignmentsTaken.add(go.getId()); categoryTaken.add(cate.getId()); break; } } } } } } if (!assignmentsTaken.isEmpty()) { if (!literalTotal && gradebook.getCategory_type() == GradebookService.CATEGORY_TYPE_WEIGHTED_CATEGORY) { for (int i = 0; i < categories.size(); i++) { Category cate = (Category) categories.get(i); if (cate != null && !cate.isRemoved() && categoryTaken.contains(cate.getId())) { totalPointsPossible += cate.getWeight().doubleValue(); } } return totalPointsPossible; } Iterator assignmentIter = countedAssigns.iterator(); while (assignmentIter.hasNext()) { Assignment asn = (Assignment) assignmentIter.next(); if (asn != null) { Double pointsPossible = asn.getPointsPossible(); if (gradebook.getCategory_type() == GradebookService.CATEGORY_TYPE_NO_CATEGORY && assignmentsTaken.contains(asn.getId())) { totalPointsPossible += pointsPossible.doubleValue(); } else if (gradebook.getCategory_type() == GradebookService.CATEGORY_TYPE_ONLY_CATEGORY && assignmentsTaken.contains(asn.getId())) { totalPointsPossible += pointsPossible.doubleValue(); } else if (literalTotal && gradebook.getCategory_type() == GradebookService.CATEGORY_TYPE_WEIGHTED_CATEGORY && assignmentsTaken.contains(asn.getId())) { totalPointsPossible += pointsPossible.doubleValue(); } } } } else totalPointsPossible = -1; return totalPointsPossible; }
From source file:org.hyperic.hq.measurement.server.session.DataManagerImpl.java
private final double[] getAggData(final List<HighLowMetricValue> historicalData) { if (historicalData.size() == 0) { return null; }/* w w w . ja v a 2s. co m*/ double high = Double.MIN_VALUE; double low = Double.MAX_VALUE; double total = 0; Double lastVal = null; int count = 0; long last = Long.MIN_VALUE; for (HighLowMetricValue mv : historicalData) { low = Math.min(mv.getLowValue(), low); high = Math.max(mv.getHighValue(), high); if (mv.getTimestamp() > last) { lastVal = new Double(mv.getValue()); } final int c = mv.getCount(); count = count + c; total = ((mv.getValue() * c) + total); } final double[] data = new double[MeasurementConstants.IND_LAST_TIME + 1]; data[MeasurementConstants.IND_MIN] = low; data[MeasurementConstants.IND_AVG] = total / count; data[MeasurementConstants.IND_MAX] = high; data[MeasurementConstants.IND_CFG_COUNT] = count; if (lastVal != null) { data[MeasurementConstants.IND_LAST_TIME] = lastVal.doubleValue(); } return data; }
From source file:eu.scape_project.planning.model.tree.Leaf.java
/** * initialises the ordinal transformer for free text scales, @see * #initTransformer()//w ww.j a v a2 s . c o m * * @param defaultTarget * if this is used (must be 0.0<=defaultTarget<=5.0, unchecked) * then for each newly added mapping, the default target is set * as provided. */ public void initTransformer(Double defaultTarget) { if (scale instanceof FreeStringScale) { FreeStringScale freeScale = (FreeStringScale) scale; // We collect all distinct actually EXISTING values OrdinalTransformer t = (OrdinalTransformer) transformer; Map<String, TargetValueObject> map = t.getMapping(); HashSet<String> allValues = new HashSet<String>(); for (Values values : valueMap.values()) { for (Value v : values.getList()) { FreeStringValue text = (FreeStringValue) v; if (!text.toString().equals("")) { for (String s : map.keySet()) { // if the value is NOT the same, but IS the same // with other case, // we replace the value with the cases predefined by // the mapping if (text.getValue().equalsIgnoreCase(s) && !text.getValue().equals(s)) { text.setValue(s); } } allValues.add(text.getValue()); } } } // We remove all values from the transformer that do not actually // occur (anymore) // I am disabling this for now - why would we want to remove known // mappings? // They don't do harm because for the lookup, we use the actually // encountered values // (see below) // HashSet<String> keysToRemove = new HashSet<String>(); // for (String s: map.keySet()) { // if (!allValues.contains(s)) { // keysToRemove.add(s); // } // } // for (String s: keysToRemove) { // map.remove(s); // } // We add all values that occur, but are not in the map yet: for (String s : allValues) { if (!map.containsKey(s)) { if (defaultTarget == null) { map.put(s, new TargetValueObject()); } else { map.put(s, new TargetValueObject(defaultTarget.doubleValue())); } } } // We also have to publish the known values // to the SCALE because it provides the reference lookup // for iterating and defining the transformation freeScale.setPossibleValues(allValues); } }
From source file:org.sakaiproject.tool.assessment.services.GradingService.java
/** * Create an EMI Score object// w ww . j av a 2s.co m * @param itemId * @param itemTextId * @param answerId * @param correct * @param score */ public EMIScore(Long itemId, Long itemTextId, Long answerId, boolean correct, Double score) { this.itemId = itemId == null ? 0L : itemId.longValue(); this.itemTextId = itemTextId == null ? 0L : itemTextId.longValue(); this.answerId = answerId == null ? 0L : answerId.longValue(); this.correct = correct; this.score = score == null ? 0L : score.doubleValue(); }
From source file:org.sakaiproject.component.gradebook.GradebookServiceHibernateImpl.java
@SuppressWarnings({ "rawtypes", "unchecked" }) private List getTotalPointsEarnedInternal(final String studentId, final Gradebook gradebook, final List categories, final List<AssignmentGradeRecord> gradeRecs, List<Assignment> countedAssigns) { int gbGradeType = gradebook.getGrade_type(); if (gbGradeType != GradebookService.GRADE_TYPE_POINTS && gbGradeType != GradebookService.GRADE_TYPE_PERCENTAGE) { if (log.isInfoEnabled()) log.error("Wrong grade type in GradebookCalculationImpl.getTotalPointsEarnedInternal"); return new ArrayList(); }/*from ww w .j a va 2 s .co m*/ if (gradeRecs == null || countedAssigns == null) { if (log.isDebugEnabled()) log.debug("getTotalPointsEarnedInternal for " + "studentId=" + studentId + " returning 0 because null gradeRecs or countedAssigns"); List returnList = new ArrayList(); returnList.add(new Double(0)); returnList.add(new Double(0)); returnList.add(new Double(0)); // 3rd one is for the pre-adjusted course grade return returnList; } double totalPointsEarned = 0; BigDecimal literalTotalPointsEarned = new BigDecimal(0d); Map cateScoreMap = new HashMap(); Map cateTotalScoreMap = new HashMap(); Set assignmentsTaken = new HashSet(); for (AssignmentGradeRecord gradeRec : gradeRecs) { if (gradeRec.getPointsEarned() != null && !gradeRec.getPointsEarned().equals("") && !gradeRec.getDroppedFromGrade()) { Assignment go = gradeRec.getAssignment(); if (go.isIncludedInCalculations() && countedAssigns.contains(go)) { Double pointsEarned = new Double(gradeRec.getPointsEarned()); //if(gbGradeType == GradebookService.GRADE_TYPE_POINTS) //{ if (gradebook.getCategory_type() == GradebookService.CATEGORY_TYPE_NO_CATEGORY) { totalPointsEarned += pointsEarned.doubleValue(); literalTotalPointsEarned = (new BigDecimal(pointsEarned.doubleValue())) .add(literalTotalPointsEarned); assignmentsTaken.add(go.getId()); } else if (gradebook.getCategory_type() == GradebookService.CATEGORY_TYPE_ONLY_CATEGORY && go != null) { totalPointsEarned += pointsEarned.doubleValue(); literalTotalPointsEarned = (new BigDecimal(pointsEarned.doubleValue())) .add(literalTotalPointsEarned); assignmentsTaken.add(go.getId()); } else if (gradebook.getCategory_type() == GradebookService.CATEGORY_TYPE_WEIGHTED_CATEGORY && go != null && categories != null) { for (int i = 0; i < categories.size(); i++) { Category cate = (Category) categories.get(i); if (cate != null && !cate.isRemoved() && go.getCategory() != null && cate.getId().equals(go.getCategory().getId())) { assignmentsTaken.add(go.getId()); literalTotalPointsEarned = (new BigDecimal(pointsEarned.doubleValue())) .add(literalTotalPointsEarned); if (cateScoreMap.get(cate.getId()) != null) { cateScoreMap.put(cate.getId(), new Double(((Double) cateScoreMap.get(cate.getId())).doubleValue() + pointsEarned.doubleValue())); } else { cateScoreMap.put(cate.getId(), new Double(pointsEarned)); } break; } } } } } } if (gradebook.getCategory_type() == GradebookService.CATEGORY_TYPE_WEIGHTED_CATEGORY && categories != null) { Iterator assgnsIter = countedAssigns.iterator(); while (assgnsIter.hasNext()) { Assignment asgn = (Assignment) assgnsIter.next(); if (assignmentsTaken.contains(asgn.getId())) { for (int i = 0; i < categories.size(); i++) { Category cate = (Category) categories.get(i); if (cate != null && !cate.isRemoved() && asgn.getCategory() != null && cate.getId().equals(asgn.getCategory().getId()) && !asgn.isExtraCredit()) { if (cateTotalScoreMap.get(cate.getId()) == null) { cateTotalScoreMap.put(cate.getId(), asgn.getPointsPossible()); } else { cateTotalScoreMap.put(cate.getId(), new Double(((Double) cateTotalScoreMap.get(cate.getId())).doubleValue() + asgn.getPointsPossible().doubleValue())); } } } } } } if (assignmentsTaken.isEmpty()) totalPointsEarned = -1; if (gradebook.getCategory_type() == GradebookService.CATEGORY_TYPE_WEIGHTED_CATEGORY) { for (int i = 0; i < categories.size(); i++) { Category cate = (Category) categories.get(i); if (cate != null && !cate.isRemoved() && cateScoreMap.get(cate.getId()) != null && cateTotalScoreMap.get(cate.getId()) != null) { totalPointsEarned += ((Double) cateScoreMap.get(cate.getId())).doubleValue() * cate.getWeight().doubleValue() / ((Double) cateTotalScoreMap.get(cate.getId())).doubleValue(); } } } if (log.isDebugEnabled()) log.debug( "getTotalPointsEarnedInternal for studentId=" + studentId + " returning " + totalPointsEarned); List returnList = new ArrayList(); returnList.add(new Double(totalPointsEarned)); returnList.add( new Double((new BigDecimal(literalTotalPointsEarned.doubleValue(), GradebookService.MATH_CONTEXT)) .doubleValue())); return returnList; }