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:mx.edu.um.mateo.inventario.dao.impl.FacturaAlmacenDaoHibernate.java

private String getFolioTemporal(Almacen almacen) {
    Query query = currentSession()
            .createQuery("select f from Folio f where f.nombre = :nombre and f.almacen.id = :almacenId");
    query.setString("nombre", "FACTURA-TEMPORAL");
    query.setLong("almacenId", almacen.getId());
    query.setLockOptions(LockOptions.UPGRADE);
    Folio folio = (Folio) query.uniqueResult();
    if (folio == null) {
        folio = new Folio("FACTURA-TEMPORAL");
        folio.setAlmacen(almacen);//from   ww w. j a v a2s  .  c om
        currentSession().save(folio);
        currentSession().flush();
        return getFolioTemporal(almacen);
    }
    folio.setValor(folio.getValor() + 1);
    java.text.NumberFormat nf = java.text.DecimalFormat.getInstance();
    nf.setGroupingUsed(false);
    nf.setMinimumIntegerDigits(9);
    nf.setMaximumIntegerDigits(9);
    nf.setMaximumFractionDigits(0);
    StringBuilder sb = new StringBuilder();
    sb.append("TF-");
    sb.append(almacen.getEmpresa().getOrganizacion().getCodigo());
    sb.append(almacen.getEmpresa().getCodigo());
    sb.append(almacen.getCodigo());
    sb.append(nf.format(folio.getValor()));
    return sb.toString();
}

From source file:org.globus.workspace.client.modes.EnsembleMonitor.java

protected void writeReports(Result result) {

    if (result == null) {
        throw new IllegalArgumentException("result may not be null");
    }/*  ww w .j  av a 2  s .  co  m*/
    if (result.workspaces == null) {
        throw new IllegalArgumentException("workspaces may not be null");
    }

    final Workspace[] workspaces = result.workspaces;

    final short numDigits;
    if (workspaces.length > 1000) {
        numDigits = 4;
    } else if (workspaces.length > 100) {
        numDigits = 3;
    } else if (workspaces.length > 10) {
        numDigits = 2;
    } else {
        numDigits = 1;
    }

    final NumberFormat format = NumberFormat.getInstance();
    format.setMinimumIntegerDigits(numDigits);
    this._writeReports(workspaces, this.args.reportDir, format);

    if (this.pr.enabled()) {
        final String msg = "wrote reports to '" + this.args.reportDir + "'";
        if (this.pr.useThis()) {
            this.pr.infoln(PrCodes.ENSMONITOR__REPORT_DIR, "  - " + msg);
        } else if (this.pr.useLogging()) {
            logger.info(msg);
        }
    }
}

From source file:org.apache.cocoon.template.instruction.FormatNumber.java

private void configureFormatter(NumberFormat formatter, Boolean isGroupingUsed, Number maxIntegerDigits,
        Number minIntegerDigits, Number maxFractionDigits, Number minFractionDigits) {
    if (isGroupingUsed != null)
        formatter.setGroupingUsed(isGroupingUsed.booleanValue());
    if (maxIntegerDigits != null)
        formatter.setMaximumIntegerDigits(maxIntegerDigits.intValue());
    if (minIntegerDigits != null)
        formatter.setMinimumIntegerDigits(minIntegerDigits.intValue());
    if (maxFractionDigits != null)
        formatter.setMaximumFractionDigits(maxFractionDigits.intValue());
    if (minFractionDigits != null)
        formatter.setMinimumFractionDigits(minFractionDigits.intValue());
}

From source file:org.cruk.genologics.api.cache.GenologicsAPICacheTest.java

/**
 * This test modifies the database, and so is controlled by the system property
 * "live.cache.test"./*from  ww w.ja  v a2 s  . c  o  m*/
 *
 * @throws Exception
 */
