Example usage for java.text NumberFormat setMinimumIntegerDigits

List of usage examples for java.text NumberFormat setMinimumIntegerDigits

Introduction

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

Prototype

public void setMinimumIntegerDigits(int newValue) 

Source Link

Document

Sets the minimum number of digits allowed in the integer portion of a number.

Usage

From source file:org.apache.hadoop.hive.ql.udf.UDFNumberFormat.java

public String evaluate(DoubleWritable d, IntWritable fracMax, IntWritable fracMin, IntWritable intMax,
        IntWritable intMin) {//from w ww.  j  av a2  s  .  com
    if (d == null || fracMax == null || intMax == null) {
        return null;
    }
    if (fracMin == null || intMin == null) {
        return null;
    }
    double ori = d.get();
    try {
        NumberFormat nFormat = NumberFormat.getNumberInstance();
        nFormat.setMaximumFractionDigits(fracMax.get());
        nFormat.setMaximumIntegerDigits(intMax.get());
        nFormat.setMinimumFractionDigits(fracMin.get());
        nFormat.setMinimumIntegerDigits(intMin.get());
        nFormat.setGroupingUsed(false);
        return nFormat.format(ori);
    } catch (Exception e) {
        LOG.error("can not format value:  " + ori);
        return null;
    }
}

From source file:org.apache.hadoop.hive.ql.udf.UDFNumberFormat.java

public String evaluate(LongWritable d, IntWritable fracMax, IntWritable fracMin, IntWritable intMax,
        IntWritable intMin) {//from  w  w w . j a v  a 2  s  .c o  m
    if (d == null || fracMax == null || intMax == null) {
        return null;
    }
    if (fracMin == null || intMin == null) {
        return null;
    }
    long ori = d.get();
    try {
        NumberFormat nFormat = NumberFormat.getNumberInstance();
        nFormat.setMaximumFractionDigits(fracMax.get());
        nFormat.setMaximumIntegerDigits(intMax.get());
        nFormat.setMinimumFractionDigits(fracMin.get());
        nFormat.setMinimumIntegerDigits(intMin.get());
        nFormat.setGroupingUsed(false);
        return nFormat.format(ori);
    } catch (Exception e) {
        LOG.error("can not format value:  " + ori);
        return null;
    }
}

From source file:no.abmu.abmstatistikk.annualstatistic.service.FolkeBibValidator.java

