List of usage examples for java.lang Double intValue
public int intValue()
From source file:stats.GaussianFitMeanStdev.java
public void CalculateMeanStdev(double[] values) { Long maxvalue = 0l;/*ww w . j a v a 2 s. c o m*/ if (values.length < 3) { log.log(Level.WARNING, "Mean/Stdev calculation had " + values.length + "initial observations! Doing simple estimate"); this.mean = StdevAvg.DoubleAvg(values); this.stdev = StdevAvg.stdevDBL(this.mean, values); return; } for (Double d : values) { if (Math.round(d) > maxvalue) maxvalue = d.longValue(); } if (maxvalue.intValue() <= 3) { log.log(Level.WARNING, "Chromosome had very little signal! Max signal value: " + maxvalue.intValue()); this.cantUse = true; return; } Double[] bins = new Double[maxvalue.intValue() + 1]; java.util.Arrays.fill(bins, 0.0d); for (Double d : values) { bins[d.intValue()] += 1; } double testmean = StdevAvg.DoubleAvg(values); double teststdev = StdevAvg.stdevDBL(testmean, values); log.log(Level.FINEST, "[GMSTDEV] testmean: " + testmean + " teststdev: " + teststdev); try { this.fitter = GaussianCurveFitter.create().withMaxIterations(50) .withStartPoint(new double[] { maxvalue * 0.4 / teststdev, testmean, teststdev * 0.5 }); } catch (TooManyIterationsException ex) { log.log(Level.WARNING, "Too many iterations for local fitter! Using regular mean and stdev."); this.mean = testmean; this.stdev = teststdev; return; } WeightedObservedPoints obs = new WeightedObservedPoints(); for (int i = 0; i < bins.length && i < testmean * 3; i++) { obs.add(i, bins[i]); } double[] parameters; try { parameters = fitter.fit(obs.toList()); } catch (TooManyIterationsException ex) { log.log(Level.WARNING, "Too many iterations for local fitter! Using regular mean and stdev."); this.mean = testmean; this.stdev = teststdev; return; } this.mean = parameters[1]; this.stdev = parameters[2]; Double mincut = parameters[1] - 2.0d * parameters[2]; Double maxcut = parameters[1] + 2.0d * parameters[2]; log.log(Level.FINEST, "[GMSTDEV] initial mean: " + this.mean + " initial stdev: " + this.stdev + " mincut, maxcut: ( " + mincut + "," + maxcut + " )"); if (maxcut - mincut < 3 || mincut < 0 || maxcut < 0) { log.log(Level.WARNING, "Mean/Stdev calculation had " + mincut + " and " + maxcut + "! Not cropping values"); return; } //java.util.Arrays.fill(bins, 0.0d); obs = new WeightedObservedPoints(); for (int i = mincut.intValue(); i < maxcut.intValue(); i++) { obs.add(i, bins[i]); } double[] par = fitter.fit(obs.toList()); this.mean = par[1]; this.stdev = par[2]; }
From source file:com.wcna.calms.jpos.services.quote.JPOSQuickQuoteAssetLoadService.java
/*** * This is used by the prices screen which opens from the proposal summary screen. * @param assetDataVo/* ww w .j a va2 s . c o m*/ * @param appId * @param loadMap * @return */ /////WARNING: PENDING REFACTORING TASK.....THIS METHODS NEEDS TO BE MOVED TO THE SERVICE LAYER...I DID HAVE SOME TROUBLE WHILE I DID TRY TO MOVE IT IN MY FIRST ATTEMPT.. /////CURRENTLY THE SAME CODE IS DUPLICATED IN JPOSQuickQuoteLoadService.java AND JPOSQuickQuoteAssetLoadService.java ////PLEASE DO CHANGE IN BOTH CLASSES IF ANY CHANGES ARE INTRODUCED TO THIS METHOD. private IJPOSApplicationAssetDataVO loadAssetSubProcess(IJPOSApplicationAssetDataVO assetDataVo, String appId, Map<String, Object> loadMap) { List<IRentACarBean> rentACarList = null; IJPOSQuickQuoteAssetInputForm assetForm = null; int modelVariantId = 0; if (!StringUtil.isEmpty(appId)) { Locale locale = getUserContainer().getLocale(); assetDataVo = quickQuoteService.loadAsset(Long.valueOf(appId), locale, false); rentACarList = quickQuoteService.getRentACarList(Long.valueOf(appId)); assetForm = new JPOSQuickQuoteAssetVO(); if (assetDataVo != null) { JPOSQuickQuoteAssetVO screenVo = new JPOSQuickQuoteAssetVO(); screenVo.setNewUsed(assetDataVo.getNewOrUsed()); screenVo.setRegistrationCode(assetDataVo.getRegPlateId()); screenVo.setFreeFormatFlag(assetDataVo.getFreeFormatFlag()); screenVo.setMakeId(assetDataVo.getMakeId()); screenVo.setModelId(assetDataVo.getModelId()); screenVo.setModelVariantId(assetDataVo.getModelVariantId()); if (!"on".equals(screenVo.getFreeFormatFlag())) { if (!StringUtil.isEmpty(screenVo.getModelVariantId())) { modelVariantId = formatService.parseInteger(screenVo.getModelVariantId(), locale, false, 0); } } else { if (!IClientConstants.EXECUTE.equals(projectProperties .getProperty(IClientConstants.ONCHANGE_FFE_CHKBOX_IMPL_DISABLE_MAKE_TOGGLE))) { screenVo.setMakeId(assetDataVo.getMakeDesc()); } screenVo.setModelId(assetDataVo.getModelDesc()); screenVo.setModelVariantId(assetDataVo.getModelVariantDesc()); } screenVo.setTaxIncludingFlag(assetDataVo.getIsTaxable()); screenVo.setRegistrationNumber(assetDataVo.getRegistrationNumber()); Date d = assetDataVo.getRegistrationDate(); if (d != null) { screenVo.setRegistrationDate(formatService.formatDate(d, locale)); } screenVo.setAssetType(assetDataVo.getAssetType()); Double meter = assetDataVo.getMeterValue(); if (meter == null) { meter = new Double(0); } screenVo.setKilometrage(formatService.formatInteger(meter.intValue(), locale)); screenVo.setVin(assetDataVo.getVin()); screenVo.setManufactureDate(formatService.formatDate(assetDataVo.getManufactureDate(), locale)); screenVo.setMortgageRegDate(formatService.formatDate(assetDataVo.getMortgageRegDate(), locale)); screenVo.setAssetUsageCode(assetDataVo.getAssetUsageCode()); screenVo.setApprovedUsedAssetCode(assetDataVo.getApprovedUsedAssetCode()); screenVo.setEnviroImpactRatingCode(assetDataVo.getEnviroImpactRatingCode()); screenVo.setEnviroImpactRatingAmount( formatService.formatDouble(assetDataVo.getEnviroImpactRatingAmount(), locale)); screenVo.setTaxHorsePowerRating( formatService.formatDouble(assetDataVo.getTaxHorsePowerRating(), locale)); screenVo.setSalePrice(formatService.formatDouble(assetDataVo.getSalePrice(), locale)); screenVo.setTaxCode(assetDataVo.getTaxCode()); screenVo.setTaxAmt(formatService.formatDouble(assetDataVo.getTaxAmt(), locale)); screenVo.setGrossCost(formatService.formatDouble(assetDataVo.getGrossCost(), locale)); screenVo.setExtraAmt(formatService.formatDouble(assetDataVo.getExtraAmount(), locale)); screenVo.setExtraTaxCode(assetDataVo.getExtraTaxCode()); screenVo.setExtraTaxAmt(formatService.formatDouble(assetDataVo.getExtraTaxAmount(), locale)); screenVo.setExtraTotalCost(assetDataVo.getExtraTotalCost()); screenVo.setTaxableDFOptionsGross(assetDataVo.getTaxableDFOptionsGross()); screenVo.setTaxableDFOptionsNet(assetDataVo.getTaxableDFOptionsNet()); String defaultZero = formatService.formatDouble(0d, locale); // this is to avoid validation issues if this is a rent-a-car deal if (StringUtils.isBlank(screenVo.getTaxableDFOptionsNet())) { screenVo.setTaxableDFOptionsNet(defaultZero); } if (StringUtils.isBlank(screenVo.getTaxableDFOptionsGross())) { screenVo.setTaxableDFOptionsGross(defaultZero); } screenVo.setTaxableDFOptionsVatAmt(assetDataVo.getTaxableDFOptionsVatAmt()); screenVo.setTaxableDFOptionsVatRate(assetDataVo.getTaxableDFOptionsVatRate()); screenVo.setNonTaxableDFOptionsGross(assetDataVo.getNonTaxableDFOptionsGross()); screenVo.setNonTaxableDFOptionsNet(assetDataVo.getNonTaxableDFOptionsNet()); if (StringUtils.isBlank(screenVo.getNonTaxableDFOptionsNet())) { screenVo.setNonTaxableDFOptionsNet(defaultZero); } if (StringUtils.isBlank(screenVo.getNonTaxableDFOptionsGross())) { screenVo.setNonTaxableDFOptionsGross(defaultZero); } screenVo.setNonTaxableDFOptionsVatAmt(assetDataVo.getNonTaxableDFOptionsVatAmt()); screenVo.setNonTaxableDFOptionsVatRate(assetDataVo.getNonTaxableDFOptionsVatRate()); screenVo.setRoadFundLicenseGross(assetDataVo.getRoadFundLicenseGross()); screenVo.setRoadFundLicenseNet(assetDataVo.getRoadFundLicenseNet()); screenVo.setRoadFundLicenseVatAmt(assetDataVo.getRoadFundLicenseVatAmt()); screenVo.setRoadFundLicenseVatRate(assetDataVo.getRoadFundLicenseVatRate()); screenVo.setFirstRegistrationGross(assetDataVo.getFirstRegistrationGross()); screenVo.setFirstRegistrationNet(assetDataVo.getFirstRegistrationNet()); screenVo.setFirstRegistrationVatAmt(assetDataVo.getFirstRegistrationVatAmt()); screenVo.setFirstRegistrationVatRate(assetDataVo.getFirstRegistrationVatRate()); screenVo.setTotalNet(assetDataVo.getTotalNet()); screenVo.setTotalGross(formatService.formatDouble(assetDataVo.getTotalCost(), locale)); screenVo.setTotalVatAmt(formatService.formatDouble(assetDataVo.getTotalVat(), locale)); screenVo.setDiscountNet(assetDataVo.getDiscountNet()); screenVo.setDiscountVatRate(assetDataVo.getDiscountVatRate()); screenVo.setDiscountVatAmt(assetDataVo.getDiscountVatAmt()); screenVo.setDiscountGross(assetDataVo.getDiscountGross()); if (IConstants.FLAG_YES.equals(assetDataVo.getDiscountAmtIsPct())) { screenVo.setDiscountAmtIsPct(IConstants.FLAG_YES); } else { screenVo.setDiscountAmtIsPct(""); } if (assetDataVo.getDiscountAmt() != null) { screenVo.setDiscountAmt(assetDataVo.getDiscountAmt()); } else { screenVo.setDiscountAmt(""); } if (assetDataVo.getDiscountPct() != null) { screenVo.setDiscountPct(assetDataVo.getDiscountPct()); } else { screenVo.setDiscountPct(""); } screenVo.setTaxPointDate(formatService.formatDate(assetDataVo.getTaxPointDate(), locale)); screenVo.setTaxRateValue(formatService.formatDouble(assetDataVo.getTaxRateValue(), locale)); loadMap.put("assetDetails", screenVo); loadMap.put("vehicleOutline", quickQuoteService.getVehicleDescription(Long.valueOf(appId))); loadMap.put("rentACarList", rentACarList); List<IVehicleFFOBean> ffoList = assetDataVo.getFfoList(); if (ffoList == null) { ffoList = new ArrayList<IVehicleFFOBean>(); } loadMap.put("ffoList", ffoList); screenVo.setTotalRvUpliftPercentage(assetDataVo.getTotalRvUpliftPercentage()); BeanUtils.copyProperties(screenVo, assetForm); } IAssetPartExchangeVO assetPartExchangeVO = (assetDataVo.getAssetPartExchange() == null) ? quickQuoteService.getDefaultPartExchange() : assetDataVo.getAssetPartExchange(); this.quickQuoteService.setAssetDetailsToContainer(0, assetForm, assetDataVo.getFfoList(), rentACarList, assetPartExchangeVO); } return assetDataVo; }
From source file:org.eclipse.nebula.widgets.nattable.layer.SizeConfig.java
/** * Will calculate the real pixel values for the positions if percentage sizing is enabled. * @param space The space that is available for rendering. * @param positionCount The number of positions that should be handled by this {@link SizeConfig} *///w w w .j a v a2s. c om public void calculatePercentages(int space, int positionCount) { if (isPercentageSizing()) { this.availableSpace = space; int percentageSpace = calculateAvailableSpace(space); int sum = 0; int real = 0; int realSum = 0; int fixedSum = 0; List<Integer> noInfoPositions = new ArrayList<Integer>(); Integer positionValue = null; for (int i = 0; i < positionCount; i++) { positionValue = this.sizeMap.get(i); if (positionValue != null) { if (isPercentageSizing(i)) { sum += positionValue; real = calculatePercentageValue(positionValue, percentageSpace); } else { real = positionValue; fixedSum += real; } realSum += real; this.realSizeMap.put(i, real); } else { //remember the position for which no size information exists //needed to calculate the size for those positions dependent on the //remaining space noInfoPositions.add(i); } } int[] correction = correctPercentageValues(sum, positionCount); if (correction != null) { sum = correction[0]; realSum = correction[1] + fixedSum; } if (!noInfoPositions.isEmpty()) { //now calculate the size for the remaining columns double remaining = new Double(space) - realSum; Double remainingColSpace = remaining / noInfoPositions.size(); for (Integer position : noInfoPositions) { sum += (remainingColSpace / space) * 100; this.realSizeMap.put(position, remainingColSpace.intValue()); } //If there are positions for which no size information exist, the size config //will use 100 percent of the available space on percentage sizing. To handle //rounding issues just set the sum to 100 for correct calculation results. sum = 100; } if (sum == 100) { //check if the sum of the calculated values is the same as the given space //if not add the missing pixels to the last value //this is needed because of rounding issues on 100% with odd-numbered pixel values int valueSum = 0; int lastPos = -1; for (Map.Entry<Integer, Integer> entry : this.realSizeMap.entrySet()) { valueSum += entry.getValue(); lastPos = Math.max(lastPos, entry.getKey()); } if (valueSum < space) { int lastPosValue = this.realSizeMap.get(lastPos); this.realSizeMap.put(lastPos, lastPosValue + (space - valueSum)); } } } }
From source file:com.zns.comicdroid.service.GoogleDriveService.java
private synchronized void PublishComics(String account, String webFolderId, boolean force) { //Get Service Drive service = null;// w w w. j a va 2 s . com try { GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(getApplicationContext(), Arrays.asList(Application.DRIVE_SCOPE_PUBLISH)); credential.setSelectedAccountName(account); credential.getToken(); service = new Drive.Builder(AndroidHttp.newCompatibleTransport(), new JacksonFactory(), credential) .build(); } catch (UserRecoverableAuthException e) { //We are not authenticated for some reason, notify user. NotifyAuthentication(); return; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); return; } catch (GoogleAuthException e) { // TODO Auto-generated catch block e.printStackTrace(); return; } //Make sure webfolder still exists try { com.google.api.services.drive.model.File webFolder = service.files().get(webFolderId).execute(); if (webFolder == null || webFolder.getExplicitlyTrashed() == Boolean.TRUE) { NotifyAuthentication(); return; } } catch (IOException e) { NotifyAuthentication(); return; } //Get some more stuff from context String outPath = getApplicationContext().getExternalFilesDir(null).toString() + "/html"; String imagePath = ((Application) getApplication()).getImagePath(true); //Let's get started File fileOut = new File(outPath); fileOut.mkdirs(); fileOut = new File(outPath, PUBLISH_INDEX_FILENAME); BufferedReader reader = null; BufferedWriter writer = null; Cursor cursor = null; try { cursor = mDb.getCursor( "SELECT _id, Title, Subtitle, Author, Image, ImageUrl, 1 AS ItemType, 0 AS BookCount, IsBorrowed, AddedDate " + "FROM tblBooks WHERE GroupId = 0 OR ifnull(GroupId, '') = '' " + "UNION " + "SELECT _id, Name AS Title, '' AS Subtitle, '' AS Author, (SELECT Image FROM tblBooks where GroupId = tblGroups._id) AS Image, ImageUrl, 2 AS ItemType, BookCount, 0 AS IsBorrowed, 0 AS PublishDate " + "FROM tblGroups " + "ORDER BY Title", null); int rowCount = cursor.getCount(); String line; //Read template StringBuilder sbTemplate = new StringBuilder(); reader = new BufferedReader(new InputStreamReader(getResources().openRawResource(R.raw.listtemplate))); while ((line = reader.readLine()) != null) { sbTemplate.append(line); } reader.close(); //Write HTML writer = new BufferedWriter(new FileWriter(fileOut)); reader = new BufferedReader(new InputStreamReader(getResources().openRawResource(R.raw.framework))); int i = 0; while ((line = reader.readLine()) != null) { if (line.trim().equals("#LISTCOMICS#")) { while (cursor.moveToNext()) { int id = cursor.getInt(0); String title = nullToEmpty(cursor.getString(1)); String subTitle = nullToEmpty(cursor.getString(2)); String author = nullToEmpty(cursor.getString(3)); String image = nullToEmpty(cursor.getString(4)); String imageUrl = nullToEmpty(cursor.getString(5)); int type = cursor.getInt(6); int date = cursor.getInt(9); StringBuilder sbChildren = new StringBuilder(); String comicLine = sbTemplate.toString(); comicLine = comicLine.replace("#TITLE#", title + (type == 1 && !subTitle.equals("") ? " - " + subTitle : "")); comicLine = comicLine.replace("#AUTHOR#", author); comicLine = comicLine.replace("#IMAGEURL#", getImageSrc(imageUrl, image, imagePath)); comicLine = comicLine.replace("#ISSUE#", ""); comicLine = comicLine.replace("#ISAGGREGATE#", type == 2 ? " Aggregate" : ""); comicLine = comicLine.replace("#MARK#", type == 2 ? "<div class=\"Mark\"></div>" : ""); comicLine = comicLine.replace("#DATE#", type == 1 ? Integer.toString(date) : ""); if (type == 2) { //Render group children List<Comic> comics = mDb.getComics(id); for (Comic comic : comics) { String childComic = sbTemplate.toString(); childComic = childComic.replace("#TITLE#", nullToEmpty(comic.getTitle()) + (!nullToEmpty(comic.getSubTitle()).equals("") ? " - " + comic.getSubTitle() : "")); childComic = childComic.replace("#AUTHOR#", nullToEmpty(comic.getAuthor())); childComic = childComic.replace("#IMAGEURL#", getImageSrc(nullToEmpty(comic.getImageUrl()), nullToEmpty(comic.getImage()), imagePath)); childComic = childComic.replace("#ISSUE#", comic.getIssue() > 0 ? Integer.toString(comic.getIssue()) : ""); childComic = childComic.replace("#DATE#", Integer.toString(comic.getAddedDateTimestamp())); childComic = childComic.replace("#ISAGGREGATE#", ""); childComic = childComic.replace("#MARK#", ""); childComic = childComic.replace("#CHILDREN#", ""); sbChildren.append(childComic); } comicLine = comicLine.replace("#CHILDREN#", sbChildren.toString()); } else { comicLine = comicLine.replace("#CHILDREN#", ""); } writer.write(comicLine); if (force) { Double part = (((double) i + 1) / (double) rowCount) * 100.0; EventBus.getDefault().post( new ProgressResult(part.intValue(), getString(R.string.progress_publish))); i++; } } } else { writer.write(line); } } } catch (Exception e) { //Gotta catch'em all! return; } finally { if (cursor != null) cursor.close(); try { if (writer != null) writer.close(); if (reader != null) reader.close(); } catch (IOException e) { } } //Upload to google drive if (force) { EventBus.getDefault().post(new ProgressResult(20, getString(R.string.progress_publishupload))); } try { //Get current index file com.google.api.services.drive.model.File fileIndex = DriveUtil.getFile(service, webFolderId, PUBLISH_INDEX_FILENAME); //Set content of file FileContent content = new FileContent("text/html", fileOut); //Insert / Update if (fileIndex == null) { com.google.api.services.drive.model.File driveFile = new com.google.api.services.drive.model.File(); driveFile.setTitle(PUBLISH_INDEX_FILENAME); driveFile.setMimeType("text/html"); driveFile.setParents(Arrays.asList(new ParentReference().setId(webFolderId))); service.files().insert(driveFile, content).execute(); } else { Update update = service.files().update(fileIndex.getId(), null, content); update.setNewRevision(false); update.execute(); } mLogger.appendLog("Published to google drive", Logger.TAG_BACKUP); } catch (Exception e) { mLogger.appendLog("Failed to publish to google drive", Logger.TAG_BACKUP); e.printStackTrace(); } if (force) { EventBus.getDefault().post(new ProgressResult(100, getString(R.string.progress_publishupload))); } }
From source file:org.polymap.kaps.exporter.VertragStaLaBaulandExporter.java
private void export(List<String> lines, VertragComposite vertrag, List<String> errors) { VertragsdatenBaulandComposite vdc = VertragsdatenBaulandComposite.Mixin.forVertrag(vertrag); // } catch (Exception e) { // VertragsdatenBaulandComposite template = QueryExpressions.templateFor( VertragsdatenBaulandComposite.class ); // BooleanExpression expr = QueryExpressions.eq( template.vertrag(), vertrag ); // return KapsRepository.instance().findEntities( VertragsdatenBaulandComposite.class, expr, 0, -1 ).find(); // }//from w w w. j a v a 2s. c o m if (vdc == null) { errors.add(error(vertrag, "Erweiterte Vertragsdaten Bauland nicht gefunden")); return; } FlurstueckComposite flurstueck = null; for (FlurstueckComposite fs : FlurstueckComposite.Mixin.forEntity(vertrag)) { NutzungComposite nutzung = fs.nutzung().get(); if (nutzung != null && (nutzung.isAgrar().get() == null || nutzung.isAgrar().get() == Boolean.FALSE)) { flurstueck = fs; break; } } if (flurstueck == null) { errors.add(error(vertrag, "Flurstck mit Nutzung Bauland nicht gefunden")); return; } RichtwertzoneComposite richtwertzone = vdc.richtwertZone().get(); if (richtwertzone == null) { errors.add(error(vertrag, "Richtwertzone nicht gefunden")); return; } GemeindeComposite gemeinde = richtwertzone.gemeinde().get(); if (gemeinde == null) { errors.add(error(vertrag, "Gemeinde nicht gefunden")); return; } VertragsdatenErweitertComposite vertragErweitert = vertrag.erweiterteVertragsdaten().get(); if (vertragErweitert == null) { errors.add(error(vertrag, "Erweiterte Vertragsdaten nicht gefunden")); return; } List<String> contents = new ArrayList<String>(); // data // bezirk contents.add("05"); // String melder = contents.add("22"); // String kennnummer = contents.add(String.format("%020d", vertrag.eingangsNr().get())); Calendar cal = new GregorianCalendar(); cal.setTime(vertrag.vertragsDatum().get()); // String tag = contents.add(String.format("%02d", cal.get(Calendar.DAY_OF_MONTH))); // String monat = contents.add(String.format("%02d", cal.get(Calendar.MONTH) + 1)); // String jahr = contents.add(String.format("%04d", cal.get(Calendar.YEAR))); if (vertragErweitert.bereinigterVollpreis().get() == null) { errors.add(error(vertrag, "Bereinigter Vollpreis nicht gefunden")); return; } // String kaufpreis = contents.add(String.format("%09d", vertragErweitert.bereinigterVollpreis().get().intValue())); Double v = vdc.verkaufteFlaecheGesamt().get(); if (v == null) { v = vdc.verkaufteFlaeche().get(); } if (v == null) { errors.add(error(vertrag, "Verkaufte Flche Gesamt nicht gefunden")); return; } // String flaeche = contents.add(String.format("%07d", v.intValue())); // String land = contents.add("14"); // String kreisGemeinde = contents.add(gemeinde.schl().get().substring(0, 3) + DELIMITER + gemeinde.schl().get().substring(3)); GrundstuecksArtBaulandStalaComposite artStala = flurstueck.nutzung().get().stala().get(); if (artStala == null) { errors.add(error(vertrag, "Art des Grundstcks nicht gefunden")); return; } // String artDesGrundstuecks = contents.add(artStala.schl().get()); ArtDesBaugebietsComposite artDesBaugebietsC = flurstueck.artDesBaugebiets().get(); if (artDesBaugebietsC == null) { errors.add(error(vertrag, "Art des Baugebiets nicht gefunden")); return; } // String artDesBaugebiets = contents.add(artDesBaugebietsC.schl().get()); KaeuferKreisComposite verkaeuferKreisComposite = vertrag.verkaeuferKreis().get(); if (verkaeuferKreisComposite == null) { errors.add(error(vertrag, "Verkufer nicht gefunden")); return; } if (verkaeuferKreisComposite.stala().get() == null) { errors.add(error(vertrag, "Verkufer - StaLa Zuordnung nicht gefunden")); return; } // String veruerer - 2 contents.add(verkaeuferKreisComposite.stala().get().schl().get()); KaeuferKreisComposite kaeuferKreisComposite = vertrag.kaeuferKreis().get(); if (kaeuferKreisComposite == null) { errors.add(error(vertrag, "Erwerber nicht gefunden")); return; } if (kaeuferKreisComposite.stala().get() == null) { errors.add(error(vertrag, "Erwerber - StaLa Zuordnung nicht gefunden")); return; } // String Erwerber - 2 contents.add(kaeuferKreisComposite.stala().get().schl().get()); VertragsArtComposite vertragsArtComposite = vertrag.vertragsArt().get(); if (vertragsArtComposite == null) { errors.add(error(vertrag, "Vertragsart nicht gefunden")); return; } if (vertragsArtComposite.stala().get() == null) { errors.add(error(vertrag, "Vertragsart - StaLa Verwandschaftsverhltnis Zuordnung nicht gefunden")); return; } // String Verwandschaftsverhltnis - 2 contents.add(vertragsArtComposite.stala().get().schl().get()); StringBuilder ret = new StringBuilder(); for (String s : contents) { ret.append(s).append(DELIMITER); } lines.add(ret.toString()); }
From source file:org.sonar.plugins.core.timemachine.NewViolationsDecorator.java
protected void notifyNewViolations(Project project, DecoratorContext context) { List<PastSnapshot> projectPastSnapshots = timeMachineConfiguration.getProjectPastSnapshots(); if (projectPastSnapshots.size() >= 1) { // we always check new violations against period1 PastSnapshot pastSnapshot = projectPastSnapshots.get(0); Double newViolationsCount = context.getMeasure(CoreMetrics.NEW_VIOLATIONS).getVariation1(); // Do not send notification if this is the first analysis or if there's no violation if (pastSnapshot.getTargetDate() != null && newViolationsCount != null && newViolationsCount > 0) { // Maybe we should check if this is the first analysis or not? DateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd"); Notification notification = new Notification("new-violations") .setDefaultMessage(/*from w w w.j a va 2 s .c o m*/ newViolationsCount.intValue() + " new violations on " + project.getLongName() + ".") .setFieldValue("count", String.valueOf(newViolationsCount.intValue())) .setFieldValue("projectName", project.getLongName()) .setFieldValue("projectKey", project.getKey()) .setFieldValue("projectId", String.valueOf(project.getId())) .setFieldValue("fromDate", dateformat.format(pastSnapshot.getTargetDate())); notificationManager.scheduleForSending(notification); } } }
From source file:org.polymap.wbv.ui.reports.Report106b.java
@Override public JasperReportBuilder build() throws DRException, JRException, IOException { List<String> arten = new ArrayList<String>(); arten.add("Privatwald"); arten.add("Kirchenwald"); arten.add("Krperschaftswald"); Map<String, Group> grouped = new HashMap<String, Group>(); for (String art : arten) { grouped.put(art, new Group()); }// w ww .ja v a 2s .c o m List<Double> flaechenGruppe = new ArrayList<Double>(); flaechenGruppe.add(1000d); flaechenGruppe.add(500d); flaechenGruppe.add(200d); flaechenGruppe.add(100d); flaechenGruppe.add(50d); flaechenGruppe.add(20d); flaechenGruppe.add(10d); flaechenGruppe.add(5d); flaechenGruppe.add(1d); flaechenGruppe.add(0d); for (Waldbesitzer wb : revierWaldbesitzer()) { for (Flurstueck flurstueck : wb.flurstuecke(revier.get())) { Group group = grouped.get(getArt(wb.eigentumsArt.get())); group.flurstuecke.add(flurstueck); List<Flurstueck> fs = null; if (flurstueck.flaecheWald.get() == null) { fs = getFlurstueckeForGroup(group.flaecheToFlurstuecke, -1d); // if (!fs.contains( flurstueck )) { fs.add(flurstueck); // } } else { for (int i = 1; i < flaechenGruppe.size(); i++) { if (flurstueck.flaecheWald.get() >= flaechenGruppe.get(i)) { fs = getFlurstueckeForGroup(group.flaecheToFlurstuecke, flaechenGruppe.get(i - 1)); fs.add(flurstueck); } } } } } Double sum; Set<Waldbesitzer> wbs; //Double durchschnittsFlaeche; for (Group group : grouped.values()) { for (Entry<Double, List<Flurstueck>> entry : group.flaecheToFlurstuecke.entrySet()) { sum = 0.0d; //durchschnittsFlaeche = 0.0d; wbs = new HashSet<Waldbesitzer>(); for (Flurstueck flurstueck : entry.getValue()) { sum += flurstueck.flaecheWald.get() != null ? flurstueck.flaecheWald.get() : 0; wbs.add(flurstueck.waldbesitzer()); } group.flaecheToGesamtFlaeche.put(entry.getKey(), sum); group.flaecheToWBS.put(entry.getKey(), wbs.size()); } } StringBuilder sb = new StringBuilder(); int index = -1; Double upperBound; Collections.reverse(flaechenGruppe); for (Double entry : flaechenGruppe) { index = flaechenGruppe.indexOf(entry); if (index + 1 < flaechenGruppe.size()) { upperBound = flaechenGruppe.get(index + 1); } else { upperBound = null; } if (upperBound != null && upperBound.intValue() >= 0) { sb.append(entry.intValue() + " bis " + upperBound.intValue()).append(" ha;"); } else { sb.append("ber " + entry.intValue() + " ha").append(";"); } Integer wbsCount; Double gesamtFlaeche; for (String art : arten) { wbsCount = grouped.get(art).flaecheToWBS.get(entry); sb.append(wbsCount == null ? 0 : wbsCount).append(";"); gesamtFlaeche = grouped.get(art).flaecheToGesamtFlaeche.get(entry); sb.append(gesamtFlaeche == null ? 0d : gesamtFlaeche).append(";"); } sb.append("\n"); } ByteArrayInputStream bis = new ByteArrayInputStream(sb.toString().getBytes()); NumberFormatter countFormatter = new NumberFormatter(1, 0, 10000, 0) { @Override public String format(Number value, ReportParameters params) { if (value.intValue() <= 0) { return ""; } else { return super.format(value, params); } } }; NumberFormatter haNumberFormatter = new NumberFormatter(1, 2, 10000, 2) { @Override public String format(Number value, ReportParameters params) { if (value.doubleValue() <= 0) { return ""; } else { return super.format(value, params) + " ha"; } } }; List<String> columns = new ArrayList<String>(); columns.add("flaechengruppe"); for (String art : arten) { columns.add(art + "_anzahl_waldbesitzer"); columns.add(art + "_gesamtflaeche"); } JRCsvDataSource datasource = new JRCsvDataSource(bis); datasource.setColumnNames(columns.toArray(new String[columns.size()])); datasource.setFieldDelimiter(';'); datasource.setUseFirstRowAsHeader(false); datasource.setNumberFormat(NumberFormat.getInstance(Locale.US)); // report TextColumnBuilder<String> flaechengruppeColumn = col .column("Flchengruppe", "flaechengruppe", type.stringType()) .setStyle(stl.style().setAlignment(HorizontalAlignment.CENTER, VerticalAlignment.MIDDLE) .setBorder(stl.pen().setLineWidth(0.5f))); Map<String, List<TextColumnBuilder<? extends Number>>> columnGroups = new HashMap<String, List<TextColumnBuilder<? extends Number>>>(); for (String art : arten) { List<TextColumnBuilder<? extends Number>> list = new ArrayList<TextColumnBuilder<? extends Number>>(); TextColumnBuilder<Integer> waldbesitzerAnzahlColumn = col .column("Anzahl", art + "_anzahl_waldbesitzer", type.integerType()) .setValueFormatter(countFormatter); TextColumnBuilder<Double> gesamtflaecheColumn = col .column("Hektar", art + "_gesamtflaeche", type.doubleType()) .setValueFormatter(haNumberFormatter); list.add(waldbesitzerAnzahlColumn); list.add(gesamtflaecheColumn); columnGroups.put(art, list); } List<ColumnGridComponentBuilder> titleGroups = new ArrayList<ColumnGridComponentBuilder>(); titleGroups.add(flaechengruppeColumn); for (String art : arten) { List<TextColumnBuilder<? extends Number>> columnGroup = columnGroups.get(art); titleGroups.add(grid.titleGroup(art, columnGroup.toArray(new TextColumnBuilder[columnGroup.size()]))); } ReportTemplateBuilder templateBuilder = template(); templateBuilder.setSubtotalLabelPosition(Position.BOTTOM); templateBuilder.setSummaryStyle(stl.style().setTopBorder(stl.pen1Point())); templateBuilder.setColumnStyle(stl.style().setBorder(stl.pen().setLineWidth(0.5f))); JasperReportBuilder report = report().setTemplate(templateBuilder).setDataSource(datasource) .setPageFormat(PageType.A4, PageOrientation.PORTRAIT) .title(cmp.text("Meldeliste Anzahl Waldbesitzer nach Grengruppen (Agrarbericht)") .setStyle(titleStyle), cmp.text("Basis: Waldflche der Waldbesitzer").setStyle(titleStyle), cmp.text("Forstbezirk: Mittelsachsen").setStyle(headerStyle), cmp.text("Revier: " + getRevier() /*+ " / Abfrage: \"" + getQuery() + "\""*/ ) .setStyle(headerStyle), cmp.text(df.format(new Date())).setStyle(headerStyle), cmp.text("").setStyle(headerStyle)) .pageFooter(cmp.pageXofY().setStyle(footerStyle)) // number of page .setDetailOddRowStyle(highlightRowStyle).setColumnTitleStyle(columnTitleStyle) .columnGrid(titleGroups.toArray(new ColumnGridComponentBuilder[titleGroups.size()])); report.addColumn(flaechengruppeColumn); List<TextColumnBuilder<? extends Number>> group; TextColumnBuilder<? extends Number> column; AggregationSubtotalBuilder<? extends Number> subtotal; for (String art : arten) { group = columnGroups.get(art); for (int i = 0; i < group.size(); i++) { column = group.get(i); report.addColumn(column); subtotal = sbt.sum(column); if (i > 0) { subtotal.setValueFormatter(haNumberFormatter); } else { subtotal.setValueFormatter(countFormatter); } report.addSubtotalAtSummary(subtotal); } } return report; }
From source file:org.openlmis.rnr.domain.RnrLineItem.java
private Integer applyRoundingRules(Integer orderQuantity) { Double packsToShip = floor(orderQuantity / packSize); Integer remainderQuantity = orderQuantity % packSize; if (remainderQuantity >= packRoundingThreshold) { packsToShip += 1;/*from w w w .j a v a 2 s .c o m*/ } if (packsToShip == 0 && !roundToZero) { packsToShip = 1d; } return packsToShip.intValue(); }
From source file:org.sonar.server.component.ws.ComponentAppAction.java
@CheckForNull private String formatMeasure(@Nullable MeasureDto measure) { if (measure != null) { Metric metric = CoreMetrics.getMetric(measure.getKey().metricKey()); Metric.ValueType metricType = metric.getType(); Double value = measure.getValue(); String data = measure.getData(); if (metricType.equals(Metric.ValueType.FLOAT) && value != null) { return i18n.formatDouble(UserSession.get().locale(), value); }//from w w w.ja v a 2 s . co m if (metricType.equals(Metric.ValueType.INT) && value != null) { return i18n.formatInteger(UserSession.get().locale(), value.intValue()); } if (metricType.equals(Metric.ValueType.PERCENT) && value != null) { return i18n.formatDouble(UserSession.get().locale(), value) + "%"; } if (metricType.equals(Metric.ValueType.WORK_DUR) && value != null) { return durations.format(UserSession.get().locale(), durations.create(value.longValue()), Durations.DurationFormat.SHORT); } if ((metricType.equals(Metric.ValueType.STRING) || metricType.equals(Metric.ValueType.RATING)) && data != null) { return data; } } return null; }
From source file:org.polymap.kaps.exporter.VertragStaLaAgrarExporter.java
private void export(List<String> lines, VertragComposite vertrag, List<String> errors) { VertragsdatenAgrarComposite vdc = VertragsdatenAgrarComposite.Mixin.forVertrag(vertrag); if (vdc == null) { errors.add(error(vertrag, "Erweiterte Vertragsdaten Agrar nicht gefunden")); return;/* w ww . java 2 s . co m*/ } FlurstueckComposite flurstueck = null; for (FlurstueckComposite fs : FlurstueckComposite.Mixin.forEntity(vertrag)) { NutzungComposite nutzung = fs.nutzung().get(); if (nutzung != null && nutzung.isAgrar().get() != null && nutzung.isAgrar().get() == Boolean.TRUE) { flurstueck = fs; break; } } if (flurstueck == null) { errors.add(error(vertrag, "Flurstck mit Nutzung Agrar nicht gefunden")); return; } GemarkungComposite gemarkung = flurstueck.gemarkung().get(); if (gemarkung == null) { errors.add(error(vertrag, "Gemarkung nicht gefunden")); return; } RichtwertzoneZeitraumComposite richtwertzoneZ = vdc.richtwertZone1().get(); if (richtwertzoneZ == null) { errors.add(error(vertrag, "Richtwertzone nicht gefunden")); return; } RichtwertzoneComposite richtwertzone = richtwertzoneZ.zone().get(); if (richtwertzone == null) { errors.add(error(vertrag, "Richtwertzone nicht gefunden")); return; } GemeindeComposite gemeinde = richtwertzone.gemeinde().get(); if (gemeinde == null) { errors.add(error(vertrag, "Gemeinde nicht gefunden")); return; } VertragsdatenErweitertComposite vertragErweitert = vertrag.erweiterteVertragsdaten().get(); if (vertragErweitert == null) { errors.add(error(vertrag, "Erweiterte Vertragsdaten fehlen")); return; } List<String> contents = new ArrayList<String>(); // data // String kennnummer = 18 contents.add(String.format("%018d", vertrag.eingangsNr().get())); // String land = contents.add("Mittelsachsen"); // String kreisGemeinde = contents.add(gemeinde.name().get()); contents.add(gemarkung.schl().get()); FlurComposite flur = flurstueck.flur().get(); // gibts in Sachsen nicht contents.add(flur == null ? "000" : flur.schl().get()); // flurstueck1 contents.add(String.format("%05d", flurstueck.hauptNummer().get())); // flurstueck2 contents.add( flurstueck.unterNummer().get() != null ? StringUtils.leftPad(flurstueck.unterNummer().get(), 5, "0") : ""); // Datum Calendar cal = new GregorianCalendar(); cal.setTime(vertrag.vertragsDatum().get()); // String tag = contents.add(String.format("%02d", cal.get(Calendar.DAY_OF_MONTH)) + String.format("%02d", cal.get(Calendar.MONTH) + 1) + String.format("%04d", cal.get(Calendar.YEAR))); KaeuferKreisComposite verkaeuferKreisComposite = vertrag.verkaeuferKreis().get(); if (verkaeuferKreisComposite == null) { errors.add(error(vertrag, "Verkufer nicht gefunden")); return; } if (verkaeuferKreisComposite.stalaAgrar().get() == null) { errors.add(error(vertrag, "Verkufer - StaLa Zuordnung nicht gefunden")); return; } // String veruerer - 2 contents.add(verkaeuferKreisComposite.stalaAgrar().get().schl().get()); KaeuferKreisComposite kaeuferKreisComposite = vertrag.kaeuferKreis().get(); if (kaeuferKreisComposite == null) { errors.add(error(vertrag, "Erwerber nicht gefunden")); return; } if (kaeuferKreisComposite.stalaAgrar().get() == null) { errors.add(error(vertrag, "Erwerber - StaLa Zuordnung nicht gefunden")); return; } // String Erwerber - 2 contents.add(kaeuferKreisComposite.stalaAgrar().get().schl().get()); ArtDesBaugebietsComposite artDesBaugebietsC = flurstueck.artDesBaugebiets().get(); if (artDesBaugebietsC == null) { errors.add(error(vertrag, "Art des Grundstcks nicht gefunden")); return; } // String artDesBaugebiets = contents.add(artDesBaugebietsC.schl().get()); // String flaeche = if (vdc.verkaufteFlaeche().get() == null) { errors.add(error(vertrag, "Verkaufte Flche gesamt nicht gefunden")); return; } contents.add(String.format("%08d", vdc.verkaufteFlaeche().get().intValue())); // String flaeche = Double flaecheLandwirtschaftStala = vdc.flaecheLandwirtschaftStala().get(); if (flaecheLandwirtschaftStala == null) { errors.add(error(vertrag, "Flche der landwirtschaftlichen Nutzung nicht gefunden, nutze 0")); } contents.add(String.format("%08d", flaecheLandwirtschaftStala != null ? flaecheLandwirtschaftStala.intValue() : 0)); if (vertragErweitert.bereinigterVollpreis().get() == null) { errors.add(error(vertrag, "Bereinigter Vollpreis nicht gefunden")); return; } // String geldwert = contents.add(String.format("%08d", vertragErweitert.bereinigterVollpreis().get().intValue())); // String hypotheken = Double h = vdc.hypothekStala().get(); // if (h == null) { // errors.add( error( vertrag, "Hypotheken nicht gefunden, nutze 0" ) ); // } contents.add(String.format("%08d", h != null ? h.intValue() : 0)); // String tauschgrundstck = h = vdc.wertTauschStala().get(); // if (h == null) { // errors.add( error( vertrag, "Wert des Tauschgrundstckes nicht gefunden, nutze 0" ) ); // } contents.add(String.format("%08d", h != null ? h.intValue() : 0)); // String sonstiges = h = vdc.wertSonstigesStala().get(); // if (h == null) { // errors.add( error( vertrag, "Wert sonstige Leistungen nicht gefunden, nutze 0" ) ); // } contents.add(String.format("%08d", h != null ? h.intValue() : 0)); String b = vdc.bemerkungStala().get(); if (b != null) { contents.add(b); } StringBuilder ret = new StringBuilder(); for (String s : contents) { ret.append(s).append(DELIMITER); } lines.add(ret.toString()); }