Example usage for java.lang NumberFormatException getMessage

List of usage examples for java.lang NumberFormatException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:net.di2e.ecdr.commons.query.CDRQueryImpl.java

protected void populateCount(MultivaluedMap<String, String> queryParameters) throws UnsupportedQueryException {
    String stringCount = queryParameters.getFirst(SearchConstants.COUNT_PARAMETER);
    count = queryCriteria.getQueryConfiguration().getDefaultCount();
    LOGGER.debug("Attempting to set 'count' value from request [{}] to int", stringCount);
    if (StringUtils.isNotBlank(stringCount)) {
        try {// www  . j  a va 2s.  c  o m
            count = Integer.parseInt(stringCount);
            if (count <= 0) {
                throw new UnsupportedQueryException("The [" + SearchConstants.COUNT_PARAMETER
                        + "] parameter cannot be less than 0 and was [" + stringCount + "]");
            }
        } catch (NumberFormatException e) {
            String message = "Invalid Number found for 'count' [" + stringCount + "].  Resulted in exception: "
                    + e.getMessage();
            LOGGER.warn(message);
            throw new UnsupportedQueryException(message);
        }
    } else {
        LOGGER.debug("'count' parameter was not specified, defaulting value to [{}]", count);
    }
}

From source file:net.di2e.ecdr.commons.query.CDRQueryImpl.java

protected void populateTimeoutMilliseconds(MultivaluedMap<String, String> queryParameters)
        throws UnsupportedQueryException {
    String timeout = queryParameters.getFirst(SearchConstants.TIMEOUT_PARAMETER);
    timeoutMilliseconds = queryCriteria.getQueryConfiguration().getDefaultTimeoutMillis();
    LOGGER.debug("Attempting to set 'timeout' value from request [" + timeout + "] to long");
    if (StringUtils.isNotBlank(timeout)) {
        try {/*from   www.jav a  2 s.  c  o m*/
            timeoutMilliseconds = Long.parseLong(timeout);
            if (timeoutMilliseconds <= 0) {
                throw new UnsupportedQueryException("The [" + SearchConstants.TIMEOUT_PARAMETER
                        + "] parameter cannot nbe less than 0 and was [" + timeout + "]");
            }
        } catch (NumberFormatException e) {
            String message = "Invalid Number found for 'timeout' [" + timeout + "].  Resulted in exception: "
                    + e.getMessage();
            LOGGER.warn(message);
            if (isStrictMode) {
                throw new UnsupportedQueryException(message);
            }
        }
    } else {
        LOGGER.debug("'timeout' parameter was not specified, defaulting value to [{}]", timeout);
    }

}

From source file:net.di2e.ecdr.commons.query.CDRQueryImpl.java

protected void populateStartIndex(MultivaluedMap<String, String> queryParameters)
        throws UnsupportedQueryException {
    String indexString = queryParameters.getFirst(SearchConstants.STARTINDEX_PARAMETER);
    int index = 1;
    LOGGER.debug("Attempting to set 'startIndex' value from request [{}] to int", indexString);
    if (StringUtils.isNotBlank(indexString)) {
        try {//from   w ww .  j a va  2  s . com
            index = Integer.parseInt(indexString);
        } catch (NumberFormatException e) {
            String message = "Invalid Number found for 'startIndex' [" + indexString
                    + "].  Resulted in exception: " + e.getMessage();
            LOGGER.warn(message);
            throw new UnsupportedQueryException(message);
        }
    } else {
        LOGGER.debug("'startIndex' parameter was not specified, defaulting value to [{}]", index);
    }
    startIndex = index < 1 ? 1 : index;
}

From source file:edu.cornell.mannlib.vitro.webapp.visualization.personpubcount.PersonPublicationCountVisCodeGenerator.java

/**
 * This method is used to setup parameters for the sparkline value object. These parameters
 * will be used in the template to construct the actual html/javascript code.
 * @param visMode/*from   w w  w  .ja  va2 s  .  c  om*/
 * @param visContainer
 * @return 
 */
