List of usage examples for java.lang Double compareTo
public int compareTo(Double anotherDouble)
From source file:org.tinygroup.jspengine.JspC.java
public void setCompilerTargetVM(String vm) { // START SJSAS 6402545 if (!JAVA_1_1.equals(vm) && !JAVA_1_2.equals(vm) && !JAVA_1_3.equals(vm) && !JAVA_1_4.equals(vm) && !JAVA_1_5.equals(vm) && !JAVA_1_6.equals(vm) && !JAVA_5.equals(vm) && !JAVA_6.equals(vm)) { throw new IllegalArgumentException(Localizer.getMessage("jspc.illegalCompilerTargetVM", vm)); }//from w ww. j av a2s.c o m // END SJSAS 6402545 // START SJSAS 6403017 if (JAVA_5.equals(vm)) { vm = JAVA_1_5; } else if (JAVA_6.equals(vm)) { vm = JAVA_1_6; } Double targetVersion = Double.valueOf(vm); if (targetVersion.compareTo(Double.valueOf(myJavaVersion)) > 0) { throw new IllegalArgumentException(Localizer.getMessage("jspc.compilerTargetVMTooHigh", vm)); } // END SJSAS 6403017 compilerTargetVM = vm; }
From source file:edu.northwestern.jcr.adapter.xtf.query.SearchIndex.java
/** * Sorts the query results based on the value of the properties. * The ORDER BY clause is actually handled here. * * @param lines array of comma-separated full paths to the query results * @param valueMap maps pid to comma-separated values * @param orderSpecs true for ascending, false for descending * @return array of sorted results//from ww w.jav a2 s .com */ private String[] sort(String[] lines, final Map<String, String> valueMap, final boolean[] orderSpecs) { Comparator<String> result_order = new Comparator<String>() { public int compare(String line1, String line2) { String pid1, pid2; String valueList1, valueList2; String[] parts; String[] valueString1, valueString2; String value1, value2; Double double1, double2; Long long1, long2; Calendar calendar1, calendar2; Boolean boolean1, boolean2; int i; int compare = 0; // get pid of the last object in the list parts = line1.split(","); pid1 = parts[parts.length - 1]; parts = line2.split(","); pid2 = parts[parts.length - 1]; // get comma-separated the value list valueList1 = valueMap.get(pid1); valueList2 = valueMap.get(pid2); valueString1 = valueList1.split(","); valueString2 = valueList2.split(","); for (i = 0; i < valueString1.length; ++i) { // loop over the values value1 = valueString1[i]; parts = value1.split("%57"); value1 = parts[parts.length - 1]; value2 = valueString2[i]; parts = value2.split("%57"); value2 = parts[parts.length - 1]; switch (Integer.parseInt(parts[0])) { case PropertyType.STRING: if (orderSpecs[i]) { compare = value1.compareTo(value2); } else { compare = value2.compareTo(value1); } break; case PropertyType.DOUBLE: double1 = Double.parseDouble(value1); double2 = Double.parseDouble(value2); if (orderSpecs[i]) { compare = double1.compareTo(double2); } else { compare = double2.compareTo(double1); } break; case PropertyType.LONG: long1 = Long.parseLong(value1); long2 = Long.parseLong(value2); if (orderSpecs[i]) { compare = long1.compareTo(long2); } else { compare = long2.compareTo(long1); } break; case PropertyType.DATE: calendar1 = ISO8601.parse(value1); calendar2 = ISO8601.parse(value2); if (orderSpecs[i]) { compare = calendar1.compareTo(calendar2); } else { compare = calendar2.compareTo(calendar1); } break; case PropertyType.BOOLEAN: boolean1 = Boolean.valueOf(value1); boolean2 = Boolean.valueOf(value2); if (orderSpecs[i]) { compare = boolean1.compareTo(boolean2); } else { compare = boolean2.compareTo(boolean1); } break; // not supported case PropertyType.BINARY: case PropertyType.REFERENCE: case PropertyType.NAME: case PropertyType.PATH: compare = 0; } if (compare != 0) { return compare; } // more comparison } return compare; } }; List<String> resultList = Arrays.asList(lines); Collections.sort(resultList, result_order); return resultList.toArray(new String[0]); }
From source file:uk.chromis.pos.inventory.ProductsEditor.java
private void setProductInfo(ProductInfoExt info) { if (info == null) return;//from w ww. j ava2 s .com try { activate(); m_jRef.setText(info.getReference()); m_jCode.setText(info.getCode()); m_jName.setText(info.getName()); m_jComment.setSelected(info.isCom()); m_jScale.setSelected(info.isScale()); m_jPriceBuy.setText(Formats.CURRENCY.formatValue(info.getPriceBuy())); m_CategoryModel.setSelectedKey(info.getCategoryID()); jComboBoxPromotion.setEnabled(true); String promID = info.getPromotionID(); if (promID != null && !promID.isEmpty()) { jCheckBoxPromotion.setSelected(true); } else { jCheckBoxPromotion.setSelected(false); } m_PromotionModel.setSelectedKey(promID); if (info.getTaxCategoryID() == null) { // Try to figure out tax category from the rate for (int n = 0; n < taxcatmodel.getSize(); ++n) { Double r = taxeslogic.getTaxRate((TaxCategoryInfo) taxcatmodel.getElementAt(n)); if (r.compareTo(info.getTaxRate()) == 0) { taxcatmodel.setSelectedItem(taxcatmodel.getElementAt(n)); } } } else { taxcatmodel.setSelectedKey(info.getTaxCategoryID()); } attmodel.setSelectedKey(info.getAttributeSetID()); m_jImage.setImage(info.getImage()); m_jstockcost.setText(Formats.CURRENCY.formatValue(info.getStockCost())); m_jstockvolume.setText(Formats.DOUBLE.formatValue(info.getStockVolume())); m_jInCatalog.setSelected(info.getInCatalog()); m_jRetired.setSelected(info.getRetired()); m_jCatalogOrder.setText(Formats.INT.formatValue(info.getCatOrder())); m_jKitchen.setSelected(info.isKitchen()); m_jService.setSelected(info.isService()); m_jDisplay.setText(info.getDisplay()); setButtonHTML(); m_jVprice.setSelected(info.isVprice()); m_jVerpatrib.setSelected(info.isVerpatrib()); m_jTextTip.setText(info.getTextTip()); m_jCheckWarrantyReceipt.setSelected(info.getWarranty()); m_jStockUnits.setText(Formats.DOUBLE.formatValue(info.getStockUnits())); m_jAlias.setText(info.getAlias()); m_jAlwaysAvailable.setSelected(info.getAlwaysAvailable()); m_jDiscounted.setSelected(info.getCanDiscount()); m_jManageStock.setSelected(info.getManageStock()); m_jIsPack.setSelected(info.getIsPack()); m_jPackQuantity.setText(Formats.DOUBLE.formatValue(info.getPackQuantity())); packproductmodel.setSelectedKey(info.getPromotionID()); String displayname = "<html>" + m_jName.getText(); originalDisplay = m_jDisplay.getText(); displayEdited = displayname.compareToIgnoreCase(originalDisplay) != 0; txtProperties.setText(info.getPropertiesXml()); if (m_jName.getText().isEmpty()) { m_jTitle.setText(AppLocal.getIntString("label.recordnew")); } else { m_jTitle.setText(m_jName.getText()); } setPriceSell(info.getPriceSell()); calculateMargin(); calculatePriceSellTax(); calculateGP(); updateBarcodeList(); } catch (BasicException ex) { Logger.getLogger(ProductsEditor.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.aerohive.nms.web.config.lbs.services.HmFolderServiceImpl.java
private List<Double> findEdgesX(HmFolder floor, double y, Perimeter perimeter) { List<Double> edges = new ArrayList<Double>(); HmVertex vertex = floor.getPerimeter().get(perimeter.start); double x1 = vertex.getX(); double y1 = vertex.getY(); double first_x = x1; double first_y = y1; for (int i = perimeter.start + 1; i <= perimeter.end; i++) { vertex = floor.getPerimeter().get(i); double x2 = vertex.getX(); double y2 = vertex.getY(); findIntersectionX(x1, y1, x2, y2, y, edges); x1 = x2;/* w w w. jav a 2 s . c o m*/ y1 = y2; } findIntersectionX(x1, y1, first_x, first_y, y, edges); Collections.sort(edges, new Comparator<Double>() { @Override public int compare(Double o1, Double o2) { return o1.compareTo(o2); } }); return edges; }
From source file:data.services.ParseBaseService.java
private void updateCarOptionValues() throws SQLException, ClassNotFoundException { List<Car> carList = carDao.getAllAsc(); HashMap<Long, Car> ourOldIdCarMap = new HashMap(); HashMap<Long, CarOptionValue> fullOldIdCovMap = new HashMap(); for (Car car : carList) { ourOldIdCarMap.put(car.getCmqId(), car); for (CarOptionValue cov : car.getCarOptionValues()) { fullOldIdCovMap.put(cov.getOldId(), cov); }/*w w w . j a v a 2 s. co m*/ } List<CarCompletionOption> fullCCOList = CCODao.getAllAsc(); HashMap<Long, CarCompletionOption> ourOldIdCCOMap = new HashMap(); for (CarCompletionOption cco : fullCCOList) { ourOldIdCCOMap.put(cco.getOldId(), cco); } HashSet<Long> fullOldCovIdInfoSet = new HashSet(); List<CarOptionValue> covListForSave = new ArrayList(); List<CarOptionValue> covListForUpdate = new ArrayList(); List<CarOptionValue> covListForDelete = new ArrayList(); ResultSet resSet = getFromQutoBase( "SELECT cmco.* FROM car_modification_completion_option cmco LEFT JOIN car_modification cm ON cmco.car_modification_id=cm.id WHERE cm.usage='ad_archive_catalog'"); while (resSet.next()) { Long carOldId = resSet.getLong("car_modification_id"); Long covOldId = resSet.getLong("id"); fullOldCovIdInfoSet.add(covOldId); Double price = resSet.getDouble("price"); String title = StringAdapter.getString(resSet.getString("title")).trim(); String desc = StringAdapter.getString(resSet.getString("description")).trim(); Long sort = resSet.getLong("sort"); Boolean isPack = resSet.getBoolean("is_package"); Long ccoOldId = resSet.getLong("car_completion_option_id"); Long imageId = resSet.getLong("car_modification_completion_option_image_id"); CarOptionValue cov = fullOldIdCovMap.get(covOldId); CarCompletionOption cco = ourOldIdCCOMap.get(ccoOldId); if (cco == null) { addError("? ? Quto:" + ccoOldId + "; "); } else { if (cov == null) { cov = new CarOptionValue(); cov.setAudial(0); cov.setVisual(0); cov.setKinestet(0); cov.setCCO(cco); cov.setCcoOldId(ccoOldId); cov.setDescription(desc); cov.setIsPack(isPack); cov.setOldId(covOldId); cov.setTitle(title); cov.setSort(sort); cov.setCar(ourOldIdCarMap.get(carOldId)); cov.setPrice(price); cov.setCovImageId(imageId); if (validate(cov, " ? ?: auto_quto_id=" + carOldId + ", cov_quto_id=" + covOldId + ", cco_quto_id=" + ccoOldId + "; ")) { covListForSave.add(cov); } } else { if (!Objects.equals(cov.getCCO().getOldId(), ccoOldId) || !desc.equals(cov.getDescription()) || isPack.compareTo(cov.isIsPack()) != 0 || !title.equals(cov.getTitle()) || !Objects.equals(cov.getSort(), sort) || price.compareTo(cov.getPrice()) != 0 || !Objects.equals(cov.getCovImageId(), imageId) || !Objects.equals(cov.getCar().getCmqId(), carOldId)) { cov.setCCO(cco); cov.setCcoOldId(ccoOldId); cov.setDescription(desc); cov.setIsPack(isPack); cov.setOldId(covOldId); cov.setTitle(title); cov.setSort(sort); cov.setCar(ourOldIdCarMap.get(carOldId)); cov.setPrice(price); cov.setCovImageId(imageId); if (validate(cov, " ? : auto_quto_id=" + carOldId + ", cov_quto_id=" + covOldId + ", cco_quto_id=" + ccoOldId + "; ")) { covListForUpdate.add(cov); } } } } } for (Long oldCovId : fullOldIdCovMap.keySet()) { if (!fullOldCovIdInfoSet.contains(oldCovId)) { covListForDelete.add(fullOldIdCovMap.get(oldCovId)); } } int s = 0; int u = 0; int d = 0; for (CarOptionValue cov : covListForSave) { carOptionValueDao.save(cov); s++; } for (CarOptionValue cov : covListForUpdate) { carOptionValueDao.update(cov); u++; } for (CarOptionValue cov : covListForDelete) { carOptionValueDao.delete(cov); d++; } addError(" : " + s + " ?, " + u + " , " + d + " ."); }
From source file:org.apache.cocoon.acting.AbstractValidatorAction.java
/** * Validates nullability and default value for given parameter. If given * constraints are not null they are validated as well. *///w ww .j a va2 s .c o m private ValidatorActionHelper validateDouble(String name, Configuration constraints, Configuration conf, Map params, boolean is_string, Object param) { boolean nullable = getNullable(conf, constraints); Double value = null; Double dflt = getDoubleValue(getDefault(conf, constraints), true); if (getLogger().isDebugEnabled()) getLogger().debug("Validating double parameter " + name + " (encoded in a string: " + is_string + ")"); try { value = getDoubleValue(param, is_string); } catch (Exception e) { // Unable to parse double return new ValidatorActionHelper(value, ValidatorActionResult.ERROR); } if (value == null) { if (getLogger().isDebugEnabled()) getLogger().debug("double parameter " + name + " is null"); if (!nullable) { return new ValidatorActionHelper(value, ValidatorActionResult.ISNULL); } else { return new ValidatorActionHelper(dflt); } } if (constraints != null) { Double eq = getAttributeAsDouble(constraints, "equals-to", null); String eqp = constraints.getAttribute("equals-to-param", ""); Double min = getAttributeAsDouble(conf, "min", null); min = getAttributeAsDouble(constraints, "min", min); Double max = getAttributeAsDouble(conf, "max", null); max = getAttributeAsDouble(constraints, "max", max); // Validate whether param is equal to constant if (eq != null) { if (getLogger().isDebugEnabled()) getLogger().debug("Double parameter " + name + " should be equal to " + eq); if (!value.equals(eq)) { if (getLogger().isDebugEnabled()) getLogger().debug("and it is not"); return new ValidatorActionHelper(value, ValidatorActionResult.NOMATCH); } } // Validate whether param is equal to another param // FIXME: take default value of param being compared with into // account? if (!"".equals(eqp)) { if (getLogger().isDebugEnabled()) getLogger().debug("Double parameter " + name + " should be equal to " + params.get(eqp)); // Request parameter is stored as string. // Need to convert it beforehand. try { Double _eqp = new Double(Double.parseDouble((String) params.get(eqp))); if (!value.equals(_eqp)) { if (getLogger().isDebugEnabled()) getLogger().debug("and it is not"); return new ValidatorActionHelper(value, ValidatorActionResult.NOMATCH); } } catch (NumberFormatException nfe) { if (getLogger().isDebugEnabled()) getLogger().debug("Double parameter " + name + ": " + eqp + " is no double", nfe); return new ValidatorActionHelper(value, ValidatorActionResult.NOMATCH); } } // Validate wheter param is at least min if (min != null) { if (getLogger().isDebugEnabled()) getLogger().debug("Double parameter " + name + " should be at least " + min); if (0 > value.compareTo(min)) { if (getLogger().isDebugEnabled()) getLogger().debug("and it is not"); return new ValidatorActionHelper(value, ValidatorActionResult.TOOSMALL); } } // Validate wheter param is at most max if (max != null) { if (getLogger().isDebugEnabled()) getLogger().debug("Double parameter " + name + " should be at most " + max); if (0 < value.compareTo(max)) { if (getLogger().isDebugEnabled()) getLogger().debug("and it is not"); return new ValidatorActionHelper(value, ValidatorActionResult.TOOLARGE); } } } return new ValidatorActionHelper(value); }
From source file:edu.harvard.iq.dataverse.ingest.IngestServiceBean.java
private void processDatasetMetadata(FileMetadataIngest fileMetadataIngest, DatasetVersion editVersion) throws IOException { for (MetadataBlock mdb : editVersion.getDataset().getOwner().getMetadataBlocks()) { if (mdb.getName().equals(fileMetadataIngest.getMetadataBlockName())) { logger.fine("Ingest Service: dataset version has " + mdb.getName() + " metadata block enabled."); editVersion.setDatasetFields(editVersion.initDatasetFields()); Map<String, Set<String>> fileMetadataMap = fileMetadataIngest.getMetadataMap(); for (DatasetFieldType dsft : mdb.getDatasetFieldTypes()) { if (dsft.isPrimitive()) { if (!dsft.isHasParent()) { String dsfName = dsft.getName(); // See if the plugin has found anything for this field: if (fileMetadataMap.get(dsfName) != null && !fileMetadataMap.get(dsfName).isEmpty()) { logger.fine("Ingest Service: found extracted metadata for field " + dsfName); // go through the existing fields: for (DatasetField dsf : editVersion.getFlatDatasetFields()) { if (dsf.getDatasetFieldType().equals(dsft)) { // yep, this is our field! // let's go through the values that the ingest // plugin found in the file for this field: Set<String> mValues = fileMetadataMap.get(dsfName); // Special rules apply to aggregation of values for // some specific fields - namely, the resolution.* // fields from the Astronomy Metadata block. // TODO: rather than hard-coded, this needs to be // programmatically defined. -- L.A. 4.0 if (dsfName.equals("resolution.Temporal") || dsfName.equals("resolution.Spatial") || dsfName.equals("resolution.Spectral")) { // For these values, we aggregate the minimum-maximum // pair, for the entire set. // So first, we need to go through the values found by // the plugin and select the min. and max. values of // these: // (note that we are assuming that they all must // validate as doubles!) Double minValue = null; Double maxValue = null; for (String fValue : mValues) { try { double thisValue = Double.parseDouble(fValue); if (minValue == null || Double.compare(thisValue, minValue) < 0) { minValue = thisValue; } if (maxValue == null || Double.compare(thisValue, maxValue) > 0) { maxValue = thisValue; } } catch (NumberFormatException e) { } } // Now let's see what aggregated values we // have stored already: // (all of these resolution.* fields have allowedMultiple set to FALSE, // so there can be only one!) //logger.fine("Min value: "+minValue+", Max value: "+maxValue); if (minValue != null && maxValue != null) { Double storedMinValue = null; Double storedMaxValue = null; String storedValue = ""; if (dsf.getDatasetFieldValues() != null && dsf.getDatasetFieldValues().get(0) != null) { storedValue = dsf.getDatasetFieldValues().get(0).getValue(); if (storedValue != null && !storedValue.equals("")) { try { if (storedValue.indexOf(" - ") > -1) { storedMinValue = Double.parseDouble(storedValue .substring(0, storedValue.indexOf(" - "))); storedMaxValue = Double.parseDouble(storedValue .substring(storedValue.indexOf(" - ") + 3)); } else { storedMinValue = Double.parseDouble(storedValue); storedMaxValue = storedMinValue; } if (storedMinValue != null && storedMinValue.compareTo(minValue) < 0) { minValue = storedMinValue; } if (storedMaxValue != null && storedMaxValue.compareTo(maxValue) > 0) { maxValue = storedMaxValue; } } catch (NumberFormatException e) { } } else { storedValue = ""; } } //logger.fine("Stored min value: "+storedMinValue+", Stored max value: "+storedMaxValue); String newAggregateValue = ""; if (minValue.equals(maxValue)) { newAggregateValue = minValue.toString(); } else { newAggregateValue = minValue.toString() + " - " + maxValue.toString(); } // finally, compare it to the value we have now: if (!storedValue.equals(newAggregateValue)) { if (dsf.getDatasetFieldValues() == null) { dsf.setDatasetFieldValues( new ArrayList<DatasetFieldValue>()); } if (dsf.getDatasetFieldValues().get(0) == null) { DatasetFieldValue newDsfv = new DatasetFieldValue(dsf); dsf.getDatasetFieldValues().add(newDsfv); } dsf.getDatasetFieldValues().get(0).setValue(newAggregateValue); } } // Ouch. } else { // Other fields are aggregated simply by // collecting a list of *unique* values encountered // for this Field throughout the dataset. // This means we need to only add the values *not yet present*. // (the implementation below may be inefficient - ?) for (String fValue : mValues) { if (!dsft.isControlledVocabulary()) { Iterator<DatasetFieldValue> dsfvIt = dsf.getDatasetFieldValues() .iterator(); boolean valueExists = false; while (dsfvIt.hasNext()) { DatasetFieldValue dsfv = dsfvIt.next(); if (fValue.equals(dsfv.getValue())) { logger.fine("Value " + fValue + " already exists for field " + dsfName); valueExists = true; break; } } if (!valueExists) { logger.fine("Creating a new value for field " + dsfName + ": " + fValue); DatasetFieldValue newDsfv = new DatasetFieldValue(dsf); newDsfv.setValue(fValue); dsf.getDatasetFieldValues().add(newDsfv); } } else { // A controlled vocabulary entry: // first, let's see if it's a legit control vocab. entry: ControlledVocabularyValue legitControlledVocabularyValue = null; Collection<ControlledVocabularyValue> definedVocabularyValues = dsft .getControlledVocabularyValues(); if (definedVocabularyValues != null) { for (ControlledVocabularyValue definedVocabValue : definedVocabularyValues) { if (fValue.equals(definedVocabValue.getStrValue())) { logger.fine("Yes, " + fValue + " is a valid controlled vocabulary value for the field " + dsfName); legitControlledVocabularyValue = definedVocabValue; break; } } } if (legitControlledVocabularyValue != null) { // Only need to add the value if it is new, // i.e. if it does not exist yet: boolean valueExists = false; List<ControlledVocabularyValue> existingControlledVocabValues = dsf .getControlledVocabularyValues(); if (existingControlledVocabValues != null) { Iterator<ControlledVocabularyValue> cvvIt = existingControlledVocabValues .iterator(); while (cvvIt.hasNext()) { ControlledVocabularyValue cvv = cvvIt.next(); if (fValue.equals(cvv.getStrValue())) { // or should I use if (legitControlledVocabularyValue.equals(cvv)) ? logger.fine("Controlled vocab. value " + fValue + " already exists for field " + dsfName); valueExists = true; break; } } } if (!valueExists) { logger.fine("Adding controlled vocabulary value " + fValue + " to field " + dsfName); dsf.getControlledVocabularyValues() .add(legitControlledVocabularyValue); } } } } }/* www .j a va 2s .c o m*/ } } } } } else { // A compound field: // See if the plugin has found anything for the fields that // make up this compound field; if we find at least one // of the child values in the map of extracted values, we'll // create a new compound field value and its child // DatasetFieldCompoundValue compoundDsfv = new DatasetFieldCompoundValue(); int nonEmptyFields = 0; for (DatasetFieldType cdsft : dsft.getChildDatasetFieldTypes()) { String dsfName = cdsft.getName(); if (fileMetadataMap.get(dsfName) != null && !fileMetadataMap.get(dsfName).isEmpty()) { logger.fine("Ingest Service: found extracted metadata for field " + dsfName + ", part of the compound field " + dsft.getName()); if (cdsft.isPrimitive()) { // probably an unnecessary check - child fields // of compound fields are always primitive... // but maybe it'll change in the future. if (!cdsft.isControlledVocabulary()) { // TODO: can we have controlled vocabulary // sub-fields inside compound fields? DatasetField childDsf = new DatasetField(); childDsf.setDatasetFieldType(cdsft); DatasetFieldValue newDsfv = new DatasetFieldValue(childDsf); newDsfv.setValue((String) fileMetadataMap.get(dsfName).toArray()[0]); childDsf.getDatasetFieldValues().add(newDsfv); childDsf.setParentDatasetFieldCompoundValue(compoundDsfv); compoundDsfv.getChildDatasetFields().add(childDsf); nonEmptyFields++; } } } } if (nonEmptyFields > 0) { // let's go through this dataset's fields and find the // actual parent for this sub-field: for (DatasetField dsf : editVersion.getFlatDatasetFields()) { if (dsf.getDatasetFieldType().equals(dsft)) { // Now let's check that the dataset version doesn't already have // this compound value - we are only interested in aggregating // unique values. Note that we need to compare compound values // as sets! -- i.e. all the sub fields in 2 compound fields // must match in order for these 2 compounds to be recognized // as "the same": boolean alreadyExists = false; for (DatasetFieldCompoundValue dsfcv : dsf.getDatasetFieldCompoundValues()) { int matches = 0; for (DatasetField cdsf : dsfcv.getChildDatasetFields()) { String cdsfName = cdsf.getDatasetFieldType().getName(); String cdsfValue = cdsf.getDatasetFieldValues().get(0).getValue(); if (cdsfValue != null && !cdsfValue.equals("")) { String extractedValue = (String) fileMetadataMap.get(cdsfName) .toArray()[0]; logger.fine("values: existing: " + cdsfValue + ", extracted: " + extractedValue); if (cdsfValue.equals(extractedValue)) { matches++; } } } if (matches == nonEmptyFields) { alreadyExists = true; break; } } if (!alreadyExists) { // save this compound value, by attaching it to the // version for proper cascading: compoundDsfv.setParentDatasetField(dsf); dsf.getDatasetFieldCompoundValues().add(compoundDsfv); } } } } } } } } }
From source file:es.sm2.openppm.front.servlets.ProjectPlanServlet.java
/** * Validate node WBS/*w w w . j a v a2s . co m*/ * @param req * @param resp * @throws IOException */ private void saveWbsNodeJX(HttpServletRequest req, HttpServletResponse resp) throws IOException { Integer idProject = ParamUtil.getInteger(req, "id", null); Integer idWbsnode = ParamUtil.getInteger(req, "wbs_id", -1); PrintWriter out = resp.getWriter(); JSONObject updateJSON = new JSONObject(); try { // Logics // ProjectLogic projectLogic = new ProjectLogic(getSettings(req), getResourceBundle(req)); WBSNodeLogic wbsNodeLogic = new WBSNodeLogic(); Wbsnode wbsNode = null; boolean isCa = false; Double oldBudget = null; if (idWbsnode != null && idWbsnode > 0) { List<String> joins = new ArrayList<String>(); joins.add(Wbsnode.WBSNODE); joins.add(Wbsnode.WBSNODES); wbsNode = wbsNodeLogic.findById(idWbsnode, joins); isCa = wbsNode.getIsControlAccount(); oldBudget = wbsNode.getBudget(); } wbsNode = setWbsNodeFromRequest(req, wbsNode); // Update milestones if (idWbsnode != -1 && isCa && !wbsNode.getIsControlAccount()) { ProjectActivityLogic projectActivityLogic = new ProjectActivityLogic(getSettings(req), getResourceBundle(req)); Projectactivity activity = projectActivityLogic.findByWBSnode(new Project(idProject), idWbsnode); MilestoneLogic milestoneLogic = new MilestoneLogic(); Projectactivity rootActivity = projectActivityLogic.consRootActivity(activity.getProject()); boolean hasMilestonesUpdated = milestoneLogic.changeActivity(activity, rootActivity); updateJSON.put("updateMilestones", hasMilestonesUpdated); } wbsNodeLogic.saveWBSnode(wbsNode, new Project(idProject), isCa); if (isCa && !wbsNode.getIsControlAccount()) { // Update root dates // ProjectActivityLogic projectActivityLogic = new ProjectActivityLogic(getSettings(req), getResourceBundle(req)); projectActivityLogic.updateRootDates(idProject); // Update project projectLogic.updateDataProject(idProject); } // Update Poc projectLogic.updatePoc(new Project(idProject), getSettings(req)); if (wbsNode.getBudget() != null && oldBudget != null) { updateJSON.put("updateEV", oldBudget.compareTo(wbsNode.getBudget()) != 0 ? true : false); } else { updateJSON.put("updateEV", false); } out.print(updateJSON); } catch (Exception e) { ExceptionUtil.evalueExceptionJX(out, req, getResourceBundle(req), LOGGER, e); } finally { out.close(); } }
From source file:org.alfresco.repo.search.impl.lucene.ADMLuceneTest.java
/** * @throws Exception/* w w w . j a v a2s. com*/ */ public void testSort() throws Exception { Collator collator = Collator.getInstance(I18NUtil.getLocale()); luceneFTS.pause(); buildBaseIndex(); runBaseTests(); ADMLuceneSearcherImpl searcher = buildSearcher(); SearchParameters sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage(SearchService.LANGUAGE_LUCENE); sp.setQuery("PATH:\"//.\""); sp.addSort("ID", true); ResultSet results = searcher.query(sp); String current = null; for (ResultSetRow row : results) { String id = row.getNodeRef().getId(); if (current != null) { if (collator.compare(current, id) > 0) { fail(); } } current = id; } results.close(); SearchParameters sp2 = new SearchParameters(); sp2.addStore(rootNodeRef.getStoreRef()); sp2.setLanguage(SearchService.LANGUAGE_LUCENE); sp2.setQuery("PATH:\"//.\""); sp2.addSort("ID", false); results = searcher.query(sp2); current = null; for (ResultSetRow row : results) { String id = row.getNodeRef().getId(); if (current != null) { if (collator.compare(current, id) < 0) { fail(); } } current = id; } results.close(); luceneFTS.resume(); SearchParameters sp3 = new SearchParameters(); sp3.addStore(rootNodeRef.getStoreRef()); sp3.setLanguage(SearchService.LANGUAGE_LUCENE); sp3.setQuery("PATH:\"//.\""); sp3.addSort(SearchParameters.SORT_IN_DOCUMENT_ORDER_ASCENDING); results = searcher.query(sp3); int count = 0; for (ResultSetRow row : results) { assertEquals(documentOrder[count++], row.getNodeRef()); } results.close(); SearchParameters sp4 = new SearchParameters(); sp4.addStore(rootNodeRef.getStoreRef()); sp4.setLanguage(SearchService.LANGUAGE_LUCENE); sp4.setQuery("PATH:\"//.\""); sp4.addSort(SearchParameters.SORT_IN_DOCUMENT_ORDER_DESCENDING); results = searcher.query(sp4); count = 1; for (ResultSetRow row : results) { assertEquals(documentOrder[documentOrder.length - (count++)], row.getNodeRef()); } results.close(); SearchParameters sp5 = new SearchParameters(); sp5.addStore(rootNodeRef.getStoreRef()); sp5.setLanguage(SearchService.LANGUAGE_LUCENE); sp5.setQuery("PATH:\"//.\""); sp5.addSort(SearchParameters.SORT_IN_SCORE_ORDER_ASCENDING); results = searcher.query(sp5); float score = 0; for (ResultSetRow row : results) { assertTrue(score <= row.getScore()); score = row.getScore(); } results.close(); SearchParameters sp6 = new SearchParameters(); sp6.addStore(rootNodeRef.getStoreRef()); sp6.setLanguage(SearchService.LANGUAGE_LUCENE); sp6.setQuery("PATH:\"//.\""); sp6.addSort(SearchParameters.SORT_IN_SCORE_ORDER_DESCENDING); results = searcher.query(sp6); score = 1.0f; for (ResultSetRow row : results) { assertTrue(score >= row.getScore()); score = row.getScore(); } results.close(); // sort by created date SearchParameters sp7 = new SearchParameters(); sp7.addStore(rootNodeRef.getStoreRef()); sp7.setLanguage(SearchService.LANGUAGE_LUCENE); sp7.setQuery("PATH:\"//.\""); sp7.addSort("@" + createdDate.getPrefixedQName(namespacePrefixResolver), true); results = searcher.query(sp7); Date date = null; for (ResultSetRow row : results) { Date currentBun = DefaultTypeConverter.INSTANCE.convert(Date.class, nodeService.getProperty(row.getNodeRef(), createdDate)); // System.out.println(currentBun); if (date != null) { assertTrue(date.compareTo(currentBun) <= 0); } date = currentBun; } results.close(); SearchParameters sp8 = new SearchParameters(); sp8.addStore(rootNodeRef.getStoreRef()); sp8.setLanguage(SearchService.LANGUAGE_LUCENE); sp8.setQuery("PATH:\"//.\""); sp8.addSort("@" + createdDate, false); results = searcher.query(sp8); date = null; for (ResultSetRow row : results) { Date currentBun = DefaultTypeConverter.INSTANCE.convert(Date.class, nodeService.getProperty(row.getNodeRef(), createdDate)); // System.out.println(currentBun); if ((date != null) && (currentBun != null)) { assertTrue(date.compareTo(currentBun) >= 0); } date = currentBun; } results.close(); SearchParameters sp_7 = new SearchParameters(); sp_7.addStore(rootNodeRef.getStoreRef()); sp_7.setLanguage(SearchService.LANGUAGE_LUCENE); sp_7.setQuery("PATH:\"//.\""); sp_7.addSort("@" + ContentModel.PROP_MODIFIED, true); results = searcher.query(sp_7); date = null; for (ResultSetRow row : results) { Date currentBun = DefaultTypeConverter.INSTANCE.convert(Date.class, nodeService.getProperty(row.getNodeRef(), ContentModel.PROP_MODIFIED)); if (currentBun != null) { Calendar c = new GregorianCalendar(); c.setTime(currentBun); c.set(Calendar.MILLISECOND, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.HOUR_OF_DAY, 0); currentBun = c.getTime(); } if ((date != null) && (currentBun != null)) { assertTrue(date.compareTo(currentBun) <= 0); } date = currentBun; } results.close(); SearchParameters sp_8 = new SearchParameters(); sp_8.addStore(rootNodeRef.getStoreRef()); sp_8.setLanguage(SearchService.LANGUAGE_LUCENE); sp_8.setQuery("PATH:\"//.\""); sp_8.addSort("@" + ContentModel.PROP_MODIFIED, false); results = searcher.query(sp_8); date = null; for (ResultSetRow row : results) { Date currentBun = DefaultTypeConverter.INSTANCE.convert(Date.class, nodeService.getProperty(row.getNodeRef(), ContentModel.PROP_MODIFIED)); // System.out.println(currentBun); if (currentBun != null) { Calendar c = new GregorianCalendar(); c.setTime(currentBun); c.set(Calendar.MILLISECOND, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.HOUR_OF_DAY, 0); currentBun = c.getTime(); } if ((date != null) && (currentBun != null)) { assertTrue(date.compareTo(currentBun) >= 0); } date = currentBun; } results.close(); // sort by double SearchParameters sp9 = new SearchParameters(); sp9.addStore(rootNodeRef.getStoreRef()); sp9.setLanguage(SearchService.LANGUAGE_LUCENE); sp9.setQuery("PATH:\"//.\""); sp9.addSort("@" + orderDouble, true); results = searcher.query(sp9); Double d = null; for (ResultSetRow row : results) { Double currentBun = DefaultTypeConverter.INSTANCE.convert(Double.class, nodeService.getProperty(row.getNodeRef(), orderDouble)); // System.out.println( (currentBun == null ? "null" : NumericEncoder.encode(currentBun))+ " "+currentBun); if (d != null) { assertTrue(d.compareTo(currentBun) <= 0); } d = currentBun; } results.close(); SearchParameters sp10 = new SearchParameters(); sp10.addStore(rootNodeRef.getStoreRef()); sp10.setLanguage(SearchService.LANGUAGE_LUCENE); sp10.setQuery("PATH:\"//.\""); sp10.addSort("@" + orderDouble, false); results = searcher.query(sp10); d = null; for (ResultSetRow row : results) { Double currentBun = DefaultTypeConverter.INSTANCE.convert(Double.class, nodeService.getProperty(row.getNodeRef(), orderDouble)); // System.out.println(currentBun); if ((d != null) && (currentBun != null)) { assertTrue(d.compareTo(currentBun) >= 0); } d = currentBun; } results.close(); // sort by float SearchParameters sp11 = new SearchParameters(); sp11.addStore(rootNodeRef.getStoreRef()); sp11.setLanguage(SearchService.LANGUAGE_LUCENE); sp11.setQuery("PATH:\"//.\""); sp11.addSort("@" + orderFloat, true); results = searcher.query(sp11); Float f = null; for (ResultSetRow row : results) { Float currentBun = DefaultTypeConverter.INSTANCE.convert(Float.class, nodeService.getProperty(row.getNodeRef(), orderFloat)); // System.out.println( (currentBun == null ? "null" : NumericEncoder.encode(currentBun))+ " "+currentBun); if (f != null) { assertTrue(f.compareTo(currentBun) <= 0); } f = currentBun; } results.close(); SearchParameters sp12 = new SearchParameters(); sp12.addStore(rootNodeRef.getStoreRef()); sp12.setLanguage(SearchService.LANGUAGE_LUCENE); sp12.setQuery("PATH:\"//.\""); sp12.addSort("@" + orderFloat, false); results = searcher.query(sp12); f = null; for (ResultSetRow row : results) { Float currentBun = DefaultTypeConverter.INSTANCE.convert(Float.class, nodeService.getProperty(row.getNodeRef(), orderFloat)); // System.out.println(currentBun); if ((f != null) && (currentBun != null)) { assertTrue(f.compareTo(currentBun) >= 0); } f = currentBun; } results.close(); // sort by long SearchParameters sp13 = new SearchParameters(); sp13.addStore(rootNodeRef.getStoreRef()); sp13.setLanguage(SearchService.LANGUAGE_LUCENE); sp13.setQuery("PATH:\"//.\""); sp13.addSort("@" + orderLong, true); results = searcher.query(sp13); Long l = null; for (ResultSetRow row : results) { Long currentBun = DefaultTypeConverter.INSTANCE.convert(Long.class, nodeService.getProperty(row.getNodeRef(), orderLong)); // System.out.println( (currentBun == null ? "null" : NumericEncoder.encode(currentBun))+ " "+currentBun); if (l != null) { assertTrue(l.compareTo(currentBun) <= 0); } l = currentBun; } results.close(); SearchParameters sp14 = new SearchParameters(); sp14.addStore(rootNodeRef.getStoreRef()); sp14.setLanguage(SearchService.LANGUAGE_LUCENE); sp14.setQuery("PATH:\"//.\""); sp14.addSort("@" + orderLong, false); results = searcher.query(sp14); l = null; for (ResultSetRow row : results) { Long currentBun = DefaultTypeConverter.INSTANCE.convert(Long.class, nodeService.getProperty(row.getNodeRef(), orderLong)); // System.out.println(currentBun); if ((l != null) && (currentBun != null)) { assertTrue(l.compareTo(currentBun) >= 0); } l = currentBun; } results.close(); // sort by int SearchParameters sp15 = new SearchParameters(); sp15.addStore(rootNodeRef.getStoreRef()); sp15.setLanguage(SearchService.LANGUAGE_LUCENE); sp15.setQuery("PATH:\"//.\""); sp15.addSort("@" + orderInt, true); results = searcher.query(sp15); Integer i = null; for (ResultSetRow row : results) { Integer currentBun = DefaultTypeConverter.INSTANCE.convert(Integer.class, nodeService.getProperty(row.getNodeRef(), orderInt)); // System.out.println( (currentBun == null ? "null" : NumericEncoder.encode(currentBun))+ " "+currentBun); if (i != null) { assertTrue(i.compareTo(currentBun) <= 0); } i = currentBun; } results.close(); SearchParameters sp16 = new SearchParameters(); sp16.addStore(rootNodeRef.getStoreRef()); sp16.setLanguage(SearchService.LANGUAGE_LUCENE); sp16.setQuery("PATH:\"//.\""); sp16.addSort("@" + orderInt, false); results = searcher.query(sp16); i = null; for (ResultSetRow row : results) { Integer currentBun = DefaultTypeConverter.INSTANCE.convert(Integer.class, nodeService.getProperty(row.getNodeRef(), orderInt)); // System.out.println(currentBun); if ((i != null) && (currentBun != null)) { assertTrue(i.compareTo(currentBun) >= 0); } i = currentBun; } results.close(); // sort by text SearchParameters sp17 = new SearchParameters(); sp17.addStore(rootNodeRef.getStoreRef()); sp17.setLanguage(SearchService.LANGUAGE_LUCENE); sp17.setQuery("PATH:\"//.\""); sp17.addSort("@" + orderText, true); results = searcher.query(sp17); String text = null; for (ResultSetRow row : results) { String currentBun = DefaultTypeConverter.INSTANCE.convert(String.class, nodeService.getProperty(row.getNodeRef(), orderText)); // System.out.println( (currentBun == null ? "null" : NumericEncoder.encode(currentBun))+ " "+currentBun); if ((text != null) && (currentBun != null)) { assertTrue(collator.compare(text, currentBun) <= 0); } text = currentBun; } results.close(); SearchParameters sp18 = new SearchParameters(); sp18.addStore(rootNodeRef.getStoreRef()); sp18.setLanguage(SearchService.LANGUAGE_LUCENE); sp18.setQuery("PATH:\"//.\""); sp18.addSort("@" + orderText, false); results = searcher.query(sp18); text = null; for (ResultSetRow row : results) { String currentBun = DefaultTypeConverter.INSTANCE.convert(String.class, nodeService.getProperty(row.getNodeRef(), orderText)); // System.out.println(currentBun); if ((text != null) && (currentBun != null)) { assertTrue(collator.compare(text, currentBun) >= 0); } text = currentBun; } results.close(); // sort by content size // sort by ML text // Locale[] testLocales = new Locale[] { I18NUtil.getLocale(), Locale.ENGLISH, Locale.FRENCH, Locale.CHINESE }; Locale[] testLocales = new Locale[] { I18NUtil.getLocale(), Locale.ENGLISH, Locale.FRENCH }; for (Locale testLocale : testLocales) { Collator localisedCollator = Collator.getInstance(testLocale); SearchParameters sp19 = new SearchParameters(); sp19.addStore(rootNodeRef.getStoreRef()); sp19.setLanguage(SearchService.LANGUAGE_LUCENE); sp19.setQuery("PATH:\"//.\""); sp19.addSort("@" + orderMLText, true); sp19.addLocale(testLocale); results = searcher.query(sp19); text = null; for (ResultSetRow row : results) { MLText mltext = DefaultTypeConverter.INSTANCE.convert(MLText.class, nodeService.getProperty(row.getNodeRef(), orderMLText)); if (mltext != null) { String currentBun = mltext.getValue(testLocale); // System.out.println( (currentBun == null ? "null" : NumericEncoder.encode(currentBun))+ " // "+currentBun); if ((text != null) && (currentBun != null)) { assertTrue(localisedCollator.compare(text, currentBun) <= 0); } text = currentBun; } } results.close(); SearchParameters sp20 = new SearchParameters(); sp20.addStore(rootNodeRef.getStoreRef()); sp20.setLanguage(SearchService.LANGUAGE_LUCENE); sp20.setQuery("PATH:\"//.\""); sp20.addSort("@" + orderMLText, false); sp20.addLocale(testLocale); results = searcher.query(sp20); text = null; for (ResultSetRow row : results) { MLText mltext = DefaultTypeConverter.INSTANCE.convert(MLText.class, nodeService.getProperty(row.getNodeRef(), orderMLText)); if (mltext != null) { String currentBun = mltext.getValue(testLocale); if ((text != null) && (currentBun != null)) { assertTrue(localisedCollator.compare(text, currentBun) >= 0); } text = currentBun; } } results.close(); } luceneFTS.resume(); SearchParameters spN = new SearchParameters(); spN.addStore(rootNodeRef.getStoreRef()); spN.setLanguage(SearchService.LANGUAGE_LUCENE); spN.setQuery("PATH:\"//.\""); spN.addSort("cabbage", false); results = searcher.query(spN); results.close(); // test sort on unkown properties ALF-4193 spN = new SearchParameters(); spN.addStore(rootNodeRef.getStoreRef()); spN.setLanguage(SearchService.LANGUAGE_LUCENE); spN.setQuery("PATH:\"//.\""); spN.addSort("PARENT", false); results = searcher.query(spN); results.close(); spN = new SearchParameters(); spN.addStore(rootNodeRef.getStoreRef()); spN.setLanguage(SearchService.LANGUAGE_LUCENE); spN.setQuery("PATH:\"//.\""); spN.addSort("@PARENT:PARENT", false); results = searcher.query(spN); results.close(); luceneFTS.resume(); // sort by content size SearchParameters sp20 = new SearchParameters(); sp20.addStore(rootNodeRef.getStoreRef()); sp20.setLanguage(SearchService.LANGUAGE_LUCENE); sp20.setQuery("PATH:\"//.\""); sp20.addSort("@" + ContentModel.PROP_CONTENT + ".size", false); results = searcher.query(sp20); Long size = null; for (ResultSetRow row : results) { ContentData currentBun = DefaultTypeConverter.INSTANCE.convert(ContentData.class, nodeService.getProperty(row.getNodeRef(), ContentModel.PROP_CONTENT)); // System.out.println(currentBun); if ((size != null) && (currentBun != null)) { assertTrue(size.compareTo(currentBun.getSize()) >= 0); } if (currentBun != null) { size = currentBun.getSize(); } } results.close(); // sort by content mimetype SearchParameters sp21 = new SearchParameters(); sp21.addStore(rootNodeRef.getStoreRef()); sp21.setLanguage(SearchService.LANGUAGE_LUCENE); sp21.setQuery("PATH:\"//.\""); sp21.addSort("@" + ContentModel.PROP_CONTENT + ".mimetype", false); results = searcher.query(sp21); String mimetype = null; for (ResultSetRow row : results) { ContentData currentBun = DefaultTypeConverter.INSTANCE.convert(ContentData.class, nodeService.getProperty(row.getNodeRef(), ContentModel.PROP_CONTENT)); // System.out.println(currentBun); if ((mimetype != null) && (currentBun != null)) { assertTrue(mimetype.compareTo(currentBun.getMimetype()) >= 0); } if (currentBun != null) { mimetype = currentBun.getMimetype(); } } results.close(); }
From source file:lasige.steeldb.jdbc.BFTRowSet.java
/** * Retrieves the value of the designated column in the current row * of this <code>CachedRowSetImpl</code> object as a * <code>boolean</code> value. * * @param columnIndex the first column is <code>1</code>, the second * is <code>2</code>, and so on; must be <code>1</code> or larger * and equal to or less than the number of columns in the rowset * @return the column value as a <code>boolean</code> in the Java progamming language; * if the value is SQL <code>NULL</code>, the result is <code>false</code> * @throws SQLException if (1) the given column index is out of bounds, * (2) the cursor is not on one of this rowset's rows or its * insert row, or (3) the designated column does not store an * SQL <code>BOOLEAN</code> value * @see #getBoolean(String)/*from w ww . j av a 2 s. c om*/ */ public boolean getBoolean(int columnIndex) throws SQLException { Object value; // sanity check. checkIndex(columnIndex); // make sure the cursor is on a valid row checkCursor(); setLastValueNull(false); value = getCurrentRow().getColumnObject(columnIndex); // check for SQL NULL if (value == null) { setLastValueNull(true); return false; } // check for Boolean... if (value instanceof Boolean) { return ((Boolean) value).booleanValue(); } // convert to a Double and compare to zero try { Double d = new Double(value.toString()); if (d.compareTo(new Double((double) 0)) == 0) { return false; } else { return true; } } catch (NumberFormatException ex) { throw new SQLException( MessageFormat.format(resBundle.handleGetObject("cachedrowsetimpl.boolfail").toString(), new Object[] { value.toString().trim(), columnIndex })); } }