Example usage for java.text NumberFormat format

List of usage examples for java.text NumberFormat format

Introduction

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

Prototype

public final String format(long number) 

Source Link

Document

Specialization of format.

Usage

From source file:com.prowidesoftware.swift.model.field.Field36B.java

/**
 * Returns a localized suitable for showing to humans string of a field component.<br>
 *
 * @param component number of the component to display
 * @param locale optional locale to format date and amounts, if null, the default locale is used
 * @return formatted component value or null if component number is invalid or not present
 * @throws IllegalArgumentException if component number is invalid for the field
 * @since 7.8//from w w  w .j a va 2  s .c o m
 */
@Override
public String getValueDisplay(int component, Locale locale) {
    if (component < 1 || component > 3) {
        throw new IllegalArgumentException("invalid component number " + component + " for field 36B");
    }
    if (locale == null) {
        locale = Locale.getDefault();
    }
    if (component == 1) {
        //default format (as is)
        return getComponent(1);
    }
    if (component == 2) {
        //default format (as is)
        return getComponent(2);
    }
    if (component == 3) {
        //number or amount
        java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale);
        Number n = getComponent3AsNumber();
        if (n != null) {
            return f.format(n);
        }
    }
    return null;
}

From source file:com.prowidesoftware.swift.model.field.Field92A.java

/**
 * Returns a localized suitable for showing to humans string of a field component.<br>
 *
 * @param component number of the component to display
 * @param locale optional locale to format date and amounts, if null, the default locale is used
 * @return formatted component value or null if component number is invalid or not present
 * @throws IllegalArgumentException if component number is invalid for the field
 * @since 7.8/*from w  w w. ja v a 2  s .c om*/
 */
@Override
public String getValueDisplay(int component, Locale locale) {
    if (component < 1 || component > 3) {
        throw new IllegalArgumentException("invalid component number " + component + " for field 92A");
    }
    if (locale == null) {
        locale = Locale.getDefault();
    }
    if (component == 1) {
        //default format (as is)
        return getComponent(1);
    }
    if (component == 2) {
        //default format (as is)
        return getComponent(2);
    }
    if (component == 3) {
        //number or amount
        java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale);
        Number n = getComponent3AsNumber();
        if (n != null) {
            return f.format(n);
        }
    }
    return null;
}

From source file:com.prowidesoftware.swift.model.field.Field93D.java

/**
 * Returns a localized suitable for showing to humans string of a field component.<br>
 *
 * @param component number of the component to display
 * @param locale optional locale to format date and amounts, if null, the default locale is used
 * @return formatted component value or null if component number is invalid or not present
 * @throws IllegalArgumentException if component number is invalid for the field
 * @since 7.8/*from   w  w w . j a v a  2  s .c om*/
 */
@Override
public String getValueDisplay(int component, Locale locale) {
    if (component < 1 || component > 3) {
        throw new IllegalArgumentException("invalid component number " + component + " for field 93D");
    }
    if (locale == null) {
        locale = Locale.getDefault();
    }
    if (component == 1) {
        //default format (as is)
        return getComponent(1);
    }
    if (component == 2) {
        //default format (as is)
        return getComponent(2);
    }
    if (component == 3) {
        //number or amount
        java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale);
        Number n = getComponent3AsNumber();
        if (n != null) {
            return f.format(n);
        }
    }
    return null;
}

From source file:com.prowidesoftware.swift.model.field.Field33G.java

/**
 * Returns a localized suitable for showing to humans string of a field component.<br>
 *
 * @param component number of the component to display
 * @param locale optional locale to format date and amounts, if null, the default locale is used
 * @return formatted component value or null if component number is invalid or not present
 * @throws IllegalArgumentException if component number is invalid for the field
 * @since 7.8/* w w w. jav a 2 s .co  m*/
 */
@Override
public String getValueDisplay(int component, Locale locale) {
    if (component < 1 || component > 3) {
        throw new IllegalArgumentException("invalid component number " + component + " for field 33G");
    }
    if (locale == null) {
        locale = Locale.getDefault();
    }
    if (component == 1) {
        //default format (as is)
        return getComponent(1);
    }
    if (component == 2) {
        //number or amount
        java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale);
        Number n = getComponent2AsNumber();
        if (n != null) {
            return f.format(n);
        }
    }
    if (component == 3) {
        //default format (as is)
        return getComponent(3);
    }
    return null;
}

From source file:com.prowidesoftware.swift.model.field.Field133.java

/**
 * Returns a localized suitable for showing to humans string of a field component.<br>
 *
 * @param component number of the component to display
 * @param locale optional locale to format date and amounts, if null, the default locale is used
 * @return formatted component value or null if component number is invalid or not present
 * @throws IllegalArgumentException if component number is invalid for the field
 * @since 7.8//www.  j a  v a 2 s  . c  o m
 */