private SparklineData setupSparklineParameters(String visMode, String providedVisContainerID) {

    SparklineData sparklineData = new SparklineData();
    sparklineData.setYearToActivityCount(yearToPublicationCount);

    int numOfYearsToBeRendered = 0;

    /*
     * It was decided that to prevent downward curve that happens if there are no publications 
     * in the current year seems a bit harsh, so we consider only publications from the last 10
     * complete years. 
     * */
    int currentYear = Calendar.getInstance().get(Calendar.YEAR) - 1;
    int shortSparkMinYear = currentYear - VisConstants.MINIMUM_YEARS_CONSIDERED_FOR_SPARKLINE + 1;

    /*
     * This is required because when deciding the range of years over which the vis
     * was rendered we dont want to be influenced by the "DEFAULT_PUBLICATION_YEAR".
     * */
    Set<String> publishedYears = new HashSet<String>(yearToPublicationCount.keySet());
    publishedYears.remove(VOConstants.DEFAULT_PUBLICATION_YEAR);

    /*
     * We are setting the default value of minPublishedYear to be 10 years before 
     * the current year (which is suitably represented by the shortSparkMinYear),
     * this in case we run into invalid set of published years.
     * */
    int minPublishedYear = shortSparkMinYear;

    String visContainerID = null;

    if (yearToPublicationCount.size() > 0) {
        try {
            minPublishedYear = Integer.parseInt(Collections.min(publishedYears));
        } catch (NoSuchElementException e1) {
            log.debug("vis: " + e1.getMessage() + " error occurred for " + yearToPublicationCount.toString());
        } catch (NumberFormatException e2) {
            log.debug("vis: " + e2.getMessage() + " error occurred for " + yearToPublicationCount.toString());
        }
    }

    int minPubYearConsidered = 0;

    /*
     * There might be a case that the author has made his first publication within the 
     * last 10 years but we want to make sure that the sparkline is representative of 
     * at least the last 10 years, so we will set the minPubYearConsidered to 
     * "currentYear - 10" which is also given by "shortSparkMinYear".
     * */
    if (minPublishedYear > shortSparkMinYear) {
        minPubYearConsidered = shortSparkMinYear;
    } else {
        minPubYearConsidered = minPublishedYear;
    }

    numOfYearsToBeRendered = currentYear - minPubYearConsidered + 1;

    sparklineData.setNumOfYearsToBeRendered(numOfYearsToBeRendered);

    int publicationCounter = 0;

    /*
     * For the purpose of this visualization I have come up with a term "Sparks" which 
     * essentially means data points. 
     * Sparks that will be rendered in full mode will always be the one's which have any year
     * associated with it. Hence.
     * */
    int renderedFullSparks = 0;

    List<YearToEntityCountDataElement> yearToPublicationCountDataTable = new ArrayList<YearToEntityCountDataElement>();

    for (int publicationYear = minPubYearConsidered; publicationYear <= currentYear; publicationYear++) {

        String stringPublishedYear = String.valueOf(publicationYear);
        Integer currentPublications = yearToPublicationCount.get(stringPublishedYear);

        if (currentPublications == null) {
            currentPublications = 0;
        }

        yearToPublicationCountDataTable.add(
                new YearToEntityCountDataElement(publicationCounter, stringPublishedYear, currentPublications));

        /*
         * Sparks that will be rendered will always be the one's which has 
         * any year associated with it. Hence.
         * */
        renderedFullSparks += currentPublications;
        publicationCounter++;
    }

    sparklineData.setYearToEntityCountDataTable(yearToPublicationCountDataTable);
    sparklineData.setRenderedSparks(renderedFullSparks);

    /*
     * Total publications will also consider publications that have no year associated with
     * it. Hence.
     * */
    Integer unknownYearPublications = 0;
    if (yearToPublicationCount.get(VOConstants.DEFAULT_PUBLICATION_YEAR) != null) {
        unknownYearPublications = yearToPublicationCount.get(VOConstants.DEFAULT_PUBLICATION_YEAR);
    }

    sparklineData.setUnknownYearPublications(unknownYearPublications);

    if (providedVisContainerID != null) {
        visContainerID = providedVisContainerID;
    } else {
        visContainerID = DEFAULT_VIS_CONTAINER_DIV_ID;
    }

    sparklineData.setVisContainerDivID(visContainerID);

    /*
     * By default these represents the range of the rendered sparks. Only in case of
     * "short" sparkline mode we will set the Earliest RenderedPublication year to
     * "currentYear - 10". 
     * */
    sparklineData.setEarliestYearConsidered(minPubYearConsidered);
    sparklineData.setEarliestRenderedPublicationYear(minPublishedYear);
    sparklineData.setLatestRenderedPublicationYear(currentYear);

    if (yearToPublicationCount.size() > 0) {

        sparklineData.setFullTimelineNetworkLink(UtilityFunctions.getCollaboratorshipNetworkLink(individualURI,
                VisualizationFrameworkConstants.PERSON_LEVEL_VIS,
                VisualizationFrameworkConstants.COAUTHOR_VIS_MODE));

        sparklineData.setDownloadDataLink(UtilityFunctions.getCSVDownloadURL(individualURI,
                VisualizationFrameworkConstants.PERSON_PUBLICATION_COUNT_VIS, ""));
    }

    /*
     * The Full Sparkline will be rendered by default. Only if the url has specific mention of
     * SHORT_SPARKLINE_MODE_URL_HANDLE then we render the short sparkline and not otherwise.
     * */
    if (VisualizationFrameworkConstants.SHORT_SPARKLINE_VIS_MODE.equalsIgnoreCase(visMode)) {

        sparklineData.setEarliestRenderedPublicationYear(shortSparkMinYear);
        sparklineData.setShortVisMode(true);

    } else {
        sparklineData.setShortVisMode(false);
    }

    return sparklineData;
}