@Test
public void fullTest() throws Exception {
    Assume.assumeTrue("Not in the CRUK-CI institute. This test will not work.",
            UnitTestApplicationContextFactory.inCrukCI());

    checkCredentialsSet();

    boolean runThisTest = Boolean.parseBoolean(System.getProperty("live.cache.test", Boolean.FALSE.toString()));

    Assume.assumeTrue("Not running the test \"GenologicsAPICachingAspectTest.fullTest\". "
            + "Set the property -Dlive.cache.test=true to make it run.", runThisTest);

    final String projectName = "Caching Aspect Test";

    if (apiUser == null || plateType == null) {
        readonlyTest();
    }

    // Find or create project

    Map<String, String> projectSearch = Collections.singletonMap("name", projectName);

    List<LimsLink<Project>> foundProjects = api.find(projectSearch, Project.class);

    if (foundProjects.isEmpty()) {
        project = new Project();
        project.setName(projectName);
        project.setResearcher(apiUser);
        project.setOpenDate(new Date());

        api.create(project);
    } else {
        LimsLink<Project> link = foundProjects.get(0);
        testAspect.setAllowedUris(link.getUri().toString());
        project = api.load(link);
        testAspect.clear();
    }

    testNotReloading(project);

    // Create a container for some samples.

    container = new Container(plateType, projectName + " Plate");

    api.create(container);

    testNotReloading(container);

    // Create some samples in the container.

    samples = new Sample[5];

    for (int i = 0; i < samples.length; i++) {
        Sample s = new Sample();
        s.setName(projectName + " sample #" + (i + 1));
        s.setDateReceived(new Date());
        s.setProject(project);
        s.setSubmitter(apiUser);

        UDF.setUDF(s, "Read Length", "50");
        UDF.setUDF(s, "Column", "2");
        UDF.setUDF(s, "Concentration", "-1");
        UDF.setUDF(s, "Library Type", "Other");
        UDF.setUDF(s, "Number of Lanes", "2");
        UDF.setUDF(s, "Pool Size", "-1");
        UDF.setUDF(s, "Priority Status", "Standard");
        UDF.setUDF(s, "Reference Genome", "Homo sapiens [GRCh37]");
        UDF.setUDF(s, "Row", "A");
        UDF.setUDF(s, "Sample Source", "Not Assigned");
        UDF.setUDF(s, "Sample Type", "DNA");
        UDF.setUDF(s, "Sequencer", "Not Assigned");
        UDF.setUDF(s, "SLX Identifier", "SLX-0000");
        UDF.setUDF(s, "Sequencing Type", "Paired End");
        UDF.setUDF(s, "Index Type", "Unspecified (Other)");
        UDF.setUDF(s, "Volume", "-1");
        UDF.setUDF(s, "Average Library Length", "-1");
        UDF.setUDF(s, "Version Number", "Not Assigned");
        UDF.setUDF(s, "Workflow", "MiSeq Express");

        s.setCreationLocation(container, (char) ('A' + i) + ":" + Integer.valueOf(i + 1));

        samples[i] = s;
    }

    api.createAll(Arrays.asList(samples));

    testNotReloading(samples[0]);

    // Try loading the samples' artifacts by individually and by batch.

    @SuppressWarnings("unchecked")
    LimsLink<Artifact>[] artifactLinks = new LimsLink[samples.length];

    for (int i = 0; i < samples.length; i++) {
        artifactLinks[i] = samples[i].getArtifact();
    }

    testAspect.setAllowedUris(artifactLinks[0], artifactLinks[4]);

    Artifact[] artifacts = new Artifact[samples.length];

    artifacts[0] = api.load(artifactLinks[0]);
    artifacts[4] = api.load(artifactLinks[4]);

    testNotReloading(artifacts[0]);

    // Mass fetch. Should only fetch the middle three.

    testAspect.setAllowedUris(artifactLinks[1], artifactLinks[2], artifactLinks[3]);

    api.loadAll(Arrays.asList(artifactLinks)).toArray(artifacts);

    testNotReloading(artifacts[2]);

    // Check fetched artifacts match their original links.

    for (int i = 0; i < samples.length; i++) {
        assertEquals("Sample/artifact " + i + " don't match", samples[i].getArtifact().getLimsid(),
                artifacts[i].getLimsid());
    }

    // Try pooling the artifacts.

    // First, assign reagent labels.
    NumberFormat reagentFormat = NumberFormat.getIntegerInstance();
    reagentFormat.setMinimumIntegerDigits(3);

    for (int i = 0; i < artifacts.length; i++) {
        artifacts[i].addReagentLabel("A" + reagentFormat.format(i + 1));
    }
    api.updateAll(Arrays.asList(artifacts));

    // Now the actual pooling.

    poolContainer = new Container(tubeType, projectName + " pool container");

    api.create(poolContainer);

    ExecutableProcess execProcess = new ExecutableProcess("Pool Accepted SLX", apiUser);
    ExecutableInputOutputMap iomap = execProcess.newInputOutputMap();

    iomap.setShared(true);
    iomap.setInputs(Arrays.asList(artifacts));
    iomap.setOutput(OutputType.ANALYTE, poolContainer, "1:1");

    GenologicsProcess poolProcess = api.executeProcess(execProcess);
    assertNotNull("No pool process returned", poolProcess);

    testNotReloading(poolProcess);

    // Try attaching a file to a sample.

    File toUpload = new File("pom.xml").getAbsoluteFile();

    try {
        GenologicsFile uploadedFile = api.uploadFile(samples[0], toUpload.toURI().toURL(), false);
        assertNotNull("No file returned", uploadedFile);

        testNotReloading(uploadedFile);

        try {
            api.deleteAndRemoveFile(uploadedFile);

            Object fetched = cacheAspect.getCache(GenologicsFile.class)
                    .getQuiet(cacheAspect.keyFromLocatable(uploadedFile));
            assertNull("Deleted file is still in the cache", fetched);
        } catch (IOException e) {
            api.delete(uploadedFile);
        }
    } catch (IOException e) {
        logger.warn("Could not upload the file to the server: ", e);
    }
}

