Example usage for java.lang NumberFormatException toString

List of usage examples for java.lang NumberFormatException toString

Introduction

In this page you can find the example usage for java.lang NumberFormatException toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:biz.varkon.shelvesom.provider.tools.ToolsStore.java

private void parsePrices(XmlPullParser parser, Tool tool) throws IOException, XmlPullParserException {

    int type;//from w w  w  .j  a  v  a 2  s.c om
    String name;
    final int depth = parser.getDepth();

    while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth)
            && type != XmlPullParser.END_DOCUMENT) {
        if (type != XmlPullParser.START_TAG) {
            continue;
        }

        name = parser.getName();
        if (RESPONSE_TAG_FORMATTEDPRICE.equals(name)) {
            if (parser.next() == XmlPullParser.TEXT) {
                String price = parser.getText();

                try {
                    if (tool.mRetailPrice == null || (tool.mRetailPrice != null && Double
                            .valueOf(tool.mRetailPrice.substring(1)) > Double.valueOf(price.substring(1)))) {
                        tool.mRetailPrice = price;
                    }
                } catch (NumberFormatException n) {
                    Log.e(LOG_TAG, n.toString());
                    if (tool.mRetailPrice == null)
                        tool.mRetailPrice = "";
                }
            }
        }
    }
}

From source file:ch.dbs.actions.reports.ILVReport.java

/**
 * Get the ILL form number from the wildcard mapping. Defaults to 0, if
 * mapping is invalid.//from  w w w.  j  av a  2 s  . c  o  m
 */
private int getIlvNumber(final String path) {

    int number = 0;

    if (path != null && path.contains("-")) {
        try {
            number = Integer.valueOf(path.substring(path.lastIndexOf('-') + 1, path.length()));
        } catch (final NumberFormatException e) {
            LOG.error(e.toString());
        }
    }

    return number;
}

From source file:biz.varkon.shelvesom.provider.toys.ToysStore.java

private void parsePrices(XmlPullParser parser, Toy toy) throws IOException, XmlPullParserException {

    int type;//w w w  .  ja  v  a 2 s  .c o  m
    String name;
    final int depth = parser.getDepth();

    while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth)
            && type != XmlPullParser.END_DOCUMENT) {
        if (type != XmlPullParser.START_TAG) {
            continue;
        }

        name = parser.getName();
        if (RESPONSE_TAG_FORMATTEDPRICE.equals(name)) {
            if (parser.next() == XmlPullParser.TEXT) {
                String price = parser.getText();

                try {
                    if (toy.mRetailPrice == null || (toy.mRetailPrice != null && Double
                            .valueOf(toy.mRetailPrice.substring(1)) > Double.valueOf(price.substring(1)))) {
                        toy.mRetailPrice = price;
                    }
                } catch (NumberFormatException n) {
                    Log.e(LOG_TAG, n.toString());
                    if (toy.mRetailPrice == null)
                        toy.mRetailPrice = "";
                }
            }
        }
    }
}

From source file:com.funambol.email.content.ContentProviderServlet.java

/**
 * Print a debug page in the response/*from   w  ww  . java 2  s  .c om*/
 * @param request The HttpServletRequest
 * @param response The HttpServletResponse
 * @throws java.io.IOException
 */
