Example usage for java.text NumberFormat setGroupingUsed

List of usage examples for java.text NumberFormat setGroupingUsed

Introduction

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

Prototype

public void setGroupingUsed(boolean newValue) 

Source Link

Document

Set whether or not grouping will be used in this format.

Usage

From source file:com.cloudera.sqoop.util.AppendUtils.java

/**
 * Move files from source to target using a specified starting partition.
 */// ww  w .  j  av  a2  s.  c om
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:StopWatch.java

/**
 * Return a string with a table describing all tasks performed.
 * For custom reporting, call getTaskInfo() and use the task info directly.
 *///from   w  w w  . j  a v a2  s .c  o  m
public String prettyPrint() {
    StringBuffer sb = new StringBuffer(shortSummary());
    sb.append('\n');
    if (!this.keepTaskList) {
        sb.append("No task info kept");
    } else {
        TaskInfo[] tasks = getTaskInfo();
        sb.append("-----------------------------------------\n");
        sb.append("ms     %     Task name\n");
        sb.append("-----------------------------------------\n");
        NumberFormat nf = NumberFormat.getNumberInstance();
        nf.setMinimumIntegerDigits(5);
        nf.setGroupingUsed(false);
        NumberFormat pf = NumberFormat.getPercentInstance();
        pf.setMinimumIntegerDigits(3);
        pf.setGroupingUsed(false);
        for (int i = 0; i < tasks.length; i++) {
            sb.append(nf.format(tasks[i].getTimeMillis()) + "  ");
            sb.append(pf.format(tasks[i].getTimeSeconds() / getTotalTimeSeconds()) + "  ");
            sb.append(tasks[i].getTaskName() + "\n");
        }
    }
    return sb.toString();
}

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

public String evaluate(DoubleWritable d, IntWritable fracMax, IntWritable fracMin, IntWritable intMax,
        IntWritable intMin) {//ww w. ja v  a 2 s . c  om
    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  a2  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: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   www . j  a va 2  s .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:com.mgmtp.perfload.perfalyzer.PerfAlyzerModule.java

@Provides
@FloatFormat/* w ww. ja  v  a  2 s  .  c  om*/
NumberFormat provideFloatFormat(final Locale locale) {
    DecimalFormatSymbols dfs = new DecimalFormatSymbols(locale);
    NumberFormat nf = new DecimalFormat("0.00", dfs);
    nf.setGroupingUsed(false);
    nf.setRoundingMode(RoundingMode.HALF_UP);
    return nf;
}

From source file:com.oonusave.coupon.MyMapStore.java

public double formatFraction(double d) {
    try {/*from   w  ww . j  av  a2 s.com*/
        NumberFormat nf = NumberFormat.getNumberInstance();
        nf.setGroupingUsed(false); // don't group by threes
        nf.setMinimumFractionDigits(5);
        nf.setMaximumFractionDigits(5);
        String sd = nf.format(d);
        return Double.valueOf(sd.trim()).doubleValue();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return d;
}

From source file:ro.cs.cm.common.Tools.java

public String getDoubleWithoutComma(double number) {
    Locale localeRo = new Locale("ro", "RO", "");
    NumberFormat nf = NumberFormat.getInstance(localeRo);
    nf.setMaximumFractionDigits(-1);/*w  ww  . ja va 2 s .  com*/
    nf.setGroupingUsed(false);
    String s = "000";
    s = nf.format(number);
    return s;
}

From source file:com.mgmtp.perfload.perfalyzer.PerfAlyzerModule.java

@Provides
@IntFormat/* w  w w.  ja  v a 2s .  co m*/
NumberFormat provideIntFormat(final Locale locale) {
    NumberFormat nf = NumberFormat.getIntegerInstance(locale);
    nf.setGroupingUsed(false);
    nf.setRoundingMode(RoundingMode.HALF_UP);
    return nf;
}

From source file:com.bdaum.zoom.gps.naming.geonaming.internal.GeoNamesService.java

@Override
public double getElevation(double lat, double lon) throws UnknownHostException, HttpException, IOException {
    NumberFormat usformat = NumberFormat.getInstance(Locale.US);
    usformat.setMaximumFractionDigits(5);
    usformat.setGroupingUsed(false);
    InputStream in = openGeonamesService(NLS.bind("http://api.geonames.org/srtm3?lat={0}&lng={1}", //$NON-NLS-1$
            usformat.format(lat), usformat.format(lon)));
    try (BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {
        String readLine = reader.readLine();
        if (readLine == null)
            return Double.NaN;
        try {/* w  w w .j  a v a 2  s .  c  o m*/
            double v = Double.parseDouble(readLine);
            return (v < -32000) ? Double.NaN : v;
        } catch (NumberFormatException e) {
            return Double.NaN;
        }
    }
}