Search in sources :

Example 86 with Format

use of java.text.Format in project mzmine2 by mzmine.

the class ExactMzDataPoint method getName.

public String getName() {
    Format mzFormat = MZmineCore.getConfiguration().getMZFormat();
    Format intensityFormat = MZmineCore.getConfiguration().getIntensityFormat();
    String str = "m/z: " + mzFormat.format(mz) + ", intensity: " + intensityFormat.format(intensity);
    return str;
}
Also used : Format(java.text.Format)

Example 87 with Format

use of java.text.Format in project mzmine2 by mzmine.

the class ScanUtils method scanToString.

/**
 * Common utility method to be used as Scan.toString() method in various Scan implementations
 *
 * @param scan Scan to be converted to String
 * @return String representation of the scan
 */
@Nonnull
public static String scanToString(@Nonnull Scan scan, @Nonnull Boolean includeFileName) {
    StringBuffer buf = new StringBuffer();
    Format rtFormat = MZmineCore.getConfiguration().getRTFormat();
    Format mzFormat = MZmineCore.getConfiguration().getMZFormat();
    if (includeFileName)
        buf.append(scan.getDataFile().getName());
    buf.append("#");
    buf.append(scan.getScanNumber());
    buf.append(" @");
    buf.append(rtFormat.format(scan.getRetentionTime()));
    buf.append(" MS");
    buf.append(scan.getMSLevel());
    if (scan.getMSLevel() > 1)
        buf.append(" (" + mzFormat.format(scan.getPrecursorMZ()) + ")");
    switch(scan.getSpectrumType()) {
        case CENTROIDED:
            buf.append(" c");
            break;
        case PROFILE:
            buf.append(" p");
            break;
        case THRESHOLDED:
            buf.append(" t");
            break;
    }
    buf.append(" ");
    buf.append(scan.getPolarity().asSingleChar());
    return buf.toString();
}
Also used : Format(java.text.Format) Nonnull(javax.annotation.Nonnull)

Example 88 with Format

use of java.text.Format in project Spark by igniterealtime.

the class BroadcastHistoryFrame method initComponents.

private void initComponents() {
    SearchButton = new javax.swing.JToggleButton();
    DateField = new javax.swing.JFormattedTextField();
    SearchDate = new javax.swing.JLabel();
    Date date = new Date();
    Format formatter = new SimpleDateFormat("yyy-MM");
    String myDate = formatter.format(date);
    DateField.setValue(myDate);
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    JScrollPane panelPane = new JScrollPane(BroadcastHistoryArea);
    SearchDate.setText(Res.getString("label.broadcast.history.search.date"));
    setTitle(Res.getString("title.broadcast.history"));
    try {
        readFromFile(myDate);
    } catch (IOException ex) {
        Log.error("Couldn't read from file" + ex.getMessage() + Arrays.toString(ex.getStackTrace()));
    }
    SearchButton.setText((Res.getString("button.search")));
    SearchButton.addMouseListener(new java.awt.event.MouseAdapter() {

        @Override
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            SearchButtonMouseClicked(evt);
        }
    });
    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addComponent(panelPane, javax.swing.GroupLayout.DEFAULT_SIZE, 533, javax.swing.GroupLayout.DEFAULT_SIZE).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(SearchDate).addComponent(SearchButton).addComponent(DateField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)).addGap(22, 22, 22)));
    layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addGap(15, 15, 15).addComponent(panelPane, javax.swing.GroupLayout.DEFAULT_SIZE, 350, javax.swing.GroupLayout.DEFAULT_SIZE)).addGroup(layout.createSequentialGroup().addGap(15, 15, 15).addComponent(SearchDate).addGap(10, 10, 10).addComponent(DateField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addGap(10, 10, 10).addComponent(SearchButton))).addContainerGap(15, Short.MAX_VALUE)));
    pack();
    final Rectangle bounds = LayoutSettingsManager.getLayoutSettings().getBroadcastHistoryBounds();
    if (bounds == null || bounds.width <= 0 || bounds.height <= 0) {
        // Use default settings.
        setLocationRelativeTo(null);
    } else {
        setBounds(bounds);
    }
    addComponentListener(new ComponentAdapter() {

        @Override
        public void componentResized(ComponentEvent e) {
            LayoutSettingsManager.getLayoutSettings().setBroadcastHistoryBounds(getBounds());
        }

        @Override
        public void componentMoved(ComponentEvent e) {
            LayoutSettingsManager.getLayoutSettings().setBroadcastHistoryBounds(getBounds());
        }
    });
}
Also used : JScrollPane(javax.swing.JScrollPane) IOException(java.io.IOException) Date(java.util.Date) Format(java.text.Format) SimpleDateFormat(java.text.SimpleDateFormat) ComponentEvent(java.awt.event.ComponentEvent) SimpleDateFormat(java.text.SimpleDateFormat) ComponentAdapter(java.awt.event.ComponentAdapter)

