Example usage for java.text NumberFormat getInstance

List of usage examples for java.text NumberFormat getInstance

Introduction

In this page you can find the example usage for java.text NumberFormat getInstance.

Prototype

public static NumberFormat getInstance(Locale inLocale) 

Source Link

Document

Returns a general-purpose number format for the specified locale.

Usage

From source file:de.vanita5.twittnuker.util.Utils.java

public static String getLocalizedNumber(final Locale locale, final Number number) {
    final NumberFormat nf = NumberFormat.getInstance(locale);
    return nf.format(number);
}

From source file:ispyb.client.mx.results.ViewResultsAction.java

@SuppressWarnings("unchecked")
public void getAutoprocessingDetails(ActionMapping mapping, ActionForm actForm, HttpServletRequest request,
        HttpServletResponse response) {/*w  w w  .  j ava 2s .c o  m*/
    LOG.debug("getAutoprocessingDetails");
    try {
        String autoProcIdS = request.getParameter("autoProcId");
        AutoProcessingDetail autoProcDetail = new AutoProcessingDetail();
        try {
            DecimalFormat df1 = (DecimalFormat) NumberFormat.getInstance(Locale.US);
            df1.applyPattern("#####0.0");
            Integer autoProcId = Integer.parseInt(autoProcIdS);
            AutoProc3VO apv = apService.findByPk(autoProcId);
            autoProcDetail.setAutoProcId(autoProcId);

            AutoProcScalingStatistics3VO apssv_overall = apssService
                    .getBestAutoProcScalingStatistic(apssService.findByAutoProcId(autoProcId, "overall"));
            AutoProcScalingStatistics3VO apssv_outer = apssService
                    .getBestAutoProcScalingStatistic(apssService.findByAutoProcId(autoProcId, "outerShell"));

            if (apssv_overall != null) {
                autoProcDetail.setOverallCompleteness("" + apssv_overall.getCompleteness() + "%");
                autoProcDetail.setOverallResolution("" + apssv_overall.getResolutionLimitLow() + "-"
                        + apssv_overall.getResolutionLimitHigh() + " Å");
                autoProcDetail.setOverallIOverSigma("" + apssv_overall.getMeanIoverSigI());
                if (apssv_overall.getRmerge() == null)
                    autoProcDetail.setOverallRsymm("");
                else {
                    autoProcDetail.setOverallRsymm("" + apssv_overall.getRmerge() + "%");
                }
                autoProcDetail.setOverallMultiplicity("" + (apssv_overall.getMultiplicity() == null ? ""
                        : new Double(df1.format(apssv_overall.getMultiplicity()))));
            }

            if (apssv_outer != null) {
                autoProcDetail.setOuterCompleteness("" + apssv_outer.getCompleteness() + "%");
                autoProcDetail.setOuterResolution("" + apssv_outer.getResolutionLimitLow() + "-"
                        + apssv_overall.getResolutionLimitHigh() + " Å");
                autoProcDetail.setOuterIOverSigma("" + apssv_outer.getMeanIoverSigI());
                autoProcDetail.setOuterRsymm("" + apssv_outer.getRmerge() + "%");
                autoProcDetail.setOuterMultiplicity("" + (apssv_outer.getMultiplicity() == null ? ""
                        : (new Double(df1.format(apssv_outer.getMultiplicity())))));
            }

            double refinedCellA = ((double) ((int) (apv.getRefinedCellA() * 10))) / 10;
            double refinedCellB = ((double) ((int) (apv.getRefinedCellB() * 10))) / 10;
            double refinedCellC = ((double) ((int) (apv.getRefinedCellC() * 10))) / 10;

            autoProcDetail.setUnitCellA("" + refinedCellA + " Å"); // angstrom symbol
            autoProcDetail.setUnitCellB("" + refinedCellB + " Å");
            autoProcDetail.setUnitCellC("" + refinedCellC + " Å");

            autoProcDetail.setUnitCellAlpha("" + apv.getRefinedCellAlpha() + " °"); // degree symbol
            autoProcDetail.setUnitCellBeta("" + apv.getRefinedCellBeta() + " °");
            autoProcDetail.setUnitCellGamma("" + apv.getRefinedCellGamma() + " °");

            //
            List<AutoProcStatus3VO> autoProcEvents = new ArrayList<AutoProcStatus3VO>();
            if (autoProcId != null) {
                List<AutoProcIntegration3VO> autoProcIntegrations = autoProcIntegrationService
                        .findByAutoProcId(autoProcId);
                if (!autoProcIntegrations.isEmpty()) {
                    autoProcEvents = (autoProcIntegrations.iterator().next()).getAutoProcStatusList();
                }
            }
            autoProcDetail.setAutoProcEvents(autoProcEvents);

            // attachments
            List<IspybAutoProcAttachment3VO> listOfAutoProcAttachment = (List<IspybAutoProcAttachment3VO>) request
                    .getSession().getAttribute(Constants.ISPYB_AUTOPROC_ATTACH_LIST);
            Integer autoProcProgramId = null;
            if (apv != null)
                autoProcProgramId = apv.getAutoProcProgramVOId();

            if (autoProcId != null) {
                List<AutoProcIntegration3VO> autoProcIntegrations = autoProcIntegrationService
                        .findByAutoProcId(autoProcId);

                if (!autoProcIntegrations.isEmpty()) {
                    autoProcProgramId = (autoProcIntegrations.iterator().next()).getAutoProcProgramVOId();
                }
            }

            List<AutoProcProgramAttachment3VO> attachments = null;
            List<AutoProcAttachmentWebBean> autoProcProgAttachmentsWebBeans = new ArrayList<AutoProcAttachmentWebBean>();
            LOG.debug("autoProcProgramId = " + autoProcProgramId);

            if (autoProcProgramId != null) {
                attachments = new ArrayList<AutoProcProgramAttachment3VO>(
                        appService.findByPk(autoProcProgramId, true).getAttachmentVOs());

                if (!attachments.isEmpty()) {
                    // attachmentWebBeans = new AutoProcAttachmentWebBean[attachments.size()];

                    LOG.debug("nb attachments = " + attachments.size());
                    for (Iterator<AutoProcProgramAttachment3VO> iterator = attachments.iterator(); iterator
                            .hasNext();) {
                        AutoProcProgramAttachment3VO att = iterator.next();
                        AutoProcAttachmentWebBean attBean = new AutoProcAttachmentWebBean(att);
                        // gets the ispyb auto proc attachment file
                        IspybAutoProcAttachment3VO aAutoProcAttachment = getAutoProcAttachment(
                                attBean.getFileName(), listOfAutoProcAttachment);
                        if (aAutoProcAttachment == null) {
                            // by default in XDS tab and output files
                            aAutoProcAttachment = new IspybAutoProcAttachment3VO(null, attBean.getFileName(),
                                    "", "XDS", "output", false);
                        }
                        attBean.setIspybAutoProcAttachment(aAutoProcAttachment);
                        autoProcProgAttachmentsWebBeans.add(attBean);
                    }

                } else
                    LOG.debug("attachments is empty");

            }

            // Issue 1507: Correction files for ID29 & ID23-1
            if (Constants.SITE_IS_ESRF()) {
                Integer dataCollectionId = null;
                if (BreadCrumbsForm.getIt(request).getSelectedDataCollection() != null)
                    dataCollectionId = BreadCrumbsForm.getIt(request).getSelectedDataCollection()
                            .getDataCollectionId();
                if (dataCollectionId != null) {
                    DataCollection3VO dataCollection = dataCollectionService.findByPk(dataCollectionId, false,
                            false);
                    String beamLineName = dataCollection.getDataCollectionGroupVO().getSessionVO()
                            .getBeamlineName();
                    String[] correctionFiles = ESRFBeamlineEnum
                            .retrieveCorrectionFilesNameWithName(beamLineName);
                    if (correctionFiles != null) {
                        for (int k = 0; k < correctionFiles.length; k++) {
                            String correctionFileName = correctionFiles[k];
                            String dir = ESRFBeamlineEnum.retrieveDirectoryNameWithName(beamLineName);
                            if (dir != null) {
                                String correctionFilePath = "/data/pyarch/" + dir + "/" + correctionFileName;
                                String fullFilePath = PathUtils.FitPathToOS(correctionFilePath);
                                File f = new File(fullFilePath);
                                if (f != null && f.exists()) {
                                    // fake attachment
                                    AutoProcProgramAttachment3VO att = new AutoProcProgramAttachment3VO(-1,
                                            null, "Correction File", correctionFileName, correctionFilePath,
                                            null);
                                    AutoProcAttachmentWebBean attBean = new AutoProcAttachmentWebBean(att);
                                    IspybAutoProcAttachment3VO aAutoProcAttachment = new IspybAutoProcAttachment3VO(
                                            null, correctionFileName, "correction file", "XDS", "correction",
                                            false);
                                    attBean.setIspybAutoProcAttachment(aAutoProcAttachment);
                                    autoProcProgAttachmentsWebBeans.add(attBean);
                                    attachments.add(attBean);
                                }
                            }
                        } // end for
                    }
                }
            }
            autoProcDetail.setAutoProcProgAttachmentsWebBeans(autoProcProgAttachmentsWebBeans);
        } catch (NumberFormatException e) {

        }
        request.getSession().setAttribute("lastAutoProcIdSelected", autoProcDetail.getAutoProcId());
        //
        HashMap<String, Object> data = new HashMap<String, Object>();
        // context path
        data.put("contextPath", request.getContextPath());
        // autoProcDetail
        data.put("autoProcDetail", autoProcDetail);
        // data => Gson
        GSonUtils.sendToJs(response, data, "dd-MM-yyyy HH:mm:ss");
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:net.sf.jasperreports.chartthemes.simple.SimpleChartTheme.java

protected void setAxisTickLabels(Axis axis, JRFont tickLabelFont, Paint tickLabelColor, String tickLabelMask,
        AxisSettings axisSettings) {//from w w  w .  j  av a2  s . com
    boolean axisTickLabelsVisible = axisSettings.getTickLabelsVisible() == null
            || axisSettings.getTickLabelsVisible();//FIXMETHEME axis visibility should be dealt with above;

    axis.setTickLabelsVisible(axisTickLabelsVisible);

    if (axisTickLabelsVisible) {
        JRBaseFont font = new JRBaseFont();
        FontUtil.copyNonNullOwnProperties(axisSettings.getTickLabelFont(), font);
        FontUtil.copyNonNullOwnProperties(tickLabelFont, font);
        font = new JRBaseFont(getChart(), font);
        axis.setTickLabelFont(getFontUtil().getAwtFont(font, getLocale()));

        RectangleInsets tickLabelInsets = axisSettings.getTickLabelInsets();
        if (tickLabelInsets != null) {
            axis.setTickLabelInsets(tickLabelInsets);
        }

        Paint tickLabelPaint = tickLabelColor != null ? tickLabelColor
                : axisSettings.getTickLabelPaint() != null ? axisSettings.getTickLabelPaint().getPaint() : null;

        if (tickLabelPaint != null) {
            axis.setTickLabelPaint(tickLabelPaint);
        }

        TimeZone timeZone = getChartContext().getTimeZone();
        if (axis instanceof DateAxis && timeZone != null) {
            // used when no mask is set
            ((DateAxis) axis).setTimeZone(timeZone);
        }

        if (tickLabelMask != null) {
            if (axis instanceof NumberAxis) {
                NumberFormat fmt = NumberFormat.getInstance(getLocale());
                if (fmt instanceof DecimalFormat)
                    ((DecimalFormat) fmt).applyPattern(tickLabelMask);
                ((NumberAxis) axis).setNumberFormatOverride(fmt);
            } else if (axis instanceof DateAxis) {
                DateFormat fmt;
                if (tickLabelMask.equals("SHORT") || tickLabelMask.equals("DateFormat.SHORT"))
                    fmt = DateFormat.getDateInstance(DateFormat.SHORT, getLocale());
                else if (tickLabelMask.equals("MEDIUM") || tickLabelMask.equals("DateFormat.MEDIUM"))
                    fmt = DateFormat.getDateInstance(DateFormat.MEDIUM, getLocale());
                else if (tickLabelMask.equals("LONG") || tickLabelMask.equals("DateFormat.LONG"))
                    fmt = DateFormat.getDateInstance(DateFormat.LONG, getLocale());
                else if (tickLabelMask.equals("FULL") || tickLabelMask.equals("DateFormat.FULL"))
                    fmt = DateFormat.getDateInstance(DateFormat.FULL, getLocale());
                else
                    fmt = new SimpleDateFormat(tickLabelMask, getLocale());

                // FIXME fmt cannot be null
                if (fmt != null) {
                    if (timeZone != null) {
                        fmt.setTimeZone(timeZone);
                    }

                    ((DateAxis) axis).setDateFormatOverride(fmt);
                } else
                    ((DateAxis) axis).setDateFormatOverride(
                            DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, getLocale()));
            }
            // ignore mask for other axis types.
        }
    }
}

From source file:net.sf.jasperreports.chartthemes.spring.GenericChartTheme.java

protected void setAxisTickLabels(Axis axis, JRFont tickLabelFont, Paint tickLabelColor, String tickLabelMask,
        Integer baseFontSize) {//from   w  w  w  . jav  a  2  s . c o m
    Boolean defaultAxisTickLabelsVisible = (Boolean) getDefaultValue(defaultAxisPropertiesMap,
            ChartThemesConstants.AXIS_TICK_LABELS_VISIBLE);
    if (defaultAxisTickLabelsVisible != null && defaultAxisTickLabelsVisible) {
        Font themeTickLabelFont = getFont(
                (JRFont) getDefaultValue(defaultAxisPropertiesMap, ChartThemesConstants.AXIS_TICK_LABEL_FONT),
                tickLabelFont, baseFontSize);
        axis.setTickLabelFont(themeTickLabelFont);

        RectangleInsets defaultTickLabelInsets = (RectangleInsets) getDefaultValue(defaultAxisPropertiesMap,
                ChartThemesConstants.AXIS_TICK_LABEL_INSETS);
        if (defaultTickLabelInsets != null) {
            axis.setTickLabelInsets(defaultTickLabelInsets);
        }
        Paint tickLabelPaint = tickLabelColor != null ? tickLabelColor
                : (Paint) getDefaultValue(defaultAxisPropertiesMap, ChartThemesConstants.AXIS_TICK_LABEL_PAINT);
        if (tickLabelPaint != null) {
            axis.setTickLabelPaint(tickLabelPaint);
        }

        TimeZone timeZone = getChartContext().getTimeZone();
        if (axis instanceof DateAxis && timeZone != null) {
            // used when no mask is set
            ((DateAxis) axis).setTimeZone(timeZone);
        }

        if (tickLabelMask != null) {
            if (axis instanceof NumberAxis) {
                NumberFormat fmt = NumberFormat.getInstance(getLocale());
                if (fmt instanceof DecimalFormat)
                    ((DecimalFormat) fmt).applyPattern(tickLabelMask);
                ((NumberAxis) axis).setNumberFormatOverride(fmt);
            } else if (axis instanceof DateAxis) {
                DateFormat fmt;
                if (tickLabelMask.equals("SHORT") || tickLabelMask.equals("DateFormat.SHORT"))
                    fmt = DateFormat.getDateInstance(DateFormat.SHORT, getLocale());
                else if (tickLabelMask.equals("MEDIUM") || tickLabelMask.equals("DateFormat.MEDIUM"))
                    fmt = DateFormat.getDateInstance(DateFormat.MEDIUM, getLocale());
                else if (tickLabelMask.equals("LONG") || tickLabelMask.equals("DateFormat.LONG"))
                    fmt = DateFormat.getDateInstance(DateFormat.LONG, getLocale());
                else if (tickLabelMask.equals("FULL") || tickLabelMask.equals("DateFormat.FULL"))
                    fmt = DateFormat.getDateInstance(DateFormat.FULL, getLocale());
                else
                    fmt = new SimpleDateFormat(tickLabelMask, getLocale());

                // FIXME fmt cannot be null
                if (fmt != null) {
                    if (timeZone != null) {
                        fmt.setTimeZone(timeZone);
                    }

                    ((DateAxis) axis).setDateFormatOverride(fmt);
                } else
                    ((DateAxis) axis).setDateFormatOverride(
                            DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, getLocale()));
            }
            // ignore mask for other axis types.
        }
    }
}

