List of usage examples for java.text NumberFormat getNumberInstance
public static final NumberFormat getNumberInstance()
From source file:no.abmu.abmstatistikk.annualstatistic.service.MobilBibValidator.java
public void validate(Object obj, Errors errors) { NumberFormat fieldNameFormater = NumberFormat.getNumberInstance(); fieldNameFormater.setMinimumIntegerDigits(3); Set fieldKeys = new HashSet(); int i;//w w w . java 2s. co m setSchemaName("mobilBibSchema"); 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)); } fieldKeys.add(fieldNameFormater.format((long) 383)); for (i = 385; i <= 387; 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 <= 99; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 389; i <= 390; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 431; i <= 452; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } break; case 4: fieldKeys.add(fieldNameFormater.format((long) 137)); fieldKeys.add(fieldNameFormater.format((long) 140)); fieldKeys.add(fieldNameFormater.format((long) 143)); fieldKeys.add(fieldNameFormater.format((long) 146)); for (i = 169; i <= 179; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } fieldKeys.add(fieldNameFormater.format((long) 371)); for (i = 392; i <= 394; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } fieldKeys.add(fieldNameFormater.format((long) 403)); break; case 5: for (i = 205; i <= 210; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 215; i <= 218; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 223; i <= 224; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 381; i <= 382; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 401; i <= 402; 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:no.abmu.abmstatistikk.annualstatistic.service.FengselBibValidator.java
public void validate(Object obj, Errors errors) { NumberFormat fieldNameFormater = NumberFormat.getNumberInstance(); fieldNameFormater.setMinimumIntegerDigits(3); Set fieldKeys = new HashSet(); int i;/* w ww . ja v a2s . c o m*/ setSchemaName("fengselBibSchema"); switch (pageNumber) { case 1: break; case 2: 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 = 34; i <= 35; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 40; i <= 41; 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)); } 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)); fieldKeys.add(fieldNameFormater.format((long) 97)); for (i = 99; i <= 100; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } fieldKeys.add(fieldNameFormater.format((long) 258)); fieldKeys.add(fieldNameFormater.format((long) 374)); fieldKeys.add(fieldNameFormater.format((long) 389)); for (i = 435; i <= 438; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 441; i <= 442; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 445; i <= 446; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 449; i <= 452; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } break; case 4: for (i = 102; i <= 107; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 117; i <= 119; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } fieldKeys.add(fieldNameFormater.format((long) 147)); fieldKeys.add(fieldNameFormater.format((long) 164)); for (i = 205; i <= 210; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } fieldKeys.add(fieldNameFormater.format((long) 384)); for (i = 223; i <= 224; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 401; i <= 402; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } fieldKeys.add(fieldNameFormater.format((long) 225)); break; case 5: for (i = 243; i <= 254; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 259; i <= 264; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } fieldKeys.add(fieldNameFormater.format((long) 266)); for (i = 381; i <= 382; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } break; default: break; } if (logger.isDebugEnabled()) { logger.debug("Keys to validate: " + fieldKeys); } setValidateFieldKeys(fieldKeys); super.validate(obj, errors); }
From source file:no.abmu.abmstatistikk.annualstatistic.service.FylkesBibValidator.java
public void validate(Object obj, Errors errors) { NumberFormat fieldNameFormater = NumberFormat.getNumberInstance(); fieldNameFormater.setMinimumIntegerDigits(3); Set fieldKeys = new HashSet(); int i;/* w ww .j av a 2s. com*/ setSchemaName("fylkesBibSchema"); 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 = 61; i <= 62; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 64; i <= 65; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 365; i <= 366; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 385; i <= 386; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } break; case 3: for (i = 276; i <= 343; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 344; i <= 355; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 362; i <= 364; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 481; i <= 483; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } fieldKeys.add(fieldNameFormater.format((long) 485)); break; case 4: fieldKeys.add(fieldNameFormater.format((long) 122)); fieldKeys.add(fieldNameFormater.format((long) 125)); fieldKeys.add(fieldNameFormater.format((long) 143)); for (i = 146; i <= 147; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 268; i <= 275; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 367; i <= 370; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 392; i <= 394; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } fieldKeys.add(fieldNameFormater.format((long) 404)); fieldKeys.add(fieldNameFormater.format((long) 484)); 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 = 219; i <= 224; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 381; i <= 382; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 401; i <= 402; 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.jactr.core.runtime.DefaultModelRunner.java
public DefaultModelRunner(ExecutorService service, IModel model, ICycleProcessor cycleRunner) { if (!(model instanceof BasicModel)) throw new RuntimeException( getClass().getSimpleName() + " only supports subclasses of " + BasicModel.class.getName()); _model = (BasicModel) model;//from ww w . ja va 2 s .c om _cycleRunner = cycleRunner; _service = service; _format = NumberFormat.getNumberInstance(); _format.setMaximumFractionDigits(3); _format.setMinimumFractionDigits(3); }
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 v a2 s. co 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:com.eu.evaluation.server.eva.EvaluateExcutorTest.java
@Test public void test() { double d = 0.987; logger.info("String.format = " + String.format("%.2f", d)); DecimalFormat df = new DecimalFormat("*.00"); logger.info("DecimalFormat = " + df.format(d)); NumberFormat nf = NumberFormat.getNumberInstance(); nf.setMaximumFractionDigits(2);/*ww w. jav a2 s .c om*/ logger.info("NumberFormat = " + nf.format(d)); DecimalFormat formater = new DecimalFormat(); formater.setMaximumFractionDigits(2); formater.setGroupingSize(0); formater.setRoundingMode(RoundingMode.FLOOR); logger.info("DecimalFormat = " + (formater.format(d))); }
From source file:com.asalfo.wiulgi.util.Utils.java
/** * Calculate distance between two LatLng points and format it nicely for * display. As this is a sample, it only statically supports metric units. * A production app should check locale and support the correct units. *//*from ww w .j a v a 2s . c om*/ @Nullable public static String formatDistanceBetween(@Nullable LatLng point1, @Nullable LatLng point2) { if (point1 == null || point2 == null) { return null; } NumberFormat numberFormat = NumberFormat.getNumberInstance(); double distance = Math.round(SphericalUtil.computeDistanceBetween(point1, point2)); // Adjust to KM if M goes over 1000 (see javadoc of method for note // on only supporting metric) if (distance >= 1000) { numberFormat.setMaximumFractionDigits(1); return numberFormat.format(distance / 1000) + DISTANCE_KM_POSTFIX; } return numberFormat.format(distance) + DISTANCE_M_POSTFIX; }
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;//from ww w .ja v 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 = 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.hadoop.hive.ql.udf.UDFNumberFormat.java
public String evaluate(LongWritable d, IntWritable fracMax, IntWritable fracMin, IntWritable intMax, IntWritable intMin) {/*w ww . jav a 2 s. co 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:adalid.util.meta.sql.MetaFolderSql.java
public MetaFolderSql(String path) { NumberFormat nf = NumberFormat.getNumberInstance(); nf.setMinimumFractionDigits(1);/*from w w w .j ava 2 s. c om*/ nf.setMaximumFractionDigits(2); logger.info("max-file-size=" + nf.format(MAX_FILE_SIZE_MEGAS) + "MB"); rootFolder = PropertiesHandler.getRootFolder(); if (rootFolder == null) { throw new RuntimeException("root folder is missing or invalid"); } rootFolderPath = Paths.get(rootFolder.getPath()); logger.info("root-folder=" + rootFolderPath); if (path == null) { throw new IllegalArgumentException("null folder path"); } else { File file = new File(path); if (file.isAbsolute()) { metaFolder = file; } else { metaFolder = new File(rootFolder.getAbsolutePath(), path); } } metaFolderPath = Paths.get(metaFolder.getPath()); logger.info("meta-folder=" + metaFolderPath); if (metaFolder.isDirectory()) { if (metaFolder.isHidden()) { throw new IllegalArgumentException(metaFolderPath + " is a hidden directory"); } } else { throw new IllegalArgumentException(metaFolderPath + " is not a directory"); } baseFolder = metaFolder.getParentFile(); baseFolderPath = Paths.get(baseFolder.getPath()); logger.info("base-folder=" + baseFolderPath); files = new TreeMap<>(); folders = new TreeMap<>(); fileTypes = new TreeMap<>(); metaFolderWrapper = new FolderWrapper(metaFolder); folders.put(getRelativeToBasePath(metaFolder), metaFolderWrapper); }