Example 89 with Format

use of java.text.Format in project hadoop by apache.

the class HumanReadableHistoryViewerPrinter method printJobCounters.

private void printJobCounters(StringBuilder buff, Counters totalCounters, Counters mapCounters, Counters reduceCounters) {
    // Killed jobs might not have counters
    if (totalCounters != null) {
        buff.append("\nCounters: \n\n");
        buff.append(String.format("|%1$-30s|%2$-30s|%3$-10s|%4$-10s|%5$-10s|", "Group Name", "Counter name", "Map Value", "Reduce Value", "Total Value"));
        buff.append("\n------------------------------------------" + "---------------------------------------------");
        for (String groupName : totalCounters.getGroupNames()) {
            CounterGroup totalGroup = totalCounters.getGroup(groupName);
            CounterGroup mapGroup = mapCounters.getGroup(groupName);
            CounterGroup reduceGroup = reduceCounters.getGroup(groupName);
            Format decimal = new DecimalFormat();
            Iterator<Counter> ctrItr = totalGroup.iterator();
            while (ctrItr.hasNext()) {
                org.apache.hadoop.mapreduce.Counter counter = ctrItr.next();
                String name = counter.getName();
                String mapValue = decimal.format(mapGroup.findCounter(name).getValue());
                String reduceValue = decimal.format(reduceGroup.findCounter(name).getValue());
                String totalValue = decimal.format(counter.getValue());
                buff.append(String.format("%n|%1$-30s|%2$-30s|%3$-10s|%4$-10s|%5$-10s", totalGroup.getDisplayName(), counter.getDisplayName(), mapValue, reduceValue, totalValue));
            }
        }
    }
}
Also used : Format(java.text.Format) FastDateFormat(org.apache.commons.lang.time.FastDateFormat) DecimalFormat(java.text.DecimalFormat) Counter(org.apache.hadoop.mapreduce.Counter) CounterGroup(org.apache.hadoop.mapreduce.CounterGroup) DecimalFormat(java.text.DecimalFormat) Counter(org.apache.hadoop.mapreduce.Counter)

Example 90 with Format

use of java.text.Format in project sonarqube by SonarSource.

the class WriteTag method formatValue.

/**
     * Format value according to specified format string (as tag attribute or
     * as string from message resources) or to current user locale.
     *
     * When a format string is retrieved from the message resources,
     * <code>applyLocalizedPattern</code> is used. For more about localized
     * patterns, see
     * <http://www.dei.unipd.it/corsi/fi2ae-docs/source/jdk1.1.7/src/java/text/resources/>.
     * (To obtain the correct value for some characters, you may need to view
     * the file in a hex editor and then use the Unicode escape form in the
     * property resources file.)
     *
     * @param valueToFormat value to process and convert to String
     * @throws JspException if a JSP exception has occurred
     */