From source file:de.cismet.cids.custom.utils.berechtigungspruefung.BerechtigungspruefungHandler.java

/**
 * DOCUMENT ME!//from   ww w.ja  v a 2 s  . c  o m
 *
 * @param   user          DOCUMENT ME!
 * @param   downloadInfo  DOCUMENT ME!
 *
 * @return  DOCUMENT ME!
 */
public String createNewSchluessel(final User user, final BerechtigungspruefungDownloadInfo downloadInfo) {
    synchronized (this) {
        final String type;
        if (BerechtigungspruefungBescheinigungDownloadInfo.PRODUKT_TYP.equals(downloadInfo.getProduktTyp())) {
            type = "BlaB";
        } else if (BerechtigungspruefungAlkisDownloadInfo.PRODUKT_TYP.equals(downloadInfo.getProduktTyp())) {
            type = "LB";
        } else {
            type = "?";
        }

        final int year = Calendar.getInstance().get(Calendar.YEAR);
        final CidsBean lastAnfrageBean = loadLastAnfrageBeanByTypeAndYear(user, type, year);
        final String lastAnfrageSchluessel = (lastAnfrageBean != null)
                ? (String) lastAnfrageBean.getProperty("schluessel")
                : null;
        final int lastNumber;
        if (lastAnfrageSchluessel != null) {
            final Pattern pattern = Pattern.compile("^" + type + "-" + year + "-(\\d{5})$");
            final Matcher matcher = pattern.matcher(lastAnfrageSchluessel);
            if (matcher.matches()) {
                final String group = matcher.group(1);
                lastNumber = (group != null) ? Integer.parseInt(group) : 0;
            } else {
                lastNumber = 0;
            }
        } else {
            lastNumber = 0;
        }

        final int newNumber = lastNumber + 1;

        final NumberFormat format = NumberFormat.getIntegerInstance();
        format.setMinimumIntegerDigits(5);
        format.setGroupingUsed(false);

        final String newAnfrageSchluessel = type + "-" + Integer.toString(year) + "-"
                + format.format(newNumber);
        return newAnfrageSchluessel;
    }
}

From source file:com.rockhoppertech.music.Note.java

/**
 * <code>toString</code>//from w w w  .ja  va2s .  c o  m
 * 
 * @return a <code>String</code> value
 */
