Skip to content
This repository has been archived by the owner on Mar 20, 2018. It is now read-only.

Parsers on CharSequence #5

Merged
merged 5 commits into from Jul 12, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions build.xml
Expand Up @@ -170,6 +170,8 @@
<taskdef resource="testngtasks" classpathref="test.path" />
<testng classpathref="test.path" outputDir="${core.test.classes}" sourceDir="${core.test}" haltonfailure="true" verbose="2">
<jvmarg value="-Xmx512M" />
<jvmarg value="-Duser.language=en" />
<jvmarg value="-Duser.country=UK" />
<classfileset dir="${core.test.classes}" includes="**/Test*.class" excludes="java/util/*" />
</testng>
</target>
Expand All @@ -178,6 +180,8 @@
<taskdef resource="testngtasks" classpathref="test.path" />
<testng classpathref="test.path" outputDir="${extra.test.classes}" sourceDir="${extra.test}" haltonfailure="true" verbose="2">
<jvmarg value="-Xmx512M" />
<jvmarg value="-Duser.language=en" />
<jvmarg value="-Duser.country=UK" />
<classfileset dir="${extra.test.classes}" includes="**/Test*.class" excludes="java/util/*" />
</testng>
</target>
Expand All @@ -186,6 +190,8 @@
<taskdef resource="testngtasks" classpathref="test.path" />
<testng classpathref="test.path" outputDir="${core.test.classes}" sourceDir="${core.test}" haltonfailure="true" verbose="2">
<jvmarg value="-Xmx512M" />
<jvmarg value="-Duser.language=en" />
<jvmarg value="-Duser.country=UK" />
<classfileset dir="${core.test.classes}" includes="javax/time/scales/Test*.class" excludes="java/util/*" />
</testng>
</target>
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/javax/time/Duration.java
Expand Up @@ -359,7 +359,7 @@ public static Duration between(InstantProvider startInclusive, InstantProvider e

//-----------------------------------------------------------------------
/**
* Obtains an instance of {@code Duration} by parsing a string.
* Obtains an instance of {@code Duration} by parsing a text string.
* <p>
* This will parse the string produced by {@link #toString()} which is
* the ISO-8601 format {@code PTnS} where {@code n} is
Expand All @@ -376,7 +376,7 @@ public static Duration between(InstantProvider startInclusive, InstantProvider e
* @return a {@code Duration}, not null
* @throws CalendricalParseException if the text cannot be parsed to a {@code Duration}
*/
public static Duration parse(final String text) {
public static Duration parse(final CharSequence text) {
Instant.checkNotNull(text, "Text to parse must not be null");
int len = text.length();
if (len < 4 ||
Expand All @@ -386,7 +386,7 @@ public static Duration parse(final String text) {
(len == 5 && text.charAt(2) == '-' && text.charAt(3) == '0')) {
throw new CalendricalParseException("Duration could not be parsed: " + text, text, 0);
}
String numberText = text.substring(2, len - 1).replace(',', '.');
String numberText = text.subSequence(2, len - 1).toString().replace(',', '.');
int dot = numberText.indexOf('.');
try {
if (dot == -1) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/javax/time/Instant.java
Expand Up @@ -318,7 +318,7 @@ public static Instant of(InstantProvider instantProvider) {
* @return an instant, not null
* @throws CalendricalParseException if the text cannot be parsed to an {@code Instant}
*/
public static Instant parse(final String text) {
public static Instant parse(final CharSequence text) {
Instant.checkNotNull(text, "Text to parse must not be null");
// TODO: Implement
throw new UnsupportedOperationException();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/javax/time/TAIInstant.java
Expand Up @@ -183,11 +183,11 @@ public static TAIInstant of(UTCInstant instant) {
* The trailing literal must be exactly specified.
* This format parses the {@code toString} format.
*
* @param text the text to parse such as '12345.123456789s(TAI)', not null
* @param text the text to parse such as "12345.123456789s(TAI)", not null
* @return the parsed instant, not null
* @throws CalendricalException if the text cannot be parsed
*/
public static TAIInstant parse(String text) {
public static TAIInstant parse(CharSequence text) {
Instant.checkNotNull(text, "Text to parse must not be null");
Matcher matcher = PARSER.matcher(text);
if (matcher.matches()) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/javax/time/calendar/LocalDate.java
Expand Up @@ -307,11 +307,11 @@ public static LocalDate from(Calendrical... calendricals) {
* <p>
* The day-of-month has 2 digits with values from 1 to 31 appropriate to the month.
*
* @param text the text to parse such as '2007-12-03', not null
* @param text the text to parse such as "2007-12-03", not null
* @return the parsed local date, not null
* @throws CalendricalParseException if the text cannot be parsed
*/
public static LocalDate parse(String text) {
public static LocalDate parse(CharSequence text) {
return DateTimeFormatters.isoLocalDate().parse(text, rule());
}

Expand All @@ -326,7 +326,7 @@ public static LocalDate parse(String text) {
* @throws UnsupportedOperationException if the formatter cannot parse
* @throws CalendricalParseException if the text cannot be parsed
*/
public static LocalDate parse(String text, DateTimeFormatter formatter) {
public static LocalDate parse(CharSequence text, DateTimeFormatter formatter) {
ISOChronology.checkNotNull(formatter, "DateTimeFormatter must not be null");
return formatter.parse(text, rule());
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/javax/time/calendar/LocalDateTime.java
Expand Up @@ -453,11 +453,11 @@ static LocalDateTime deriveFrom(CalendricalNormalizer normalized) {
* The second has 2 digits with values from 0 to 59.
* The nanosecond fraction has from 1 to 9 digits with values from 0 to 999,999,999.
*
* @param text the text to parse such as '2007-12-03T10:15:30', not null
* @param text the text to parse such as "2007-12-03T10:15:30", not null
* @return the parsed local date-time, not null
* @throws CalendricalParseException if the text cannot be parsed
*/
public static LocalDateTime parse(String text) {
public static LocalDateTime parse(CharSequence text) {
return DateTimeFormatters.isoLocalDateTime().parse(text, rule());
}

Expand All @@ -472,7 +472,7 @@ public static LocalDateTime parse(String text) {
* @throws UnsupportedOperationException if the formatter cannot parse
* @throws CalendricalParseException if the text cannot be parsed
*/
public static LocalDateTime parse(String text, DateTimeFormatter formatter) {
public static LocalDateTime parse(CharSequence text, DateTimeFormatter formatter) {
ISOChronology.checkNotNull(formatter, "DateTimeFormatter must not be null");
return formatter.parse(text, rule());
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/javax/time/calendar/LocalTime.java
Expand Up @@ -385,11 +385,11 @@ public static LocalTime from(Calendrical... calendricals) {
* The second has 2 digits with values from 0 to 59.
* The nanosecond fraction has from 1 to 9 digits with values from 0 to 999,999,999.
*
* @param text the text to parse such as '10:15:30', not null
* @param text the text to parse such as "10:15:30", not null
* @return the parsed local time, not null
* @throws CalendricalParseException if the text cannot be parsed
*/
public static LocalTime parse(String text) {
public static LocalTime parse(CharSequence text) {
return DateTimeFormatters.isoLocalTime().parse(text, rule());
}

Expand All @@ -404,7 +404,7 @@ public static LocalTime parse(String text) {
* @throws UnsupportedOperationException if the formatter cannot parse
* @throws CalendricalParseException if the text cannot be parsed
*/
public static LocalTime parse(String text, DateTimeFormatter formatter) {
public static LocalTime parse(CharSequence text, DateTimeFormatter formatter) {
ISOChronology.checkNotNull(formatter, "DateTimeFormatter must not be null");
return formatter.parse(text, rule());
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/javax/time/calendar/MonthDay.java
Expand Up @@ -225,11 +225,11 @@ static MonthDay deriveFrom(CalendricalNormalizer merger) {
* <p>
* The day-of-month has 2 digits with values from 1 to 31 appropriate to the month.
*
* @param text the text to parse such as '--12-03', not null
* @param text the text to parse such as "--12-03", not null
* @return the parsed month-day, not null
* @throws CalendricalParseException if the text cannot be parsed
*/
public static MonthDay parse(String text) {
public static MonthDay parse(CharSequence text) {
return PARSER.parse(text, rule());
}

Expand All @@ -244,7 +244,7 @@ public static MonthDay parse(String text) {
* @throws UnsupportedOperationException if the formatter cannot parse
* @throws CalendricalParseException if the text cannot be parsed
*/
public static MonthDay parse(String text, DateTimeFormatter formatter) {
public static MonthDay parse(CharSequence text, DateTimeFormatter formatter) {
ISOChronology.checkNotNull(formatter, "DateTimeFormatter must not be null");
return formatter.parse(text, rule());
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/javax/time/calendar/OffsetDate.java
Expand Up @@ -251,11 +251,11 @@ static OffsetDate deriveFrom(CalendricalNormalizer normalized) {
* <p>
* The offset ID is the normalized form as defined in {@link ZoneOffset}.
*
* @param text the text to parse such as '2007-12-03+01:00', not null
* @param text the text to parse such as "2007-12-03+01:00", not null
* @return the parsed offset date, not null
* @throws CalendricalParseException if the text cannot be parsed
*/
public static OffsetDate parse(String text) {
public static OffsetDate parse(CharSequence text) {
return DateTimeFormatters.isoOffsetDate().parse(text, rule());
}

Expand All @@ -270,7 +270,7 @@ public static OffsetDate parse(String text) {
* @throws UnsupportedOperationException if the formatter cannot parse
* @throws CalendricalParseException if the text cannot be parsed
*/
public static OffsetDate parse(String text, DateTimeFormatter formatter) {
public static OffsetDate parse(CharSequence text, DateTimeFormatter formatter) {
ISOChronology.checkNotNull(formatter, "DateTimeFormatter must not be null");
return formatter.parse(text, rule());
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/javax/time/calendar/OffsetDateTime.java
Expand Up @@ -478,11 +478,11 @@ static OffsetDateTime deriveFrom(CalendricalNormalizer normalized) {
* <p>
* The offset ID is the normalized form as defined in {@link ZoneOffset}.
*
* @param text the text to parse such as '2007-12-03T10:15:30+01:00', not null
* @param text the text to parse such as "2007-12-03T10:15:30+01:00", not null
* @return the parsed offset date-time, not null
* @throws CalendricalParseException if the text cannot be parsed
*/
public static OffsetDateTime parse(String text) {
public static OffsetDateTime parse(CharSequence text) {
return DateTimeFormatters.isoOffsetDateTime().parse(text, rule());
}

Expand All @@ -497,7 +497,7 @@ public static OffsetDateTime parse(String text) {
* @throws UnsupportedOperationException if the formatter cannot parse
* @throws CalendricalParseException if the text cannot be parsed
*/
public static OffsetDateTime parse(String text, DateTimeFormatter formatter) {
public static OffsetDateTime parse(CharSequence text, DateTimeFormatter formatter) {
ISOChronology.checkNotNull(formatter, "DateTimeFormatter must not be null");
return formatter.parse(text, rule());
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/javax/time/calendar/OffsetTime.java
Expand Up @@ -272,11 +272,11 @@ static OffsetTime deriveFrom(CalendricalNormalizer normalized) {
* <p>
* The offset ID is the normalized form as defined in {@link ZoneOffset}.
*
* @param text the text to parse such as '10:15:30+01:00', not null
* @param text the text to parse such as "10:15:30+01:00", not null
* @return the parsed local time, not null
* @throws CalendricalParseException if the text cannot be parsed
*/
public static OffsetTime parse(String text) {
public static OffsetTime parse(CharSequence text) {
return DateTimeFormatters.isoOffsetTime().parse(text, rule());
}

Expand All @@ -291,7 +291,7 @@ public static OffsetTime parse(String text) {
* @throws UnsupportedOperationException if the formatter cannot parse
* @throws CalendricalParseException if the text cannot be parsed
*/
public static OffsetTime parse(String text, DateTimeFormatter formatter) {
public static OffsetTime parse(CharSequence text, DateTimeFormatter formatter) {
ISOChronology.checkNotNull(formatter, "DateTimeFormatter must not be null");
return formatter.parse(text, rule());
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/javax/time/calendar/Period.java
Expand Up @@ -555,7 +555,7 @@ public static Period daysBetween(DateProvider startDateProvider, DateProvider en
* @return the parsed period, not null
* @throws CalendricalParseException if the text cannot be parsed to a Period
*/
public static Period parse(final String text) {
public static Period parse(final CharSequence text) {
PeriodFields.checkNotNull(text, "Text to parse must not be null");
return new PeriodParser(text).parse();
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/javax/time/calendar/PeriodParser.java
Expand Up @@ -90,14 +90,14 @@ final class PeriodParser {
/**
* Original text.
*/
private String text;
private CharSequence text;

/**
* Constructor.
*
* @param text the text to parse, not null
*/
PeriodParser(String text) {
PeriodParser(CharSequence text) {
this.text = text;
}

Expand All @@ -111,8 +111,8 @@ final class PeriodParser {
*/
Period parse() {
// force to upper case and coerce the comma to dot
String s = text.toUpperCase().replace(',', '.');

String s = text.toString().toUpperCase().replace(',', '.');
// check for zero and skip parse
if (ZERO.equals(s)) {
return Period.ZERO;
Expand Down Expand Up @@ -243,7 +243,7 @@ private String parseNumber(String s) {
return s.substring(start, index);
}

private void validateCharactersAndOrdering(String s, String text) {
private void validateCharactersAndOrdering(String s, CharSequence text) {
char[] chars = s.toCharArray();
int tokenPos = 0;
boolean lastLetter = false;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/javax/time/calendar/Year.java
Expand Up @@ -206,11 +206,11 @@ static Year deriveFrom(CalendricalNormalizer merger) {
* Negative years are allowed, but not negative zero.
* <p>
*
* @param text the text to parse such as '2007', not null
* @param text the text to parse such as "2007", not null
* @return the parsed year, not null
* @throws CalendricalParseException if the text cannot be parsed
*/
public static Year parse(String text) {
public static Year parse(CharSequence text) {
return PARSER.parse(text, rule());
}

Expand All @@ -225,7 +225,7 @@ public static Year parse(String text) {
* @throws UnsupportedOperationException if the formatter cannot parse
* @throws CalendricalParseException if the text cannot be parsed
*/
public static Year parse(String text, DateTimeFormatter formatter) {
public static Year parse(CharSequence text, DateTimeFormatter formatter) {
ISOChronology.checkNotNull(formatter, "DateTimeFormatter must not be null");
return formatter.parse(text, rule());
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/javax/time/calendar/YearMonth.java
Expand Up @@ -204,11 +204,11 @@ static YearMonth deriveFrom(CalendricalNormalizer merger) {
* <p>
* The month-of-year has 2 digits and has values from 1 to 12.
*
* @param text the text to parse such as '2007-12', not null
* @param text the text to parse such as "2007-12", not null
* @return the parsed year-month, not null
* @throws CalendricalParseException if the text cannot be parsed
*/
public static YearMonth parse(String text) {
public static YearMonth parse(CharSequence text) {
return PARSER.parse(text, rule());
}

Expand All @@ -223,7 +223,7 @@ public static YearMonth parse(String text) {
* @throws UnsupportedOperationException if the formatter cannot parse
* @throws CalendricalParseException if the text cannot be parsed
*/
public static YearMonth parse(String text, DateTimeFormatter formatter) {
public static YearMonth parse(CharSequence text, DateTimeFormatter formatter) {
ISOChronology.checkNotNull(formatter, "DateTimeFormatter must not be null");
return formatter.parse(text, rule());
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/javax/time/calendar/ZoneOffset.java
Expand Up @@ -147,7 +147,7 @@ public static CalendricalRule<ZoneOffset> rule() {
* @return the ZoneOffset, not null
* @throws IllegalArgumentException if the offset id is invalid
*/
public static ZoneOffset of(String offsetID) {
public static ZoneOffset of(CharSequence offsetID) {
if (offsetID == null) {
throw new NullPointerException("The offset ID must not be null");
}
Expand Down Expand Up @@ -208,7 +208,7 @@ public static ZoneOffset of(String offsetID) {
* @param precededByColon should this number be prefixed by a precededByColon
* @return the parsed number, from 0 to 99
*/
private static int parseNumber(String offsetID, int pos, boolean precededByColon) {
private static int parseNumber(CharSequence offsetID, int pos, boolean precededByColon) {
if (precededByColon && offsetID.charAt(pos - 1) != ':') {
throw new IllegalArgumentException("Zone offset id '" + offsetID + "' is invalid: Colon not found when expected");
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/javax/time/calendar/ZonedDateTime.java
Expand Up @@ -526,11 +526,11 @@ static ZonedDateTime deriveFrom(CalendricalNormalizer normalized) {
* <p>
* The zone ID is the normalized form as defined in {@link ZoneId#getID()}.
*
* @param text the text to parse such as '2007-12-03T10:15:30+01:00[Europe/Paris]', not null
* @param text the text to parse such as "2007-12-03T10:15:30+01:00[Europe/Paris]", not null
* @return the parsed zoned date-time, not null
* @throws CalendricalParseException if the text cannot be parsed
*/
public static ZonedDateTime parse(String text) {
public static ZonedDateTime parse(CharSequence text) {
return DateTimeFormatters.isoZonedDateTime().parse(text, rule());
}

Expand All @@ -545,7 +545,7 @@ public static ZonedDateTime parse(String text) {
* @throws UnsupportedOperationException if the formatter cannot parse
* @throws CalendricalParseException if the text cannot be parsed
*/
public static ZonedDateTime parse(String text, DateTimeFormatter formatter) {
public static ZonedDateTime parse(CharSequence text, DateTimeFormatter formatter) {
ISOChronology.checkNotNull(formatter, "DateTimeFormatter must not be null");
return formatter.parse(text, rule());
}
Expand Down