public void validate(Object obj, Errors errors) {
    NumberFormat fieldNameFormater = NumberFormat.getNumberInstance();
    fieldNameFormater.setMinimumIntegerDigits(3);
    Set fieldKeys = new HashSet();
    int i;//from   w w  w.  j  a  va  2  s.c  o  m

    setSchemaName("folkeBibSchema");

    switch (pageNumber) {
    case 1:
        break;
    case 2:
        for (i = 13; i <= 14; i++) {
            fieldKeys.add(fieldNameFormater.format((long) i));
        }
        for (i = 16; i <= 17; i++) {
            fieldKeys.add(fieldNameFormater.format((long) i));
        }
        for (i = 19; i <= 20; i++) {
            fieldKeys.add(fieldNameFormater.format((long) i));
        }
        for (i = 22; i <= 23; i++) {
            fieldKeys.add(fieldNameFormater.format((long) i));
        }
        for (i = 31; i <= 32; i++) {
            fieldKeys.add(fieldNameFormater.format((long) i));
        }
        for (i = 34; i <= 35; i++) {
            fieldKeys.add(fieldNameFormater.format((long) i));
        }
        for (i = 37; i <= 38; i++) {
            fieldKeys.add(fieldNameFormater.format((long) i));
        }
        for (i = 40; i <= 41; i++) {
            fieldKeys.add(fieldNameFormater.format((long) i));
        }
        for (i = 46; i <= 47; i++) {
            fieldKeys.add(fieldNameFormater.format((long) i));
        }
        for (i = 49; i <= 50; i++) {
            fieldKeys.add(fieldNameFormater.format((long) i));
        }
        for (i = 58; i <= 59; i++) {
            fieldKeys.add(fieldNameFormater.format((long) i));
        }
        for (i = 385; i <= 387; i++) {
            fieldKeys.add(fieldNameFormater.format((long) i));
        }
        for (i = 410; i <= 430; i++) {
            fieldKeys.add(fieldNameFormater.format((long) i));
        }
        break;
    case 3:
        fieldKeys.add(fieldNameFormater.format((long) 82));

        for (i = 84; i <= 86; i++) {
            fieldKeys.add(fieldNameFormater.format((long) i));
        }
        fieldKeys.add(fieldNameFormater.format((long) 90));

        for (i = 97; i <= 101; i++) {
            fieldKeys.add(fieldNameFormater.format((long) i));
        }
        fieldKeys.add(fieldNameFormater.format((long) 257));
        for (i = 389; i <= 390; i++) {
            fieldKeys.add(fieldNameFormater.format((long) i));
        }
        for (i = 431; i <= 484; i++) {
            fieldKeys.add(fieldNameFormater.format((long) i));
        }

        break;
    case 4:
        fieldKeys.add(fieldNameFormater.format((long) 137));
        fieldKeys.add(fieldNameFormater.format((long) 143));
        for (i = 146; i <= 147; i++) {
            fieldKeys.add(fieldNameFormater.format((long) i));
        }
        fieldKeys.add(fieldNameFormater.format((long) 150));
        fieldKeys.add(fieldNameFormater.format((long) 186));
        for (i = 188; i <= 191; i++) {
            fieldKeys.add(fieldNameFormater.format((long) i));
        }
        for (i = 193; i <= 201; i++) {
            fieldKeys.add(fieldNameFormater.format((long) i));
        }
        for (i = 391; i <= 398; i++) {
            fieldKeys.add(fieldNameFormater.format((long) i));
        }
        break;
    case 5:
        for (i = 205; i <= 210; i++) {
            fieldKeys.add(fieldNameFormater.format((long) i));
        }
        for (i = 215; i <= 216; i++) {
            fieldKeys.add(fieldNameFormater.format((long) i));
        }
        for (i = 223; i <= 225; i++) {
            fieldKeys.add(fieldNameFormater.format((long) i));
        }
        for (i = 230; i <= 242; i++) {
            fieldKeys.add(fieldNameFormater.format((long) i));
        }
        fieldKeys.add(fieldNameFormater.format((long) 244));
        for (i = 399; i <= 402; i++) {
            fieldKeys.add(fieldNameFormater.format((long) i));
        }

        break;
    case 6:
        for (i = 259; i <= 266; i++) {
            fieldKeys.add(fieldNameFormater.format((long) i));
        }
        for (i = 381; i <= 382; i++) {
            fieldKeys.add(fieldNameFormater.format((long) i));
        }
        break;
    default:
        break;
    }
    logger.debug("Keys to validate: " + fieldKeys);
    setValidateFieldKeys(fieldKeys);
    super.validate(obj, errors);
}

From source file:org.davidmendoza.esu.web.admin.ArticuloController.java

private void inicializaPublicacion(Model model, Publicacion publicacion) {
    List<Integer> anios = new ArrayList<>();
    for (int i = (publicacion.getAnio() + 1); i >= 2011; i--) {
        anios.add(i);/*from   w w  w . ja va2s .com*/
    }
    model.addAttribute("anios", anios);

    List<String> trimestres = new ArrayList<>();
    trimestres.add("t1");
    trimestres.add("t2");
    trimestres.add("t3");
    trimestres.add("t4");
    model.addAttribute("trimestres", trimestres);

    NumberFormat nf = NumberFormat.getInstance();
    nf.setMinimumIntegerDigits(2);
    List<String> lecciones = new ArrayList<>();
    for (int i = 1; i < 15; i++) {
        lecciones.add("l" + nf.format(i));
    }
    model.addAttribute("lecciones", lecciones);

    List<String> temas = new ArrayList<>();
    temas.add("tema1");
    temas.add("tema2");
    temas.add("tema3");
    temas.add("tema4");
    temas.add("tema5");
    model.addAttribute("temas", temas);

    List<String> tipos = new ArrayList<>();
    tipos.add("comunica");
    tipos.add("dialoga");
    tipos.add("leccion");
    tipos.add("versiculo");
    tipos.add("video");
    tipos.add("imagen");
    tipos.add("jovenes");
    tipos.add("podcast");
    model.addAttribute("tipos", tipos);

    List<String> dias = new ArrayList<>();
    dias.add("domingo");
    dias.add("lunes");
    dias.add("martes");
    dias.add("miercoles");
    dias.add("jueves");
    dias.add("viernes");
    dias.add("sabado");
    model.addAttribute("dias", dias);

    List<String> estados = new ArrayList<>();
    estados.add("PUBLICADO");
    estados.add("PENDIENTE");
    estados.add("RECHAZADO");
    model.addAttribute("estados", estados);
}

