}
}
- protected static Date getDateFromStringByParameters(String x, String inputDateFormat, Locale inputLocale, TimeZone inputTimeZone) throws MFormatConversionException {
+ protected static Date getDateFromStringByParameters(String x, String inputDateFormat, Locale inputLocale, TimeZone inputTimeZone) throws MInvalidConversionFormatException {
if (MText.isBlank(x)) {
throw new IllegalArgumentException("Invalid 'x': null or empty.");
}
d1 = sdf.parse(x);
}
catch (ParseException exception) {
- throw new MFormatConversionException(String.format("Invalid 'x' or parsing: %s (input format: %s).", x, inputDateFormat)); // no need to propagate exception
+ throw new MInvalidConversionFormatException(String.format("Invalid 'x' or parsing: %s (input format: %s).", x, inputDateFormat)); // no need to propagate exception
}
Calendar c2 = Calendar.getInstance(inputTimeZone, inputLocale);
c2.clear();
c2.set(Calendar.SECOND, c1.get(Calendar.SECOND));
Date d2 = c2.getTime();
if (!x.equals(sdf.format(d2))) {
- throw new MFormatConversionException(String.format("Invalid 'x' or parsing: %s (input format: %s).", x, inputDateFormat));
+ throw new MInvalidConversionFormatException(String.format("Invalid 'x' or parsing: %s (input format: %s).", x, inputDateFormat));
}
return d2;
}
return sdf.format(date);
}
- public Date getDateFromString(String x) throws MFormatConversionException {
+ public Date getDateFromString(String x) throws MInvalidConversionFormatException {
Date y = null;
for (String dateFormat: this.getDateFormatsReference()) {
try {
y = this.getDateFromStringByParameters(x, dateFormat, this.getLocale(), this.getTimeZoneReference());
return y;
}
- catch (MFormatConversionException exception) {
+ catch (MInvalidConversionFormatException exception) {
}
}
if (null == y) {
- throw new MFormatConversionException(String.format("Invalid 'x': %s.", x));
+ throw new MInvalidConversionFormatException(String.format("Invalid 'x': %s.", x));
}
return y; // necessary to avoid Java compilation errors
}
+++ /dev/null
-/**
- * Macaco
- * Copyright (c) 2009-2015 Marco Zanon <info@marcozanon.com>.
- * Released under MIT license (see LICENSE for details).
- */
-
-package com.marcozanon.macaco.conversion;
-
-@SuppressWarnings("serial")
-public class MFormatConversionException extends MConversionException {
-
- /* */
-
- public MFormatConversionException() {
- super();
- }
-
- public MFormatConversionException(String message) {
- super(message);
- }
-
- public MFormatConversionException(Throwable error) {
- super(error);
- }
-
- public MFormatConversionException(String message, Throwable error) {
- super(message, error);
- }
-
-}
--- /dev/null
+/**
+ * Macaco
+ * Copyright (c) 2009-2015 Marco Zanon <info@marcozanon.com>.
+ * Released under MIT license (see LICENSE for details).
+ */
+
+package com.marcozanon.macaco.conversion;
+
+@SuppressWarnings("serial")
+public class MInvalidConversionFormatException extends MConversionException {
+
+ /* */
+
+ public MInvalidConversionFormatException() {
+ super();
+ }
+
+ public MInvalidConversionFormatException(String message) {
+ super(message);
+ }
+
+ public MInvalidConversionFormatException(Throwable error) {
+ super(error);
+ }
+
+ public MInvalidConversionFormatException(String message, Throwable error) {
+ super(message, error);
+ }
+
+}
}
}
- protected static BigDecimal getNumberFromStringByParameters(String x, String inputNumberFormat, Locale inputLocale) throws MFormatConversionException {
+ protected static BigDecimal getNumberFromStringByParameters(String x, String inputNumberFormat, Locale inputLocale) throws MInvalidConversionFormatException {
if (MText.isBlank(x)) {
throw new IllegalArgumentException("Invalid 'x': null or empty.");
}
ParsePosition validPosition = new ParsePosition(0);
BigDecimal bd = (BigDecimal)df.parse(x, validPosition);
if (validPosition.getIndex() < x.length()) {
- throw new MFormatConversionException(String.format("Invalid 'x' or parsing: %s (input format: %s).", x, inputNumberFormat));
+ throw new MInvalidConversionFormatException(String.format("Invalid 'x' or parsing: %s (input format: %s).", x, inputNumberFormat));
}
return bd;
}
return df.format(number);
}
- public BigDecimal getNumberFromString(String x) throws MFormatConversionException {
+ public BigDecimal getNumberFromString(String x) throws MInvalidConversionFormatException {
BigDecimal y = null;
for (String numberFormat: this.getNumberFormatsReference()) {
try {
y = this.getNumberFromStringByParameters(x, numberFormat, this.getLocale());
return y;
}
- catch (MFormatConversionException exception) {
+ catch (MInvalidConversionFormatException exception) {
}
}
if (null == y) {
- throw new MFormatConversionException(String.format("Invalid 'x': %s.", x));
+ throw new MInvalidConversionFormatException(String.format("Invalid 'x': %s.", x));
}
return y; // necessary to avoid Java compilation errors
}