From source file:it.prato.comune.sit.LayerTerritorio.java

/**
 * @param store//from   w  w w .  j a  va 2s  .com
 * @param query
 * @param tempdirpath
 * @return File
 * @throws SITException
 */
public File csvExport(DataStore store, Query query, String tempdirpath) throws SITException {

    File csvFile = null;
    try {
        SimpleFeatureSource featureSource = store.getFeatureSource(this.getTypeName());
        SimpleFeatureType ft = featureSource.getSchema();

        String fileName = ft.getTypeName();

        csvFile = new File(tempdirpath, fileName + ".csv");

        // //////////////////////////////////////////////////
        // Creazione del writer da usare per il CSV finale
        // //////////////////////////////////////////////////
        BufferedWriter w = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(csvFile, false)));

        SimpleFeatureCollection collection = featureSource.getFeatures(query);

        if (collection.getSchema() instanceof SimpleFeatureType) {
            // Scrittura dell'intestazione
            SimpleFeatureType featureType = (SimpleFeatureType) collection.getSchema();
            w.write("FID,");
            for (int i = 0; i < ft.getAttributeCount(); i++) {
                AttributeDescriptor ad = featureType.getDescriptor(i);
                w.write(prepCSVField(ad.getLocalName()));

                if (i < ft.getAttributeCount() - 1) {
                    w.write(",");
                }
            }
        } else {
            // Features complesse
            w.write("gml:id,");

            int i = 0;
            for (PropertyDescriptor att : collection.getSchema().getDescriptors()) {
                // Escludere attributi temporanei
                if (!att.getName().getLocalPart().startsWith("FEATURE_LINK")) {
                    if (i > 0) {
                        w.write(",");
                    }
                    String elName = att.getName().toString();
                    Object xsd = att.getUserData().get(XSDElementDeclaration.class);
                    if (xsd != null && xsd instanceof XSDElementDeclarationImpl) {
                        // ////////////////////////////////////////////////////////////////////////
                        // Ottenere il nome del prefisso, se possibile, altrimenti il default 
                        //  il nome completo dello spazio dei nomi con URI
                        // ////////////////////////////////////////////////////////////////////////
                        XSDElementDeclarationImpl xsdEl = (XSDElementDeclarationImpl) xsd;
                        elName = xsdEl.getQName();
                    }

                    w.write(prepCSVField(elName));
                    i++;
                }
            }
        }

        w.write("\r\n");

        //
        // Preparare il formatter per i campi numerici
        //
        NumberFormat coordFormatter = NumberFormat.getInstance(Locale.US);
        coordFormatter.setMaximumFractionDigits(3);
        coordFormatter.setGroupingUsed(false);

        //
        // Scrivere le features per compilare il file CSV finale
        // 
        FeatureIterator<?> i = collection.features();
        try {
            while (i.hasNext()) {
                Feature f = i.next();
                // Recupero del fid
                w.write(prepCSVField(f.getIdentifier().getID()));
                w.write(",");
                if (f instanceof SimpleFeature) {
                    // Resupero degli attributi
                    for (int j = 0; j < ((SimpleFeature) f).getAttributeCount(); j++) {
                        Object att = ((SimpleFeature) f).getAttribute(j);
                        if (att != null) {
                            String value = formatToString(att, coordFormatter);
                            w.write(prepCSVField(value));
                        }
                        if (j < ((SimpleFeature) f).getAttributeCount() - 1) {
                            w.write(",");
                        }
                    }
                } else {
                    // Features complesse
                    Iterator<PropertyDescriptor> descriptors = collection.getSchema().getDescriptors()
                            .iterator();

                    // Resupero degli attributi
                    int j = 0;
                    while (descriptors.hasNext()) {
                        PropertyDescriptor desc = descriptors.next();

                        if (desc.getName().getLocalPart().startsWith("FEATURE_LINK")) {
                            // Saltare attributi temporanei
                            continue;
                        }
                        if (j > 0) {
                            w.write(",");
                        }
                        j++;

                        // Propriet multivalore non sono supportate, solamente per SF0 per adesso
                        Collection<Property> values = f.getProperties(desc.getName());
                        if (values.size() > 1) {
                            throw new UnsupportedOperationException(
                                    "Propriet multivalore non sono supportate per il formato CSV!");
                        }

                        Object att = null;
                        if (!values.isEmpty()) {
                            att = values.iterator().next().getValue();
                        }

                        if (att != null) {
                            String value = formatToString(att, coordFormatter);
                            w.write(prepCSVField(value));
                        }
                    }
                }

                w.write("\r\n");
            }

        } finally {
            i.close();
        }

        w.flush();

    } catch (Exception e) {
        String errMsg = "Errore durante la ricerca del filtro";
        logger.error(errMsg, e);
        throw new SITException(errMsg, e);
    }

    filtroTotale.ResetFiltro();
    return csvFile;
}