@Override
public String getValueDisplay(int component, Locale locale) {
    if (component < 1 || component > 4) {
        throw new IllegalArgumentException("invalid component number " + component + " for field 133");
    }
    if (locale == null) {
        locale = Locale.getDefault();
    }
    if (component == 1) {
        //default format (as is)
        return getComponent(1);
    }
    if (component == 2) {
        //default format (as is)
        return getComponent(2);
    }
    if (component == 3) {
        //default format (as is)
        return getComponent(3);
    }
    if (component == 4) {
        //number or amount
        java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale);
        Number n = getComponent4AsNumber();
        if (n != null) {
            return f.format(n);
        }
    }
    return null;
}

From source file:com.prowidesoftware.swift.model.field.Field137.java

/**
 * Returns a localized suitable for showing to humans string of a field component.<br>
 *
 * @param component number of the component to display
 * @param locale optional locale to format date and amounts, if null, the default locale is used
 * @return formatted component value or null if component number is invalid or not present
 * @throws IllegalArgumentException if component number is invalid for the field
 * @since 7.8//from  w  w  w.  j ava  2s.c  o m
 */
@Override
public String getValueDisplay(int component, Locale locale) {
    if (component < 1 || component > 4) {
        throw new IllegalArgumentException("invalid component number " + component + " for field 137");
    }
    if (locale == null) {
        locale = Locale.getDefault();
    }
    if (component == 1) {
        //default format (as is)
        return getComponent(1);
    }
    if (component == 2) {
        //default format (as is)
        return getComponent(2);
    }
    if (component == 3) {
        //default format (as is)
        return getComponent(3);
    }
    if (component == 4) {
        //number or amount
        java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale);
        Number n = getComponent4AsNumber();
        if (n != null) {
            return f.format(n);
        }
    }
    return null;
}

From source file:com.prowidesoftware.swift.model.field.Field39P.java

/**
 * Returns a localized suitable for showing to humans string of a field component.<br>
 *
 * @param component number of the component to display
 * @param locale optional locale to format date and amounts, if null, the default locale is used
 * @return formatted component value or null if component number is invalid or not present
 * @throws IllegalArgumentException if component number is invalid for the field
 * @since 7.8/*ww w.j  a  v a  2  s  .  com*/
 */
@Override
public String getValueDisplay(int component, Locale locale) {
    if (component < 1 || component > 3) {
        throw new IllegalArgumentException("invalid component number " + component + " for field 39P");
    }
    if (locale == null) {
        locale = Locale.getDefault();
    }
    if (component == 1) {
        //default format (as is)
        return getComponent(1);
    }
    if (component == 2) {
        //default format (as is)
        return getComponent(2);
    }
    if (component == 3) {
        //number or amount
        java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale);
        Number n = getComponent3AsNumber();
        if (n != null) {
            return f.format(n);
        }
    }
    return null;
}

From source file:gov.nasa.arc.geocam.geocam.GeoCamMobile.java

private void updateLocation(Location location) {
    double lat, lon;
    int status;/* w  w  w .  jav a 2s.  c om*/

    if (location == null) {
        lat = 0.0;
        lon = 0.0;
        status = LocationProvider.TEMPORARILY_UNAVAILABLE;
    } else {
        mLocation = location;
        mLocationProvider = mLocation.getProvider();
        status = LocationProvider.AVAILABLE;
        lat = mLocation.getLatitude();
        lon = mLocation.getLongitude();
    }

    NumberFormat nf = NumberFormat.getInstance();
    nf.setMaximumFractionDigits(6);
    TextView latText = (TextView) findViewById(R.id.main_latitude_textview);
    TextView lonText = (TextView) findViewById(R.id.main_longitude_textview);
    latText.setText(nf.format(lat) + DEGREE_SYMBOL);
    lonText.setText(nf.format(lon) + DEGREE_SYMBOL);

    ((TextView) findViewById(R.id.main_location_provider_textview)).setText(mLocationProvider);
    TextView locationStatusText = ((TextView) findViewById(R.id.main_location_status_textview));
    switch (status) {
    case LocationProvider.AVAILABLE:
        locationStatusText.setText("available");
        break;
    case LocationProvider.TEMPORARILY_UNAVAILABLE:
        locationStatusText.setText("unavailable");
        break;
    case LocationProvider.OUT_OF_SERVICE:
        locationStatusText.setText("no service");
        break;
    default:
        locationStatusText.setText("unknown");
        break;
    }
}

From source file:com.mycompany.jpegrenamer.MetaDataReader.java