protected String formatValue(Object valueToFormat) throws JspException {
    Format format = null;
    Object value = valueToFormat;
    Locale locale = TagUtils.getInstance().getUserLocale(pageContext, this.localeKey);
    boolean formatStrFromResources = false;
    String formatString = formatStr;
    // Return String object as is.
    if (value instanceof java.lang.String) {
        return (String) value;
    } else {
        // formatKey.
        if ((formatString == null) && (formatKey != null)) {
            formatString = retrieveFormatString(this.formatKey);
            if (formatString != null) {
                formatStrFromResources = true;
            }
        }
        // Prepare format object for numeric values.
        if (value instanceof Number) {
            if (formatString == null) {
                if ((value instanceof Byte) || (value instanceof Short) || (value instanceof Integer) || (value instanceof Long) || (value instanceof BigInteger)) {
                    formatString = retrieveFormatString(INT_FORMAT_KEY);
                } else if ((value instanceof Float) || (value instanceof Double) || (value instanceof BigDecimal)) {
                    formatString = retrieveFormatString(FLOAT_FORMAT_KEY);
                }
                if (formatString != null) {
                    formatStrFromResources = true;
                }
            }
            if (formatString != null) {
                try {
                    format = NumberFormat.getNumberInstance(locale);
                    if (formatStrFromResources) {
                        ((DecimalFormat) format).applyLocalizedPattern(formatString);
                    } else {
                        ((DecimalFormat) format).applyPattern(formatString);
                    }
                } catch (IllegalArgumentException e) {
                    JspException ex = new JspException(messages.getMessage("write.format", formatString));
                    TagUtils.getInstance().saveException(pageContext, ex);
                    throw ex;
                }
            }
        } else if (value instanceof java.util.Date) {
            if (formatString == null) {
                if (value instanceof java.sql.Timestamp) {
                    formatString = retrieveFormatString(SQL_TIMESTAMP_FORMAT_KEY);
                } else if (value instanceof java.sql.Date) {
                    formatString = retrieveFormatString(SQL_DATE_FORMAT_KEY);
                } else if (value instanceof java.sql.Time) {
                    formatString = retrieveFormatString(SQL_TIME_FORMAT_KEY);
                } else if (value instanceof java.util.Date) {
                    formatString = retrieveFormatString(DATE_FORMAT_KEY);
                }
            }
            if (formatString != null) {
                format = new SimpleDateFormat(formatString, locale);
            }
        }
    }
    if (format != null) {
        return format.format(value);
    } else {
        return value.toString();
    }
}
Also used : Locale(java.util.Locale) DecimalFormat(java.text.DecimalFormat) JspException(javax.servlet.jsp.JspException) Format(java.text.Format) DecimalFormat(java.text.DecimalFormat) SimpleDateFormat(java.text.SimpleDateFormat) NumberFormat(java.text.NumberFormat) BigDecimal(java.math.BigDecimal) BigInteger(java.math.BigInteger) BigInteger(java.math.BigInteger) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

Format (java.text.Format)160 SimpleDateFormat (java.text.SimpleDateFormat)63 DecimalFormat (java.text.DecimalFormat)39 Test (org.junit.Test)38 DateFormat (java.text.DateFormat)34 Date (java.util.Date)32 NumberFormat (java.text.NumberFormat)29 DateTimeFormatter (java.time.format.DateTimeFormatter)27 ChoiceFormat (java.text.ChoiceFormat)24 ParsePosition (java.text.ParsePosition)22 MessageFormat (java.text.MessageFormat)20 FieldPosition (java.text.FieldPosition)16 Test (org.testng.annotations.Test)16 IOException (java.io.IOException)15 ParseException (java.text.ParseException)11 ArrayList (java.util.ArrayList)11 Locale (java.util.Locale)10 AttributedString (java.text.AttributedString)9 TemporalAccessor (java.time.temporal.TemporalAccessor)7 Calendar (java.util.Calendar)7