Java Code Examples for org.joda.time.DateTimeFieldType#era()

The following examples show how to use org.joda.time.DateTimeFieldType#era() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BasicSingleEraDateTimeField.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** @inheritDoc */
public long set(long instant, String text, Locale locale) {
    if (iEraText.equals(text) == false && "1".equals(text) == false) {
        throw new IllegalFieldValueException(DateTimeFieldType.era(), text);
    }
    return instant;
}
 
Example 2
Source File: GJLocaleSymbols.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public int eraTextToValue(String text) {
    Integer era = iParseEras.get(text);
    if (era != null) {
        return era.intValue();
    }
    throw new IllegalFieldValueException(DateTimeFieldType.era(), text);
}
 
Example 3
Source File: BasicSingleEraDateTimeField.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** @inheritDoc */
public long set(long instant, String text, Locale locale) {
    if (iEraText.equals(text) == false && "1".equals(text) == false) {
        throw new IllegalFieldValueException(DateTimeFieldType.era(), text);
    }
    return instant;
}
 
Example 4
Source File: GJLocaleSymbols.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public int eraTextToValue(String text) {
    Integer era = iParseEras.get(text);
    if (era != null) {
        return era.intValue();
    }
    throw new IllegalFieldValueException(DateTimeFieldType.era(), text);
}
 
Example 5
Source File: Time_20_DateTimeFormatterBuilder_t.java    From coming with MIT License 4 votes vote down vote up
@SuppressWarnings("unchecked")
public int parseInto(DateTimeParserBucket bucket, String text, int position) {
    Locale locale = bucket.getLocale();
    // handle languages which might have non ASCII A-Z or punctuation
    // bug 1788282
    Set<String> validValues = null;
    int maxLength = 0;
    synchronized (cParseCache) {
        Map<DateTimeFieldType, Object[]> innerMap = cParseCache.get(locale);
        if (innerMap == null) {
            innerMap = new HashMap<DateTimeFieldType, Object[]>();
            cParseCache.put(locale, innerMap);
        }
        Object[] array = innerMap.get(iFieldType);
        if (array == null) {
            validValues = new HashSet<String>(32);
            MutableDateTime dt = new MutableDateTime(0L, DateTimeZone.UTC);
            Property property = dt.property(iFieldType);
            int min = property.getMinimumValueOverall();
            int max = property.getMaximumValueOverall();
            if (max - min > 32) {  // protect against invalid fields
                return ~position;
            }
            maxLength = property.getMaximumTextLength(locale);
            for (int i = min; i <= max; i++) {
                property.set(i);
                validValues.add(property.getAsShortText(locale));
                validValues.add(property.getAsShortText(locale).toLowerCase(locale));
                validValues.add(property.getAsShortText(locale).toUpperCase(locale));
                validValues.add(property.getAsText(locale));
                validValues.add(property.getAsText(locale).toLowerCase(locale));
                validValues.add(property.getAsText(locale).toUpperCase(locale));
            }
            if ("en".equals(locale.getLanguage()) && iFieldType == DateTimeFieldType.era()) {
                // hack to support for parsing "BCE" and "CE" if the language is English
                validValues.add("BCE");
                validValues.add("bce");
                validValues.add("CE");
                validValues.add("ce");
                maxLength = 3;
            }
            array = new Object[] {validValues, Integer.valueOf(maxLength)};
            innerMap.put(iFieldType, array);
        } else {
            validValues = (Set<String>) array[0];
            maxLength = ((Integer) array[1]).intValue();
        }
    }
    // match the longest string first using our knowledge of the max length
    int limit = Math.min(text.length(), position + maxLength);
    for (int i = limit; i > position; i--) {
        String match = text.substring(position, i);
        if (validValues.contains(match)) {
            bucket.saveField(iFieldType, match, locale);
            return i;
        }
    }
    return ~position;
}
 