@Override
public String toString() {
    final StringBuilder sb = new StringBuilder();
    final NumberFormat nf = NumberFormat.getInstance();
    nf.setMaximumFractionDigits(2);
    nf.setMinimumFractionDigits(2);
    nf.setMaximumIntegerDigits(3);
    nf.setMinimumIntegerDigits(3);
    sb.append(this.getClass().getSimpleName()).append('[');
    sb.append("startBeat: ").append(nf.format(startBeat));
    sb.append(" pitch: ").append(pitch);
    sb.append(" dur: ").append(nf.format(duration));
    sb.append(" : ").append(getDurationString());

    sb.append(" endBeat: ").append(nf.format(endBeat));
    sb.append(" midinum: ").append(pitch.getMidiNumber());
    sb.append(" rest: ").append(rest);
    sb.append(']');
    return sb.toString();
}

From source file:com.autentia.intra.bean.contacts.AlbaranBean.java

public String siguienteNumero() {
    int maximo = 0;
    NumberFormat nf = NumberFormat.getInstance();
    nf.setMinimumIntegerDigits(2);
    String regex = "A\\d+/";
    String anio = nf.format(new Date().getYear() - 100);
    regex = regex.concat(anio);/*from   ww w . java2 s  . com*/
    List<Albaran> list = albaranDAO.search(null);
    for (Albaran o : list) {
        String numero = o.getName();
        if (numero != null && numero.matches(regex)) {
            int x = Integer.parseInt(numero.substring(1, numero.indexOf('/')));
            if (x > maximo)
                maximo = x;
        }
    }
    nf.setMinimumIntegerDigits(3);
    return "A".concat(nf.format(maximo + 1)).concat("/").concat(anio);
}

From source file:org.globus.workspace.client.modes.DeployRun.java

void run() throws ParameterProblem, ExecutionProblem, ExitNow {

    this.populateCreate(this.eitherCreate);

    this.eitherCreate.validateAll();

    // dryrun cutoff in this:
    this.delegateIfNecessary();

    // delegate may have changed opt params
    this.eitherCreate.validateOptionalParameters();

    if (this.d.dryrun) {

        if (this.pr.enabled()) {
            final String msg = "Dryrun, done.";
            if (this.pr.useThis()) {
                this.pr.infoln(PrCodes.CREATE__DRYRUN, msg);
            } else if (this.pr.useLogging()) {
                logger.info(msg);// w  w w  .  jav  a2s . c  om
            }
        }

        return; // *** EARLY RETURN ***
    }

    if (this.d.subscribeAfterDeployment && this.d.subscribeLaunch == null) {
        throw new IllegalStateException("internal inconsistency: "
                + "subscribe after deployment needed but no launch object " + "was prepared");
    }

    if (this.singleCreate != null) {

        final Workspace workspace = this.single();
        if (this.d.shortName != null) {
            workspace.setDisplayName(this.d.shortName);
        }
        if (this.pr.enabled() && this.pr.useThis()) {
            this.pr.infoln(PrCodes.CREATE__EXTRALINES, "");
        }
        if (this.d.subscribeAfterDeployment) {
            final Workspace[] warray = { workspace };
            this.subscribe(warray);
        }

    } else {

        final Group group = this.group();

        final NumberFormat format = NumberFormat.getInstance();
        format.setMinimumIntegerDigits(this.groupCreate.getSettings().getGroupSuffixMinCharacters());

        // only override nameToPrint if no short, display name was given
        if (this.d.shortName == null) {
            this.d.nameToPrint = group.getGroupID();
            if (this.d.subscribeLaunch != null) {
                this.d.subscribeLaunch.setName(this.d.nameToPrint);
            }
        }

        // optional write of each EPR is triggered by groupBaseName
        final String baseName = this.d.groupBaseName;
        final Workspace[] warray = group.getWorkspaces();
        if (baseName != null) {

            final String elem = this.eitherCreate.getSettings().getGeneratedEprElementName();

            // suppress console prints of individual EPR writes if > 10
            final Print print;
            boolean suppressed = false;
            if (warray.length > 10) {
                print = new Print();
                suppressed = true;
            } else {
                print = this.pr;
            }

            for (int i = 0; i < warray.length; i++) {
                final int key = warray[i].getID().intValue();
                final String name = baseName + "-" + format.format(key);
                warray[i].setDisplayName(name);
                final String path = name + ".epr";
                writeOneWorkspaceEprPossibly(warray[i], path, elem, print);
                writeOneWorkspaceEprAndIpPossibly(warray[i], this.d.args.eprIdDir);

            }

            if (suppressed && this.pr.enabled()) {
                final String msg = "Wrote " + warray.length + " individual EPR files (base name: '" + baseName
                        + "'";
                if (this.pr.useThis()) {
                    this.pr.infoln(PrCodes.CREATE__INSTANCE_EPRFILE_WRITES_OVERFLOW, msg);
                } else if (this.pr.useLogging()) {
                    logger.info(msg);
                }
            }

        } else {
            for (int i = 0; i < warray.length; i++) {
                final int key = warray[i].getID().intValue();
                final String name = this.d.nameToPrint + "-" + format.format(key);
                warray[i].setDisplayName(name);
            }
        }

        if (this.pr.enabled() && this.pr.useThis()) {
            this.pr.infoln(PrCodes.CREATE__EXTRALINES, "");
        }
        if (this.d.subscribeAfterDeployment) {
            this.subscribe(group.getWorkspaces());
        }
    }
}

