List of usage examples for java.math BigDecimal ROUND_HALF_EVEN
int ROUND_HALF_EVEN
To view the source code for java.math BigDecimal ROUND_HALF_EVEN.
Click Source Link
From source file:org.egov.egf.web.actions.voucher.VoucherSearchAction.java
@ValidationErrorPage(value = SEARCH) @Action(value = "/voucher/voucherSearch-search") public String search() throws ApplicationException, ParseException { if (parameters.get(SHOW_MODE) != null) showMode = parameters.get(SHOW_MODE)[0]; if (voucherHeader.getModuleId() != null && voucherHeader.getModuleId() == -1) voucherHeader.setModuleId(null); // validate if mode is edit and financial year is not active if (showMode != null && showMode.equalsIgnoreCase("edit")) { final boolean validateFinancialYearForPosting = voucherSearchUtil .validateFinancialYearForPosting(fromDate, toDate); if (!validateFinancialYearForPosting) throw new ValidationException(Arrays.asList(new ValidationError( "Financial Year Not active for Posting(either year or date within selected date range)", "Financial Year Not active for Posting(either year or date within selected date range)"))); }/* w w w . j a v a 2s. c o m*/ List<CVoucherHeader> list; List<Query> qryObj; boolean ismodifyJv = false; voucherList = new ArrayList<>(); // for view voucher implementing paginated result if (isBlank(showMode)) { qryObj = voucherSearchUtil.voucherSearchQuery(voucherHeader, fromDate, toDate, showMode); final Query qry = qryObj.get(0); final Long count = (Long) persistenceService.find(qryObj.get(1).getQueryString()); final Page resPage = new Page(qry, page, pageSize); pagedResults = new EgovPaginatedList(resPage, count.intValue()); list = pagedResults.getList(); } else if (showMode.equalsIgnoreCase("nonbillPayment")) list = voucherSearchUtil.searchNonBillVouchers(voucherHeader, fromDate, toDate, showMode); else list = voucherSearchUtil.search(voucherHeader, fromDate, toDate, showMode); Map<String, Object> voucherMap; if (isBlank(showMode)) { for (final CVoucherHeader voucherheader : list) { voucherMap = new HashMap<>(); final BigDecimal amt = voucherheader.getTotalAmount(); voucherMap.put("id", voucherheader.getId()); voucherMap.put("vouchernumber", voucherheader.getVoucherNumber()); voucherMap.put(TYPE, voucherheader.getType()); voucherMap.put("name", voucherheader.getName()); voucherMap.put("deptName", voucherheader.getVouchermis().getDepartmentid().getName()); voucherMap.put("voucherdate", voucherheader.getVoucherDate()); voucherMap.put("fundname", voucherheader.getFundId().getName()); if (voucherheader.getModuleId() == null) voucherMap.put(SOURCE, INTERNAL); else voucherMap.put(SOURCE, sourceMap.get(voucherheader.getModuleId())); voucherMap.put("amount", amt.setScale(2, BigDecimal.ROUND_HALF_EVEN).toString()); voucherMap.put("status", getVoucherStatus(voucherheader.getStatus())); voucherList.add(voucherMap); } pagedResults.setList(voucherList); } else for (final CVoucherHeader voucherheader : list) { if (voucherheader.getState() != null) { final EgBillregistermis billMis = (EgBillregistermis) persistenceService .find("from EgBillregistermis where voucherHeader.id=?", voucherheader.getId()); if (billMis != null) { /* * bill state will be null if created from create JV screen and voucher is in end state */ if (billMis.getEgBillregister().getState() == null && voucherheader.getState().getValue().contains("END")) ismodifyJv = true; else ismodifyJv = false; } else if (voucherheader.getName() .equalsIgnoreCase(FinancialConstants.JOURNALVOUCHER_NAME_GENERAL) && voucherheader.getState().getValue().contains("END")) ismodifyJv = true; } else ismodifyJv = true; if (ismodifyJv) { voucherMap = new HashMap<>(); voucherMap.put("id", voucherheader.getId()); voucherMap.put("vouchernumber", voucherheader.getVoucherNumber()); voucherMap.put(TYPE, voucherheader.getType()); voucherMap.put("name", voucherheader.getName()); voucherMap.put("deptName", voucherheader.getVouchermis().getDepartmentid().getName()); voucherMap.put("voucherdate", voucherheader.getVoucherDate()); voucherMap.put("fundname", voucherheader.getFundId().getName()); if (voucherheader.getModuleId() == null) voucherMap.put(SOURCE, INTERNAL); else voucherMap.put(SOURCE, sourceMap.get(voucherheader.getModuleId())); voucherMap.put("amount", voucherheader.getTotalAmount().setScale(2, BigDecimal.ROUND_HALF_EVEN).toString()); voucherMap.put("status", getVoucherStatus(voucherheader.getStatus())); voucherList.add(voucherMap); } } return SEARCH; }
From source file:org.goko.tinyg.controller.TinyGCommunicator.java
private BigDecimal findVelocity(JsonObject statusReport) { JsonValue velocityReport = statusReport.get(TinyGJsonUtils.STATUS_REPORT_VELOCITY); if (velocityReport != null) { return velocityReport.asBigDecimal().setScale(3, BigDecimal.ROUND_HALF_EVEN); }//from ww w .j a va2 s. c om return null; }
From source file:com.ardhi.businessgame.services.BusinessGameService.java
public String checkUserStorage(HttpServletRequest req) { String val = "No", id = ""; boolean isAvailable; SqlRowSet srs1, srs2;// w w w. j av a 2 s . c om double tmp = 0; ArrayList<String> data = new ArrayList<String>(); srs1 = db.getJdbc() .queryForRowSet("select [level] from storage where id='" + req.getParameter("storage") + "'"); isAvailable = srs1.next(); if (isAvailable) { id = req.getParameter("storage"); } else { srs1 = db.getJdbc().queryForRowSet("select id,[level] from storage where [user]='" + req.getParameter("user") + "' and [zone]='" + req.getParameter("zone") + "'"); isAvailable = srs1.next(); if (isAvailable) id = srs1.getString("id"); } if (isAvailable) { int level = srs1.getInt("level") - 1; double capacity = 0, fill = 0, upgrade = 0, inc = 0; srs1 = db.getJdbc().queryForRowSet( "select [value] from info_values where name='storage' union select [value] from info_values where name='storage_inc' union select [value] from info_values where name='cost_storage_upgrade'"); if (srs1.next()) { capacity = Double.parseDouble(srs1.getString("value")); } else return "0"; if (srs1.next()) { capacity += level * Double.parseDouble(srs1.getString("value")); inc = Double.parseDouble(srs1.getString("value")); } else return "0"; if (srs1.next()) { upgrade = Double.parseDouble(srs1.getString("value")); } else return "0"; srs1 = db.getJdbc().queryForRowSet( "select storage_product.id,product,quality,size,draw from storage_product,desc_product,info_product where storage='" + id + "' and desc_product.id=storage_product.[desc] and product=name"); ArrayList<StorageProduct> storageProducts = new ArrayList<StorageProduct>(); ArrayList<MarketProduct> marketProducts = new ArrayList<MarketProduct>(); while (srs1.next()) { tmp = srs1.getDouble("size"); srs2 = db.getJdbc().queryForRowSet( "select market_product.id,product,market_product.price,quality,market_product.size,draw from market_product,desc_product,info_product,storage_product where storage_product_id='" + srs1.getString("id") + "' and storage_product_id=storage_product.id and desc_product.id=storage_product.[desc] and product=name"); while (srs2.next()) { tmp -= srs2.getDouble("size"); marketProducts.add(new MarketProduct(srs2.getString("id"), "", srs2.getString("product"), srs2.getDouble("price"), srs2.getInt("quality"), srs2.getDouble("size"), srs2.getString("draw"))); } if (tmp > 0) storageProducts.add(new StorageProduct(srs1.getString("id"), srs1.getString("product"), srs1.getInt("quality"), new BigDecimal(Double.valueOf(tmp)) .setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue(), srs1.getString("draw"))); fill += srs1.getDouble("size"); } srs1 = db.getJdbc().queryForRowSet( "select storage_equipment.id,equipment,quality,durability,size,operational,draw from storage_equipment,list_equipment,desc_equipment,info_equipment where storage='" + id + "' and storage_equipment.id=list_equipment.id and list_equipment.[desc]=desc_equipment.id and name=equipment"); ArrayList<StorageEquipment> storageEquipments = new ArrayList<StorageEquipment>(); ArrayList<MarketEquipment> marketEquipments = new ArrayList<MarketEquipment>(); while (srs1.next()) { srs2 = db.getJdbc().queryForRowSet( "select market_equipment.id,equipment,market_equipment.price,quality,durability,size,operational,draw from storage_equipment,market_equipment,desc_equipment,list_equipment,info_equipment where storage_equipment_id='" + srs1.getString("id") + "' and storage_equipment.id=storage_equipment_id and list_equipment.id=storage_equipment.id and list_equipment.[desc]=desc_equipment.id and equipment=name"); if (srs2.next()) { marketEquipments.add(new MarketEquipment(srs2.getString("id"), "", srs2.getString("equipment"), srs2.getDouble("price"), srs2.getInt("quality"), srs2.getDouble("durability"), srs2.getDouble("size"), srs2.getDouble("operational"), srs2.getString("draw"))); } else { storageEquipments.add(new StorageEquipment(srs1.getString("id"), srs1.getString("equipment"), srs1.getInt("quality"), srs1.getDouble("durability"), srs1.getDouble("size"), srs1.getDouble("operational"), srs1.getString("draw"))); } fill += srs1.getDouble("size"); } data.add(gson.toJson(isAvailable)); data.add(gson.toJson(capacity)); data.add(gson.toJson(fill)); data.add(gson.toJson(upgrade)); data.add(gson.toJson(inc)); data.add(gson.toJson(level + 1)); data.add(gson.toJson(storageProducts)); data.add(gson.toJson(storageEquipments)); data.add(gson.toJson(marketProducts)); data.add(gson.toJson(marketEquipments)); val = gson.toJson(data); storageProducts = null; storageEquipments = null; marketProducts = null; marketEquipments = null; } else { srs2 = db.getJdbc().queryForRowSet("select [value] from info_values where name='cost_storage'"); if (srs2.next()) { data.add(gson.toJson(isAvailable)); data.add(gson.toJson(Double.parseDouble(srs2.getString("value")))); val = gson.toJson(data); } else return "0"; } data = null; srs1 = null; srs2 = null; gc(); return val; }
From source file:com.ggvaidya.scinames.summary.NameStabilityView.java
public void init() { Project project = projectView.getProject(); // What do we actually need to do? boolean flag_calculateNameSimilarity = (toCalculate & NAME_SIMILARITY) == NAME_SIMILARITY; boolean flag_calculateClusterSimilarity = (toCalculate & CLUSTER_SIMILARITY) == CLUSTER_SIMILARITY; boolean flag_calculateCircumscriptionSimilarity = (toCalculate & CIRCUMSCRIPTIONAL_SIMILARITY) == CIRCUMSCRIPTIONAL_SIMILARITY; // Setup stage. stage.setTitle("Name stability between " + project.getDatasets().size() + " datasets"); // Setup table. controller.getTableEditableProperty().set(false); //controller.setTableColumnResizeProperty(TableView.CONSTRAINED_RESIZE_POLICY); ObservableList<TableColumn> cols = controller.getTableColumnsProperty(); cols.clear();//w w w . j a va 2 s. co m // Precalculating. Table<Dataset, String, String> precalc = HashBasedTable.create(); // Set up columns. cols.add(createTableColumnFromPrecalc(precalc, "dataset")); cols.add(createTableColumnFromPrecalc(precalc, "date")); cols.add(createTableColumnFromPrecalc(precalc, "year")); cols.add(createTableColumnFromPrecalc(precalc, "count_binomial")); cols.add(createTableColumnFromPrecalc(precalc, "count_genera")); cols.add(createTableColumnFromPrecalc(precalc, "count_monotypic_genera")); cols.add(createTableColumnFromPrecalc(precalc, "names_added")); //cols.add(createTableColumnFromPrecalc(precalc, "names_added_list")); cols.add(createTableColumnFromPrecalc(precalc, "names_deleted")); //cols.add(createTableColumnFromPrecalc(precalc, "names_deleted_list")); cols.add(createTableColumnFromPrecalc(precalc, "species_added")); //cols.add(createTableColumnFromPrecalc(precalc, "species_added_list")); cols.add(createTableColumnFromPrecalc(precalc, "species_deleted")); //cols.add(createTableColumnFromPrecalc(precalc, "species_deleted_list")); cols.add(createTableColumnFromPrecalc(precalc, "mean_binomials_per_genera")); cols.add(createTableColumnFromPrecalc(precalc, "median_binomials_per_genera")); cols.add(createTableColumnFromPrecalc(precalc, "mode_binomials_per_genera_list")); /* All them stability calculations */ if (flag_calculateNameSimilarity) { cols.add(createTableColumnFromPrecalc(precalc, "names_identical_to_prev")); cols.add(createTableColumnFromPrecalc(precalc, "names_identical_to_prev_pc_this")); cols.add(createTableColumnFromPrecalc(precalc, "names_identical_to_prev_pc_union")); cols.add(createTableColumnFromPrecalc(precalc, "names_identical_to_prev_pc_prev")); cols.add(createTableColumnFromPrecalc(precalc, "names_identical_to_next")); cols.add(createTableColumnFromPrecalc(precalc, "names_identical_to_next_pc_this")); cols.add(createTableColumnFromPrecalc(precalc, "names_identical_to_next_pc_union")); cols.add(createTableColumnFromPrecalc(precalc, "names_identical_to_next_pc_next")); cols.add(createTableColumnFromPrecalc(precalc, "names_identical_to_first")); cols.add(createTableColumnFromPrecalc(precalc, "names_identical_to_first_pc_this")); cols.add(createTableColumnFromPrecalc(precalc, "names_identical_to_first_pc_union")); cols.add(createTableColumnFromPrecalc(precalc, "names_identical_to_first_pc_first")); cols.add(createTableColumnFromPrecalc(precalc, "names_identical_to_last")); cols.add(createTableColumnFromPrecalc(precalc, "names_identical_to_last_pc_this")); cols.add(createTableColumnFromPrecalc(precalc, "names_identical_to_last_pc_union")); cols.add(createTableColumnFromPrecalc(precalc, "names_identical_to_last_pc_last")); } if (flag_calculateClusterSimilarity) { cols.add(createTableColumnFromPrecalc(precalc, "clusters_identical_to_prev")); cols.add(createTableColumnFromPrecalc(precalc, "clusters_identical_to_prev_pc_this")); cols.add(createTableColumnFromPrecalc(precalc, "clusters_identical_to_prev_pc_union")); cols.add(createTableColumnFromPrecalc(precalc, "clusters_identical_to_prev_pc_prev")); cols.add(createTableColumnFromPrecalc(precalc, "clusters_identical_to_next")); cols.add(createTableColumnFromPrecalc(precalc, "clusters_identical_to_next_pc_this")); cols.add(createTableColumnFromPrecalc(precalc, "clusters_identical_to_next_pc_union")); cols.add(createTableColumnFromPrecalc(precalc, "clusters_identical_to_next_pc_next")); cols.add(createTableColumnFromPrecalc(precalc, "clusters_identical_to_first")); cols.add(createTableColumnFromPrecalc(precalc, "clusters_identical_to_first_pc_this")); cols.add(createTableColumnFromPrecalc(precalc, "clusters_identical_to_first_pc_union")); cols.add(createTableColumnFromPrecalc(precalc, "clusters_identical_to_first_pc_first")); cols.add(createTableColumnFromPrecalc(precalc, "clusters_identical_to_last")); cols.add(createTableColumnFromPrecalc(precalc, "clusters_identical_to_last_pc_this")); cols.add(createTableColumnFromPrecalc(precalc, "clusters_identical_to_last_pc_union")); cols.add(createTableColumnFromPrecalc(precalc, "clusters_identical_to_last_pc_last")); } if (flag_calculateCircumscriptionSimilarity) { cols.add(createTableColumnFromPrecalc(precalc, "circumscriptions_identical_to_prev")); cols.add(createTableColumnFromPrecalc(precalc, "circumscriptions_identical_to_prev_pc_this")); cols.add(createTableColumnFromPrecalc(precalc, "circumscriptions_identical_to_prev_pc_union")); cols.add(createTableColumnFromPrecalc(precalc, "circumscriptions_identical_to_prev_pc_prev")); cols.add(createTableColumnFromPrecalc(precalc, "circumscriptions_identical_to_next")); cols.add(createTableColumnFromPrecalc(precalc, "circumscriptions_identical_to_next_pc_this")); cols.add(createTableColumnFromPrecalc(precalc, "circumscriptions_identical_to_next_pc_union")); cols.add(createTableColumnFromPrecalc(precalc, "circumscriptions_identical_to_next_pc_next")); cols.add(createTableColumnFromPrecalc(precalc, "circumscriptions_identical_to_first")); cols.add(createTableColumnFromPrecalc(precalc, "circumscriptions_identical_to_first_pc_this")); cols.add(createTableColumnFromPrecalc(precalc, "circumscriptions_identical_to_first_pc_union")); cols.add(createTableColumnFromPrecalc(precalc, "circumscriptions_identical_to_first_pc_first")); cols.add(createTableColumnFromPrecalc(precalc, "circumscriptions_identical_to_last")); cols.add(createTableColumnFromPrecalc(precalc, "circumscriptions_identical_to_last_pc_this")); cols.add(createTableColumnFromPrecalc(precalc, "circumscriptions_identical_to_last_pc_union")); cols.add(createTableColumnFromPrecalc(precalc, "circumscriptions_identical_to_last_pc_last")); } Set<String> recognitionColumns = new HashSet<>(); // Calculate binomials per dataset. Map<Name, Set<Dataset>> datasetsPerName = new HashMap<>(); // Prepare to loop! List<Dataset> checklists = project.getChecklists(); // BIRD HACK! Include all datasets! // checklists = project.getDatasets(); // Set table items. We're only interested in checklists, because // there's no such thing as "name stability" between non-checklist datasets. controller.getTableItemsProperty().set(FXCollections.observableArrayList(checklists)); List<Dataset> prevChecklists = new LinkedList<>(); Dataset firstChecklist = checklists.get(0); Dataset lastChecklist = checklists.get(checklists.size() - 1); // TODO: This used to be prevDataset, but prevChecklist makes a lot more sense, since we // want to compare checklists with each other, ignoring datasets. Would be nice if someone // with copious free time could look over the calculations and make sure they don't assume // that the previous checklist is also the previous dataset? Dataset prevChecklist = null; int index = -1; for (Dataset ds : checklists) { index++; Dataset nextChecklist = (index < (checklists.size() - 1) ? checklists.get(index + 1) : null); precalc.put(ds, "dataset", ds.getName()); precalc.put(ds, "date", ds.getDate().asYYYYmmDD("-")); precalc.put(ds, "year", ds.getDate().getYearAsString()); Set<Name> recognizedBinomials = project.getRecognizedNames(ds).stream().flatMap(n -> n.asBinomial()) .collect(Collectors.toSet()); precalc.put(ds, "count_binomial", String.valueOf(recognizedBinomials.size())); Set<Name> recognizedGenera = recognizedBinomials.stream().flatMap(n -> n.asGenus()) .collect(Collectors.toSet()); precalc.put(ds, "count_genera", String.valueOf(recognizedGenera.size())); precalc.put(ds, "mean_binomials_per_genera", new BigDecimal(((double) recognizedBinomials.size()) / recognizedGenera.size()) .setScale(2, BigDecimal.ROUND_HALF_EVEN).toPlainString()); Map<Name, List<Name>> countBinomialsPerGenus = recognizedBinomials.stream() // Eliminate names that have zero (or more than one?!) genus name. .filter(n -> (n.asGenus().count() == 1)) .collect(Collectors.groupingBy(n -> n.asGenus().findAny().get())); /* LOGGER.info("Debugging: list of " + recognizedGenera.size() + " genera: " + recognizedGenera.stream().map(n -> n.getFullName()).collect(Collectors.joining(", ")) ); */ precalc.put(ds, "count_monotypic_genera", String.valueOf(countBinomialsPerGenus.entrySet().stream() .filter(entry -> new HashSet<>(entry.getValue()).size() == 1).count())); /* LOGGER.info("Debugging: list of monotypic genera: " + countBinomialsPerGenus.entrySet().stream() .filter(entry -> new HashSet<>(entry.getValue()).size() == 1) .map(entry -> entry.getKey().getFullName()) .collect(Collectors.joining(", ")) ); */ // Species added and deleted Set<Name> namesAdded = ds.getChanges(project).filter(ch -> ch.getType().equals(ChangeType.ADDITION)) .flatMap(ch -> ch.getToStream()).collect(Collectors.toSet()); Set<Name> namesDeleted = ds.getChanges(project).filter(ch -> ch.getType().equals(ChangeType.DELETION)) .flatMap(ch -> ch.getFromStream()).collect(Collectors.toSet()); // TODO: This isn't so useful -- the more useful measure would be the number of all species added // and all species deleted, making sure there isn't a cluster-al overlap. precalc.put(ds, "names_added", String.valueOf(namesAdded.size())); //precalc.put(ds, "names_added_list", namesAdded.stream().sorted().map(n -> n.getFullName()).collect(Collectors.joining(", "))); precalc.put(ds, "names_deleted", String.valueOf(namesDeleted.size())); //precalc.put(ds, "names_deleted_list", namesDeleted.stream().sorted().map(n -> n.getFullName()).collect(Collectors.joining(", "))); // Eliminate names that have been added, but were previously recognized at the species level. Set<Name> speciesAdded = namesAdded; if (prevChecklist != null) { Set<Name> prevRecognizedNames = project.getNameClusterManager() .getClusters(project.getRecognizedNames(prevChecklist)).stream() .flatMap(nc -> nc.getNames().stream()).collect(Collectors.toSet()); speciesAdded = namesAdded.stream().filter(n -> !prevRecognizedNames.contains(n)) .collect(Collectors.toSet()); } // Eliminate names that are still represented in the checklist by a species cluster. // (Note that this includes cases where a subspecies is removed, but another subspecies // or the nominal species is still recognized!) Set<Name> currentlyRecognizedBinomialNames = project.getNameClusterManager() .getClusters(project.getRecognizedNames(ds)).stream().flatMap(nc -> nc.getNames().stream()) .flatMap(n -> n.asBinomial()).collect(Collectors.toSet()); Set<Name> speciesDeleted = namesDeleted.stream() .filter(n -> !n.asBinomial().anyMatch(bn -> currentlyRecognizedBinomialNames.contains(bn))) .collect(Collectors.toSet()); precalc.put(ds, "species_added", String.valueOf(speciesAdded.size())); precalc.put(ds, "species_added_list", speciesAdded.stream().sorted().map(n -> n.getFullName()).collect(Collectors.joining(", "))); precalc.put(ds, "species_deleted", String.valueOf(speciesDeleted.size())); precalc.put(ds, "species_deleted_list", speciesDeleted.stream().sorted().map(n -> n.getFullName()).collect(Collectors.joining(", "))); // Measures of species per genera java.util.Map<String, Set<Name>> binomialsPerGenera = recognizedBinomials.stream() .collect(Collectors.toMap(n -> n.getGenus(), n -> { Set<Name> set = new HashSet<Name>(); set.add(n); return set; }, (a, b) -> { a.addAll(b); return a; })); List<Integer> binomialsPerGeneraCounts = binomialsPerGenera.values().stream().map(set -> set.size()) .sorted().collect(Collectors.toList()); Frequency freq = new Frequency(); for (String genus : binomialsPerGenera.keySet()) { // Blech. for (Name binom : binomialsPerGenera.get(genus)) { freq.addValue(genus); } } List<Comparable<?>> modeGenera = freq.getMode(); precalc.put(ds, "mode_binomials_per_genera_list", modeGenera.stream().map(o -> o.toString() + ": " + freq.getCount(o) + " binomials") .collect(Collectors.joining("; "))); double[] binomialsPerGeneraCountsAsDouble = binomialsPerGeneraCounts.stream() .mapToDouble(Integer::doubleValue).toArray(); Median median = new Median(); precalc.put(ds, "median_binomials_per_genera", String.valueOf(median.evaluate(binomialsPerGeneraCountsAsDouble))); if (firstChecklist == null) { // precalc.put(ds, "names_identical_to_first", "NA"); // precalc.put(ds, "names_identical_to_first_pc", "NA"); } else { if (flag_calculateNameSimilarity) { precalc.put(ds, "names_identical_to_first", String.valueOf(getBinomialNamesIntersection(project, ds, firstChecklist).size())); precalc.put(ds, "names_identical_to_first_pc_this", new BigDecimal((double) getBinomialNamesIntersection(project, ds, firstChecklist).size() / recognizedBinomials.size() * 100).setScale(2, BigDecimal.ROUND_HALF_EVEN) .toPlainString()); precalc.put(ds, "names_identical_to_first_pc_union", new BigDecimal((double) getBinomialNamesIntersection(project, ds, firstChecklist).size() / getBinomialNamesUnion(project, ds, firstChecklist).size() * 100) .setScale(2, BigDecimal.ROUND_HALF_EVEN).toPlainString()); precalc.put(ds, "names_identical_to_first_pc_first", new BigDecimal((double) getBinomialNamesIntersection(project, ds, firstChecklist).size() / getBinomialNamesUnion(project, firstChecklist, firstChecklist).size() * 100) .setScale(2, BigDecimal.ROUND_HALF_EVEN).toPlainString()); } if (flag_calculateClusterSimilarity) { int clustersForDataset = project.getNameClusterManager().getClusters(recognizedBinomials) .size(); if (clustersForDataset != recognizedBinomials.size()) { throw new RuntimeException( "We have " + clustersForDataset + " clusters for this dataset, but " + recognizedBinomials.size() + " recognized binomials. What?"); } precalc.put(ds, "clusters_identical_to_first", String.valueOf(getBinomialClustersIntersection(project, ds, firstChecklist).size())); precalc.put(ds, "clusters_identical_to_first_pc_this", new BigDecimal( (double) getBinomialClustersIntersection(project, ds, firstChecklist).size() / getBinomialClustersUnion(project, ds, ds).size() * 100) .setScale(2, BigDecimal.ROUND_HALF_EVEN).toPlainString()); precalc.put(ds, "clusters_identical_to_first_pc_union", new BigDecimal( (double) getBinomialClustersIntersection(project, ds, firstChecklist).size() / getBinomialClustersUnion(project, ds, firstChecklist).size() * 100) .setScale(2, BigDecimal.ROUND_HALF_EVEN).toPlainString()); precalc.put(ds, "clusters_identical_to_first_pc_first", new BigDecimal( (double) getBinomialClustersIntersection(project, ds, firstChecklist).size() / getBinomialClustersUnion(project, firstChecklist, firstChecklist).size() * 100).setScale(2, BigDecimal.ROUND_HALF_EVEN).toPlainString()); } if (flag_calculateCircumscriptionSimilarity) { precalc.put(ds, "circumscriptions_identical_to_first", String .valueOf(getBinomialTaxonConceptsIntersection(project, ds, firstChecklist).size())); precalc.put(ds, "circumscriptions_identical_to_first_pc_this", new BigDecimal( (double) getBinomialTaxonConceptsIntersection(project, ds, firstChecklist).size() / getBinomialTaxonConceptsUnion(project, ds, ds).size() * 100) .setScale(2, BigDecimal.ROUND_HALF_EVEN).toPlainString()); precalc.put(ds, "circumscriptions_identical_to_first_pc_union", new BigDecimal( (double) getBinomialTaxonConceptsIntersection(project, ds, firstChecklist).size() / getBinomialTaxonConceptsUnion(project, ds, firstChecklist).size() * 100) .setScale(2, BigDecimal.ROUND_HALF_EVEN).toPlainString()); precalc.put(ds, "circumscriptions_identical_to_first_pc_first", new BigDecimal( (double) getBinomialTaxonConceptsIntersection(project, ds, firstChecklist).size() / getBinomialTaxonConceptsUnion(project, firstChecklist, firstChecklist).size() * 100).setScale(2, BigDecimal.ROUND_HALF_EVEN).toPlainString()); } } if (lastChecklist == null) { // precalc.put(ds, "names_identical_to_first", "NA"); // precalc.put(ds, "names_identical_to_first_pc", "NA"); } else { if (flag_calculateNameSimilarity) { precalc.put(ds, "names_identical_to_last", String.valueOf(getBinomialNamesIntersection(project, ds, lastChecklist).size())); precalc.put(ds, "names_identical_to_last_pc_this", new BigDecimal((double) getBinomialNamesIntersection(project, ds, lastChecklist).size() / recognizedBinomials.size() * 100).setScale(2, BigDecimal.ROUND_HALF_EVEN) .toPlainString()); precalc.put(ds, "names_identical_to_last_pc_union", new BigDecimal((double) getBinomialNamesIntersection(project, ds, lastChecklist).size() / getBinomialNamesUnion(project, ds, lastChecklist).size() * 100) .setScale(2, BigDecimal.ROUND_HALF_EVEN).toPlainString()); precalc.put(ds, "names_identical_to_last_pc_last", new BigDecimal((double) getBinomialNamesIntersection(project, ds, lastChecklist).size() / getBinomialNamesUnion(project, lastChecklist, lastChecklist).size() * 100) .setScale(2, BigDecimal.ROUND_HALF_EVEN).toPlainString()); } if (flag_calculateClusterSimilarity) { int clustersForDataset = project.getNameClusterManager().getClusters(recognizedBinomials) .size(); if (clustersForDataset != recognizedBinomials.size()) { throw new RuntimeException( "We have " + clustersForDataset + " clusters for this dataset, but " + recognizedBinomials.size() + " recognized binomials. What?"); } precalc.put(ds, "clusters_identical_to_last", String.valueOf(getBinomialClustersIntersection(project, ds, lastChecklist).size())); precalc.put(ds, "clusters_identical_to_last_pc_this", new BigDecimal( (double) getBinomialClustersIntersection(project, ds, lastChecklist).size() / getBinomialClustersUnion(project, ds, ds).size() * 100) .setScale(2, BigDecimal.ROUND_HALF_EVEN).toPlainString()); precalc.put(ds, "clusters_identical_to_last_pc_union", new BigDecimal( (double) getBinomialClustersIntersection(project, ds, lastChecklist).size() / getBinomialClustersUnion(project, ds, lastChecklist).size() * 100) .setScale(2, BigDecimal.ROUND_HALF_EVEN).toPlainString()); precalc.put(ds, "clusters_identical_to_last_pc_last", new BigDecimal( (double) getBinomialClustersIntersection(project, ds, lastChecklist).size() / getBinomialClustersUnion(project, lastChecklist, lastChecklist).size() * 100) .setScale(2, BigDecimal.ROUND_HALF_EVEN).toPlainString()); } if (flag_calculateCircumscriptionSimilarity) { precalc.put(ds, "circumscriptions_identical_to_last", String .valueOf(getBinomialTaxonConceptsIntersection(project, ds, lastChecklist).size())); precalc.put(ds, "circumscriptions_identical_to_last_pc_this", new BigDecimal( (double) getBinomialTaxonConceptsIntersection(project, ds, lastChecklist).size() / getBinomialTaxonConceptsUnion(project, ds, ds).size() * 100) .setScale(2, BigDecimal.ROUND_HALF_EVEN).toPlainString()); precalc.put(ds, "circumscriptions_identical_to_last_pc_union", new BigDecimal( (double) getBinomialTaxonConceptsIntersection(project, ds, lastChecklist).size() / getBinomialTaxonConceptsUnion(project, ds, lastChecklist).size() * 100) .setScale(2, BigDecimal.ROUND_HALF_EVEN).toPlainString()); precalc.put(ds, "circumscriptions_identical_to_last_pc_last", new BigDecimal( (double) getBinomialTaxonConceptsIntersection(project, ds, lastChecklist).size() / getBinomialTaxonConceptsUnion(project, lastChecklist, lastChecklist).size() * 100).setScale(2, BigDecimal.ROUND_HALF_EVEN).toPlainString()); } } if (prevChecklist == null) { // precalc.put(ds, "names_identical_to_prev", "NA"); // precalc.put(ds, "names_identical_to_prev_pc", "NA"); } else { if (flag_calculateNameSimilarity) { precalc.put(ds, "names_identical_to_prev", String.valueOf(getBinomialNamesIntersection(project, ds, prevChecklist).size())); precalc.put(ds, "names_identical_to_prev_pc_this", new BigDecimal((double) getBinomialNamesIntersection(project, ds, prevChecklist).size() / recognizedBinomials.size() * 100).setScale(2, BigDecimal.ROUND_HALF_EVEN) .toPlainString()); precalc.put(ds, "names_identical_to_prev_pc_union", new BigDecimal((double) getBinomialNamesIntersection(project, ds, prevChecklist).size() / getBinomialNamesUnion(project, ds, prevChecklist).size() * 100) .setScale(2, BigDecimal.ROUND_HALF_EVEN).toPlainString()); precalc.put(ds, "names_identical_to_prev_pc_prev", new BigDecimal((double) getBinomialNamesIntersection(project, ds, prevChecklist).size() / getBinomialNamesUnion(project, prevChecklist, prevChecklist).size() * 100) .setScale(2, BigDecimal.ROUND_HALF_EVEN).toPlainString()); } if (flag_calculateClusterSimilarity) { int clustersForDataset = project.getNameClusterManager().getClusters(recognizedBinomials) .size(); if (clustersForDataset != recognizedBinomials.size()) { throw new RuntimeException( "We have " + clustersForDataset + " clusters for this dataset, but " + recognizedBinomials.size() + " recognized binomials. What?"); } precalc.put(ds, "clusters_identical_to_prev", String.valueOf(getBinomialClustersIntersection(project, ds, prevChecklist).size())); precalc.put(ds, "clusters_identical_to_prev_pc_this", new BigDecimal( (double) getBinomialClustersIntersection(project, ds, prevChecklist).size() / getBinomialClustersUnion(project, ds, ds).size() * 100) .setScale(2, BigDecimal.ROUND_HALF_EVEN).toPlainString()); precalc.put(ds, "clusters_identical_to_prev_pc_union", new BigDecimal( (double) getBinomialClustersIntersection(project, ds, prevChecklist).size() / getBinomialClustersUnion(project, ds, prevChecklist).size() * 100) .setScale(2, BigDecimal.ROUND_HALF_EVEN).toPlainString()); precalc.put(ds, "clusters_identical_to_prev_pc_prev", new BigDecimal( (double) getBinomialClustersIntersection(project, ds, prevChecklist).size() / getBinomialClustersUnion(project, prevChecklist, prevChecklist).size() * 100) .setScale(2, BigDecimal.ROUND_HALF_EVEN).toPlainString()); } if (flag_calculateCircumscriptionSimilarity) { precalc.put(ds, "circumscriptions_identical_to_prev", String .valueOf(getBinomialTaxonConceptsIntersection(project, ds, prevChecklist).size())); precalc.put(ds, "circumscriptions_identical_to_prev_pc_this", new BigDecimal( (double) getBinomialTaxonConceptsIntersection(project, ds, prevChecklist).size() / getBinomialTaxonConceptsUnion(project, ds, ds).size() * 100) .setScale(2, BigDecimal.ROUND_HALF_EVEN).toPlainString()); precalc.put(ds, "circumscriptions_identical_to_prev_pc_union", new BigDecimal( (double) getBinomialTaxonConceptsIntersection(project, ds, prevChecklist).size() / getBinomialTaxonConceptsUnion(project, ds, prevChecklist).size() * 100) .setScale(2, BigDecimal.ROUND_HALF_EVEN).toPlainString()); precalc.put(ds, "circumscriptions_identical_to_prev_pc_prev", new BigDecimal( (double) getBinomialTaxonConceptsIntersection(project, ds, prevChecklist).size() / getBinomialTaxonConceptsUnion(project, prevChecklist, prevChecklist).size() * 100).setScale(2, BigDecimal.ROUND_HALF_EVEN).toPlainString()); } // FYI, getBinomialTaxonConceptsUnion(project, ds, prevChecklist).size() should always be equal to the number of species in the dataset. } if (nextChecklist == null) { // precalc.put(ds, "names_identical_to_prev", "NA"); // precalc.put(ds, "names_identical_to_prev_pc", "NA"); } else { if (flag_calculateNameSimilarity) { precalc.put(ds, "names_identical_to_next", String.valueOf(getBinomialNamesIntersection(project, ds, nextChecklist).size())); precalc.put(ds, "names_identical_to_next_pc_this", new BigDecimal((double) getBinomialNamesIntersection(project, ds, nextChecklist).size() / recognizedBinomials.size() * 100).setScale(2, BigDecimal.ROUND_HALF_EVEN) .toPlainString()); precalc.put(ds, "names_identical_to_next_pc_union", new BigDecimal((double) getBinomialNamesIntersection(project, ds, nextChecklist).size() / getBinomialNamesUnion(project, ds, nextChecklist).size() * 100) .setScale(2, BigDecimal.ROUND_HALF_EVEN).toPlainString()); precalc.put(ds, "names_identical_to_next_pc_next", new BigDecimal((double) getBinomialNamesIntersection(project, ds, nextChecklist).size() / getBinomialNamesUnion(project, nextChecklist, nextChecklist).size() * 100) .setScale(2, BigDecimal.ROUND_HALF_EVEN).toPlainString()); } if (flag_calculateClusterSimilarity) { int clustersForDataset = project.getNameClusterManager().getClusters(recognizedBinomials) .size(); if (clustersForDataset != recognizedBinomials.size()) { throw new RuntimeException( "We have " + clustersForDataset + " clusters for this dataset, but " + recognizedBinomials.size() + " recognized binomials. What?"); } precalc.put(ds, "clusters_identical_to_next", String.valueOf(getBinomialClustersIntersection(project, ds, nextChecklist).size())); precalc.put(ds, "clusters_identical_to_next_pc_this", new BigDecimal( (double) getBinomialClustersIntersection(project, ds, nextChecklist).size() / getBinomialClustersUnion(project, ds, ds).size() * 100) .setScale(2, BigDecimal.ROUND_HALF_EVEN).toPlainString()); precalc.put(ds, "clusters_identical_to_next_pc_union", new BigDecimal( (double) getBinomialClustersIntersection(project, ds, nextChecklist).size() / getBinomialClustersUnion(project, ds, nextChecklist).size() * 100) .setScale(2, BigDecimal.ROUND_HALF_EVEN).toPlainString()); precalc.put(ds, "clusters_identical_to_next_pc_next", new BigDecimal( (double) getBinomialClustersIntersection(project, ds, nextChecklist).size() / getBinomialClustersUnion(project, nextChecklist, nextChecklist).size() * 100) .setScale(2, BigDecimal.ROUND_HALF_EVEN).toPlainString()); } if (flag_calculateCircumscriptionSimilarity) { precalc.put(ds, "circumscriptions_identical_to_next", String .valueOf(getBinomialTaxonConceptsIntersection(project, ds, nextChecklist).size())); precalc.put(ds, "circumscriptions_identical_to_next_pc_this", new BigDecimal( (double) getBinomialTaxonConceptsIntersection(project, ds, nextChecklist).size() / getBinomialTaxonConceptsUnion(project, ds, ds).size() * 100) .setScale(2, BigDecimal.ROUND_HALF_EVEN).toPlainString()); precalc.put(ds, "circumscriptions_identical_to_next_pc_union", new BigDecimal( (double) getBinomialTaxonConceptsIntersection(project, ds, nextChecklist).size() / getBinomialTaxonConceptsUnion(project, ds, nextChecklist).size() * 100) .setScale(2, BigDecimal.ROUND_HALF_EVEN).toPlainString()); precalc.put(ds, "circumscriptions_identical_to_next_pc_next", new BigDecimal( (double) getBinomialTaxonConceptsIntersection(project, ds, nextChecklist).size() / getBinomialTaxonConceptsUnion(project, nextChecklist, nextChecklist).size() * 100).setScale(2, BigDecimal.ROUND_HALF_EVEN).toPlainString()); } } /* // For the visualization thingie. int total = prevChecklists.size(); List<Integer> counts = new LinkedList<>(); for(Name name: recognizedBinomials) { int prevRecognized = 0; if(!datasetsPerName.containsKey(name)) { datasetsPerName.put(name, new HashSet<>()); } else { prevRecognized = datasetsPerName.get(name).size(); } datasetsPerName.get(name).add(ds); counts.add( (int)( ((double)prevRecognized)/total*100 ) ); } Map<Integer, List<Integer>> countsByPercentage = counts.stream().sorted().collect(Collectors.groupingBy(n -> (int)(n/10)*10)); for(int percentage: countsByPercentage.keySet()) { precalc.put(ds, "previously_recognized_" + percentage + "pc", String.valueOf(countsByPercentage.get(percentage).size())); recognitionColumns.add("previously_recognized_" + percentage + "pc"); } prevChecklists.add(ds); */ // Set up the previous checklist for the next loop. prevChecklist = ds; } /* LinkedList<String> recognitionColumnsList = new LinkedList<>(recognitionColumns); recognitionColumnsList.sort(null); for(String colName: recognitionColumnsList) { cols.add(createTableColumnFromPrecalc(precalc, colName)); }*/ }
From source file:org.goko.tinyg.controller.TinyGCommunicator.java
private BigDecimal findFeedrate(JsonObject feedrate) { JsonValue feedrateReport = feedrate.get(TinyGJsonUtils.STATUS_REPORT_FEEDRATE); if (feedrateReport != null) { return feedrateReport.asBigDecimal().setScale(3, BigDecimal.ROUND_HALF_EVEN); }/*from w ww . j a v a 2 s . c o m*/ return null; }
From source file:org.goko.controller.tinyg.controller.TinyGCommunicator.java
private Speed findFeedrate(JsonObject feedrate) { JsonValue feedrateReport = feedrate.get(TinyGJsonUtils.STATUS_REPORT_FEEDRATE); if (feedrateReport != null) { Unit<Speed> unit = SpeedUnit.MILLIMETRE_PER_MINUTE; if (tinyg.getCurrentUnit().equals(LengthUnit.INCH)) { unit = SpeedUnit.INCH_PER_MINUTE; }// ww w. j a v a2 s . c o m return Speed.valueOf(feedrateReport.asBigDecimal().setScale(3, BigDecimal.ROUND_HALF_EVEN), unit); } return null; }
From source file:com.lp.server.artikel.fastlanereader.ArtikellisteHandler.java
public QueryResult getPageAt(Integer rowIndex) throws EJBExceptionLP { QueryResult result = null;/* w w w. j av a 2 s . c o m*/ SessionFactory factory = FLRSessionFactory.getFactory(); Session session = null; Iterator resultListIterator = null; List resultList = null; try { int colCount = getTableInfo().getColumnClasses().length; int pageSize = getLimit(); int startIndex = Math.max(rowIndex.intValue() - (pageSize / 2), 0); int endIndex = startIndex + pageSize - 1; session = factory.openSession(); session = setFilter(session); String queryString = "SELECT artikelliste.i_id FROM FLRArtikelliste AS artikelliste " + " LEFT OUTER JOIN artikelliste.artikellagerset AS alager " + " LEFT OUTER JOIN artikelliste.flrgeometrie AS geo " + " LEFT OUTER JOIN artikelliste.artikellieferantset AS artikellieferantset " + " LEFT OUTER JOIN artikelliste.stuecklisten AS stuecklisten " + " LEFT OUTER JOIN artikelliste.artikelsprset AS aspr " + " LEFT OUTER JOIN artikelliste.flrartikelgruppe AS ag " + " LEFT OUTER JOIN artikelliste.flrartikelklasse AS ak " + this.buildWhereClause() + this.buildGroupByClause() + this.buildOrderByClause(); Query query = session.createQuery(queryString); query.setFirstResult(startIndex); query.setMaxResults(pageSize); resultList = query.list(); Object[][] rows = new Object[resultList.size()][colCount]; Integer[] iIds = new Integer[resultList.size()]; iIds = (Integer[]) resultList.toArray(iIds); String in = ""; String inArtikel_i_id = ""; HashMap hmRabattsatzFixpreis = new HashMap(); HashMap hmPreisbasis = new HashMap(); HashMap<Integer, String> hmKommentarTooltip = new HashMap<Integer, String>(); if (resultList.size() > 0) { in = " AND artikelliste.i_id IN("; inArtikel_i_id = " pl.artikel_i_id IN("; String inKommentar = " ko.artikelkommentar.artikel_i_id IN("; for (int i = 0; i < iIds.length; i++) { if (i == iIds.length - 1) { in += iIds[i]; inArtikel_i_id += iIds[i]; inKommentar += iIds[i]; } else { in += iIds[i] + ","; inArtikel_i_id += iIds[i] + ","; inKommentar += iIds[i] + ","; } } in += ") "; inArtikel_i_id += ") "; inKommentar += ") "; // String ins = StringUtils.join(iIds, ",") ; session.close(); session = factory.openSession(); session = setFilter(session); queryString = this.getFromClause() + this.buildWhereClause() + in + this.buildGroupByClause() + this.buildOrderByClause(); query = session.createQuery(queryString); resultList = query.list(); Session sessionVkPreisBasis = factory.openSession(); String rabattsatzFixpreis = "SELECT pl.artikel_i_id, pl.n_artikelstandardrabattsatz ,pl.n_artikelfixpreis FROM FLRVkpfartikelpreis AS pl WHERE pl.vkpfartikelpreisliste_i_id=" + vkPreisliste + " AND " + inArtikel_i_id + " ORDER BY t_preisgueltigab DESC "; Query queryRabattsatzFixpreis = sessionVkPreisBasis.createQuery(rabattsatzFixpreis); List resultListRabattsatzFixpreis = queryRabattsatzFixpreis.list(); Iterator resultListIteratorRabattsatzFixpreis = resultListRabattsatzFixpreis.iterator(); while (resultListIteratorRabattsatzFixpreis.hasNext()) { Object[] o = (Object[]) resultListIteratorRabattsatzFixpreis.next(); if (!hmRabattsatzFixpreis.containsKey(o[0])) { hmRabattsatzFixpreis.put(o[0], o); } } sessionVkPreisBasis.close(); sessionVkPreisBasis = factory.openSession(); String preisbasis; if (bVkPreisLief1preis) { preisbasis = "SELECT pl.artikel_i_id, pl.n_nettopreis FROM FLRArtikellieferant AS pl WHERE " + inArtikel_i_id + " ORDER BY i_sort ASC "; } else { preisbasis = "SELECT pl.artikel_i_id, pl.n_verkaufspreisbasis FROM FLRVkpfartikelverkaufspreisbasis AS pl WHERE " + inArtikel_i_id + " AND t_verkaufspreisbasisgueltigab <='" + Helper.formatDateWithSlashes(new java.sql.Date(System.currentTimeMillis())) + "'" + " ORDER BY t_verkaufspreisbasisgueltigab DESC "; } Query queryPreisbasis = sessionVkPreisBasis.createQuery(preisbasis); List resultListPreisbasis = queryPreisbasis.list(); Iterator resultListIteratorPreisbasis = resultListPreisbasis.iterator(); while (resultListIteratorPreisbasis.hasNext()) { Object[] o = (Object[]) resultListIteratorPreisbasis.next(); if (!hmPreisbasis.containsKey(o[0])) { hmPreisbasis.put(o[0], o[1]); } } sessionVkPreisBasis.close(); // PJ18025 sessionVkPreisBasis = factory.openSession(); String kommentare = "SELECT ko.artikelkommentar.artikel_i_id, ko.x_kommentar, ko.artikelkommentar.flrartikelkommentarart.c_nr FROM FLRArtikelkommentarspr AS ko WHERE " + inKommentar + " AND ko.locale='" + theClientDto.getLocUiAsString() + "' AND ko.artikelkommentar.flrartikelkommentarart.b_tooltip=1 "; Query queryKommentare = sessionVkPreisBasis.createQuery(kommentare); List resultListKommentare = queryKommentare.list(); Iterator resultListIteratorKommentare = resultListKommentare.iterator(); while (resultListIteratorKommentare.hasNext()) { Object[] o = (Object[]) resultListIteratorKommentare.next(); if (o[2] != null) { String kommentar = "<b>" + (String) o[2] + ":</b>\n" + (String) o[1]; String kommentarVorhanden = ""; if (hmKommentarTooltip.containsKey(o[0])) { kommentarVorhanden = hmKommentarTooltip.get(o[0]) + "<br><br>" + kommentar; } else { kommentarVorhanden = kommentar; } hmKommentarTooltip.put((Integer) o[0], kommentarVorhanden); } } sessionVkPreisBasis.close(); } rows = new Object[resultList.size()][colCount]; resultListIterator = resultList.iterator(); int row = 0; String[] tooltipData = new String[resultList.size()]; while (resultListIterator.hasNext()) { Object o[] = (Object[]) resultListIterator.next(); Object[] rowToAddCandidate = new Object[colCount]; rowToAddCandidate[getTableColumnInformation().getViewIndex("i_id")] = o[0]; rowToAddCandidate[getTableColumnInformation().getViewIndex("artikel.artikelnummerlang")] = o[1]; rowToAddCandidate[getTableColumnInformation().getViewIndex("lp.stuecklistenart")] = o[13] != null ? ((String) o[13]).trim() : o[13]; if (bKurzbezeichnungAnzeigen) { prepareKurzbezeichnung(o, rowToAddCandidate); } rowToAddCandidate[getTableColumnInformation().getViewIndex("bes.artikelbezeichnung")] = o[2]; if (bAbmessungenStattZusatzbezeichnung || bArtikelgruppeStattZusatzbezeichnung) { if (bAbmessungenStattZusatzbezeichnung) { prepareAbmessungen(o, rowToAddCandidate); } else { prepareArtikelGruppeInAbmessung(o, rowToAddCandidate); } } else { rowToAddCandidate[getTableColumnInformation().getViewIndex("artikel.zusatzbez")] = o[6]; } if (bArtikelgruppeAnzeigen) { prepareArtikelGruppe(o, rowToAddCandidate); } else { if (bArtikelklasseAnzeigen) { prepareArtikelKlasse(o, rowToAddCandidate); } } if (bVkPreisStattGestpreis == true) { prepareVkPreis(hmRabattsatzFixpreis, hmPreisbasis, o, rowToAddCandidate); } if (o[4] != null && Helper.short2boolean((Short) o[5])) { rowToAddCandidate[getTableColumnInformation().getViewIndex("lp.lagerstand")] = o[3]; } else { rowToAddCandidate[getTableColumnInformation().getViewIndex("lp.lagerstand")] = new BigDecimal( 0); } if (bLagerplaetzeAnzeigen) { prepareLagerplaetze((Integer) o[0], rowToAddCandidate); } if (bDarfPreiseSehen) { // Gestehungspreis holen BigDecimal gestehungspreis = (BigDecimal) o[4]; if (gestehungspreis != null && ((BigDecimal) rowToAddCandidate[getTableColumnInformation() .getViewIndex("lp.lagerstand")]).doubleValue() > 0) { gestehungspreis = gestehungspreis.divide( new BigDecimal(((BigDecimal) rowToAddCandidate[getTableColumnInformation() .getViewIndex("lp.lagerstand")]).doubleValue()), 4, BigDecimal.ROUND_HALF_EVEN); } else { // Projekt 10870: WH: Wenn kein Gestpreis zustandekommt, // dann Gestpreis des Hauptlagers anzeigen if (Helper.short2boolean((Short) o[5]) && o[8] != null) { gestehungspreis = (BigDecimal) o[8]; } else { gestehungspreis = new BigDecimal(0); } } if (bVkPreisStattGestpreis == false) { rowToAddCandidate[getTableColumnInformation().getViewIndex("lp.preis")] = gestehungspreis; } } else { rowToAddCandidate[getTableColumnInformation().getViewIndex("lp.preis")] = new BigDecimal(0); } Long lAnzahlReklamationen = (Long) o[15]; Boolean hatOffeneReklamationen = (lAnzahlReklamationen != null) && lAnzahlReklamationen.intValue() > 0; FLRArtikelsperren as = (FLRArtikelsperren) o[7]; if (as != null || hatOffeneReklamationen) { String gesperrt = null; if (as != null) { gesperrt = as.getFlrsperren().getC_bez(); } if (hatOffeneReklamationen) { rowToAddCandidate[getTableColumnInformation() .getViewIndex("Icon")] = getStatusMitUebersetzung(gesperrt, new java.sql.Timestamp(System.currentTimeMillis()), "R"); } else { rowToAddCandidate[getTableColumnInformation().getViewIndex("Icon")] = gesperrt; } } if (!Helper.short2boolean((Short) o[18])) { rowToAddCandidate[getTableColumnInformation().getViewIndex("Color")] = new Color(0, 0, 255); } rows[row] = rowToAddCandidate; // PJ18025 String tooltip = (String) hmKommentarTooltip.get(o[0]); if (tooltip != null) { String text = tooltip; text = text.replaceAll("\n", "<br>"); text = "<html>" + text + "</html>"; tooltipData[row] = text; } row++; } result = new QueryResult(rows, getRowCount(), startIndex, endIndex, 0, tooltipData); } catch (Exception e) { throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, e); } finally { closeSession(session); } return result; }
From source file:org.yes.cart.service.vo.impl.VoShopServiceImpl.java
protected void addCustomerConfig(final VoShopSummary summary, final String lang, final Map<String, VoAttrValueShop> masterAttrsMap, final Map<String, VoAttrValueShop> subAttrsMap) { summary.setAdminEmail(/*from w w w .j a v a 2s . co m*/ getShopAttributeConfig(masterAttrsMap, AttributeNamesKeys.Shop.SHOP_ADMIN_EMAIL, lang, "-")); final MutablePair<String, String> subAdminEmail = getShopAttributeConfig(subAttrsMap, AttributeNamesKeys.Shop.SHOP_ADMIN_EMAIL, lang, "-"); if (!summary.getAdminEmail().getSecond().equals(subAdminEmail.getSecond())) { summary.getAdminEmail() .setSecond(subAdminEmail.getSecond() + " (" + summary.getAdminEmail().getSecond() + ")"); } // B2B address book + strict price is from SUB summary.setB2bAddressbookActive(getBooleanShopAttributeConfig(subAttrsMap, AttributeNamesKeys.Shop.SHOP_B2B_ADDRESSBOOK, lang, false)); summary.setB2bStrictPriceActive(getBooleanShopAttributeConfig(subAttrsMap, AttributeNamesKeys.Shop.SHOP_B2B_STRICT_PRICE, lang, false)); summary.setB2bProfileActive( getBooleanShopAttributeConfig(masterAttrsMap, AttributeNamesKeys.Shop.SHOP_B2B, lang, false)); summary.setCookiePolicy(getBooleanShopAttributeConfig(masterAttrsMap, AttributeNamesKeys.Shop.SHOP_COOKIE_POLICY_ENABLE, lang, false)); summary.setAnonymousBrowsing(getBooleanShopAttributeConfig(masterAttrsMap, AttributeNamesKeys.Shop.SHOP_SF_REQUIRE_LOGIN, lang, true)); final MutablePair<String, String> sessionExpiry = getShopAttributeConfig(masterAttrsMap, AttributeNamesKeys.Shop.CART_SESSION_EXPIRY_SECONDS, lang, "21600"); int sessionExpirySeconds = NumberUtils.toInt(sessionExpiry.getFirst()); String time = "6h"; if (sessionExpirySeconds > 3600) { // more than hour time = new BigDecimal(sessionExpirySeconds) .divide(new BigDecimal(60 * 60), 1, BigDecimal.ROUND_HALF_EVEN).toPlainString() + "h"; } else if (sessionExpirySeconds > 60) { // more than minute time = new BigDecimal(sessionExpirySeconds).divide(new BigDecimal(60), 1, BigDecimal.ROUND_HALF_EVEN) .toPlainString() + "m"; } summary.setCustomerSession(MutablePair.of(sessionExpiry.getFirst(), time)); final Set<String> knownCustomerTypes = new HashSet<String>(); final VoAttrValueShop registrationTypesCsv = masterAttrsMap .get(AttributeNamesKeys.Shop.SHOP_CUSTOMER_TYPES); if (registrationTypesCsv != null && StringUtils.isNotBlank(registrationTypesCsv.getVal())) { final String[] registrationTypes = StringUtils.split(registrationTypesCsv.getVal(), ','); final String[] registrationTypesNames = StringUtils.split( getDisplayName(registrationTypesCsv.getDisplayVals(), registrationTypesCsv.getVal(), lang), ','); for (int i = 0; i < registrationTypes.length; i++) { final MutablePair<String, String> typeAndName = MutablePair.of(registrationTypes[i], registrationTypesNames.length > i ? registrationTypesNames[i] : registrationTypes[i]); knownCustomerTypes.add(typeAndName.getFirst()); summary.getCustomerTypes().add(typeAndName); } if (!knownCustomerTypes.contains(AttributeNamesKeys.Cart.CUSTOMER_TYPE_GUEST)) { knownCustomerTypes.add(AttributeNamesKeys.Cart.CUSTOMER_TYPE_GUEST); summary.getCustomerTypes().add(MutablePair.of(AttributeNamesKeys.Cart.CUSTOMER_TYPE_GUEST, "-")); } } // Registrations are at master level since we do not know the SUB yet final MutablePair<String, List<String>> ableToRegister = getCsvShopAttributeConfig(masterAttrsMap, AttributeNamesKeys.Shop.SHOP_CUSTOMER_TYPES, lang); // Email related config is at master level final MutablePair<String, List<String>> approveRegister = getCsvShopAttributeConfig(masterAttrsMap, AttributeNamesKeys.Shop.SHOP_SF_REQUIRE_REG_APPROVE, lang); final MutablePair<String, List<String>> notifyRegister = getCsvShopAttributeConfig(masterAttrsMap, AttributeNamesKeys.Shop.SHOP_SF_REQUIRE_REG_NOTIFICATION, lang); // Tax information is at Master level final MutablePair<String, List<String>> seeTax = getCsvShopAttributeConfig(masterAttrsMap, AttributeNamesKeys.Shop.SHOP_PRODUCT_ENABLE_PRICE_TAX_INFO, lang); final MutablePair<String, List<String>> seeNetPrice = getCsvShopAttributeConfig(masterAttrsMap, AttributeNamesKeys.Shop.SHOP_PRODUCT_ENABLE_PRICE_TAX_INFO_SHOW_NET, lang); final MutablePair<String, List<String>> seeTaxAmount = getCsvShopAttributeConfig(masterAttrsMap, AttributeNamesKeys.Shop.SHOP_PRODUCT_ENABLE_PRICE_TAX_INFO_SHOW_AMOUNT, lang); final MutablePair<String, List<String>> changeTax = getCsvShopAttributeConfig(masterAttrsMap, AttributeNamesKeys.Shop.SHOP_PRODUCT_ENABLE_PRICE_TAX_INFO_CHANGE_TYPES, lang); // RFQ, approvals, checkout block, repeat order, shopping list and address book disabling is at sub level final MutablePair<String, List<String>> rfq = getCsvShopAttributeConfig(subAttrsMap, AttributeNamesKeys.Shop.SHOP_RFQ_CUSTOMER_TYPES, lang); final MutablePair<String, List<String>> approve = getCsvShopAttributeConfig(subAttrsMap, AttributeNamesKeys.Shop.SHOP_SF_REQUIRE_ORDER_APPROVE, lang); final MutablePair<String, List<String>> blockCheckout = getCsvShopAttributeConfig(subAttrsMap, AttributeNamesKeys.Shop.SHOP_SF_CANNOT_PLACE_ORDER, lang); final MutablePair<String, List<String>> repeatOrders = getCsvShopAttributeConfig(subAttrsMap, AttributeNamesKeys.Shop.SHOP_SF_REPEAT_ORDER_TYPES, lang); final MutablePair<String, List<String>> orderLineRemarks = getCsvShopAttributeConfig(subAttrsMap, AttributeNamesKeys.Shop.SHOP_SF_B2B_LINE_REMARKS_TYPES, lang); final MutablePair<String, List<String>> orderForm = getCsvShopAttributeConfig(subAttrsMap, AttributeNamesKeys.Shop.SHOP_SF_B2B_ORDER_FORM_TYPES, lang); final MutablePair<String, List<String>> shoppingLists = getCsvShopAttributeConfig(subAttrsMap, AttributeNamesKeys.Shop.SHOP_SF_SHOPPING_LIST_TYPES, lang); final MutablePair<String, List<String>> addressBookDisabled = getCsvShopAttributeConfig(subAttrsMap, AttributeNamesKeys.Shop.SHOP_ADDRESSBOOK_DISABLED_CUSTOMER_TYPES, lang); final Set<String> additionalTypes = new HashSet<String>(); additionalTypes.addAll(ableToRegister.getSecond()); additionalTypes.addAll(approveRegister.getSecond()); additionalTypes.addAll(notifyRegister.getSecond()); additionalTypes.addAll(seeTax.getSecond()); additionalTypes.addAll(seeNetPrice.getSecond()); additionalTypes.addAll(seeTaxAmount.getSecond()); additionalTypes.addAll(changeTax.getSecond()); additionalTypes.addAll(rfq.getSecond()); additionalTypes.addAll(approve.getSecond()); additionalTypes.addAll(blockCheckout.getSecond()); additionalTypes.addAll(repeatOrders.getSecond()); additionalTypes.addAll(orderLineRemarks.getSecond()); additionalTypes.addAll(orderForm.getSecond()); additionalTypes.addAll(shoppingLists.getSecond()); additionalTypes.addAll(addressBookDisabled.getSecond()); if (CollectionUtils.isNotEmpty(additionalTypes)) { additionalTypes.removeAll(knownCustomerTypes); if (!additionalTypes.isEmpty()) { for (final String newType : additionalTypes) { knownCustomerTypes.add(newType); summary.getCustomerTypes().add(MutablePair.of(newType, newType)); } } } summary.setCustomerTypesAbleToRegister(ableToRegister); summary.setCustomerTypesRequireRegistrationApproval(approveRegister); summary.setCustomerTypesRequireRegistrationNotification(notifyRegister); summary.setCustomerTypesSeeTax(seeTax); summary.setCustomerTypesSeeNetPrice(seeNetPrice); summary.setCustomerTypesSeeTaxAmount(seeTaxAmount); summary.setCustomerTypesChangeTaxView(changeTax); summary.setCustomerTypesRfq(rfq); summary.setCustomerTypesOrderApproval(approve); summary.setCustomerTypesBlockCheckout(blockCheckout); summary.setCustomerTypesRepeatOrders(repeatOrders); summary.setCustomerTypesB2BOrderLineRemarks(orderLineRemarks); summary.setCustomerTypesB2BOrderForm(orderForm); summary.setCustomerTypesShoppingLists(shoppingLists); summary.setCustomerTypesAddressBookDisabled(addressBookDisabled); }
From source file:com.photon.phresco.framework.commons.FrameworkUtil.java
public static float roundFloat(int decimal, double value) { BigDecimal roundThroughPut = new BigDecimal(value); return roundThroughPut.setScale(decimal, BigDecimal.ROUND_HALF_EVEN).floatValue(); }
From source file:org.egov.stms.notice.service.SewerageNoticeService.java
public ReportOutput generateReportOutputDataForEstimation( final SewerageApplicationDetails sewerageApplicationDetails) { ReportRequest reportInput = null;//w w w . j a va 2s.co m final Map<String, Object> reportParams = new HashMap<>(); if (sewerageApplicationDetails != null) { final AssessmentDetails assessmentDetails = sewerageTaxUtils.getAssessmentDetailsForFlag( sewerageApplicationDetails.getConnectionDetail().getPropertyIdentifier(), PropertyExternalService.FLAG_FULL_DETAILS); String[] doorNo = null; if (null != assessmentDetails.getPropertyAddress()) doorNo = assessmentDetails.getPropertyAddress().split(","); String ownerName = ""; if (null != assessmentDetails.getOwnerNames()) for (final OwnerName names : assessmentDetails.getOwnerNames()) { ownerName = names.getOwnerName(); break; } if (sewerageApplicationDetails.getApplicationType() != null) reportParams.put(APPLICATION_TYPE, WordUtils.capitalize(sewerageApplicationDetails.getApplicationType().getName())); reportParams.put("cityName", cityService.getMunicipalityName()); reportParams.put(DISTRICT, cityService.getDistrictName()); reportParams.put("estimationDate", getDefaultFormattedDate(sewerageApplicationDetails.getApplicationDate())); reportParams.put("cityLogo", cityService.getCityLogoURL()); reportParams.put("estimationNumber", sewerageApplicationDetails.getEstimationNumber()); reportParams.put(ASSESSMENT_NO, sewerageApplicationDetails.getConnectionDetail().getPropertyIdentifier()); if (sewerageApplicationDetails.getCurrentDemand() != null) for (final EgDemandDetails egDmdDetails : sewerageApplicationDetails.getCurrentDemand() .getEgDemandDetails()) if (egDmdDetails.getEgDemandReason().getEgDemandReasonMaster().getCode() .equalsIgnoreCase(SewerageTaxConstants.FEES_DONATIONCHARGE_CODE)) donationCharges = egDmdDetails.getAmount().subtract(egDmdDetails.getAmtCollected()); // TODO: CHECK THIS LOGIC AGAIN. IF FEE TYPE IS ESTIMATION FEES, // THEN WE NEED TO GROUP ALL FEESES. for (final SewerageConnectionFee scf : sewerageApplicationDetails.getConnectionFees()) { if (scf.getFeesDetail().getCode() .equalsIgnoreCase(SewerageTaxConstants.FEES_ESTIMATIONCHARGES_CODE)) estimationCharges = BigDecimal.valueOf(scf.getAmount()); if (scf.getFeesDetail().getCode().equalsIgnoreCase(SewerageTaxConstants.FEES_SEWERAGETAX_CODE)) sewerageCharges = BigDecimal.valueOf(scf.getAmount()); } final BigDecimal totalCharges = estimationCharges.add(donationCharges).add(sewerageCharges); reportParams.put(ESTIMATION_CHARGES, estimationCharges); reportParams.put(DONATION_CHARGES, donationCharges); reportParams.put("sewerageCharges", sewerageCharges); reportParams.put(TOTAL_CHARGES, totalCharges); reportParams.put("amountInWords", getTotalAmountInWords(totalCharges.setScale(2, BigDecimal.ROUND_HALF_EVEN))); reportParams.put(APPLICATION_DATE, getDefaultFormattedDate(sewerageApplicationDetails.getApplicationDate())); reportParams.put("applicantName", ownerName); reportParams.put(ADDRESS, assessmentDetails.getPropertyAddress()); reportParams.put("inspectionDetails", sewerageApplicationDetails.getFieldInspections().get(0).getFieldInspectionDetails()); reportParams.put("estimationDetails", sewerageApplicationDetails.getEstimationDetails()); reportParams.put("houseNo", doorNo != null ? doorNo[0] : ""); reportInput = new ReportRequest(ESTIMATION_NOTICE, sewerageApplicationDetails, reportParams); } return reportService.createReport(reportInput); }