private void printDebugPage(HttpServletRequest request, HttpServletResponse response) throws IOException {

    ContentProviderManager contentServiceManager = new ContentProviderManager();

    PrintWriter out = response.getWriter();
    try {
        response.setContentType("text/html;charset=UTF-8");

        out.println("<html>");
        out.println("<head>");
        out.println("<title>Content Provider Errorr</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Servlet AttachmentProvider at " + request.getContextPath() + "</h1>");

        String authToken = request.getParameter(PARAMETER_AUTH);
        if (authToken == null || "".equals(authToken)) {
            out.println("<p>Empty authorization token name received</p>");
            return;
        }

        String username = request.getParameter(PARAMETER_USER);
        if (username == null || "".equals(username)) {
            out.println("<p>Empty user name received</p>");
            return;
        }

        String attachIdx = request.getParameter(PARAMETER_INDEX);
        if (attachIdx == null || "".equals(attachIdx)) {
            out.println("<p>Empty Attachment id received</p>");
            return;
        }
        int attachmentIndex = 0;
        try {
            attachmentIndex = Integer.parseInt(attachIdx);
        } catch (NumberFormatException ex) {
            out.println("<p>NumberFormatException: " + ex.toString() + "</p>");
            return;
        }

        out.println("<p>Authorization token: " + authToken + "</p>");
        out.println("<p>User name: " + username + "</p>");
        out.println("<p>Attachment index: " + attachIdx + "</p>");

        MailServerAccount mailServerAccount = contentServiceManager.retrieveMailServerAccount(username);
        if (mailServerAccount == null) {
            out.println("<p>Unable to retrieve the mail server account for user: " + username + "</p>");
            return;
        }
        out.println("<p>Retrieved mail server account</p>");

        String mailServerProtocol = mailServerAccount.getMailServer().getProtocol();
        if (mailServerProtocol == null || "".equals(mailServerProtocol)) {
            out.println("<p>Invalid mail server protocol</p>");
            return;
        }
        out.println("<p>Mail server protocol: " + mailServerProtocol + "</p>");

        contentServiceManager.openConnection(mailServerAccount);
        out.println("<p>Connection opened</p>");

        String mailGUID = contentServiceManager.authorize(username, authToken);
        if (mailGUID == null) {
            out.println("<p>Request not authorized</p>");
            return;
        }
        String messageid = Utility.getKeyPart(mailGUID, 2);
        if (messageid == null || "".equals(messageid)) {
            out.println("<p>Unable to retrieve the message id from the GUID</p>");
            return;
        }
        out.println("<p>Mail message id: " + messageid + "</p>");

        Message message = contentServiceManager.getMessage(messageid);
        if (message == null) {
            out.println("<p>Unable to retrieve the mail message</p>");
            return;
        }
        out.println("<p>Mail message retrieved</p>");

        List partsList = MessageParser.getAllPartsOfMessage(message, false);
        if (partsList != null && partsList.size() > attachmentIndex) {
            InternalPart part = (InternalPart) partsList.get(attachmentIndex);

            if (part == null || part.getDHandler() == null || part.getDHandler().getInputStream() == null) {
                out.println("<p>Unable to retrieve the mail part</p>");
                return;
            }
        }
    } catch (EmailAccessException ex) {
        out.println("<p>EmailAccessException: " + ex.toString() + "</p>");
    } catch (EntityException ex) {
        out.println("<p>EntityException: ");
        ex.printStackTrace(out);
        out.println("</p>");
    } catch (Exception ex) {
        out.println("<p>Exception: " + ex.toString() + "</p>");
    } catch (Throwable ex) {
        out.println("<p>Throwable: " + ex.toString() + "</p>");
    } finally {
        try {
            contentServiceManager.closeConnection();
        } catch (ContentProviderException ex) {
            out.println("<p>AttachmentException: " + ex.toString() + "</p>");
        }
        out.println("<p>Connection closed</p>");
        out.println("</body>");
        out.println("</html>");
        out.flush();
        out.close();

        //
        // Since the session is not really useful, we force that a request is
        // served by a new session and that a session serves just one request.
        // In such way, we don't have useless sessions. As drawback for every
        // request a new session is created. 
        // Comparing advantages vs drawbacks, we prefer one session - one request.
        //
        request.getSession().invalidate();
    }
}

From source file:biz.varkon.shelvesom.provider.apparel.ApparelStore.java

private void parsePrices(XmlPullParser parser, Apparel apparel) throws IOException, XmlPullParserException {

    int type;//  w ww.  j  a  va 2  s  .c o m
    String name;
    final int depth = parser.getDepth();

    while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth)
            && type != XmlPullParser.END_DOCUMENT) {
        if (type != XmlPullParser.START_TAG) {
            continue;
        }

        name = parser.getName();
        if (RESPONSE_TAG_FORMATTEDPRICE.equals(name)) {
            if (parser.next() == XmlPullParser.TEXT) {
                String price = parser.getText();

                try {
                    if (apparel.mRetailPrice == null || (apparel.mRetailPrice != null && Double
                            .valueOf(apparel.mRetailPrice.substring(1)) > Double.valueOf(price.substring(1)))) {
                        apparel.mRetailPrice = price;
                    }
                } catch (NumberFormatException n) {
                    Log.e(LOG_TAG, n.toString());
                    if (apparel.mRetailPrice == null)
                        apparel.mRetailPrice = "";
                }
            }
        }
    }
}

From source file:biz.varkon.shelvesom.provider.software.SoftwareStore.java

private void parsePrices(XmlPullParser parser, Software software) throws IOException, XmlPullParserException {

    int type;/* w w w  . jav a  2 s. c om*/
    String name;
    final int depth = parser.getDepth();

    while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth)
            && type != XmlPullParser.END_DOCUMENT) {
        if (type != XmlPullParser.START_TAG) {
            continue;
        }

        name = parser.getName();
        if (RESPONSE_TAG_FORMATTEDPRICE.equals(name)) {
            if (parser.next() == XmlPullParser.TEXT) {
                String price = parser.getText();

                try {
                    if (software.mRetailPrice == null || (software.mRetailPrice != null
                            && Double.valueOf(software.mRetailPrice.substring(1)) > Double
                                    .valueOf(price.substring(1)))) {
                        software.mRetailPrice = price;
                    }
                } catch (NumberFormatException n) {
                    Log.e(LOG_TAG, n.toString());
                    if (software.mRetailPrice == null)
                        software.mRetailPrice = "";
                }
            }
        }
    }
}

