List of usage examples for java.text NumberFormat setGroupingUsed
public void setGroupingUsed(boolean newValue)
From source file:com.opensymphony.xwork2.conversion.impl.XWorkBasicConverter.java
private Object doConvertToNumber(Map<String, Object> context, Object value, Class toType) { if (value instanceof String) { if (toType == BigDecimal.class) { return new BigDecimal((String) value); } else if (toType == BigInteger.class) { return new BigInteger((String) value); } else if (toType.isPrimitive()) { Object convertedValue = super.convertValue(context, value, toType); String stringValue = (String) value; if (!isInRange((Number) convertedValue, stringValue, toType)) throw new XWorkException("Overflow or underflow casting: \"" + stringValue + "\" into class " + convertedValue.getClass().getName()); return convertedValue; } else {/*from w ww . ja v a 2s .co m*/ String stringValue = (String) value; if (!toType.isPrimitive() && (stringValue == null || stringValue.length() == 0)) { return null; } NumberFormat numFormat = NumberFormat.getInstance(getLocale(context)); ParsePosition parsePos = new ParsePosition(0); if (isIntegerType(toType)) { numFormat.setParseIntegerOnly(true); } numFormat.setGroupingUsed(true); Number number = numFormat.parse(stringValue, parsePos); if (parsePos.getIndex() != stringValue.length()) { throw new XWorkException( "Unparseable number: \"" + stringValue + "\" at position " + parsePos.getIndex()); } else { if (!isInRange(number, stringValue, toType)) throw new XWorkException("Overflow or underflow casting: \"" + stringValue + "\" into class " + number.getClass().getName()); value = super.convertValue(context, number, toType); } } } else if (value instanceof Object[]) { Object[] objArray = (Object[]) value; if (objArray.length == 1) { return doConvertToNumber(context, objArray[0], toType); } } // pass it through DefaultTypeConverter return super.convertValue(context, value, toType); }
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 a 2 s . com 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(); }
From source file:mx.edu.um.mateo.inventario.dao.impl.SalidaDaoHibernate.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", "SALIDA-TEMPORAL"); query.setLong("almacenId", almacen.getId()); query.setLockOptions(LockOptions.UPGRADE); Folio folio = (Folio) query.uniqueResult(); if (folio == null) { folio = new Folio("SALIDA-TEMPORAL"); folio.setAlmacen(almacen);/*from ww w .j a v a2s. co m*/ 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("TS-"); 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.geowebcache.rest.seed.SeedFormRestlet.java
private void makeTaskList(StringBuilder doc, TileLayer tl, boolean listAll) { doc.append(makeKillallThreadsForm(tl, listAll)); doc.append("<h4>List of currently executing tasks:</h4>\n"); Iterator<GWCTask> iter = seeder.getRunningAndPendingTasks(); boolean tasks = false; if (!iter.hasNext()) { doc.append("<ul><li><i>none</i></li></ul>\n"); } else {//from ww w . j a va2s .co m doc.append("<table border=\"0\">"); doc.append( "<tr style=\"font-weight: bold;\"><td style=\"padding-right:20px;\">Id</td><td style=\"padding-right:20px;\">Layer</td><td style=\"padding-right:20px;\">Status</td><td style=\"padding-right:20px;\">Type</td><td>Estimated # of tiles</td>" + "<td style=\"padding-right:20px;\">Tiles completed</td><td style=\"padding-right:20px;\">Time elapsed</td><td>Time remaining</td><td>Tasks</td><td> </td>"); doc.append("</tr>"); tasks = true; } int row = 0; final String layerName = tl.getName(); while (iter.hasNext()) { GWCTask task = iter.next(); if (!listAll && !layerName.equals(task.getLayerName())) { continue; } final long spent = task.getTimeSpent(); final long remining = task.getTimeRemaining(); final long tilesDone = task.getTilesDone(); final long tilesTotal = task.getTilesTotal(); NumberFormat nf = NumberFormat.getInstance(Locale.ENGLISH); nf.setGroupingUsed(true); final String tilesTotalStr; if (tilesTotal < 0) { tilesTotalStr = "Too many to count"; } else { tilesTotalStr = nf.format(tilesTotal); } final String tilesDoneStr = nf.format(task.getTilesDone()); final STATE state = task.getState(); final String status = STATE.UNSET.equals(state) || STATE.READY.equals(state) ? "PENDING" : state.toString(); String timeSpent = toTimeString(spent, tilesDone, tilesTotal); String timeRemaining = toTimeString(remining, tilesDone, tilesTotal); String bgColor = ++row % 2 == 0 ? "#FFFFFF" : "#DDDDDD"; doc.append("<tr style=\"background-color:" + bgColor + ";\">"); doc.append("<td style=\"text-align:right\">").append(task.getTaskId()).append("</td>"); doc.append("<td>"); if (!layerName.equals(task.getLayerName())) { doc.append("<a href=\"./").append(task.getLayerName()).append("\">"); } doc.append(task.getLayerName()); if (!layerName.equals(task.getLayerName())) { doc.append("</a>"); } doc.append("</td>"); doc.append("<td>").append(status).append("</td>"); doc.append("<td>").append(task.getType()).append("</td>"); doc.append("<td>").append(tilesTotalStr).append("</td>"); doc.append("<td>").append(tilesDoneStr).append("</td>"); doc.append("<td>").append(timeSpent).append("</td>"); doc.append("<td>").append(timeRemaining).append("</td>"); doc.append("<td>(Task ").append(task.getThreadOffset() + 1).append(" of ").append(task.getThreadCount()) .append(") </td>"); doc.append("<td>").append(makeThreadKillForm(task.getTaskId(), tl)).append("</td>"); doc.append("<tr>"); } if (tasks) { doc.append("</table>"); } doc.append("<p><a href=\"./" + layerName + "\">Refresh list</a></p>\n"); }
From source file:mx.edu.um.mateo.inventario.dao.impl.EntradaDaoHibernate.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", "ENTRADA"); query.setLong("almacenId", almacen.getId()); query.setLockOptions(LockOptions.UPGRADE); Folio folio = (Folio) query.uniqueResult(); if (folio == null) { folio = new Folio("ENTRADA"); folio.setAlmacen(almacen);//from w w w. j a va 2s .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("E-"); 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:mx.edu.um.mateo.inventario.dao.impl.EntradaDaoHibernate.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", "ENTRADA-TEMPORAL"); query.setLong("almacenId", almacen.getId()); query.setLockOptions(LockOptions.UPGRADE); Folio folio = (Folio) query.uniqueResult(); if (folio == null) { folio = new Folio("ENTRADA-TEMPORAL"); folio.setAlmacen(almacen);//from w w w. ja v a 2 s.c o m 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("TE-"); 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.apache.empire.struts2.jsp.controls.TextInputControl.java
protected NumberFormat getNumberFormat(DataType dataType, Locale locale, Column column) { if (column == null) return NumberFormat.getNumberInstance(locale); // Column is supplied String type = StringUtils.valueOf(column.getAttribute(InputControl.NUMBER_FORMAT_ATTRIBUTE)); NumberFormat nf = null; if (type.equalsIgnoreCase("Integer")) nf = NumberFormat.getIntegerInstance(locale); /*//w ww. jav a 2 s.c om else if (type.equalsIgnoreCase("Currency")) { // nf = NumberFormat.getCurrencyInstance(locale); // Currency does not work as desired! nf = NumberFormat.getNumberInstance(locale); } else if (type.equalsIgnoreCase("Percent")) nf = NumberFormat.getPercentInstance(locale); */ else nf = NumberFormat.getNumberInstance(locale); // Groups Separator? Object groupSep = column.getAttribute(InputControl.NUMBER_GROUPSEP_ATTRIBUTE); if (groupSep != null) nf.setGroupingUsed(ObjectUtils.getBoolean(groupSep)); // Fraction Digits? Object fractDigit = column.getAttribute(InputControl.NUMBER_FRACTION_DIGITS); if (fractDigit != null) { int fractionDigits = ObjectUtils.getInteger(fractDigit); nf.setMaximumFractionDigits(fractionDigits); nf.setMinimumFractionDigits(fractionDigits); } // Number format return nf; }
From source file:de.zib.scalaris.examples.wikipedia.bliki.MyWikiModel.java
/** * Formats the given number using the wiki's locale. * //from w w w. jav a 2s .co m * Note: Currently, the English locale is always used. * * @param rawNumber * whether the raw number should be returned * @param number * the number * * @return the formatted number */ public String formatStatisticNumber(boolean rawNumber, Number number) { if (rawNumber) { return number.toString(); } else { // TODO: use locale from Wiki NumberFormat nf = NumberFormat.getNumberInstance(Locale.ENGLISH); nf.setGroupingUsed(true); return nf.format(number); } }
From source file:org.apache.tajo.storage.StorageManager.java
/** * Finalizes result data. Tajo stores result data in the staging directory. * If the query fails, clean up the staging directory. * Otherwise the query is successful, move to the final directory from the staging directory. * * @param queryContext The query property * @param finalEbId The final execution block id * @param plan The query plan//from www . jav a 2 s . c o m * @param schema The final output schema * @param tableDesc The description of the target table * @param changeFileSeq If true change result file name with max sequence. * @return Saved path * @throws java.io.IOException */ protected Path commitOutputData(OverridableConf queryContext, ExecutionBlockId finalEbId, LogicalPlan plan, Schema schema, TableDesc tableDesc, boolean changeFileSeq) throws IOException { Path stagingDir = new Path(queryContext.get(QueryVars.STAGING_DIR)); Path stagingResultDir = new Path(stagingDir, TajoConstants.RESULT_DIR_NAME); Path finalOutputDir; if (!queryContext.get(QueryVars.OUTPUT_TABLE_PATH, "").isEmpty()) { finalOutputDir = new Path(queryContext.get(QueryVars.OUTPUT_TABLE_PATH)); try { FileSystem fs = stagingResultDir.getFileSystem(conf); if (queryContext.getBool(QueryVars.OUTPUT_OVERWRITE, false)) { // INSERT OVERWRITE INTO // It moves the original table into the temporary location. // Then it moves the new result table into the original table location. // Upon failed, it recovers the original table if possible. boolean movedToOldTable = false; boolean committed = false; Path oldTableDir = new Path(stagingDir, TajoConstants.INSERT_OVERWIRTE_OLD_TABLE_NAME); ContentSummary summary = fs.getContentSummary(stagingResultDir); if (!queryContext.get(QueryVars.OUTPUT_PARTITIONS, "").isEmpty() && summary.getFileCount() > 0L) { // This is a map for existing non-leaf directory to rename. A key is current directory and a value is // renaming directory. Map<Path, Path> renameDirs = TUtil.newHashMap(); // This is a map for recovering existing partition directory. A key is current directory and a value is // temporary directory to back up. Map<Path, Path> recoveryDirs = TUtil.newHashMap(); try { if (!fs.exists(finalOutputDir)) { fs.mkdirs(finalOutputDir); } visitPartitionedDirectory(fs, stagingResultDir, finalOutputDir, stagingResultDir.toString(), renameDirs, oldTableDir); // Rename target partition directories for (Map.Entry<Path, Path> entry : renameDirs.entrySet()) { // Backup existing data files for recovering if (fs.exists(entry.getValue())) { String recoveryPathString = entry.getValue().toString() .replaceAll(finalOutputDir.toString(), oldTableDir.toString()); Path recoveryPath = new Path(recoveryPathString); fs.rename(entry.getValue(), recoveryPath); fs.exists(recoveryPath); recoveryDirs.put(entry.getValue(), recoveryPath); } // Delete existing directory fs.delete(entry.getValue(), true); // Rename staging directory to final output directory fs.rename(entry.getKey(), entry.getValue()); } } catch (IOException ioe) { // Remove created dirs for (Map.Entry<Path, Path> entry : renameDirs.entrySet()) { fs.delete(entry.getValue(), true); } // Recovery renamed dirs for (Map.Entry<Path, Path> entry : recoveryDirs.entrySet()) { fs.delete(entry.getValue(), true); fs.rename(entry.getValue(), entry.getKey()); } throw new IOException(ioe.getMessage()); } } else { // no partition try { // if the final output dir exists, move all contents to the temporary table dir. // Otherwise, just make the final output dir. As a result, the final output dir will be empty. if (fs.exists(finalOutputDir)) { fs.mkdirs(oldTableDir); for (FileStatus status : fs.listStatus(finalOutputDir, StorageManager.hiddenFileFilter)) { fs.rename(status.getPath(), oldTableDir); } movedToOldTable = fs.exists(oldTableDir); } else { // if the parent does not exist, make its parent directory. fs.mkdirs(finalOutputDir); } // Move the results to the final output dir. for (FileStatus status : fs.listStatus(stagingResultDir)) { fs.rename(status.getPath(), finalOutputDir); } // Check the final output dir committed = fs.exists(finalOutputDir); } catch (IOException ioe) { // recover the old table if (movedToOldTable && !committed) { // if commit is failed, recover the old data for (FileStatus status : fs.listStatus(finalOutputDir, StorageManager.hiddenFileFilter)) { fs.delete(status.getPath(), true); } for (FileStatus status : fs.listStatus(oldTableDir)) { fs.rename(status.getPath(), finalOutputDir); } } throw new IOException(ioe.getMessage()); } } } else { String queryType = queryContext.get(QueryVars.COMMAND_TYPE); if (queryType != null && queryType.equals(NodeType.INSERT.name())) { // INSERT INTO an existing table NumberFormat fmt = NumberFormat.getInstance(); fmt.setGroupingUsed(false); fmt.setMinimumIntegerDigits(3); if (!queryContext.get(QueryVars.OUTPUT_PARTITIONS, "").isEmpty()) { for (FileStatus eachFile : fs.listStatus(stagingResultDir)) { if (eachFile.isFile()) { LOG.warn("Partition table can't have file in a staging dir: " + eachFile.getPath()); continue; } moveResultFromStageToFinal(fs, stagingResultDir, eachFile, finalOutputDir, fmt, -1, changeFileSeq); } } else { int maxSeq = StorageUtil.getMaxFileSequence(fs, finalOutputDir, false) + 1; for (FileStatus eachFile : fs.listStatus(stagingResultDir)) { if (eachFile.getPath().getName().startsWith("_")) { continue; } moveResultFromStageToFinal(fs, stagingResultDir, eachFile, finalOutputDir, fmt, maxSeq++, changeFileSeq); } } // checking all file moved and remove empty dir verifyAllFileMoved(fs, stagingResultDir); FileStatus[] files = fs.listStatus(stagingResultDir); if (files != null && files.length != 0) { for (FileStatus eachFile : files) { LOG.error("There are some unmoved files in staging dir:" + eachFile.getPath()); } } } else { // CREATE TABLE AS SELECT (CTAS) if (fs.exists(finalOutputDir)) { for (FileStatus status : fs.listStatus(stagingResultDir)) { fs.rename(status.getPath(), finalOutputDir); } } else { fs.rename(stagingResultDir, finalOutputDir); } LOG.info("Moved from the staging dir to the output directory '" + finalOutputDir); } } // remove the staging directory if the final output dir is given. Path stagingDirRoot = stagingDir.getParent(); fs.delete(stagingDirRoot, true); } catch (Throwable t) { LOG.error(t); throw new IOException(t); } } else { finalOutputDir = new Path(stagingDir, TajoConstants.RESULT_DIR_NAME); } return finalOutputDir; }
From source file:org.jumpmind.vaadin.ui.sqlexplorer.TabularResultLayout.java
private void setEditor(Grid.Column gridColumn, Column tableColumn, List<TextField> primaryKeyEditors) { TextField editor = new TextField(); int typeCode = tableColumn.getMappedTypeCode(); switch (typeCode) { case Types.DATE: editor.setConverter(new ObjectConverter(Date.class, typeCode)); break;/*from w w w . j av a2 s . c om*/ case Types.TIME: editor.setConverter(new ObjectConverter(Time.class, typeCode)); break; case Types.TIMESTAMP: editor.setConverter(new ObjectConverter(Timestamp.class, typeCode)); break; case Types.BIT: editor.setConverter(new StringToBooleanConverter()); break; case Types.TINYINT: case Types.SMALLINT: case Types.BIGINT: case Types.INTEGER: editor.setConverter(new StringToLongConverter() { private static final long serialVersionUID = 1L; public NumberFormat getFormat(Locale locale) { NumberFormat format = super.getFormat(locale); format.setGroupingUsed(false); return format; } }); break; case Types.FLOAT: case Types.DOUBLE: case Types.REAL: case Types.NUMERIC: case Types.DECIMAL: editor.setConverter(new StringToBigDecimalConverter() { private static final long serialVersionUID = 1L; public NumberFormat getFormat(Locale locale) { NumberFormat format = super.getFormat(locale); format.setGroupingUsed(false); return format; } }); break; default: break; } editor.addValidator(new TableChangeValidator(editor, tableColumn)); editor.setNullRepresentation(""); if (!tableColumn.isRequired()) { editor.setNullSettingAllowed(true); } if (tableColumn.isPrimaryKey()) { primaryKeyEditors.add(editor); } gridColumn.setEditorField(editor); }