Example 6
Source File: Time_20_DateTimeFormatterBuilder_s.java    From coming with MIT License 4 votes vote down vote up
@SuppressWarnings("unchecked")
public int parseInto(DateTimeParserBucket bucket, String text, int position) {
    Locale locale = bucket.getLocale();
    // handle languages which might have non ASCII A-Z or punctuation
    // bug 1788282
    Set<String> validValues = null;
    int maxLength = 0;
    synchronized (cParseCache) {
        Map<DateTimeFieldType, Object[]> innerMap = cParseCache.get(locale);
        if (innerMap == null) {
            innerMap = new HashMap<DateTimeFieldType, Object[]>();
            cParseCache.put(locale, innerMap);
        }
        Object[] array = innerMap.get(iFieldType);
        if (array == null) {
            validValues = new HashSet<String>(32);
            MutableDateTime dt = new MutableDateTime(0L, DateTimeZone.UTC);
            Property property = dt.property(iFieldType);
            int min = property.getMinimumValueOverall();
            int max = property.getMaximumValueOverall();
            if (max - min > 32) {  // protect against invalid fields
                return ~position;
            }
            maxLength = property.getMaximumTextLength(locale);
            for (int i = min; i <= max; i++) {
                property.set(i);
                validValues.add(property.getAsShortText(locale));
                validValues.add(property.getAsShortText(locale).toLowerCase(locale));
                validValues.add(property.getAsShortText(locale).toUpperCase(locale));
                validValues.add(property.getAsText(locale));
                validValues.add(property.getAsText(locale).toLowerCase(locale));
                validValues.add(property.getAsText(locale).toUpperCase(locale));
            }
            if ("en".equals(locale.getLanguage()) && iFieldType == DateTimeFieldType.era()) {
                // hack to support for parsing "BCE" and "CE" if the language is English
                validValues.add("BCE");
                validValues.add("bce");
                validValues.add("CE");
                validValues.add("ce");
                maxLength = 3;
            }
            array = new Object[] {validValues, Integer.valueOf(maxLength)};
            innerMap.put(iFieldType, array);
        } else {
            validValues = (Set<String>) array[0];
            maxLength = ((Integer) array[1]).intValue();
        }
    }
    // match the longest string first using our knowledge of the max length
    int limit = Math.min(text.length(), position + maxLength);
    for (int i = limit; i > position; i--) {
        String match = text.substring(position, i);
        if (validValues.contains(match)) {
            bucket.saveField(iFieldType, match, locale);
            return i;
        }
    }
    return ~position;
}
 
Example 7
Source File: DateTimeFormatterBuilder.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public int parseInto(DateTimeParserBucket bucket, String text, int position) {
    Locale locale = bucket.getLocale();
    // handle languages which might have non ASCII A-Z or punctuation
    // bug 1788282
    Set<String> validValues = null;
    int maxLength = 0;
    synchronized (cParseCache) {
        Map<DateTimeFieldType, Object[]> innerMap = cParseCache.get(locale);
        if (innerMap == null) {
            innerMap = new HashMap<DateTimeFieldType, Object[]>();
            cParseCache.put(locale, innerMap);
        }
        Object[] array = innerMap.get(iFieldType);
        if (array == null) {
            validValues = new HashSet<String>(32);
            MutableDateTime dt = new MutableDateTime(0L, DateTimeZone.UTC);
            Property property = dt.property(iFieldType);
            int min = property.getMinimumValueOverall();
            int max = property.getMaximumValueOverall();
            if (max - min > 32) {  // protect against invalid fields
                return ~position;
            }
            maxLength = property.getMaximumTextLength(locale);
            for (int i = min; i <= max; i++) {
                property.set(i);
                validValues.add(property.getAsShortText(locale));
                validValues.add(property.getAsShortText(locale).toLowerCase(locale));
                validValues.add(property.getAsShortText(locale).toUpperCase(locale));
                validValues.add(property.getAsText(locale));
                validValues.add(property.getAsText(locale).toLowerCase(locale));
                validValues.add(property.getAsText(locale).toUpperCase(locale));
            }
            if ("en".equals(locale.getLanguage()) && iFieldType == DateTimeFieldType.era()) {
                // hack to support for parsing "BCE" and "CE" if the language is English
                validValues.add("BCE");
                validValues.add("bce");
                validValues.add("CE");
                validValues.add("ce");
                maxLength = 3;
            }
            array = new Object[] {validValues, Integer.valueOf(maxLength)};
            innerMap.put(iFieldType, array);
        } else {
            validValues = (Set<String>) array[0];
            maxLength = ((Integer) array[1]).intValue();
        }
    }
    // match the longest string first using our knowledge of the max length
    int limit = Math.min(text.length(), position + maxLength);
    for (int i = limit; i > position; i--) {
        String match = text.substring(position, i);
        if (validValues.contains(match)) {
            bucket.saveField(iFieldType, match, locale);
            return i;
        }
    }
    return ~position;
}
 
