Skip to content

Commit 967c033

Browse files
committed
Parse based on CharSequence internally
Only access to CharSequence is via DateTimeParserBucket Fixes JodaOrg#111
1 parent 20f6e45 commit 967c033

File tree

10 files changed

+300
-74
lines changed

10 files changed

+300
-74
lines changed

RELEASE-NOTES.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ Enhancements since 2.3
3030
Potential for performance improvements due to lower garbage churn
3131
Improvement only of interest to applications willing to write specialist code
3232

33+
- Support CharSequence throughout parsing
34+
Ensure that CharSequence can be used in parsing [#111]
35+
This can only be accessed by creating a mutable DateTimeParserBucket
36+
The bucket is a low-level construct for advanced use cases
37+
Potential for performance improvements due to lower garbage churn
38+
No API change
39+
3340
- Support Appendable throughout printing
3441
Ensure that Appendable can be used efficiently in printing [#120, #121, #122]
3542
No API change

src/main/java/org/joda/time/format/DateTimeFormat.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ private static int selectStyle(char ch) {
785785

786786
//-----------------------------------------------------------------------
787787
static class StyleFormatter
788-
implements InternalPrinter, DateTimeParser {
788+
implements InternalPrinter, InternalParser {
789789

790790
private static final ConcurrentHashMap<StyleFormatterCacheKey, DateTimeFormatter> cCache = new ConcurrentHashMap<StyleFormatterCacheKey, DateTimeFormatter>();
791791

@@ -820,8 +820,8 @@ public int estimateParsedLength() {
820820
return 40; // guess
821821
}
822822

823-
public int parseInto(DateTimeParserBucket bucket, String text, int position) {
824-
DateTimeParser p = getFormatter(bucket.getLocale()).getParser();
823+
public int parseInto(DateTimeParserBucket bucket, CharSequence text, int position) {
824+
InternalParser p = getFormatter(bucket.getLocale()).getParser0();
825825
return p.parseInto(bucket, text, position);
826826
}
827827

src/main/java/org/joda/time/format/DateTimeFormatter.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public class DateTimeFormatter {
9292
/** The internal printer used to output the datetime. */
9393
private final InternalPrinter iPrinter;
9494
/** The internal parser used to output the datetime. */
95-
private final DateTimeParser iParser;
95+
private final InternalParser iParser;
9696
/** The locale to use for printing and parsing. */
9797
private final Locale iLocale;
9898
/** Whether the offset is parsed. */
@@ -115,7 +115,7 @@ public class DateTimeFormatter {
115115
*/
116116
public DateTimeFormatter(
117117
DateTimePrinter printer, DateTimeParser parser) {
118-
this(DateTimePrinterInternalPrinter.of(printer), parser);
118+
this(DateTimePrinterInternalPrinter.of(printer), DateTimeParserInternalParser.of(parser));
119119
}
120120

121121
/**
@@ -126,7 +126,7 @@ public DateTimeFormatter(
126126
* @param parser the internal parser, null if cannot parse
127127
*/
128128
DateTimeFormatter(
129-
InternalPrinter printer, DateTimeParser parser) {
129+
InternalPrinter printer, InternalParser parser) {
130130
super();
131131
iPrinter = printer;
132132
iParser = parser;
@@ -142,7 +142,7 @@ public DateTimeFormatter(
142142
* Constructor.
143143
*/
144144
private DateTimeFormatter(
145-
InternalPrinter printer, DateTimeParser parser,
145+
InternalPrinter printer, InternalParser parser,
146146
Locale locale, boolean offsetParsed,
147147
Chronology chrono, DateTimeZone zone,
148148
Integer pivotYear, int defaultYear) {
@@ -200,6 +200,10 @@ public boolean isParser() {
200200
* @return the internal parser; is null if parsing not supported
201201
*/
202202
public DateTimeParser getParser() {
203+
return InternalParserDateTimeParser.of(iParser);
204+
}
205+
206+
InternalParser getParser0() {
203207
return iParser;
204208
}
205209

@@ -728,7 +732,7 @@ private InternalPrinter requirePrinter() {
728732
* @throws IllegalArgumentException if any field is out of range
729733
*/
730734
public int parseInto(ReadWritableInstant instant, String text, int position) {
731-
DateTimeParser parser = requireParser();
735+
InternalParser parser = requireParser();
732736
if (instant == null) {
733737
throw new IllegalArgumentException("Instant must not be null");
734738
}
@@ -770,7 +774,7 @@ public int parseInto(ReadWritableInstant instant, String text, int position) {
770774
* @throws IllegalArgumentException if the text to parse is invalid
771775
*/
772776
public long parseMillis(String text) {
773-
DateTimeParser parser = requireParser();
777+
InternalParser parser = requireParser();
774778
Chronology chrono = selectChronology(iChrono);
775779
DateTimeParserBucket bucket = new DateTimeParserBucket(0, chrono, iLocale, iPivotYear, iDefaultYear);
776780
return bucket.doParseMillis(parser, text);
@@ -827,7 +831,7 @@ public LocalTime parseLocalTime(String text) {
827831
* @since 2.0
828832
*/
829833
public LocalDateTime parseLocalDateTime(String text) {
830-
DateTimeParser parser = requireParser();
834+
InternalParser parser = requireParser();
831835

832836
Chronology chrono = selectChronology(null).withUTC(); // always use UTC, avoiding DST gaps
833837
DateTimeParserBucket bucket = new DateTimeParserBucket(0, chrono, iLocale, iPivotYear, iDefaultYear);
@@ -868,7 +872,7 @@ public LocalDateTime parseLocalDateTime(String text) {
868872
* @throws IllegalArgumentException if the text to parse is invalid
869873
*/
870874
public DateTime parseDateTime(String text) {
871-
DateTimeParser parser = requireParser();
875+
InternalParser parser = requireParser();
872876

873877
Chronology chrono = selectChronology(null);
874878
DateTimeParserBucket bucket = new DateTimeParserBucket(0, chrono, iLocale, iPivotYear, iDefaultYear);
@@ -913,7 +917,7 @@ public DateTime parseDateTime(String text) {
913917
* @throws IllegalArgumentException if the text to parse is invalid
914918
*/
915919
public MutableDateTime parseMutableDateTime(String text) {
916-
DateTimeParser parser = requireParser();
920+
InternalParser parser = requireParser();
917921

918922
Chronology chrono = selectChronology(null);
919923
DateTimeParserBucket bucket = new DateTimeParserBucket(0, chrono, iLocale, iPivotYear, iDefaultYear);
@@ -945,8 +949,8 @@ public MutableDateTime parseMutableDateTime(String text) {
945949
*
946950
* @throws UnsupportedOperationException if parsing is not supported
947951
*/
948-
private DateTimeParser requireParser() {
949-
DateTimeParser parser = iParser;
952+
private InternalParser requireParser() {
953+
InternalParser parser = iParser;
950954
if (parser == null) {
951955
throw new UnsupportedOperationException("Parsing not supported");
952956
}

0 commit comments

Comments
 (0)