From source file:net.solarnetwork.node.weather.nz.metservice.MetserviceSupport.java

/**
 * Parse a FLoat from an attribute value.
 * /*w  w  w . j a  va  2 s .c  o  m*/
 * <p>
 * If the Float cannot be parsed, <em>null</em> will be returned.
 * </p>
 * 
 * @param key
 *        the attribute key to obtain from the {@code data} node
 * @param data
 *        the attributes
 * @return the parsed {@link Float}, or <em>null</em> if an error occurs or
 *         the specified attribute {@code key} is not available
 */
protected Float parseFloatAttribute(String key, JsonNode data) {
    Float num = null;
    if (data != null) {
        JsonNode node = data.get(key);
        if (node != null) {
            try {
                num = Float.valueOf(node.asText());
            } catch (NumberFormatException e) {
                log.debug("Error parsing float attribute [{}] value [{}]: {}",
                        new Object[] { key, data.get(key), e.getMessage() });
            }
        }
    }
    return num;
}

From source file:net.solarnetwork.node.weather.nz.metservice.MetserviceSupport.java

/**
 * Parse a Double from an attribute value.
 * /* www. ja  v  a  2  s  .c  om*/
 * <p>
 * If the Double cannot be parsed, <em>null</em> will be returned.
 * </p>
 * 
 * @param key
 *        the attribute key to obtain from the {@code data} Map
 * @param data
 *        the attributes
 * @return the parsed {@link Double}, or <em>null</em> if an error occurs or
 *         the specified attribute {@code key} is not available
 */
protected Double parseDoubleAttribute(String key, JsonNode data) {
    Double num = null;
    if (data != null) {
        JsonNode node = data.get(key);
        if (node != null) {
            try {
                num = Double.valueOf(node.asText());
            } catch (NumberFormatException e) {
                log.debug("Error parsing double attribute [{}] value [{}]: {}",
                        new Object[] { key, data.get(key), e.getMessage() });
            }
        }
    }
    return num;
}

From source file:net.solarnetwork.node.weather.nz.metservice.MetserviceSupport.java

/**
 * Parse a Integer from an attribute value.
 * //from  w w w . j a v  a2  s  . c om
 * <p>
 * If the Integer cannot be parsed, <em>null</em> will be returned.
 * </p>
 * 
 * @param key
 *        the attribute key to obtain from the {@code data} node
 * @param data
 *        the attributes
 * @return the parsed {@link Integer}, or <em>null</em> if an error occurs
 *         or the specified attribute {@code key} is not available
 */