Example 8
Source File: BasicSingleEraDateTimeField.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Restricted constructor.
 */
BasicSingleEraDateTimeField(String text) {
    super(DateTimeFieldType.era());
    iEraText = text;
}
 
Example 9
Source File: GJEraDateTimeField.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Restricted constructor
 */
GJEraDateTimeField(BasicChronology chronology) {
    super(DateTimeFieldType.era());
    iChronology = chronology;
}
 
Example 10
Source File: DateTimeFormatterBuilder.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public int parseInto(DateTimeParserBucket bucket, String text, int position) {
    Locale locale = bucket.getLocale();
    // handle languages which might have non ASCII A-Z or punctuation
    // bug 1788282
    Set<String> validValues = null;
    int maxLength = 0;
    synchronized (cParseCache) {
        Map<DateTimeFieldType, Object[]> innerMap = cParseCache.get(locale);
        if (innerMap == null) {
            innerMap = new HashMap<DateTimeFieldType, Object[]>();
            cParseCache.put(locale, innerMap);
        }
        Object[] array = innerMap.get(iFieldType);
        if (array == null) {
            validValues = new HashSet<String>(32);
            MutableDateTime dt = new MutableDateTime(0L, DateTimeZone.UTC);
            Property property = dt.property(iFieldType);
            int min = property.getMinimumValueOverall();
            int max = property.getMaximumValueOverall();
            if (max - min > 32) {  // protect against invalid fields
                return ~position;
            }
            maxLength = property.getMaximumTextLength(locale);
            for (int i = min; i <= max; i++) {
                property.set(i);
                validValues.add(property.getAsShortText(locale));
                validValues.add(property.getAsShortText(locale).toLowerCase(locale));
                validValues.add(property.getAsShortText(locale).toUpperCase(locale));
                validValues.add(property.getAsText(locale));
                validValues.add(property.getAsText(locale).toLowerCase(locale));
                validValues.add(property.getAsText(locale).toUpperCase(locale));
            }
            if ("en".equals(locale.getLanguage()) && iFieldType == DateTimeFieldType.era()) {
                // hack to support for parsing "BCE" and "CE" if the language is English
                validValues.add("BCE");
                validValues.add("bce");
                validValues.add("CE");
                validValues.add("ce");
                maxLength = 3;
            }
            array = new Object[] {validValues, Integer.valueOf(maxLength)};
            innerMap.put(iFieldType, array);
        } else {
            validValues = (Set<String>) array[0];
            maxLength = ((Integer) array[1]).intValue();
        }
    }
    // match the longest string first using our knowledge of the max length
    int limit = Math.min(text.length(), position + maxLength);
    for (int i = limit; i > position; i--) {
        String match = text.substring(position, i);
        if (validValues.contains(match)) {
            bucket.saveField(iFieldType, match, locale);
            return i;
        }
    }
    return ~position;
}
 
Example 11
Source File: BasicSingleEraDateTimeField.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Restricted constructor.
 */
BasicSingleEraDateTimeField(String text) {
    super(DateTimeFieldType.era());
    iEraText = text;
}
 
Example 12
Source File: GJEraDateTimeField.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Restricted constructor
 */
GJEraDateTimeField(BasicChronology chronology) {
    super(DateTimeFieldType.era());
    iChronology = chronology;
}