From source file:org.liferayhub.pc.service.impl.PowerConsoleServiceImpl.java

private String getUptime(long time) {
    long uptimeDiff = System.currentTimeMillis() - time;
    long days = uptimeDiff / Time.DAY;
    long hours = (uptimeDiff / Time.HOUR) % 24;
    long minutes = (uptimeDiff / Time.MINUTE) % 60;
    long seconds = (uptimeDiff / Time.SECOND) % 60;

    NumberFormat numberFormat = NumberFormat.getInstance();

    numberFormat.setMaximumIntegerDigits(2);
    numberFormat.setMinimumIntegerDigits(2);
    String response = "";
    if (days > 0) {
        response = days + (days > 1 ? " days " : " day ");
    }/*from   w  ww  . j  av  a 2  s. c o m*/
    response += numberFormat.format(hours) + ":" + numberFormat.format(minutes) + ":"
            + numberFormat.format(seconds);
    return response;
}

From source file:edu.cornell.med.icb.goby.modes.SplitTranscriptsMode.java

/**
 * Get a number formatter to print leading zeros up to n.
 *
 * @param n The largest number that will be formatted
 * @return the NumberFormat for n/*from   w  w  w  .  jav a2s .  co m*/
 */
public NumberFormat getNumberFormatter(final int n) {
    assert n >= 0 : "n must be non-negative";
    final int numDigits;
    if (n == 0) {
        numDigits = 1;
    } else {
        numDigits = 1 + (int) (Math.log10(n));
    }

    final NumberFormat numberFormat = NumberFormat.getInstance();
    numberFormat.setGroupingUsed(false);
    numberFormat.setMinimumIntegerDigits(numDigits);
    return numberFormat;
}

From source file:de.tor.tribes.ui.algo.TimeFrameVisualizer.java

private void renderDayMarkers(long pStart, long pEnd, Graphics2D pG2D) {
    Date d = new Date(pStart);
    d = DateUtils.setHours(d, 0);//from   ww  w  .java2  s. c o m
    d = DateUtils.setMinutes(d, 0);
    d = DateUtils.setSeconds(d, 0);
    d = DateUtils.setMilliseconds(d, 0);

    for (long mark = d.getTime(); mark <= pEnd; mark += DateUtils.MILLIS_PER_HOUR) {
        int markerPos = Math.round((mark - pStart) / DateUtils.MILLIS_PER_MINUTE);
        pG2D.setColor(Color.YELLOW);
        pG2D.fillRect(markerPos, 20, 2, 10);
        pG2D.setColor(Color.WHITE);
        pG2D.setFont(pG2D.getFont().deriveFont(Font.BOLD, 10.0f));
        pG2D.fillRect(markerPos - 5, 15, 12, 10);
        pG2D.setColor(Color.BLACK);
        Calendar cal = Calendar.getInstance();
        cal.setTime(new Date(mark));
        NumberFormat f = NumberFormat.getNumberInstance();
        f.setMinimumIntegerDigits(2);
        f.setMaximumFractionDigits(2);
        pG2D.drawString(f.format(cal.get(Calendar.HOUR_OF_DAY)), markerPos - 5, 23);
    }

    long currentDay = d.getTime();
    while (currentDay < pEnd) {
        currentDay += DateUtils.MILLIS_PER_DAY;
        int markerPos = Math.round((currentDay - pStart) / DateUtils.MILLIS_PER_MINUTE);
        pG2D.setColor(new Color(123, 123, 123));
        pG2D.fillRect(markerPos, 15, 3, 30);
        SimpleDateFormat f = new SimpleDateFormat("dd.MM.yy");
        String dayLabel = f.format(currentDay);
        Rectangle2D labelBounds = pG2D.getFontMetrics().getStringBounds(dayLabel, pG2D);
        pG2D.setColor(Color.YELLOW);
        int labelWidth = (int) labelBounds.getWidth() + 5;
        pG2D.fillRect(markerPos - (int) Math.rint(labelWidth / 2), 15, labelWidth, 10);
        pG2D.setColor(Color.BLACK);
        pG2D.setFont(pG2D.getFont().deriveFont(Font.BOLD, 10.0f));
        pG2D.drawString(dayLabel, markerPos - (int) Math.rint(labelWidth / 2) + 2, 23);
    }
}