protected Integer parseIntegerAttribute(String key, JsonNode data) {
    Integer num = null;
    if (data != null) {
        JsonNode node = data.get(key);
        if (node != null) {
            try {
                num = Integer.valueOf(node.asText());
            } catch (NumberFormatException e) {
                log.debug("Error parsing integer attribute [{}] value [{}]: {}",
                        new Object[] { key, data.get(key), e.getMessage() });
            }
        }
    }
    return num;
}

From source file:com.boxupp.dao.ProjectDAOManager.java

public <E> List<E> retireveProjectsForUser(String UserID) {
    List<ProjectBean> projectList = new ArrayList<ProjectBean>();
    try {//from w w w. ja  v a  2 s  .co  m

        List<UserProjectMapping> users = userProjectMappingDao.queryForAll();
        userProjectsQuery.setArgumentHolderValue(0,
                UserDAOManager.getInstance().userDetailDao.queryForId(Integer.parseInt(UserID)));
        projectList = projectDao.query(userProjectsQuery);

    } catch (NumberFormatException e) {
        logger.error("Error parsing user ID : " + e.getMessage());
    } catch (SQLException e) {
        logger.error("Error fetching projects for user " + UserID + " : " + e.getMessage());
    }
    return (List<E>) projectList;
}

From source file:com.boxupp.dao.ProjectDAOManager.java

public <E> List<E> retireveAllModules() {
    List<PuppetModuleBean> puppetModuleList = new ArrayList<PuppetModuleBean>();
    try {/*from   w w w.  jav  a2 s . c  o m*/
        puppetModuleList = PuppetModuleDAOManager.getInstance().puppetModuleDao.queryForEq("isDisabled", false);
    } catch (NumberFormatException e) {
        logger.error("Error in retireveing module :" + e.getMessage());
    } catch (SQLException e) {
        logger.error("Error in retireveing module :" + e.getMessage());
    }
    return (List<E>) puppetModuleList;
}

From source file:edu.cornell.mannlib.vitro.webapp.visualization.persongrantcount.PersonGrantCountVisCodeGenerator.java

/**
 * This method is used to setup parameters for the sparkline value object. These parameters
 * will be used in the template to construct the actual html/javascript code.
 * @param visMode/*from   w  ww  .  j  a v  a2  s.c  om*/
 * @param visContainer
 * @param authorDocuments
 * @return 
 */
