Java Code Examples for java.time.chrono.Chronology#getId()

The following examples show how to use java.time.chrono.Chronology#getId() . 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: DateTimeFormatterBuilder.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int parse(DateTimeParseContext context, CharSequence text, int position) {
    // simple looping parser to find the chronology
    if (position < 0 || position > text.length()) {
        throw new IndexOutOfBoundsException();
    }
    Set<Chronology> chronos = Chronology.getAvailableChronologies();
    Chronology bestMatch = null;
    int matchLen = -1;
    for (Chronology chrono : chronos) {
        String name;
        if (textStyle == null) {
            name = chrono.getId();
        } else {
            name = getChronologyName(chrono, context.getLocale());
        }
        int nameLen = name.length();
        if (nameLen > matchLen && context.subSequenceEquals(text, position, name, 0, nameLen)) {
            bestMatch = chrono;
            matchLen = nameLen;
        }
    }
    if (bestMatch == null) {
        return ~position;
    }
    context.setParsed(bestMatch);
    return position + matchLen;
}
 
Example 2
Source File: Period.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Validates that the temporal has the correct chronology.
 */
private void validateChrono(TemporalAccessor temporal) {
    Objects.requireNonNull(temporal, "temporal");
    Chronology temporalChrono = temporal.query(TemporalQueries.chronology());
    if (temporalChrono != null && IsoChronology.INSTANCE.equals(temporalChrono) == false) {
        throw new DateTimeException("Chronology mismatch, expected: ISO, actual: " + temporalChrono.getId());
    }
}
 
Example 3
Source File: TestFormatter.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private String getClassName(Object o) {
    Class<?> c = o.getClass();
    String clname = c.getName().substring(c.getPackage().getName().length() + 1);
    if (o instanceof TemporalAccessor) {
        Chronology chrono = ((TemporalAccessor)o).query(TemporalQueries.chronology());
        if (chrono != null) {
            clname = clname + "(" + chrono.getId() + ")";
        }
    }
    if (o instanceof Calendar) {
        String type = ((Calendar)o).getCalendarType();
        clname = clname + "(" + type + ")";
    }
    return clname;
}
 
Example 4
Source File: Period.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Validates that the temporal has the correct chronology.
 */
private void validateChrono(TemporalAccessor temporal) {
    Objects.requireNonNull(temporal, "temporal");
    Chronology temporalChrono = temporal.query(TemporalQueries.chronology());
    if (temporalChrono != null && IsoChronology.INSTANCE.equals(temporalChrono) == false) {
        throw new DateTimeException("Chronology mismatch, expected: ISO, actual: " + temporalChrono.getId());
    }
}
 
Example 5
Source File: DateTimeFormatterBuilder.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int parse(DateTimeParseContext context, CharSequence text, int position) {
    // simple looping parser to find the chronology
    if (position < 0 || position > text.length()) {
        throw new IndexOutOfBoundsException();
    }
    Set<Chronology> chronos = Chronology.getAvailableChronologies();
    Chronology bestMatch = null;
    int matchLen = -1;
    for (Chronology chrono : chronos) {
        String name;
        if (textStyle == null) {
            name = chrono.getId();
        } else {
            name = getChronologyName(chrono, context.getLocale());
        }
        int nameLen = name.length();
        if (nameLen > matchLen && context.subSequenceEquals(text, position, name, 0, nameLen)) {
            bestMatch = chrono;
            matchLen = nameLen;
        }
    }
    if (bestMatch == null) {
        return ~position;
    }
    context.setParsed(bestMatch);
    return position + matchLen;
}
 
Example 6
Source File: TestFormatter.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private String getClassName(Object o) {
    Class<?> c = o.getClass();
    String clname = c.getName().substring(c.getPackage().getName().length() + 1);
    if (o instanceof TemporalAccessor) {
        Chronology chrono = ((TemporalAccessor)o).query(TemporalQueries.chronology());
        if (chrono != null) {
            clname = clname + "(" + chrono.getId() + ")";
        }
    }
    if (o instanceof Calendar) {
        String type = ((Calendar)o).getCalendarType();
        clname = clname + "(" + type + ")";
    }
    return clname;
}
 
Example 7
Source File: Period.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Validates that the temporal has the correct chronology.
 */
private void validateChrono(TemporalAccessor temporal) {
    Objects.requireNonNull(temporal, "temporal");
    Chronology temporalChrono = temporal.query(TemporalQueries.chronology());
    if (temporalChrono != null && IsoChronology.INSTANCE.equals(temporalChrono) == false) {
        throw new DateTimeException("Chronology mismatch, expected: ISO, actual: " + temporalChrono.getId());
    }
}
 
