< prev index next >

src/java.base/share/classes/java/time/chrono/ThaiBuddhistEra.java

Print this page
rev 17640 : [mq]: 8171049


  44  *    and/or other materials provided with the distribution.
  45  *
  46  *  * Neither the name of JSR-310 nor the names of its contributors
  47  *    may be used to endorse or promote products derived from this software
  48  *    without specific prior written permission.
  49  *
  50  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  51  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  52  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  53  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  54  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  55  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  56  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  57  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  58  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  59  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  60  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  61  */
  62 package java.time.chrono;
  63 


  64 import java.time.DateTimeException;



  65 
  66 /**
  67  * An era in the Thai Buddhist calendar system.
  68  * <p>
  69  * The Thai Buddhist calendar system has two eras.
  70  * The current era, for years from 1 onwards, is known as the 'Buddhist' era.
  71  * All previous years, zero or earlier in the proleptic count or one and greater
  72  * in the year-of-era count, are part of the 'Before Buddhist' era.
  73  *
  74  * <table class="striped" style="text-align:left">
  75  * <caption style="display:none">Buddhist years and eras</caption>
  76  * <thead>
  77  * <tr>
  78  * <th scope="col">year-of-era</th>
  79  * <th scope="col">era</th>
  80  * <th scope="col">proleptic-year</th>
  81  * <th scope="col">ISO proleptic-year</th>
  82  * </tr>
  83  * </thead>
  84  * <tbody>


 136             case 1:
 137                 return BE;
 138             default:
 139                 throw new DateTimeException("Invalid era: " + thaiBuddhistEra);
 140         }
 141     }
 142 
 143     //-----------------------------------------------------------------------
 144     /**
 145      * Gets the numeric era {@code int} value.
 146      * <p>
 147      * The era BEFORE_BE has the value 0, while the era BE has the value 1.
 148      *
 149      * @return the era value, from 0 (BEFORE_BE) to 1 (BE)
 150      */
 151     @Override
 152     public int getValue() {
 153         return ordinal();
 154     }
 155 















 156 }


  44  *    and/or other materials provided with the distribution.
  45  *
  46  *  * Neither the name of JSR-310 nor the names of its contributors
  47  *    may be used to endorse or promote products derived from this software
  48  *    without specific prior written permission.
  49  *
  50  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  51  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  52  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  53  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  54  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  55  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  56  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  57  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  58  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  59  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  60  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  61  */
  62 package java.time.chrono;
  63 
  64 import static java.time.temporal.ChronoField.ERA;
  65 
  66 import java.time.DateTimeException;
  67 import java.time.format.DateTimeFormatterBuilder;
  68 import java.time.format.TextStyle;
  69 import java.util.Locale;
  70 
  71 /**
  72  * An era in the Thai Buddhist calendar system.
  73  * <p>
  74  * The Thai Buddhist calendar system has two eras.
  75  * The current era, for years from 1 onwards, is known as the 'Buddhist' era.
  76  * All previous years, zero or earlier in the proleptic count or one and greater
  77  * in the year-of-era count, are part of the 'Before Buddhist' era.
  78  *
  79  * <table class="striped" style="text-align:left">
  80  * <caption style="display:none">Buddhist years and eras</caption>
  81  * <thead>
  82  * <tr>
  83  * <th scope="col">year-of-era</th>
  84  * <th scope="col">era</th>
  85  * <th scope="col">proleptic-year</th>
  86  * <th scope="col">ISO proleptic-year</th>
  87  * </tr>
  88  * </thead>
  89  * <tbody>


 141             case 1:
 142                 return BE;
 143             default:
 144                 throw new DateTimeException("Invalid era: " + thaiBuddhistEra);
 145         }
 146     }
 147 
 148     //-----------------------------------------------------------------------
 149     /**
 150      * Gets the numeric era {@code int} value.
 151      * <p>
 152      * The era BEFORE_BE has the value 0, while the era BE has the value 1.
 153      *
 154      * @return the era value, from 0 (BEFORE_BE) to 1 (BE)
 155      */
 156     @Override
 157     public int getValue() {
 158         return ordinal();
 159     }
 160 
 161     /**
 162      * {@inheritDoc}
 163      *
 164      * @param style {@inheritDoc}
 165      * @param locale {@inheritDoc}
 166      */
 167     @Override
 168     public String getDisplayName(TextStyle style, Locale locale) {
 169         return new DateTimeFormatterBuilder()
 170             .appendText(ERA, style)
 171             .toFormatter(locale)
 172             .withChronology(ThaiBuddhistChronology.INSTANCE)
 173             .format(this == BE ? ThaiBuddhistDate.of(1, 1, 1) : ThaiBuddhistDate.of(0, 1, 1));
 174     }
 175 
 176 }
< prev index next >