From source file:biz.varkon.shelvesom.provider.videogames.VideoGamesStore.java

private void parsePrices(XmlPullParser parser, VideoGame videogame) throws IOException, XmlPullParserException {

    int type;//  ww w .  jav  a  2  s. co  m
    String name;
    final int depth = parser.getDepth();

    while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth)
            && type != XmlPullParser.END_DOCUMENT) {
        if (type != XmlPullParser.START_TAG) {
            continue;
        }

        name = parser.getName();
        if (RESPONSE_TAG_FORMATTEDPRICE.equals(name)) {
            if (parser.next() == XmlPullParser.TEXT) {
                String price = parser.getText();

                try {
                    if (videogame.mRetailPrice == null || (videogame.mRetailPrice != null
                            && Double.valueOf(videogame.mRetailPrice.substring(1)) > Double
                                    .valueOf(price.substring(1)))) {
                        videogame.mRetailPrice = price;
                    }
                } catch (NumberFormatException n) {
                    Log.e(LOG_TAG, n.toString());
                    if (videogame.mRetailPrice == null)
                        videogame.mRetailPrice = "";
                }
            }
        }
    }
}

From source file:biz.varkon.shelvesom.provider.music.MusicStore.java

private void parsePrices(XmlPullParser parser, Music music) throws IOException, XmlPullParserException {

    int type;/*from   w w w  .  j  av a  2 s . c  o  m*/
    String name;
    final int depth = parser.getDepth();

    while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth)
            && type != XmlPullParser.END_DOCUMENT) {
        if (type != XmlPullParser.START_TAG) {
            continue;
        }

        name = parser.getName();
        if (RESPONSE_TAG_FORMATTEDPRICE.equals(name)) {
            if (parser.next() == XmlPullParser.TEXT) {
                String price = parser.getText();

                try {
                    if (music.mRetailPrice == null || (music.mRetailPrice != null && Double
                            .valueOf(music.mRetailPrice.substring(1)) > Double.valueOf(price.substring(1)))) {
                        music.mRetailPrice = price;
                    }
                } catch (NumberFormatException n) {
                    Log.e(LOG_TAG, n.toString());
                    if (music.mRetailPrice == null)
                        music.mRetailPrice = "";
                }
            }
        }
    }
}

From source file:com.deafgoat.ml.prognosticator.Charter.java

/**
 * Creates data set containing categorical attributes along with prediction
 * confidence//from  w ww  .  ja v  a2  s.co  m
 * 
 * @param files
 *            List of files containing predictions to chart
 * @return the series collection to chart
 */
private DefaultCategoryDataset createCategoricalDataset(String[] files) {
    _logger.info("Collating data");
    BufferedReader br = null;
    // final XYSeriesCollection dataset = new XYSeriesCollection();
    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    XYSeries prediction = null;
    for (String dataFile : files) {
        try {
            String sCurrentLine;
            prediction = new XYSeries(dataFile);
            br = new BufferedReader(new FileReader(dataFile));
            HashMap<String, Double> avgConfidence = new HashMap<String, Double>();
            HashMap<String, Integer> valueCount = new HashMap<String, Integer>();
            while ((sCurrentLine = br.readLine()) != null) {
                String[] data = sCurrentLine.split("\t");
                try {
                    if (avgConfidence.containsKey(data[0])) {
                        avgConfidence.put(data[0], avgConfidence.get(data[0]) + Double.parseDouble(data[1]));
                        valueCount.put(data[0], valueCount.get(data[0]) + 1);
                    } else {
                        avgConfidence.put(data[0], Double.parseDouble(data[1]));
                        valueCount.put(data[0], 1);
                    }
                } catch (NumberFormatException e) {
                    continue;
                }
            }
            for (Entry<String, Double> entry : avgConfidence.entrySet()) {
                dataset.addValue(entry.getValue() / valueCount.get(entry.getKey()), entry.getKey(), dataFile);
            }
        } catch (IOException e) {
            _logger.error(e.toString());
        } finally {
            try {
                if (br != null) {
                    br.close();
                }
            } catch (IOException e) {
                _logger.error(e.toString());
            }
        }
        if (prediction != null) {
            // dataset.addSeries(prediction);
        }
    }
    return dataset;
}

