List of usage examples for java.text NumberFormat setMinimumIntegerDigits
public void setMinimumIntegerDigits(int newValue)
From source file:dk.nsi.haiba.lprimporter.importer.StatisticsTest.java
private List<String> generateCprList(int size) { List<String> returnValue = new ArrayList<String>(); NumberFormat numberFormat = NumberFormat.getNumberInstance(); numberFormat.setMinimumIntegerDigits(10); for (int i = 0; i < size; i++) { returnValue.add(numberFormat.format(i)); }/*from w w w .j a v a 2 s .co m*/ return returnValue; }
From source file:com.jgoodies.validation.tutorial.formatted.NumberExample.java
/** * Appends the demo rows to the given builder and returns the List of * formatted text fields.//from w w w .j a v a 2s . c o m * * @param builder the builder used to add components to * @return the List of formatted text fields */ private List appendDemoRows(DefaultFormBuilder builder) { // The Formatter is choosen by the initial value. JFormattedTextField defaultNumberField = new JFormattedTextField(new Long(42)); // The Formatter is choosen by the given Format. JFormattedTextField noInitialValueField = new JFormattedTextField(NumberFormat.getIntegerInstance()); // Uses a custom NumberFormat. NumberFormat customFormat = NumberFormat.getIntegerInstance(); customFormat.setMinimumIntegerDigits(3); JFormattedTextField customFormatField = new JFormattedTextField(new NumberFormatter(customFormat)); // Uses a custom NumberFormatter that prints natural language strings. JFormattedTextField customFormatterField = new JFormattedTextField(new CustomNumberFormatter()); // Uses a custom FormatterFactory that used different formatters // for the display and while editing. DefaultFormatterFactory formatterFactory = new DefaultFormatterFactory(new NumberFormatter(), new CustomNumberFormatter()); JFormattedTextField formatterFactoryField = new JFormattedTextField(formatterFactory); // Wraps a NumberFormatter to map empty strings to null and vice versa. JFormattedTextField numberOrNullField = new JFormattedTextField(new EmptyNumberFormatter()); // Wraps a NumberFormatter to map empty strings to -1 and vice versa. Integer emptyValue = new Integer(-1); JFormattedTextField numberOrEmptyValueField = new JFormattedTextField(new EmptyNumberFormatter(emptyValue)); numberOrEmptyValueField.setValue(emptyValue); // Commits values on valid edit texts. DefaultFormatter formatter = new NumberFormatter(); formatter.setCommitsOnValidEdit(true); JFormattedTextField commitOnValidEditField = new JFormattedTextField(formatter); // Returns number values of type Integer NumberFormatter numberFormatter = new NumberFormatter(); numberFormatter.setValueClass(Integer.class); JFormattedTextField integerField = new JFormattedTextField(numberFormatter); Format displayFormat = new DisplayFormat(NumberFormat.getIntegerInstance()); Format typedDisplayFormat = new DisplayFormat(NumberFormat.getIntegerInstance(), true); List fields = new LinkedList(); fields.add(Utils.appendRow(builder, "Default", defaultNumberField, typedDisplayFormat)); fields.add(Utils.appendRow(builder, "No initial value", noInitialValueField, displayFormat)); fields.add(Utils.appendRow(builder, "Empty <-> null", numberOrNullField, displayFormat)); fields.add(Utils.appendRow(builder, "Empty <-> -1", numberOrEmptyValueField, displayFormat)); fields.add(Utils.appendRow(builder, "Custom format", customFormatField, displayFormat)); fields.add(Utils.appendRow(builder, "Custom formatter", customFormatterField, displayFormat)); fields.add(Utils.appendRow(builder, "Formatter factory", formatterFactoryField, displayFormat)); fields.add(Utils.appendRow(builder, "Commits on valid edit", commitOnValidEditField, displayFormat)); fields.add(Utils.appendRow(builder, "Integer Result", integerField, typedDisplayFormat)); return fields; }
From source file:no.abmu.abmstatistikk.annualstatistic.service.GrunnskoleBibValidator.java
public void computeValidateFieldKeys() { NumberFormat fieldNameFormater = NumberFormat.getNumberInstance(); fieldNameFormater.setMinimumIntegerDigits(3); Set fieldKeys = new HashSet(); int i;// ww w . ja v a2s .c o m switch (pageNumber) { case 1: break; case 2: fieldKeys.add(fieldNameFormater.format((long) 226)); for (i = 405; i <= 409; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } break; case 3: for (i = 13; i <= 18; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 25; i <= 30; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 202; i <= 203; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 148; i <= 150; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 67; i <= 68; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } break; case 4: for (i = 102; i <= 104; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 108; i <= 119; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 165; i <= 166; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 183; i <= 184; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } fieldKeys.add(fieldNameFormater.format((long) 225)); break; case 5: fieldKeys.add(fieldNameFormater.format((long) 244)); fieldKeys.add(fieldNameFormater.format((long) 247)); fieldKeys.add(fieldNameFormater.format((long) 250)); fieldKeys.add(fieldNameFormater.format((long) 253)); for (i = 381; i <= 382; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } break; default: break; } logger.debug("Keys to validate: " + fieldKeys); setValidateFieldKeys(fieldKeys); }
From source file:org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.MapReducePOStoreImpl.java
private String getPartName(JobConf conf) { int partition = conf.getInt("mapred.task.partition", -1); NumberFormat numberFormat = NumberFormat.getInstance(); numberFormat.setMinimumIntegerDigits(5); numberFormat.setGroupingUsed(false); return "part-" + numberFormat.format(partition); }
From source file:edu.cornell.med.icb.goby.modes.SplitFastaMode.java
/** * Split a fasta / fastq file by (a) readlength and (b) the maximum number of * entries per file. This will output the files that are written to stdout * @throws IOException error reading / writing files. *//*w w w . j ava 2s. c om*/ @Override public void execute() throws IOException { final FastXReader reader = new FastXReader(inputFile); final Int2ObjectMap<PrintStream> outputMap = new Int2ObjectOpenHashMap<PrintStream>(); final Int2IntMap entriesPerReadLen = new Int2IntOpenHashMap(); final Int2IntMap filesPerReadLen = new Int2IntOpenHashMap(); final List<String> removeExt = Arrays.asList("gz", "fa", "mpfa", "fna", "fsa", "fas", "fasta", "fq", "mpfq", "fnq", "fsq", "fas", "fastq"); String inputName = FilenameUtils.getName(inputFile); while (true) { // Remove the unwanted extensions from the file name final String ext = FilenameUtils.getExtension(inputName); if (!removeExt.contains(ext)) { break; } inputName = FilenameUtils.getBaseName(inputName); } final String outputFilenameTemplate = FilenameUtils.getFullPath(inputFile) + inputName + "._READLENGTH_._PART_." + reader.getFileType(); final NumberFormat nf3 = NumberFormat.getInstance(); nf3.setMinimumIntegerDigits(3); final NumberFormat nf2 = NumberFormat.getInstance(); nf2.setMinimumIntegerDigits(2); for (final FastXEntry entry : reader) { final int readLen = Math.min(fastxSplitMaxLength, roundReadLen(entry.getReadLength(), splitReadsMod)); PrintStream out = outputMap.get(readLen); if (out == null) { filesPerReadLen.put(readLen, 1); entriesPerReadLen.put(readLen, 0); String outputFilename = outputFilenameTemplate.replaceAll("_READLENGTH_", nf3.format(readLen)); outputFilename = outputFilename.replaceAll("_PART_", nf2.format(1)); System.out.println(outputFilename); out = new PrintStream(new BufferedOutputStream(new FileOutputStream(outputFilename))); outputMap.put(readLen, out); } int numEntries = entriesPerReadLen.get(readLen); if (numEntries == maxReadsPerFile) { out.close(); numEntries = 0; int numFiles = filesPerReadLen.get(readLen); numFiles++; filesPerReadLen.put(readLen, numFiles); String outputFilename = outputFilenameTemplate.replaceAll("_READLENGTH_", nf3.format(readLen)); outputFilename = outputFilename.replaceAll("_PART_", nf2.format(numFiles)); System.out.println(outputFilename); out = new PrintStream(new BufferedOutputStream(new FileOutputStream(outputFilename))); outputMap.put(readLen, out); } out.println(entry.getEntry()); entriesPerReadLen.put(readLen, numEntries + 1); } for (final PrintStream out : outputMap.values()) { out.close(); } outputMap.clear(); reader.close(); }
From source file:net.kjmaster.cookiemom.booth.add.AddBoothDialogFragment.java
private void showDateTimeDialog() { // Create the dialog final Dialog mDateTimeDialog = new Dialog(getActivity()); // Inflate the root layout final RelativeLayout mDateTimeDialogView = (RelativeLayout) getActivity().getLayoutInflater() .inflate(R.layout.ui_date_time_dialog, null); // Grab widget instance final DateTimePicker mDateTimePicker = (DateTimePicker) mDateTimeDialogView .findViewById(R.id.DateTimePicker); // Check is system is set to use 24h time (this doesn't seem to work as expected though) final String timeS = android.provider.Settings.System.getString(getActivity().getContentResolver(), android.provider.Settings.System.TIME_12_24); final boolean is24h = !(timeS == null || timeS.equals("12")); // Update demo TextViews when the "OK" button is clicked mDateTimeDialogView.findViewById(R.id.SetDateTime).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { mDateTimePicker.clearFocus(); // TODO Auto-generated method stub String eventDate = SimpleDateFormat.getDateInstance(DateFormat.LONG) .format(new Date(mDateTimePicker.getDateTimeMillis())); ((TextView) getActivity().findViewById(R.id.Date)).setText(eventDate); if (mDateTimePicker.is24HourView()) { ((TextView) getActivity().findViewById(R.id.Time)).setText( mDateTimePicker.get(Calendar.HOUR_OF_DAY) + ":" + mDateTimePicker.get(Calendar.MINUTE)); } else { NumberFormat fmt = NumberFormat.getNumberInstance(); fmt.setMinimumIntegerDigits(2); ((TextView) getActivity().findViewById(R.id.Time)) .setText(fmt.format(mDateTimePicker.get(Calendar.HOUR)) + ":" + fmt.format(mDateTimePicker.get(Calendar.MINUTE)) + " " + (mDateTimePicker.get(Calendar.AM_PM) == Calendar.AM ? "AM" : "PM")); }//from w ww . j av a2s . c o m hiddenDateTime.setText(String.valueOf(mDateTimePicker.getDateTimeMillis())); mDateTimeDialog.dismiss(); } }); // Cancel the dialog when the "Cancel" button is clicked mDateTimeDialogView.findViewById(R.id.CancelDialog).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub mDateTimeDialog.cancel(); } }); // Reset Date and Time pickers when the "Reset" button is clicked mDateTimeDialogView.findViewById(R.id.ResetDateTime).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub mDateTimePicker.reset(); } }); // Setup TimePicker mDateTimePicker.setIs24HourView(is24h); // No title on the dialog window mDateTimeDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); // Set the dialog content view mDateTimeDialog.setContentView(mDateTimeDialogView); // Display the dialog mDateTimeDialog.show(); }
From source file:escuela.AlumnoDaoTest.java
/** * Test of lista method, of class AlumnoDao. *//* w w w . j a va 2 s. co m*/ @Test public void debieraObtenerListaDeAlumnos() { log.debug("lista"); NumberFormat nf = DecimalFormat.getInstance(); NumberFormat nf2 = DecimalFormat.getInstance(); nf.setMinimumIntegerDigits(4); nf.setGroupingUsed(false); nf2.setMinimumIntegerDigits(2); for (int i = 1; i <= 10; i++) { StringBuilder sb = new StringBuilder(); sb.append("Alumno").append(nf2.format(i)); Alumno alumno = new Alumno(nf.format(i), sb.toString(), sb.toString()); instance.crea(alumno); } List<Alumno> result = instance.lista(); assertNotNull(result); assertEquals(10, result.size()); }
From source file:com.cloudera.sqoop.util.AppendUtils.java
/** * Move files from source to target using a specified starting partition. *///from w w w .ja va2s.c o m private void moveFiles(FileSystem fs, Path sourceDir, Path targetDir, int partitionStart) throws IOException { NumberFormat numpart = NumberFormat.getInstance(); numpart.setMinimumIntegerDigits(PARTITION_DIGITS); numpart.setGroupingUsed(false); Pattern patt = Pattern.compile("part.*-([0-9][0-9][0-9][0-9][0-9]).*"); FileStatus[] tempFiles = fs.listStatus(sourceDir); if (null == tempFiles) { // If we've already checked that the dir exists, and now it can't be // listed, this is a genuine error (permissions, fs integrity, or other). throw new IOException("Could not list files from " + sourceDir); } // Move and rename files & directories from temporary to target-dir thus // appending file's next partition for (FileStatus fileStat : tempFiles) { if (!fileStat.isDir()) { // Move imported data files String filename = fileStat.getPath().getName(); Matcher mat = patt.matcher(filename); if (mat.matches()) { String name = getFilename(filename); String fileToMove = name.concat(numpart.format(partitionStart++)); String extension = getFileExtension(filename); if (extension != null) { fileToMove = fileToMove.concat(extension); } LOG.debug("Filename: " + filename + " repartitioned to: " + fileToMove); fs.rename(fileStat.getPath(), new Path(targetDir, fileToMove)); } } else { // Move directories (_logs & any other) String dirName = fileStat.getPath().getName(); Path path = new Path(targetDir, dirName); int dirNumber = 0; while (fs.exists(path)) { path = new Path(targetDir, dirName.concat("-").concat(numpart.format(dirNumber++))); } LOG.debug("Directory: " + dirName + " renamed to: " + path.getName()); fs.rename(fileStat.getPath(), path); } } }
From source file:mx.edu.um.mateo.inventario.dao.impl.CancelacionDaoHibernate.java
@Override public 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", "CANCELACION"); query.setLong("almacenId", almacen.getId()); query.setLockOptions(LockOptions.UPGRADE); Folio folio = (Folio) query.uniqueResult(); if (folio == null) { folio = new Folio("CANCELACION"); folio.setAlmacen(almacen);/*w w w.j a v a2 s . c o m*/ 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("C-"); 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:no.abmu.abmstatistikk.annualstatistic.service.VideregaaendeSkoleBibValidator.java
public void computeValidateFieldKeys() { NumberFormat fieldNameFormater = NumberFormat.getNumberInstance(); fieldNameFormater.setMinimumIntegerDigits(3); Set fieldKeys = new HashSet(); int i;/* ww w.jav a2 s. c o m*/ switch (pageNumber) { case 1: break; case 2: fieldKeys.add(fieldNameFormater.format((long) 226)); for (i = 405; i <= 409; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } break; case 3: for (i = 19; i <= 30; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 34; i <= 36; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 40; i <= 42; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 49; i <= 51; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 55; i <= 60; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 64; i <= 66; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 202; i <= 204; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } break; case 4: for (i = 69; i <= 70; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } fieldKeys.add(fieldNameFormater.format((long) 80)); fieldKeys.add(fieldNameFormater.format((long) 82)); for (i = 84; i <= 86; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 91; i <= 96; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } fieldKeys.add(fieldNameFormater.format((long) 486)); break; case 5: for (i = 102; i <= 104; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 108; i <= 119; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 148; i <= 150; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 167; i <= 168; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } fieldKeys.add(fieldNameFormater.format((long) 183)); fieldKeys.add(fieldNameFormater.format((long) 185)); break; case 6: for (i = 211; i <= 214; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 225; i <= 229; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } break; case 7: fieldKeys.add(fieldNameFormater.format((long) 244)); fieldKeys.add(fieldNameFormater.format((long) 247)); fieldKeys.add(fieldNameFormater.format((long) 250)); fieldKeys.add(fieldNameFormater.format((long) 253)); for (i = 381; i <= 382; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } break; default: break; } logger.debug("Keys to validate: " + fieldKeys); setValidateFieldKeys(fieldKeys); }