From source file:com.vgi.mafscaling.Rescale.java

private void createControlPanel(JPanel dataPanel) {
    JPanel cntlPanel = new JPanel();
    GridBagConstraints gbl_ctrlPanel = new GridBagConstraints();
    gbl_ctrlPanel.insets = insets3;/*  w ww .j av a  2s .com*/
    gbl_ctrlPanel.anchor = GridBagConstraints.PAGE_START;
    gbl_ctrlPanel.fill = GridBagConstraints.HORIZONTAL;
    gbl_ctrlPanel.weightx = 1.0;
    gbl_ctrlPanel.gridx = 0;
    gbl_ctrlPanel.gridy = 0;
    dataPanel.add(cntlPanel, gbl_ctrlPanel);

    GridBagLayout gbl_cntlPanel = new GridBagLayout();
    gbl_cntlPanel.columnWidths = new int[] { 0, 0, 0, 0, 0, 0, 0, 0 };
    gbl_cntlPanel.rowHeights = new int[] { 0, 0 };
    gbl_cntlPanel.columnWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 };
    gbl_cntlPanel.rowWeights = new double[] { 0 };
    cntlPanel.setLayout(gbl_cntlPanel);

    NumberFormat doubleFmt = NumberFormat.getNumberInstance();
    doubleFmt.setGroupingUsed(false);
    doubleFmt.setMaximumIntegerDigits(1);
    doubleFmt.setMinimumIntegerDigits(1);
    doubleFmt.setMaximumFractionDigits(3);
    doubleFmt.setMinimumFractionDigits(1);
    doubleFmt.setRoundingMode(RoundingMode.HALF_UP);

    NumberFormat scaleDoubleFmt = NumberFormat.getNumberInstance();
    scaleDoubleFmt.setGroupingUsed(false);
    scaleDoubleFmt.setMaximumIntegerDigits(1);
    scaleDoubleFmt.setMinimumIntegerDigits(1);
    scaleDoubleFmt.setMaximumFractionDigits(8);
    scaleDoubleFmt.setMinimumFractionDigits(1);
    scaleDoubleFmt.setRoundingMode(RoundingMode.HALF_UP);

    GridBagConstraints gbc_cntlPanelLabel = new GridBagConstraints();
    gbc_cntlPanelLabel.anchor = GridBagConstraints.EAST;
    gbc_cntlPanelLabel.insets = new Insets(2, 3, 2, 1);
    gbc_cntlPanelLabel.gridx = 0;
    gbc_cntlPanelLabel.gridy = 0;

    GridBagConstraints gbc_cntlPanelInput = new GridBagConstraints();
    gbc_cntlPanelInput.anchor = GridBagConstraints.WEST;
    gbc_cntlPanelInput.insets = new Insets(2, 1, 2, 3);
    gbc_cntlPanelInput.gridx = 1;
    gbc_cntlPanelInput.gridy = 0;

    cntlPanel.add(new JLabel("New Max V"), gbc_cntlPanelLabel);

    newMaxVFmtTextBox = new JFormattedTextField(doubleFmt);
    newMaxVFmtTextBox.setColumns(7);
    newMaxVFmtTextBox.addPropertyChangeListener("value", new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent e) {
            Object source = e.getSource();
            if (source == newMaxVFmtTextBox)
                updateNewMafScale();
        }
    });
    cntlPanel.add(newMaxVFmtTextBox, gbc_cntlPanelInput);

    gbc_cntlPanelLabel.gridx += 2;
    cntlPanel.add(new JLabel("Min V"), gbc_cntlPanelLabel);

    minVFmtTextBox = new JFormattedTextField(doubleFmt);
    minVFmtTextBox.setColumns(7);
    minVFmtTextBox.addPropertyChangeListener("value", new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent e) {
            Object source = e.getSource();
            if (source == minVFmtTextBox)
                updateNewMafScale();
        }
    });
    gbc_cntlPanelInput.gridx += 2;
    cntlPanel.add(minVFmtTextBox, gbc_cntlPanelInput);

    gbc_cntlPanelLabel.gridx += 2;
    cntlPanel.add(new JLabel("Max Unchanged"), gbc_cntlPanelLabel);

    maxVUnchangedFmtTextBox = new JFormattedTextField(doubleFmt);
    maxVUnchangedFmtTextBox.setColumns(7);
    maxVUnchangedFmtTextBox.addPropertyChangeListener("value", new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent e) {
            Object source = e.getSource();
            if (source == maxVUnchangedFmtTextBox)
                updateNewMafScale();
        }
    });
    gbc_cntlPanelInput.gridx += 2;
    cntlPanel.add(maxVUnchangedFmtTextBox, gbc_cntlPanelInput);

    gbc_cntlPanelLabel.gridx += 2;
    cntlPanel.add(new JLabel("Mode deltaV"), gbc_cntlPanelLabel);

    modeDeltaVFmtTextBox = new JFormattedTextField(scaleDoubleFmt);
    modeDeltaVFmtTextBox.setColumns(7);
    modeDeltaVFmtTextBox.setEditable(false);
    modeDeltaVFmtTextBox.setBackground(new Color(210, 210, 210));
    gbc_cntlPanelInput.gridx += 2;
    cntlPanel.add(modeDeltaVFmtTextBox, gbc_cntlPanelInput);
}