From source file:fr.ign.cogit.geoxygene.appli.layer.LayerViewAwtPanel.java

private void saveImage() {
    LayerViewAwtPanel.logger.debug("record"); //$NON-NLS-1$
    Color bg = this.getBackground();
    BufferedImage image = new BufferedImage(this.getWidth(), this.getHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics2D graphics = image.createGraphics();
    graphics.setColor(bg);//from  w ww . j  av a2  s . c o m
    graphics.fillRect(0, 0, this.getWidth(), this.getHeight());
    this.getRenderingManager().copyTo(graphics);
    this.recording = false;
    // this.paintOverlays(graphics);
    graphics.dispose();
    try {
        NumberFormat format = NumberFormat.getInstance();
        format.setMinimumIntegerDigits(3);
        ImgUtil.saveImage(image, this.recordFileName + format.format(this.recordIndex) + ".png"); //$NON-NLS-1$
        this.recordIndex++;
    } catch (IOException e1) {
        e1.printStackTrace();
    }
}

From source file:org.efaps.esjp.common.uiform.Create_Base.java

private void insertFieldSetsOld(final Parameter _parameter, final Instance _instance,
        final List<FieldSet> _fieldsets) throws EFapsException {
    final Map<?, ?> others = (HashMap<?, ?>) _parameter.get(ParameterValues.OTHERS);
    // to find out if new values where added for a field set, first it is checked
    // if it exists in this map
    if (others != null) {

        final NumberFormat nf = NumberFormat.getInstance();
        nf.setMinimumIntegerDigits(2);
        nf.setMaximumIntegerDigits(2);/*from   ww w. j av a 2s  .  c  o  m*/

        for (final FieldSet fieldset : _fieldsets) {
            final String[] yCoords = (String[]) others.get(fieldset.getName() + "_eFapsNew");
            if (yCoords != null) {
                final String setName = fieldset.getAttribute();
                final AttributeSet set = AttributeSet.find(_instance.getType().getName(), setName);

                for (final String yCoord : yCoords) {
                    final Insert insert = new Insert(set);
                    insert.add(set.getAttribute(setName), ((Long) _instance.getId()).toString());
                    int xCoord = 0;
                    for (final String attrName : fieldset.getOrder()) {
                        final Attribute child = set.getAttribute(attrName);
                        final String fieldName = fieldset.getName() + "_eFapsNew_"
                                + nf.format(Integer.parseInt(yCoord)) + nf.format(xCoord);
                        if (_parameter.getParameters().containsKey(fieldName)) {
                            add2Insert(_parameter, insert, child, fieldName, 0);
                        }
                        xCoord++;
                    }
                    insert.execute();
                }
            }
        }
    }
}

From source file:org.mycore.datamodel.ifs.MCRAudioVideoExtender.java

/**
 * Returns the streaming bitrate formatted as a String, e. g. "1.3 MBit" or
 * "300 kBit"./*w ww.j  av  a 2 s.c  o  m*/
 * 
 * @return the streaming bitrate formatted as a String
 */
public String getBitRateFormatted() {
    NumberFormat bitRateFormatter = NumberFormat.getInstance(Locale.ROOT);
    bitRateFormatter.setMinimumIntegerDigits(1);
    bitRateFormatter.setGroupingUsed(false);
    if (bitRate > 100 * 1024) {
        bitRateFormatter.setMaximumFractionDigits(2);
        double b = bitRate / (1024f * 1024f);
        return bitRateFormatter.format(b) + " MBit";
    }
    bitRateFormatter.setMaximumFractionDigits(1);
    double b = bitRate / 1024f;
    return bitRateFormatter.format(b) + " kBit";
}