private SparklineData setupSparklineParameters(String visMode, String providedVisContainerID) {

    SparklineData sparklineData = new SparklineData();
    sparklineData.setYearToActivityCount(yearToGrantCount);

    int numOfYearsToBeRendered = 0;

    /*
     * It was decided that to prevent downward curve that happens if there are no publications 
     * in the current year seems a bit harsh, so we consider only publications from the last 10
     * complete years. 
     * */
    int currentYear = Calendar.getInstance().get(Calendar.YEAR) - 1;
    int shortSparkMinYear = currentYear - VisConstants.MINIMUM_YEARS_CONSIDERED_FOR_SPARKLINE + 1;

    /*
     * This is required because when deciding the range of years over which
     * the vis was rendered we dont want to be influenced by the
     * "DEFAULT_GRANT_YEAR".
     */
    Set<String> grantYears = new HashSet<String>(yearToGrantCount.keySet());
    grantYears.remove(VOConstants.DEFAULT_GRANT_YEAR);

    /*
     * We are setting the default value of minGrantYear to be 10 years
     * before the current year (which is suitably represented by the
     * shortSparkMinYear), this in case we run into invalid set of grant
     * years.
     */
    int minGrantYear = shortSparkMinYear;

    String visContainerID = null;

    if (yearToGrantCount.size() > 0) {
        try {
            minGrantYear = Integer.parseInt(Collections.min(grantYears));
        } catch (NoSuchElementException e1) {
            log.debug("vis: " + e1.getMessage() + " error occurred for " + yearToGrantCount.toString());
        } catch (NumberFormatException e2) {
            log.debug("vis: " + e2.getMessage() + " error occurred for " + yearToGrantCount.toString());
        }
    }

    int minGrantYearConsidered = 0;

    /*
     * There might be a case that the author investigated his first grant
     * within the last 10 years but we want to make sure that the sparkline
     * is representative of at least the last 10 years, so we will set the
     * minGrantYearConsidered to "currentYear - 10" which is also given by
     * "shortSparkMinYear".
     */
    if (minGrantYear > shortSparkMinYear) {
        minGrantYearConsidered = shortSparkMinYear;
    } else {
        minGrantYearConsidered = minGrantYear;
    }

    numOfYearsToBeRendered = currentYear - minGrantYearConsidered + 1;

    sparklineData.setNumOfYearsToBeRendered(numOfYearsToBeRendered);

    int grantCounter = 0;

    /*
     * For the purpose of this visualization I have come up with a term
     * "Sparks" which essentially means data points. Sparks that will be
     * rendered in full mode will always be the one's which have any year
     * associated with it. Hence.
     */
    int renderedFullSparks = 0;

    List<YearToEntityCountDataElement> yearToGrantCountDataTable = new ArrayList<YearToEntityCountDataElement>();

    for (int grantYear = minGrantYearConsidered; grantYear <= currentYear; grantYear++) {

        String stringInvestigatedYear = String.valueOf(grantYear);
        Integer currentGrants = yearToGrantCount.get(stringInvestigatedYear);

        if (currentGrants == null) {
            currentGrants = 0;
        }

        yearToGrantCountDataTable
                .add(new YearToEntityCountDataElement(grantCounter, stringInvestigatedYear, currentGrants));

        /*
         * Sparks that will be rendered will always be the one's which has
         * any year associated with it. Hence.
         */
        renderedFullSparks += currentGrants;
        grantCounter++;

    }

    sparklineData.setYearToEntityCountDataTable(yearToGrantCountDataTable);
    sparklineData.setRenderedSparks(renderedFullSparks);

    /*
     * Total grants will also consider grants that have no year
     * associated with it. Hence.
     */
    Integer unknownYearGrants = 0;
    if (yearToGrantCount.get(VOConstants.DEFAULT_GRANT_YEAR) != null) {
        unknownYearGrants = yearToGrantCount.get(VOConstants.DEFAULT_GRANT_YEAR);
    }

    sparklineData.setUnknownYearGrants(unknownYearGrants);

    if (providedVisContainerID != null) {
        visContainerID = providedVisContainerID;
    } else {
        visContainerID = DEFAULT_VIS_CONTAINER_DIV_ID;
    }

    sparklineData.setVisContainerDivID(visContainerID);

    /*
     * By default these represents the range of the rendered sparks. Only in
     * case of "short" sparkline mode we will set the Earliest
     * RenderedGrant year to "currentYear - 10".
     */
    sparklineData.setEarliestYearConsidered(minGrantYearConsidered);
    sparklineData.setEarliestRenderedGrantYear(minGrantYear);
    sparklineData.setLatestRenderedGrantYear(currentYear);

    /*
     * The Full Sparkline will be rendered by default. Only if the url has
     * specific mention of SHORT_SPARKLINE_MODE_URL_HANDLE then we render
     * the short sparkline and not otherwise.
     */
    if (VisualizationFrameworkConstants.SHORT_SPARKLINE_VIS_MODE.equalsIgnoreCase(visMode)) {

        sparklineData.setEarliestRenderedGrantYear(shortSparkMinYear);
        sparklineData.setShortVisMode(true);

    } else {
        sparklineData.setShortVisMode(false);
    }

    if (yearToGrantCount.size() > 0) {

        sparklineData.setFullTimelineNetworkLink(UtilityFunctions.getCollaboratorshipNetworkLink(individualURI,
                VisualizationFrameworkConstants.PERSON_LEVEL_VIS,
                VisualizationFrameworkConstants.COPI_VIS_MODE));

        sparklineData.setDownloadDataLink(UtilityFunctions.getCSVDownloadURL(individualURI,
                VisualizationFrameworkConstants.PERSON_GRANT_COUNT_VIS, ""));
    }
    return sparklineData;
}