public Map<String, String> getMetaData(final File jpegImageFile) throws ImageProcessingException, IOException {
    Metadata metadata = ImageMetadataReader.readMetadata(jpegImageFile);
    Map<String, String> res = new HashMap<>();
    res.put("date", "Pinding");
    for (Directory directory : metadata.getDirectories()) {
        for (Tag tag : directory.getTags()) {
            logger.debug("{} - {} = {}", directory.getName(), tag.getTagName(), tag.getDescription());
        }//from   w w w .j a  va  2s .c  o  m
        if (directory.hasErrors()) {
            for (String error : directory.getErrors()) {
                logger.debug("ERROR: {}", error);
            }
        }
    }
    // obtain the Exif directory
    ExifSubIFDDirectory directory = metadata.getFirstDirectoryOfType(ExifSubIFDDirectory.class);
    // query the tag's value
    if (directory == null) {
        return res;
    }
    PanasonicMakernoteDirectory pmd = metadata.getFirstDirectoryOfType(PanasonicMakernoteDirectory.class);
    if (pmd != null) {
        String country = "";
        String city = "";
        String landmark = "";
        for (Tag tag : pmd.getTags()) {

            if (tag.getTagType() == PanasonicMakernoteDirectory.TAG_COUNTRY) {
                country = tag.getDescription();
                if (!country.equals("---")) {
                    res.put("country", country);
                }
            } else if (tag.getTagType() == PanasonicMakernoteDirectory.TAG_CITY) {

                city = tag.getDescription();
                if (!city.equals("---")) {
                    res.put("locality", city);
                }
            } else if (tag.getTagType() == PanasonicMakernoteDirectory.TAG_LANDMARK) {

                landmark = tag.getDescription();
                if (!landmark.equals("---")) {
                    res.put("premise", landmark);
                }
            }
        }
        logger.info("Panasonic fafa " + country + " x " + city + " x " + landmark);
    }

    Date dateOfCapture = directory.getDate(ExifSubIFDDirectory.TAG_DATETIME_ORIGINAL);
    final DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH.mm.ss", Locale.ENGLISH);
    String s = null;
    if (dateOfCapture != null) {
        s = df.format(dateOfCapture);
    } else {
        return res;
    }
    logger.info("Date " + dateOfCapture.toString());
    logger.info("Date f " + s);
    res.put("date", s);

    //        if (res.get("country") != null) {
    //            // We have some data from Panasonic Makernotes, so no need to lookup GPS
    //            return res;
    //        }
    // See whether it has GPS data
    Collection<GpsDirectory> gpsDirectories = metadata.getDirectoriesOfType(GpsDirectory.class);
    if (gpsDirectories == null) {
        return res;
    }
    for (GpsDirectory gpsDirectory : gpsDirectories) {
        // Try to read out the location, making sure it's non-zero
        GeoLocation geoLocation = gpsDirectory.getGeoLocation();
        if (geoLocation != null && !geoLocation.isZero()) {
            // Add to our collection for use below
            logger.info("Geo " + geoLocation.toString());
            double lat = geoLocation.getLatitude();
            double lon = geoLocation.getLongitude();
            Locale fmtLocale = Locale.US;
            NumberFormat formatter = NumberFormat.getNumberInstance(fmtLocale);
            formatter.setGroupingUsed(false);
            Map<String, String> location = new HashMap();
            ;
            try {
                location = getAddressByGpsCoordinates(formatter.format(lat), formatter.format(lon));
                logger.info("Location " + location);
                res.putAll(location);
            } catch (MalformedURLException ex) {
                logger.error("", ex);
            } catch (org.json.simple.parser.ParseException ex) {
                logger.error("", ex);
            }
            break;
        }
    }
    return res;
}

From source file:com.prowidesoftware.swift.model.field.Field130.java

/**
 * Returns a localized suitable for showing to humans string of a field component.<br>
 *
 * @param component number of the component to display
 * @param locale optional locale to format date and amounts, if null, the default locale is used
 * @return formatted component value or null if component number is invalid or not present
 * @throws IllegalArgumentException if component number is invalid for the field
 * @since 7.8/*w w  w . j  a  v a 2 s. c  o m*/
 */
@Override
public String getValueDisplay(int component, Locale locale) {
    if (component < 1 || component > 4) {
        throw new IllegalArgumentException("invalid component number " + component + " for field 130");
    }
    if (locale == null) {
        locale = Locale.getDefault();
    }
    if (component == 1) {
        //number or amount
        java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale);
        Number n = getComponent1AsNumber();
        if (n != null) {
            return f.format(n);
        }
    }
    if (component == 2) {
        //default format (as is)
        return getComponent(2);
    }
    if (component == 3) {
        //number or amount
        java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale);
        Number n = getComponent3AsNumber();
        if (n != null) {
            return f.format(n);
        }
    }
    if (component == 4) {
        //default format (as is)
        return getComponent(4);
    }
    return null;
}