--- old/src/share/classes/java/time/format/DateTimeParseContext.java 2013-02-08 10:48:03.000000000 -0800
+++ new/src/share/classes/java/time/format/DateTimeParseContext.java 2013-02-08 10:48:03.000000000 -0800
@@ -61,10 +61,19 @@
*/
package java.time.format;
+import java.time.DateTimeException;
+import java.time.ZoneId;
+import java.time.chrono.Chronology;
+import java.time.chrono.IsoChronology;
+import java.time.temporal.ChronoField;
+import java.time.temporal.Queries;
+import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalField;
+import java.time.temporal.TemporalQuery;
import java.util.ArrayList;
-import java.util.List;
+import java.util.HashMap;
import java.util.Locale;
+import java.util.Map;
import java.util.Objects;
/**
@@ -84,7 +93,7 @@
*
* @since 1.8
*/
-final class DateTimeParseContext {
+final class DateTimeParseContext implements TemporalAccessor {
/**
* The formatter, not null.
@@ -130,7 +139,7 @@
*
* @return the locale, not null
*/
- public Locale getLocale() {
+ Locale getLocale() {
return formatter.getLocale();
}
@@ -141,17 +150,33 @@
*
* @return the formatting symbols, not null
*/
- public DateTimeFormatSymbols getSymbols() {
+ DateTimeFormatSymbols getSymbols() {
return formatter.getSymbols();
}
+ /**
+ * Gets the effective chronology during parsing.
+ *
+ * @return the effective parsing chronology, not null
+ */
+ Chronology getEffectiveChronology() {
+ Chronology chrono = currentParsed().chrono;
+ if (chrono == null) {
+ chrono = formatter.getChronology();
+ if (chrono == null) {
+ chrono = IsoChronology.INSTANCE;
+ }
+ }
+ return chrono;
+ }
+
//-----------------------------------------------------------------------
/**
* Checks if parsing is case sensitive.
*
* @return true if parsing is case sensitive, false if case insensitive
*/
- public boolean isCaseSensitive() {
+ boolean isCaseSensitive() {
return caseSensitive;
}
@@ -160,10 +185,11 @@
*
* @param caseSensitive changes the parsing to be case sensitive or not from now on
*/
- public void setCaseSensitive(boolean caseSensitive) {
+ void setCaseSensitive(boolean caseSensitive) {
this.caseSensitive = caseSensitive;
}
+ //-----------------------------------------------------------------------
/**
* Helper to compare two {@code CharSequence} instances.
* This uses {@link #isCaseSensitive()}.
@@ -175,7 +201,7 @@
* @param length the length to check, valid
* @return true if equal
*/
- public boolean subSequenceEquals(CharSequence cs1, int offset1, CharSequence cs2, int offset2, int length) {
+ boolean subSequenceEquals(CharSequence cs1, int offset1, CharSequence cs2, int offset2, int length) {
if (offset1 + length > cs1.length() || offset2 + length > cs2.length()) {
return false;
}
@@ -200,6 +226,34 @@
return true;
}
+ /**
+ * Helper to compare two {@code char}.
+ * This uses {@link #isCaseSensitive()}.
+ *
+ * @param ch1 the first character
+ * @param ch2 the second character
+ * @return true if equal
+ */
+ boolean charEquals(char ch1, char ch2) {
+ if (isCaseSensitive()) {
+ return ch1 == ch2;
+ }
+ return charEqualsIgnoreCase(ch1, ch2);
+ }
+
+ /**
+ * Compares two characters ignoring case.
+ *
+ * @param c1 the first
+ * @param c2 the second
+ * @return true if equal
+ */
+ static boolean charEqualsIgnoreCase(char c1, char c2) {
+ return c1 == c2 ||
+ Character.toUpperCase(c1) == Character.toUpperCase(c2) ||
+ Character.toLowerCase(c1) == Character.toLowerCase(c2);
+ }
+
//-----------------------------------------------------------------------
/**
* Checks if parsing is strict.
@@ -208,7 +262,7 @@
*
* @return true if parsing is strict, false if lenient
*/
- public boolean isStrict() {
+ boolean isStrict() {
return strict;
}
@@ -217,7 +271,7 @@
*
* @param strict changes the parsing to be strict or lenient from now on
*/
- public void setStrict(boolean strict) {
+ void setStrict(boolean strict) {
this.strict = strict;
}
@@ -264,45 +318,8 @@
* @param field the field to query from the map, null returns null
* @return the value mapped to the specified field, null if field was not parsed
*/
- public Long getParsed(TemporalField field) {
- for (Object obj : currentParsed().parsed) {
- if (obj instanceof FieldValue) {
- FieldValue fv = (FieldValue) obj;
- if (fv.field.equals(field)) {
- return fv.value;
- }
- }
- }
- return null;
- }
-
- /**
- * Gets the first value that was parsed for the specified type.
- *
- * This searches the results of the parse, returning the first date-time found
- * of the specified type. No attempt is made to derive a value.
- *
- * @param clazz the type to query from the map, not null
- * @return the temporal object, null if it was not parsed
- */
- @SuppressWarnings("unchecked")
- public T getParsed(Class clazz) {
- for (Object obj : currentParsed().parsed) {
- if (clazz.isInstance(obj)) {
- return (T) obj;
- }
- }
- return null;
- }
-
- /**
- * Gets the list of parsed temporal information.
- *
- * @return the list of parsed temporal objects, not null, no nulls
- */
- List