src/share/classes/java/time/chrono/ThaiBuddhistChronology.java

Print this page

        

*** 52,73 **** * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ ! package java.time.calendar; import static java.time.temporal.ChronoField.YEAR; import java.io.Serializable; import java.time.DateTimeException; import java.time.LocalDate; ! import java.time.temporal.Chrono; import java.time.temporal.ChronoField; - import java.time.temporal.ChronoLocalDate; - import java.time.temporal.Era; - import java.time.temporal.ISOChrono; import java.time.temporal.TemporalAccessor; import java.time.temporal.ValueRange; import java.util.Arrays; import java.util.HashMap; import java.util.List; --- 52,72 ---- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ ! package java.time.chrono; import static java.time.temporal.ChronoField.YEAR; import java.io.Serializable; + import java.time.Clock; import java.time.DateTimeException; + import java.time.Instant; import java.time.LocalDate; ! import java.time.ZoneId; import java.time.temporal.ChronoField; import java.time.temporal.TemporalAccessor; import java.time.temporal.ValueRange; import java.util.Arrays; import java.util.HashMap; import java.util.List;
*** 99,123 **** * <h3>Specification for implementors</h3> * This class is immutable and thread-safe. * * @since 1.8 */ ! public final class ThaiBuddhistChrono extends Chrono<ThaiBuddhistChrono> implements Serializable { /** * Singleton instance of the Buddhist chronology. */ ! public static final ThaiBuddhistChrono INSTANCE = new ThaiBuddhistChrono(); /** * The singleton instance for the era before the current one - Before Buddhist - * which has the value 0. */ ! public static final Era<ThaiBuddhistChrono> ERA_BEFORE_BE = ThaiBuddhistEra.BEFORE_BE; /** * The singleton instance for the current era - Buddhist - which has the value 1. */ ! public static final Era<ThaiBuddhistChrono> ERA_BE = ThaiBuddhistEra.BE; /** * Serialization version. */ private static final long serialVersionUID = 2775954514031616474L; --- 98,122 ---- * <h3>Specification for implementors</h3> * This class is immutable and thread-safe. * * @since 1.8 */ ! public final class ThaiBuddhistChronology extends Chronology implements Serializable { /** * Singleton instance of the Buddhist chronology. */ ! public static final ThaiBuddhistChronology INSTANCE = new ThaiBuddhistChronology(); /** * The singleton instance for the era before the current one - Before Buddhist - * which has the value 0. */ ! public static final Era ERA_BEFORE_BE = ThaiBuddhistEra.BEFORE_BE; /** * The singleton instance for the current era - Buddhist - which has the value 1. */ ! public static final Era ERA_BE = ThaiBuddhistEra.BE; /** * Serialization version. */ private static final long serialVersionUID = 2775954514031616474L;
*** 162,172 **** } /** * Restricted constructor. */ ! private ThaiBuddhistChrono() { } /** * Resolve singleton. * --- 161,171 ---- } /** * Restricted constructor. */ ! private ThaiBuddhistChronology() { } /** * Resolve singleton. *
*** 178,189 **** //----------------------------------------------------------------------- /** * Gets the ID of the chronology - 'ThaiBuddhist'. * <p> ! * The ID uniquely identifies the {@code Chrono}. ! * It can be used to lookup the {@code Chrono} using {@link #of(String)}. * * @return the chronology ID - 'ThaiBuddhist' * @see #getCalendarType() */ @Override --- 177,188 ---- //----------------------------------------------------------------------- /** * Gets the ID of the chronology - 'ThaiBuddhist'. * <p> ! * The ID uniquely identifies the {@code Chronology}. ! * It can be used to lookup the {@code Chronology} using {@link #of(String)}. * * @return the chronology ID - 'ThaiBuddhist' * @see #getCalendarType() */ @Override
*** 194,204 **** /** * Gets the calendar type of the underlying calendar system - 'buddhist'. * <p> * The calendar type is an identifier defined by the * <em>Unicode Locale Data Markup Language (LDML)</em> specification. ! * It can be used to lookup the {@code Chrono} using {@link #of(String)}. * It can also be used as part of a locale, accessible via * {@link Locale#getUnicodeLocaleType(String)} with the key 'ca'. * * @return the calendar system type - 'buddhist' * @see #getId() --- 193,203 ---- /** * Gets the calendar type of the underlying calendar system - 'buddhist'. * <p> * The calendar type is an identifier defined by the * <em>Unicode Locale Data Markup Language (LDML)</em> specification. ! * It can be used to lookup the {@code Chronology} using {@link #of(String)}. * It can also be used as part of a locale, accessible via * {@link Locale#getUnicodeLocaleType(String)} with the key 'ca'. * * @return the calendar system type - 'buddhist' * @see #getId()
*** 208,233 **** return "buddhist"; } //----------------------------------------------------------------------- @Override ! public ChronoLocalDate<ThaiBuddhistChrono> date(int prolepticYear, int month, int dayOfMonth) { return new ThaiBuddhistDate(LocalDate.of(prolepticYear - YEARS_DIFFERENCE, month, dayOfMonth)); } @Override ! public ChronoLocalDate<ThaiBuddhistChrono> dateYearDay(int prolepticYear, int dayOfYear) { return new ThaiBuddhistDate(LocalDate.ofYearDay(prolepticYear - YEARS_DIFFERENCE, dayOfYear)); } @Override ! public ChronoLocalDate<ThaiBuddhistChrono> date(TemporalAccessor temporal) { if (temporal instanceof ThaiBuddhistDate) { return (ThaiBuddhistDate) temporal; } return new ThaiBuddhistDate(LocalDate.from(temporal)); } //----------------------------------------------------------------------- /** * Checks if the specified year is a leap year. * <p> --- 207,272 ---- return "buddhist"; } //----------------------------------------------------------------------- @Override ! public ThaiBuddhistDate date(int prolepticYear, int month, int dayOfMonth) { return new ThaiBuddhistDate(LocalDate.of(prolepticYear - YEARS_DIFFERENCE, month, dayOfMonth)); } @Override ! public ThaiBuddhistDate dateYearDay(int prolepticYear, int dayOfYear) { return new ThaiBuddhistDate(LocalDate.ofYearDay(prolepticYear - YEARS_DIFFERENCE, dayOfYear)); } @Override ! public ThaiBuddhistDate date(TemporalAccessor temporal) { if (temporal instanceof ThaiBuddhistDate) { return (ThaiBuddhistDate) temporal; } return new ThaiBuddhistDate(LocalDate.from(temporal)); } + @Override + public ThaiBuddhistDate date(Era era, int yearOfEra, int month, int dayOfMonth) { + return date(prolepticYear(era, yearOfEra), month, dayOfMonth); + + } + + @Override + public ThaiBuddhistDate dateYearDay(Era era, int yearOfEra, int dayOfYear) { + return dateYearDay(prolepticYear(era, yearOfEra), dayOfYear); + } + + @Override + public ThaiBuddhistDate dateNow() { + return dateNow(Clock.systemDefaultZone()); + } + + @Override + public ThaiBuddhistDate dateNow(ZoneId zone) { + return dateNow(Clock.system(zone)); + } + + @Override + public ThaiBuddhistDate dateNow(Clock clock) { + return date(LocalDate.now(clock)); + } + + @Override + public ChronoLocalDateTime<ThaiBuddhistDate> localDateTime(TemporalAccessor temporal) { + return (ChronoLocalDateTime<ThaiBuddhistDate>)super.localDateTime(temporal); + } + + @Override + public ChronoZonedDateTime<ThaiBuddhistDate> zonedDateTime(TemporalAccessor temporal) { + return (ChronoZonedDateTime<ThaiBuddhistDate>)super.zonedDateTime(temporal); + } + + @Override + public ChronoZonedDateTime<ThaiBuddhistDate> zonedDateTime(Instant instant, ZoneId zone) { + return (ChronoZonedDateTime<ThaiBuddhistDate>)super.zonedDateTime(instant, zone); + } //----------------------------------------------------------------------- /** * Checks if the specified year is a leap year. * <p>
*** 238,266 **** * @param prolepticYear the proleptic-year to check, not validated for range * @return true if the year is a leap year */ @Override public boolean isLeapYear(long prolepticYear) { ! return ISOChrono.INSTANCE.isLeapYear(prolepticYear - YEARS_DIFFERENCE); } @Override ! public int prolepticYear(Era<ThaiBuddhistChrono> era, int yearOfEra) { if (era instanceof ThaiBuddhistEra == false) { throw new DateTimeException("Era must be BuddhistEra"); } return (era == ThaiBuddhistEra.BE ? yearOfEra : 1 - yearOfEra); } @Override ! public Era<ThaiBuddhistChrono> eraOf(int eraValue) { return ThaiBuddhistEra.of(eraValue); } @Override ! public List<Era<ThaiBuddhistChrono>> eras() { ! return Arrays.<Era<ThaiBuddhistChrono>>asList(ThaiBuddhistEra.values()); } //----------------------------------------------------------------------- @Override public ValueRange range(ChronoField field) { --- 277,305 ---- * @param prolepticYear the proleptic-year to check, not validated for range * @return true if the year is a leap year */ @Override public boolean isLeapYear(long prolepticYear) { ! return IsoChronology.INSTANCE.isLeapYear(prolepticYear - YEARS_DIFFERENCE); } @Override ! public int prolepticYear(Era era, int yearOfEra) { if (era instanceof ThaiBuddhistEra == false) { throw new DateTimeException("Era must be BuddhistEra"); } return (era == ThaiBuddhistEra.BE ? yearOfEra : 1 - yearOfEra); } @Override ! public Era eraOf(int eraValue) { return ThaiBuddhistEra.of(eraValue); } @Override ! public List<Era> eras() { ! return Arrays.<Era>asList(ThaiBuddhistEra.values()); } //----------------------------------------------------------------------- @Override public ValueRange range(ChronoField field) {