Example usage for java.text ParseException getMessage

List of usage examples for java.text ParseException getMessage

Introduction

In this page you can find the example usage for java.text ParseException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:Main.java

/**
 * Convert a string number into a double value
 *
 * @param text the text to be converted to number
 * @return the double value/*w  w w  .  ja v  a  2  s  .  c o m*/
 */
private static double stringToDouble(String text) {

    text = text.replaceAll(",", ".");
    NumberFormat nf = NumberFormat.getInstance(Locale.US);
    try {
        return nf.parse(text).doubleValue();
    } catch (ParseException e) {
        Log.e(TAG, e.getMessage(), e);
        return 0.0;
    }
}

From source file:Main.java

/**
 * Get a Date object corresponding to the provided ISO 8601 string
 *
 * @param date the date string/*from w w  w.  ja v a2 s .c  o  m*/
 * @return a Date object corresponding to the provided ISO 8601 string, or null
 * if the string cannot be parsed.
 */
public static Date getDateFromIso8601String(String date) {
    initFormatter();
    try {
        return mIso8601WithMillisFormat.parse(date);
    } catch (ParseException e) {
        try {
            return mIso8601Format.parse(date);
        } catch (ParseException e1) {
            Log.e(TAG, e1.getMessage(), e1);
        }
    }
    return null;
}

From source file:org.artifactory.cron.CronUtils.java

/**
 * Returns a String value representing the validity message given invalid Cron Expression
 *
 * @param cronExpression A Cron Expression
 * @return String - the invalid message returned when expression is not valid, or null if valid
 *///from  ww w  . j  a v  a 2  s  .com
public static @Nullable String getInvalidMessage(String cronExpression) {
    try {
        new CronExpression(cronExpression);
        return null;
    } catch (ParseException pe) {
        return pe.getMessage();
    }
}

From source file:HtmlDimensions.java

public static Double decode(String size) {
    // TODO - handle px,ex,pt enc suffixes.
    double d = 0;
    try {/*from   w w  w  . j a  va2  s.c o m*/
        if (size != null) {
            if (PATTERN_NUMERIC.matcher(size).matches()) {
                synchronized (numericFormat) {
                    d = numericFormat.parse(size).doubleValue();
                }
            } else if (PATTERN_PX.matcher(size).matches()) {
                synchronized (pxFormat) {
                    d = pxFormat.parse(size).doubleValue();
                }
            } else if (PATTERN_PCT.matcher(size).matches()) {
                synchronized (pctFormat) {
                    d = pctFormat.parse(size).doubleValue();
                }
            }
        }
    } catch (ParseException e) {
        throw new IllegalArgumentException(e.getMessage());
    }
    return new Double(d);
}

From source file:org.artifactory.cron.CronUtils.java

/**
 * Returns the next execution time based on the given Cron Expression
 *
 * @param cronExpression A Cron Expression
 * @return Date - The next time the given Cron Expression should fire
 *//*from w w  w .  ja  v  a  2  s. co  m*/
public static Date getNextExecution(String cronExpression) {
    try {
        CronExpression cron = new CronExpression(cronExpression);
        return cron.getNextValidTimeAfter(new Date(System.currentTimeMillis()));
    } catch (ParseException e) {
        throw new IllegalArgumentException(e.getMessage());
    }
}

From source file:architecture.common.license.LicenseManager.java

public static Date getDateProperty(String property, License license) {
    Date d = null;/*from  w  w w. j  av a  2s . c  om*/

    String dataString = (String) license.getProperties().get(property);
    if (dataString != null)
        try {
            d = dateFormat.parse(dataString);
        } catch (ParseException e) {
            log.fatal(e.getMessage(), e);
        }
    return d;
}

From source file:org.artifactory.cron.CronUtils.java

/**
 * Checks if the given cron expression interval is less or equals to a certain minimum.
 *
 * @param cronExpression the cron expression to check
 *///from   ww  w .  j  a  v a2s  . c  om
public static boolean isCronIntervalLessThanMinimum(String cronExpression) {
    try {
        // If input is empty or invalid simply return false as default
        if (StringUtils.isBlank(cronExpression) || !isValid(cronExpression)) {
            return false;
        }

        CronExpression cron = new CronExpression(cronExpression);
        final Date firstExecution = cron.getNextValidTimeAfter(new Date(System.currentTimeMillis()));
        final Date secondExecution = cron.getNextValidTimeAfter(firstExecution);

        Minutes intervalMinutes = Minutes.minutesBetween(new DateTime(firstExecution),
                new DateTime(secondExecution));
        return !intervalMinutes.isGreaterThan(MINIMUM_ALLOWED_MINUTES);
    } catch (ParseException e) {
        throw new IllegalArgumentException(e.getMessage());
    }
}

From source file:de.micromata.genome.gdbfs.FsDateFormat.java

/**
 * convert Stringified date to internal Date
 * /*w ww. j a  v a2  s  .  c om*/
 * Todo use utc.
 *
 * @param date the date
 * @return the date
 */
public static Date string2date(String date) {
    if (StringUtils.isEmpty(date) == true) {
        return null;
    }
    try {
        Date ld = internalTimestamp.get().parse(date);
        return ld;
    } catch (ParseException ex) {
        throw new RuntimeException("Cannot parse date: " + date + "; " + ex.getMessage(), ex);

    }
}

From source file:gov.nasa.jpl.analytics.util.CommonUtil.java

public static String formatTimestamp(String sdate) {
    if (SIMPLE_DATE_FORMAT) {
        String timestamp = null;/*from  w  w w.  j a v  a  2 s .c  o m*/
        try {
            long epoch = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss z").parse(ifNullString(sdate))
                    .getTime();
            timestamp = String.valueOf(epoch);
        } catch (ParseException pe) {
            LOG.warn(pe.getMessage());
        }
        return timestamp;
    } else {
        return ifNullString(sdate);
    }
}

From source file:org.gbif.portal.web.util.DateUtil.java

/**
 * Construct a date//from w  w w .jav  a 2  s. c om
 * @param request
 * @param dateFieldName
 * @return
 */
public static Date getDateFromRequest(HttpServletRequest request, String dateFieldName) {

    String day = request.getParameter(dateFieldName + "_day");
    String month = request.getParameter(dateFieldName + "_month");
    String year = request.getParameter(dateFieldName + "_year");
    request.setAttribute(dateFieldName + "_day", day);
    request.setAttribute(dateFieldName + "_month", month);
    request.setAttribute(dateFieldName + "_year", year);

    if (day == null || month == null && year == null)
        return null;

    try {
        return DateUtils.parseDate(day + month + year, new String[] { "ddMMyyyy" });
    } catch (ParseException e) {
        log.trace(e.getMessage(), e);
    }
    return null;
}