Example 8
Source File: DateTimeFormatterBuilder.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int parse(DateTimeParseContext context, CharSequence text, int position) {
    // simple looping parser to find the chronology
    if (position < 0 || position > text.length()) {
        throw new IndexOutOfBoundsException();
    }
    Set<Chronology> chronos = Chronology.getAvailableChronologies();
    Chronology bestMatch = null;
    int matchLen = -1;
    for (Chronology chrono : chronos) {
        String name;
        if (textStyle == null) {
            name = chrono.getId();
        } else {
            name = getChronologyName(chrono, context.getLocale());
        }
        int nameLen = name.length();
        if (nameLen > matchLen && context.subSequenceEquals(text, position, name, 0, nameLen)) {
            bestMatch = chrono;
            matchLen = nameLen;
        }
    }
    if (bestMatch == null) {
        return ~position;
    }
    context.setParsed(bestMatch);
    return position + matchLen;
}
 
Example 9
Source File: DateTimeFormatterBuilder.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int parse(DateTimeParseContext context, CharSequence text, int position) {
    // simple looping parser to find the chronology
    if (position < 0 || position > text.length()) {
        throw new IndexOutOfBoundsException();
    }
    Set<Chronology> chronos = Chronology.getAvailableChronologies();
    Chronology bestMatch = null;
    int matchLen = -1;
    for (Chronology chrono : chronos) {
        String name;
        if (textStyle == null) {
            name = chrono.getId();
        } else {
            name = getChronologyName(chrono, context.getLocale());
        }
        int nameLen = name.length();
        if (nameLen > matchLen && context.subSequenceEquals(text, position, name, 0, nameLen)) {
            bestMatch = chrono;
            matchLen = nameLen;
        }
    }
    if (bestMatch == null) {
        return ~position;
    }
    context.setParsed(bestMatch);
    return position + matchLen;
}
 
Example 10
Source File: DateTimeFormatterBuilder.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
@Override
public int parse(DateTimeParseContext context, CharSequence text, int position) {
    // simple looping parser to find the chronology
    if (position < 0 || position > text.length()) {
        throw new IndexOutOfBoundsException();
    }
    Set<Chronology> chronos = Chronology.getAvailableChronologies();
    Chronology bestMatch = null;
    int matchLen = -1;
    for (Chronology chrono : chronos) {
        String name;
        if (textStyle == null) {
            name = chrono.getId();
        } else {
            name = getChronologyName(chrono, context.getLocale());
        }
        int nameLen = name.length();
        if (nameLen > matchLen && context.subSequenceEquals(text, position, name, 0, nameLen)) {
            bestMatch = chrono;
            matchLen = nameLen;
        }
    }
    if (bestMatch == null) {
        return ~position;
    }
    context.setParsed(bestMatch);
    return position + matchLen;
}
 
Example 11
Source File: DateTimeFormatterBuilder.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int parse(DateTimeParseContext context, CharSequence text, int position) {
    // simple looping parser to find the chronology
    if (position < 0 || position > text.length()) {
        throw new IndexOutOfBoundsException();
    }
    Set<Chronology> chronos = Chronology.getAvailableChronologies();
    Chronology bestMatch = null;
    int matchLen = -1;
    for (Chronology chrono : chronos) {
        String name;
        if (textStyle == null) {
            name = chrono.getId();
        } else {
            name = getChronologyName(chrono, context.getLocale());
        }
        int nameLen = name.length();
        if (nameLen > matchLen && context.subSequenceEquals(text, position, name, 0, nameLen)) {
            bestMatch = chrono;
            matchLen = nameLen;
        }
    }
    if (bestMatch == null) {
        return ~position;
    }
    context.setParsed(bestMatch);
    return position + matchLen;
}
 
Example 12
Source File: TestFormatter.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private String getClassName(Object o) {
    Class<?> c = o.getClass();
    String clname = c.getName().substring(c.getPackage().getName().length() + 1);
    if (o instanceof TemporalAccessor) {
        Chronology chrono = ((TemporalAccessor)o).query(TemporalQueries.chronology());
        if (chrono != null) {
            clname = clname + "(" + chrono.getId() + ")";
        }
    }
    if (o instanceof Calendar) {
        String type = ((Calendar)o).getCalendarType();
        clname = clname + "(" + type + ")";
    }
    return clname;
}
 
Example 13
Source File: TestFormatter.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private String getClassName(Object o) {
    Class<?> c = o.getClass();
    String clname = c.getName().substring(c.getPackage().getName().length() + 1);
    if (o instanceof TemporalAccessor) {
        Chronology chrono = ((TemporalAccessor)o).query(TemporalQueries.chronology());
        if (chrono != null) {
            clname = clname + "(" + chrono.getId() + ")";
        }
    }
    if (o instanceof Calendar) {
        String type = ((Calendar)o).getCalendarType();
        clname = clname + "(" + type + ")";
    }
    return clname;
}
 