From source file:mx.edu.um.mateo.inventario.dao.impl.SalidaDaoHibernate.java

private String getFolio(Almacen almacen) {
    Query query = currentSession()
            .createQuery("select f from Folio f where f.nombre = :nombre and f.almacen.id = :almacenId");
    query.setString("nombre", "SALIDA");
    query.setLong("almacenId", almacen.getId());
    query.setLockOptions(LockOptions.UPGRADE);
    Folio folio = (Folio) query.uniqueResult();
    if (folio == null) {
        folio = new Folio("SALIDA");
        folio.setAlmacen(almacen);/*from  w  w w.j a v  a2  s. c  om*/
        currentSession().save(folio);
        return getFolio(almacen);
    }
    folio.setValor(folio.getValor() + 1);
    java.text.NumberFormat nf = java.text.DecimalFormat.getInstance();
    nf.setGroupingUsed(false);
    nf.setMinimumIntegerDigits(9);
    nf.setMaximumIntegerDigits(9);
    nf.setMaximumFractionDigits(0);
    StringBuilder sb = new StringBuilder();
    sb.append("S-");
    sb.append(almacen.getEmpresa().getOrganizacion().getCodigo());
    sb.append(almacen.getEmpresa().getCodigo());
    sb.append(almacen.getCodigo());
    sb.append(nf.format(folio.getValor()));
    return sb.toString();
}