From source file:ispyb.client.mx.results.ViewResultsAction.java

public void getResultData(ActionMapping mapping, ActionForm actForm, HttpServletRequest request,
        HttpServletResponse response) {//from  w  w w.  j av a  2 s . c  o  m
    LOG.debug("getResultData");
    List<String> errors = new ArrayList<String>();
    try {
        List<AutoProcessingInformation> autoProcList = new ArrayList<AutoProcessingInformation>();
        BreadCrumbsForm bar = BreadCrumbsForm.getIt(request);

        boolean displayOutputParam = false;
        boolean displayDenzoContent = false;

        // booleans to fix which tab will be selected by default
        boolean isEDNACharacterisation = false;
        boolean isAutoprocessing = false;

        String rMerge = (String) request.getSession().getAttribute(Constants.RSYMM);
        String iSigma = (String) request.getSession().getAttribute(Constants.ISIGMA);

        double rMerge_d = DEFAULT_RMERGE;
        double iSigma_d = DEFAULT_ISIGMA;

        int nbRemoved = 0;

        try {
            if (rMerge != null && !rMerge.equals("undefined") && !rMerge.equals(""))
                rMerge_d = Double.parseDouble(rMerge);
            if (iSigma != null && !iSigma.equals("undefined") && !iSigma.equals(""))
                iSigma_d = Double.parseDouble(iSigma);
        } catch (NumberFormatException nfe) {
            nfe.printStackTrace();
        }
        Integer dataCollectionId = null;
        List<List<AutoProcStatus3VO>> interruptedAutoProcEvents1 = new ArrayList<List<AutoProcStatus3VO>>();
        DataCollection3VO dc = null;
        // Just one of them could be visible on the bar
        if (bar.getSelectedDataCollection() != null) {
            dataCollectionId = bar.getSelectedDataCollection().getDataCollectionId();
        }
        if (dataCollectionId == null && request.getParameter(Constants.DATA_COLLECTION_ID) != null)
            dataCollectionId = new Integer(request.getParameter(Constants.DATA_COLLECTION_ID));
        if (dataCollectionId == null && request.getSession().getAttribute(Constants.DATA_COLLECTION_ID) != null)
            dataCollectionId = new Integer(
                    (Integer) request.getSession().getAttribute(Constants.DATA_COLLECTION_ID));

        if (dataCollectionId == null) {
            errors.add("dataCollectionId is null");
            HashMap<String, Object> data = new HashMap<String, Object>();
            data.put("errors", errors);
            // data => Gson
            GSonUtils.sendToJs(response, data, "dd-MM-yyyy HH:mm:ss");
            return;
        }
        dc = dataCollectionService.findByPk(dataCollectionId, false, true);

        // interrupted autoProc
        if (dc != null) {
            List<AutoProcIntegration3VO> autoProcIntegrationList = dc.getAutoProcIntegrationsList();
            if (autoProcIntegrationList != null) {
                for (Iterator<AutoProcIntegration3VO> au = autoProcIntegrationList.iterator(); au.hasNext();) {
                    AutoProcIntegration3VO autoProcIntegration = au.next();
                    if (autoProcIntegration.getAutoProcProgramVO() == null
                            && autoProcIntegration.getAutoProcStatusList() != null) {
                        List<AutoProcStatus3VO> events = autoProcIntegration.getAutoProcStatusList();
                        interruptedAutoProcEvents1.add(events);
                    }
                }
            }
        }

        for (int i = 0; i < 2; i++) {
            boolean anomalous = (i > 0);
            List<AutoProc3VO> autoProcsAnomalous = apService
                    .findByAnomalousDataCollectionIdAndOrderBySpaceGroupNumber(dataCollectionId, anomalous);
            if (autoProcsAnomalous != null) {
                nbRemoved = 0;
                LOG.debug("..nbAutoProc " + anomalous + " found before rMerge =" + autoProcsAnomalous.size());
                for (Iterator<AutoProc3VO> a = autoProcsAnomalous.iterator(); a.hasNext();) {
                    AutoProc3VO apv = a.next();

                    List<AutoProcScalingStatistics3VO> scalingStatistics = apssService
                            .findByAutoProcId(apv.getAutoProcId(), "innerShell");
                    boolean existsUnderRmergeAndOverSigma = false;

                    for (Iterator<AutoProcScalingStatistics3VO> j = scalingStatistics.iterator(); j
                            .hasNext();) {
                        AutoProcScalingStatistics3VO stats = j.next();
                        if (stats.getRmerge() != null && stats.getRmerge() < rMerge_d
                                && stats.getMeanIoverSigI() > iSigma_d)
                            existsUnderRmergeAndOverSigma = true;
                    }

                    if (!existsUnderRmergeAndOverSigma) {
                        a.remove();
                        nbRemoved = nbRemoved + 1;
                    }
                }
                LOG.debug("..nbAutoProc " + anomalous + " found=" + autoProcsAnomalous.size());
                for (Iterator<AutoProc3VO> iterator = autoProcsAnomalous.iterator(); iterator.hasNext();) {
                    AutoProc3VO o = iterator.next();
                    String cmdLine = "";
                    if (o.getAutoProcProgramVO() != null
                            && o.getAutoProcProgramVO().getProcessingPrograms() != null) {
                        cmdLine = o.getAutoProcProgramVO().getProcessingPrograms();
                    }
                    float refinedCellA = ((float) ((int) (o.getRefinedCellA() * 10))) / 10; // round to 1 dp
                    float refinedCellB = ((float) ((int) (o.getRefinedCellB() * 10))) / 10; // round to 1 dp
                    float refinedCellC = ((float) ((int) (o.getRefinedCellC() * 10))) / 10; // round to 1 dp
                    float refinedCellAlpha = ((float) ((int) (o.getRefinedCellAlpha() * 10))) / 10; // round to 1 dp
                    float refinedCellBeta = ((float) ((int) (o.getRefinedCellBeta() * 10))) / 10; // round to 1 dp
                    float refinedCellGamma = ((float) ((int) (o.getRefinedCellGamma() * 10))) / 10; // round to 1 dp

                    String anoTxt = "OFF (Friedel pairs merged)"; // false
                    if (anomalous) {
                        anoTxt = "ON (Friedel pairs unmerged)"; // true
                    }
                    // String anomalousS = anomalous+"= "+anoTxt;
                    AutoProcessingInformation info = new AutoProcessingInformation(o.getAutoProcId(), cmdLine,
                            o.getSpaceGroup(), anoTxt, refinedCellA, refinedCellB, refinedCellC,
                            refinedCellAlpha, refinedCellBeta, refinedCellGamma);
                    autoProcList.add(info);
                }
            }

        }
        Integer autoProcIdSelected = (Integer) request.getSession().getAttribute("lastAutoProcIdSelected");
        // check if autoProcIdSelected is in the list
        boolean idExists = false;
        if (autoProcIdSelected != null) {
            for (Iterator<AutoProcessingInformation> iterator = autoProcList.iterator(); iterator.hasNext();) {
                AutoProcessingInformation info = iterator.next();
                if (info.getAutoProcId().equals(autoProcIdSelected)) {
                    idExists = true;
                    break;
                }
            }
        }
        if (!idExists) {
            autoProcIdSelected = null;
        }

        List<DataCollection3VO> listLastCollectVO = new ArrayList<DataCollection3VO>();
        if (dc != null)
            listLastCollectVO.add(dc);
        AutoProcShellWrapper wrapper = ViewDataCollectionAction.getAutoProcStatistics(listLastCollectVO,
                rMerge_d, iSigma_d);
        int dcIndex = 0;
        // is autoproc ?
        List<AutoProc3VO> autoProcs = apService.findByDataCollectionId(dataCollectionId);
        if (autoProcs != null && autoProcs.size() > 0)
            isAutoprocessing = true;

        String beamLineName = "";
        String proposal = "";
        String proteinAcronym = "";
        String pdbFileName = "";
        String experimentType = "";
        if (dc != null) {
            beamLineName = dc.getDataCollectionGroupVO().getSessionVO().getBeamlineName();
            proposal = dc.getDataCollectionGroupVO().getSessionVO().getProposalVO().getCode()
                    + dc.getDataCollectionGroupVO().getSessionVO().getProposalVO().getNumber();

            BLSample3VO sample = dc.getDataCollectionGroupVO().getBlSampleVO();
            if (sample != null && sample.getCrystalVO() != null && sample.getCrystalVO().getProteinVO() != null)
                proteinAcronym = sample.getCrystalVO().getProteinVO().getAcronym();

            if (sample != null && sample.getCrystalVO() != null && sample.getCrystalVO().hasPdbFile()) {
                pdbFileName = sample.getCrystalVO().getPdbFileName();
            }
            experimentType = dc.getDataCollectionGroupVO().getExperimentType();
        }

        AutoProc3VO autoProc = null;
        AutoProcScalingStatistics3VO autoProcStatisticsOverall = null;
        AutoProcScalingStatistics3VO autoProcStatisticsInner = null;
        AutoProcScalingStatistics3VO autoProcStatisticsOuter = null;
        ScreeningOutputLattice3VO lattice = null;
        ScreeningOutput3VO screeningOutput = null;

        String snapshotFullPath = "";
        boolean hasSnapshot = false;
        Screening3VO[] tabScreening = null;
        if (dc != null) {
            snapshotFullPath = dc.getXtalSnapshotFullPath1();
            snapshotFullPath = PathUtils.FitPathToOS(snapshotFullPath);

            if (snapshotFullPath != null)
                hasSnapshot = (new File(snapshotFullPath)).exists();

            autoProc = wrapper.getAutoProcs()[dcIndex];
            autoProcStatisticsOverall = wrapper.getScalingStatsOverall()[dcIndex];
            autoProcStatisticsInner = wrapper.getScalingStatsInner()[dcIndex];
            autoProcStatisticsOuter = wrapper.getScalingStatsOuter()[dcIndex];
            DataCollectionGroup3VO dcGroup = dataCollectionGroupService
                    .findByPk(dc.getDataCollectionGroupVOId(), false, true);
            tabScreening = dcGroup.getScreeningsTab();
        }

        if (tabScreening != null && tabScreening.length > 0) {
            displayOutputParam = true;// there is at least 1 screening so we display the output params
            Screening3VO screeningVO = tabScreening[0];
            ScreeningOutput3VO[] screeningOutputTab = screeningVO.getScreeningOutputsTab();
            if (screeningOutputTab != null && screeningOutputTab.length > 0) {
                if (screeningOutputTab[0].getScreeningOutputLatticesTab() != null
                        && screeningOutputTab[0].getScreeningOutputLatticesTab().length > 0) {
                    lattice = screeningOutputTab[0].getScreeningOutputLatticesTab()[0];
                }
                screeningOutput = screeningOutputTab[0];
            }
        }

        String autoprocessingStatus = "";
        String autoprocessingStep = "";
        if (wrapper != null && wrapper.getAutoProcs() != null && wrapper.getAutoProcs().length > dcIndex) {
            AutoProcIntegration3VO autoProcIntegration = wrapper.getAutoProcIntegrations()[dcIndex];
            if (autoProcIntegration != null) {
                List<AutoProcStatus3VO> autoProcEvents = autoProcIntegration.getAutoProcStatusList();
                if (autoProcEvents != null && autoProcEvents.size() > 0) {
                    AutoProcStatus3VO st = autoProcEvents.get(autoProcEvents.size() - 1);
                    autoprocessingStatus = st.getStatus();
                    autoprocessingStep = st.getStep();
                }
            }
        }

        boolean hasAutoProcAttachment = false;
        if (wrapper != null && wrapper.getAutoProcs() != null) {

            for (int a = 0; a < autoProcs.size(); a++) {
                Integer autoProcProgramId = autoProcs.get(a).getAutoProcProgramVOId();
                if (autoProcProgramId != null) {
                    List<AutoProcProgramAttachment3VO> attachments = appService
                            .findByPk(autoProcProgramId, true).getAttachmentListVOs();
                    if (attachments != null && attachments.size() > 0) {
                        hasAutoProcAttachment = true;
                        break;
                    }
                }
            }
        }

        DataCollectionBean dataCollection = null;
        if (dc != null) {
            dataCollection = new DataCollectionBean(dc, beamLineName, proposal, proteinAcronym, pdbFileName,
                    experimentType, hasSnapshot, autoProc, autoProcStatisticsOverall, autoProcStatisticsInner,
                    autoProcStatisticsOuter, screeningOutput, lattice, autoprocessingStatus, autoprocessingStep,
                    hasAutoProcAttachment);
        }

        BeamLineSetup3VO beamline = null;
        Session3VO session = null;
        Detector3VO detector = null;

        String fullDenzoPath = null;
        boolean DenzonContentPresent = false;

        if (dc != null) {
            // beamline setup
            beamline = dc.getDataCollectionGroupVO().getSessionVO().getBeamLineSetupVO();
            // Session
            session = dc.getDataCollectionGroupVO().getSessionVO();
            // Detector
            detector = dc.getDetectorVO();

            // energy
            DecimalFormat df3 = (DecimalFormat) NumberFormat.getInstance(Locale.US);
            df3.applyPattern("#####0.000");
            Double energy = null;
            if (dc.getWavelength() != null && dc.getWavelength().compareTo(new Double(0)) != 0)
                energy = Constants.WAVELENGTH_TO_ENERGY_CONSTANT / dc.getWavelength();
            if (energy != null)
                dataCollection.setEnergy(new Double(df3.format(energy)));
            else
                dataCollection.setEnergy(null);
            // axis start label
            String axisStartLabel = dc.getRotationAxis() == null ? "" : dc.getRotationAxis() + " start";
            dataCollection.setAxisStartLabel(axisStartLabel);
            // totalExposureTime
            if (dc.getExposureTime() != null && dc.getNumberOfImages() != null) {
                dataCollection.setTotalExposureTime(
                        new Double(df3.format(dataCollection.getExposureTime() * dc.getNumberOfImages())));
            }
            // kappa
            Double kappa = dc.getKappaStart();
            String kappaStr = "";
            if (kappa == null || kappa.equals(Constants.SILLY_NUMBER))
                kappaStr = new String("0");
            else
                kappaStr = new String(kappa.toString());
            dataCollection.setKappa(kappaStr);
            // phi
            Double phi = dc.getPhiStart();
            String phiStr = "";
            if (phi == null || phi.equals(Constants.SILLY_NUMBER))
                phiStr = new String("0");
            else
                phiStr = new String(phi.toString());
            dataCollection.setPhi(phiStr);
            // undulatorGaps
            DecimalFormat df2 = (DecimalFormat) NumberFormat.getInstance(Locale.US);
            // DecimalFormat df2 = new DecimalFormat("##0.##");
            df2.applyPattern("##0.##");
            StringBuffer buf = new StringBuffer();
            // if no type then there is no meaningful value
            // if no undulator 1 then no 2 and no 3
            if (beamline.getUndulatorType1() != null && beamline.getUndulatorType1().length() > 0) {
                if (dc.getUndulatorGap1() != null && !dc.getUndulatorGap1().equals(Constants.SILLY_NUMBER)) {
                    Double gap1 = new Double(df2.format(dc.getUndulatorGap1()));
                    buf.append(gap1.toString()).append(" mm ");
                }
                if (beamline.getUndulatorType2() != null && beamline.getUndulatorType2().length() > 0) {
                    if (dc.getUndulatorGap2() != null
                            && !dc.getUndulatorGap2().equals(Constants.SILLY_NUMBER)) {
                        Double gap2 = new Double(df2.format(dc.getUndulatorGap2()));
                        buf.append(gap2.toString()).append(" mm ");
                    }
                    if (beamline.getUndulatorType3() != null && beamline.getUndulatorType3().length() > 0) {
                        if (dc.getUndulatorGap3() != null
                                && !dc.getUndulatorGap3().equals(Constants.SILLY_NUMBER)) {
                            Double gap3 = new Double(df2.format(dc.getUndulatorGap3()));
                            buf.append(gap3.toString()).append(" mm ");
                        }
                    }
                }
            }
            String undulatorGaps = buf.toString();
            dataCollection.setUndulatorGaps(undulatorGaps);

            DecimalFormat nf1 = (DecimalFormat) NumberFormat.getInstance(Locale.UK);
            nf1.applyPattern("#");
            DecimalFormat df5 = (DecimalFormat) NumberFormat.getInstance(Locale.US);
            df5.applyPattern("#####0.00000");

            // slitGapHorizontalMicro
            Integer slitGapHorizontalMicro = null;
            if (dc.getSlitGapHorizontal() != null) {
                // in DB beamsize unit is mm, display is in micrometer => conversion
                slitGapHorizontalMicro = new Integer(
                        nf1.format(dc.getSlitGapHorizontal().doubleValue() * 1000));
            }
            dataCollection.setSlitGapHorizontalMicro(slitGapHorizontalMicro);
            // slitGapVerticalMicro
            Integer slitGapVerticalMicro = null;
            if (dc.getSlitGapVertical() != null) {
                // in DB beamsize unit is mm, display is in micrometer => conversion
                slitGapVerticalMicro = new Integer(nf1.format(dc.getSlitGapVertical().doubleValue() * 1000));
            }
            dataCollection.setSlitGapVerticalMicro(slitGapVerticalMicro);
            // detectorPixelSizeHorizontalMicro
            Double detectorPixelSizeHorizontalMicro = null;
            if (detector != null && detector.getDetectorPixelSizeHorizontal() != null) {
                // in DB pixel size unit is mm,
                detectorPixelSizeHorizontalMicro = new Double(
                        df5.format(detector.getDetectorPixelSizeHorizontal()));
            }
            dataCollection.setDetectorPixelSizeHorizontalMicro(detectorPixelSizeHorizontalMicro);
            // detectorPixelSizeHorizontalMicro
            Double detectorPixelSizeVerticalMicro = null;
            if (detector != null && detector.getDetectorPixelSizeVertical() != null) {
                // in DB pixel size unit is mm,
                detectorPixelSizeVerticalMicro = new Double(
                        df5.format(detector.getDetectorPixelSizeVertical()));
            }
            dataCollection.setDetectorPixelSizeVerticalMicro(detectorPixelSizeVerticalMicro);
            // beamSizeAtSampleXMicro
            Integer beamSizeAtSampleXMicro = null;
            if (dc.getBeamSizeAtSampleX() != null) {
                // in DB beamsize unit is mm, display is in micrometer => conversion
                beamSizeAtSampleXMicro = new Integer(
                        nf1.format(dc.getBeamSizeAtSampleX().doubleValue() * 1000));
            }
            dataCollection.setBeamSizeAtSampleXMicro(beamSizeAtSampleXMicro);
            // beamSizeAtSampleYMicro
            Integer beamSizeAtSampleYMicro = null;
            if (dc.getBeamSizeAtSampleY() != null) {
                // in DB beamsize unit is mm, display is in micrometer => conversion
                beamSizeAtSampleYMicro = new Integer(
                        nf1.format(dc.getBeamSizeAtSampleY().doubleValue() * 1000));
            }
            dataCollection.setBeamSizeAtSampleYMicro(beamSizeAtSampleYMicro);
            // beamDivergenceHorizontalInt
            Integer beamDivergenceHorizontalInt = null;
            if (beamline.getBeamDivergenceHorizontal() != null) {
                beamDivergenceHorizontalInt = new Integer(nf1.format(beamline.getBeamDivergenceHorizontal()));
            }
            dataCollection.setBeamDivergenceHorizontalInt(beamDivergenceHorizontalInt);
            // beamDivergenceVerticalInt
            Integer beamDivergenceVerticalInt = null;
            if (beamline.getBeamDivergenceVertical() != null) {
                beamDivergenceVerticalInt = new Integer(nf1.format(beamline.getBeamDivergenceVertical()));
            }
            dataCollection.setBeamDivergenceVerticalInt(beamDivergenceVerticalInt);
            // DNA or EDNA Content present ?
            String fullDNAPath = PathUtils.getFullDNAPath(dc);
            String fullEDNAPath = PathUtils.getFullEDNAPath(dc);
            boolean EDNAContentPresent = (new File(fullEDNAPath + EDNA_FILES_INDEX_FILE)).exists()
                    || (new File(fullDNAPath + Constants.DNA_FILES_INDEX_FILE)).exists();
            isEDNACharacterisation = EDNAContentPresent;

            // Denzo Content present ?

            if (Constants.DENZO_ENABLED) {
                fullDenzoPath = FileUtil.GetFullDenzoPath(dc);
                DenzonContentPresent = (new File(fullDenzoPath)).exists();
                displayDenzoContent = DisplayDenzoContent(dc);

                if (DenzonContentPresent) // Check html file present
                {
                    File denzoIndex = new File(fullDenzoPath + DENZO_HTML_INDEX);
                    if (!denzoIndex.exists()) {
                        errors.add("Denzo File does not exist " + denzoIndex);
                        DenzonContentPresent = false;
                    }
                }
            }
        }

        //
        HashMap<String, Object> data = new HashMap<String, Object>();
        // context path
        data.put("contextPath", request.getContextPath());
        // autoProcList
        data.put("autoProcList", autoProcList);
        // autoProcIdSelected
        data.put("autoProcIdSelected", autoProcIdSelected);
        // rMerge & iSigma
        data.put("rMerge", rMerge);
        data.put("iSigma", iSigma);
        data.put("nbRemoved", nbRemoved);
        data.put("dataCollectionId", dataCollectionId);
        data.put("dataCollection", dataCollection);
        // beamlinesetup
        data.put("beamline", beamline);
        // session
        data.put("session", session);
        // detector
        data.put("detector", detector);
        // interrupted autoProc
        data.put("interruptedAutoProcEvents", interruptedAutoProcEvents1);
        // displayOutputParam
        data.put("displayOutputParam", displayOutputParam);
        // isEDNACharacterisation
        data.put("isEDNACharacterisation", isEDNACharacterisation);
        // isAutoprocessing
        data.put("isAutoprocessing", isAutoprocessing);
        // displayDenzoContent
        data.put("displayDenzoContent", displayDenzoContent);
        // DenzonContentPresent
        data.put("DenzonContentPresent", DenzonContentPresent);
        // fullDenzoPath
        data.put("fullDenzoPath", fullDenzoPath);
        // data => Gson
        GSonUtils.sendToJs(response, data, "dd-MM-yyyy HH:mm:ss");
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:net.sf.jasperreports.engine.util.JRApiWriter.java

/**
 *
 *///  w w w  .j a v  a2 s .  c  om
protected void write(String pattern, Float value, Float defaultValue) {
    if (value != null && value != defaultValue) {
        String strFloat = MessageFormat.format("{0}f",
                new Object[] { NumberFormat.getInstance(Locale.ENGLISH).format(value).replaceAll(",", "") });
        write(MessageFormat.format(pattern, new Object[] { strFloat }));
    }
}

From source file:net.sf.jasperreports.engine.util.JRApiWriter.java

/**
 *
 *//*from www.  j  ava 2  s. c  o  m*/
protected void write(String pattern, Double value, Double defaultValue) {
    if (value != null && value != defaultValue) {
        String strDouble = MessageFormat.format("{0}d",
                new Object[] { NumberFormat.getInstance(Locale.ENGLISH).format(value).replaceAll(",", "") });
        write(MessageFormat.format(pattern, new Object[] { strDouble }));
    }
}