From source file:com.orange.datavenue.ValueFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {

    case R.id.action_add_value:
        /**//from   www  .  j  a  va  2s. c  o  m
         * Add value
         */
        mDialog = new android.app.Dialog(getActivity());
        mDialog.setContentView(R.layout.create_value_dialog);
        mDialog.setTitle(R.string.add_value);

        final EditText at = (EditText) mDialog.findViewById(R.id.at);
        final EditText metadata = (EditText) mDialog.findViewById(R.id.metadata);
        final EditText latitude = (EditText) mDialog.findViewById(R.id.latitude);
        final EditText longitude = (EditText) mDialog.findViewById(R.id.longitude);
        final EditText value = (EditText) mDialog.findViewById(R.id.value);

        SimpleDateFormat ISO8601DATEFORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
        Date now = new Date();
        at.setText(ISO8601DATEFORMAT.format(now));

        Button addButton = (Button) mDialog.findViewById(R.id.add_button);
        addButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.d(TAG_NAME, "at : " + at.getText().toString());
                Log.d(TAG_NAME, "metadata : " + metadata.getText().toString());
                Log.d(TAG_NAME, "value : " + value.getText().toString());

                Value newValue = new Value();
                newValue.setAt(at.getText().toString());

                Double[] location = null;

                String strLatitude = latitude.getText().toString();
                String strLongitude = longitude.getText().toString();

                try {
                    if ((!"".equals(strLatitude)) && (!"".equals(strLongitude))) {
                        location = new Double[2];
                        location[0] = Double.parseDouble(strLatitude);
                        location[1] = Double.parseDouble(strLongitude);
                    }
                } catch (NumberFormatException e) {
                    Log.e(TAG_NAME, e.toString());
                    location = null;
                }

                newValue.setLocation(location);

                if (!"".equals(value.getText().toString())) {

                    try {
                        JSONObject valueJson = (JSONObject) new JSONParser().parse(value.getText().toString());
                        newValue.setValue(valueJson);
                    } catch (ParseException e) {
                        Log.e(TAG_NAME, e.toString());
                        newValue.setValue(value.getText().toString());
                    } catch (ClassCastException ce) {
                        Log.e(TAG_NAME, ce.toString());
                        newValue.setValue(value.getText().toString());
                    }

                } else {
                    newValue.setValue(null);
                }

                if (!"".equals(metadata.getText().toString())) {

                    try {
                        JSONObject metadataJson = (JSONObject) new JSONParser()
                                .parse(metadata.getText().toString());
                        newValue.setMetadata(metadataJson);
                    } catch (ParseException e) {
                        Log.e(TAG_NAME, e.toString());
                        newValue.setMetadata(metadata.getText().toString());
                    } catch (ClassCastException ce) {
                        Log.e(TAG_NAME, ce.toString());
                        newValue.setMetadata(metadata.getText().toString());
                    }

                } else {
                    newValue.setMetadata(null);
                }

                CreateValueOperation createValueOperation = new CreateValueOperation(Model.instance.oapiKey,
                        Model.instance.key, Model.instance.currentDatasource, Model.instance.currentStream,
                        newValue, new OperationCallback() {
                            @Override
                            public void process(Object object, Exception exception) {
                                if (exception == null) {
                                    mPageNumber = 1;
                                    getValues(mPageNumber, true);
                                } else {
                                    Errors.displayError(getActivity(), exception);
                                }
                            }
                        });

                createValueOperation.execute("");

                mDialog.dismiss();
            }
        });

        Button cancelButton = (Button) mDialog.findViewById(R.id.cancel_button);
        cancelButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mDialog.dismiss();
            }
        });

        mDialog.setCancelable(false);
        mDialog.show();
        return true;
    case R.id.action_add_sensor_sensor:
        /**
         * Geolocation
         */
        mDialog = new android.app.Dialog(getActivity());

        mDialog.setContentView(R.layout.add_sensor_value_dialog);
        mDialog.setTitle(R.string.geolocation);

        llInfo = (LinearLayout) mDialog.findViewById(R.id.info);
        llValue = (LinearLayout) mDialog.findViewById(R.id.value);
        llValue.setVisibility(View.GONE);
        tvLatitude = (TextView) mDialog.findViewById(R.id.latitude);
        tvLongitude = (TextView) mDialog.findViewById(R.id.longitude);

        if (mLocationService != null) {
            mLocationService.setServiceParameters(Model.instance.oapiKey, Model.instance.key,
                    Model.instance.currentDatasource, Model.instance.currentStream);
            mLocationService.register(this);
            mLocationService.start();
        }

        Button cButton = (Button) mDialog.findViewById(R.id.cancel_button);
        cButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                if (mLocationService != null) {
                    mLocationService.stop();
                }

                tvLatitude = null;
                tvLongitude = null;

                mDialog.dismiss();
            }
        });
        mDialog.setCancelable(false);
        mDialog.show();
        return true;
    default:
        break;
    }

    return false;
}