Example 14
Source File: Period.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Validates that the temporal has the correct chronology.
 */
private void validateChrono(TemporalAccessor temporal) {
    Objects.requireNonNull(temporal, "temporal");
    Chronology temporalChrono = temporal.query(TemporalQueries.chronology());
    if (temporalChrono != null && IsoChronology.INSTANCE.equals(temporalChrono) == false) {
        throw new DateTimeException("Chronology mismatch, expected: ISO, actual: " + temporalChrono.getId());
    }
}
 
Example 15
Source File: DateTimeFormatterBuilder.java    From hottub with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the chronology name of the given chrono in the given locale
 * if available, or the chronology Id otherwise. The regular ResourceBundle
 * search path is used for looking up the chronology name.
 *
 * @param chrono  the chronology, not null
 * @param locale  the locale, not null
 * @return the chronology name of chrono in locale, or the id if no name is available
 * @throws NullPointerException if chrono or locale is null
 */
private String getChronologyName(Chronology chrono, Locale locale) {
    String key = "calendarname." + chrono.getCalendarType();
    String name = DateTimeTextProvider.getLocalizedResource(key, locale);
    return name != null ? name : chrono.getId();
}
 
Example 16
Source File: DateTimeFormatterBuilder.java    From Java8CN with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the chronology name of the given chrono in the given locale
 * if available, or the chronology Id otherwise. The regular ResourceBundle
 * search path is used for looking up the chronology name.
 *
 * @param chrono  the chronology, not null
 * @param locale  the locale, not null
 * @return the chronology name of chrono in locale, or the id if no name is available
 * @throws NullPointerException if chrono or locale is null
 */
private String getChronologyName(Chronology chrono, Locale locale) {
    String key = "calendarname." + chrono.getCalendarType();
    String name = DateTimeTextProvider.getLocalizedResource(key, locale);
    return name != null ? name : chrono.getId();
}
 
Example 17
Source File: DateTimeFormatterBuilder.java    From jdk8u-dev-jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the chronology name of the given chrono in the given locale
 * if available, or the chronology Id otherwise. The regular ResourceBundle
 * search path is used for looking up the chronology name.
 *
 * @param chrono  the chronology, not null
 * @param locale  the locale, not null
 * @return the chronology name of chrono in locale, or the id if no name is available
 * @throws NullPointerException if chrono or locale is null
 */
private String getChronologyName(Chronology chrono, Locale locale) {
    String key = "calendarname." + chrono.getCalendarType();
    String name = DateTimeTextProvider.getLocalizedResource(key, locale);
    return name != null ? name : chrono.getId();
}
 
Example 18
Source File: DateTimeFormatterBuilder.java    From jdk8u-jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the chronology name of the given chrono in the given locale
 * if available, or the chronology Id otherwise. The regular ResourceBundle
 * search path is used for looking up the chronology name.
 *
 * @param chrono  the chronology, not null
 * @param locale  the locale, not null
 * @return the chronology name of chrono in locale, or the id if no name is available
 * @throws NullPointerException if chrono or locale is null
 */
private String getChronologyName(Chronology chrono, Locale locale) {
    String key = "calendarname." + chrono.getCalendarType();
    String name = DateTimeTextProvider.getLocalizedResource(key, locale);
    return name != null ? name : chrono.getId();
}
 
Example 19
Source File: DateTimeFormatterBuilder.java    From dragonwell8_jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the chronology name of the given chrono in the given locale
 * if available, or the chronology Id otherwise. The regular ResourceBundle
 * search path is used for looking up the chronology name.
 *
 * @param chrono  the chronology, not null
 * @param locale  the locale, not null
 * @return the chronology name of chrono in locale, or the id if no name is available
 * @throws NullPointerException if chrono or locale is null
 */
private String getChronologyName(Chronology chrono, Locale locale) {
    String key = "calendarname." + chrono.getCalendarType();
    String name = DateTimeTextProvider.getLocalizedResource(key, locale);
    return name != null ? name : chrono.getId();
}
 
Example 20
Source File: DateTimeFormatterBuilder.java    From openjdk-jdk8u with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the chronology name of the given chrono in the given locale
 * if available, or the chronology Id otherwise. The regular ResourceBundle
 * search path is used for looking up the chronology name.
 *
 * @param chrono  the chronology, not null
 * @param locale  the locale, not null
 * @return the chronology name of chrono in locale, or the id if no name is available
 * @throws NullPointerException if chrono or locale is null
 */
private String getChronologyName(Chronology chrono, Locale locale) {
    String key = "calendarname." + chrono.getCalendarType();
    String name = DateTimeTextProvider.getLocalizedResource(key, locale);
    return name != null ? name : chrono.getId();
}