Skip to content

Commit 0be6473

Browse files
author
Keith Donald
committed
javadoc polishing--named Parser String arg name to 'text'
1 parent fbfa67e commit 0be6473

File tree

7 files changed

+31
-39
lines changed

7 files changed

+31
-39
lines changed

org.springframework.context/src/main/java/org/springframework/format/Parser.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,22 @@
2020
import java.util.Locale;
2121

2222
/**
23-
* Parses objects of type T from their printed representations.
23+
* Parses text strings to produce instances of T.
2424
*
2525
* @author Keith Donald
2626
* @since 3.0
27-
* @param <T> the type of object this Parser parses
27+
* @param <T> the type of object this Parser produces
2828
*/
2929
public interface Parser<T> {
3030

3131
/**
32-
* Parse an object from its printed representation.
33-
* @param printed a printed representation
32+
* Parse a text String to produce a T.
33+
* @param text the text string
3434
* @param locale the current user locale
35-
* @return the parsed object
35+
* @return an instance of T
3636
* @throws ParseException when a parse exception occurs in a java.text parsing library
37-
* @throws RuntimeException when a parse exception occurs
37+
* @throws IllegalArgumentException when a parse exception occurs
3838
*/
39-
T parse(String printed, Locale locale) throws ParseException;
39+
T parse(String text, Locale locale) throws ParseException;
4040

4141
}

org.springframework.context/src/main/java/org/springframework/format/Printer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ public interface Printer<T> {
2929

3030
/**
3131
* Print the object of type T for display.
32-
* @param object the object to print
32+
* @param object the instance to print
3333
* @param locale the current user locale
34-
* @return the printed string
34+
* @return the printed text string
3535
*/
3636
String print(T object, Locale locale);
3737

org.springframework.context/src/main/java/org/springframework/format/datetime/DateFormatter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ public String print(Date date, Locale locale) {
101101
return getDateFormat(locale).format(date);
102102
}
103103

104-
public Date parse(String formatted, Locale locale) throws ParseException {
105-
return getDateFormat(locale).parse(formatted);
104+
public Date parse(String text, Locale locale) throws ParseException {
105+
return getDateFormat(locale).parse(text);
106106
}
107107

108108

org.springframework.context/src/main/java/org/springframework/format/datetime/joda/DateTimeParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public DateTimeParser(DateTimeFormatter formatter) {
3939
this.formatter = formatter;
4040
}
4141

42-
public DateTime parse(String printed, Locale locale) throws ParseException {
43-
return JodaTimeContextHolder.getFormatter(this.formatter, locale).parseDateTime(printed);
42+
public DateTime parse(String text, Locale locale) throws ParseException {
43+
return JodaTimeContextHolder.getFormatter(this.formatter, locale).parseDateTime(text);
4444
}
4545
}

org.springframework.context/src/main/java/org/springframework/format/number/AbstractNumberFormatter.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,21 @@ public void setLenient(boolean lenient) {
4444
this.lenient = lenient;
4545
}
4646

47-
public String print(Number integer, Locale locale) {
48-
return getNumberFormat(locale).format(integer);
47+
public String print(Number number, Locale locale) {
48+
return getNumberFormat(locale).format(number);
4949
}
5050

51-
public Number parse(String formatted, Locale locale) throws ParseException {
51+
public Number parse(String text, Locale locale) throws ParseException {
5252
NumberFormat format = getNumberFormat(locale);
5353
ParsePosition position = new ParsePosition(0);
54-
Number number = format.parse(formatted, position);
54+
Number number = format.parse(text, position);
5555
if (position.getErrorIndex() != -1) {
56-
throw new ParseException(formatted, position.getIndex());
56+
throw new ParseException(text, position.getIndex());
5757
}
5858
if (!this.lenient) {
59-
if (formatted.length() != position.getIndex()) {
59+
if (text.length() != position.getIndex()) {
6060
// indicates a part of the string that was not parsed
61-
throw new ParseException(formatted, position.getIndex());
61+
throw new ParseException(text, position.getIndex());
6262
}
6363
}
6464
return number;

org.springframework.context/src/main/java/org/springframework/format/number/CurrencyFormatter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ public void setCurrency(Currency currency) {
7575
}
7676

7777

78-
public BigDecimal parse(String formatted, Locale locale) throws ParseException {
79-
BigDecimal decimal = (BigDecimal) super.parse(formatted, locale);
78+
public BigDecimal parse(String text, Locale locale) throws ParseException {
79+
BigDecimal decimal = (BigDecimal) super.parse(text, locale);
8080
if (decimal != null) {
8181
if (this.roundingMode != null) {
8282
decimal = decimal.setScale(this.fractionDigits, this.roundingMode);

org.springframework.context/src/main/java/org/springframework/format/support/FormattingConversionService.java

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@
1717
package org.springframework.format.support;
1818

1919
import java.lang.annotation.Annotation;
20-
import java.text.ParseException;
2120
import java.util.Set;
2221

2322
import org.springframework.context.i18n.LocaleContextHolder;
2423
import org.springframework.core.GenericTypeResolver;
25-
import org.springframework.core.convert.ConversionException;
2624
import org.springframework.core.convert.ConversionFailedException;
2725
import org.springframework.core.convert.ConversionService;
2826
import org.springframework.core.convert.TypeDescriptor;
@@ -164,27 +162,21 @@ public Class<?>[][] getConvertibleTypes() {
164162
}
165163

166164
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
167-
String submittedValue = (String) source;
168-
if (submittedValue == null || submittedValue.length() == 0) {
165+
String text = (String) source;
166+
if (text == null || text.length() == 0) {
169167
return null;
170168
}
171-
Object parsedValue;
172169
try {
173-
parsedValue = this.parser.parse(submittedValue, LocaleContextHolder.getLocale());
170+
Object result = this.parser.parse(text, LocaleContextHolder.getLocale());
171+
TypeDescriptor resultType = TypeDescriptor.valueOf(result.getClass());
172+
if (!resultType.isAssignableTo(targetType)) {
173+
result = this.conversionService.convert(result, resultType, targetType);
174+
}
175+
return result;
174176
}
175-
catch (ParseException ex) {
177+
catch (Exception ex) {
176178
throw new ConversionFailedException(sourceType, targetType, source, ex);
177179
}
178-
TypeDescriptor parsedObjectType = TypeDescriptor.valueOf(parsedValue.getClass());
179-
if (!parsedObjectType.isAssignableTo(targetType)) {
180-
try {
181-
parsedValue = this.conversionService.convert(parsedValue, parsedObjectType, targetType);
182-
}
183-
catch (ConversionException ex) {
184-
throw new ConversionFailedException(sourceType, targetType, source, ex);
185-
}
186-
}
187-
return parsedValue;
188180
}
189181

190182
public String toString() {

0 commit comments

Comments
 (0)