001package biweekly.property;
002
003import java.util.Arrays;
004import java.util.Collection;
005
006/*
007 Copyright (c) 2013, Michael Angstadt
008 All rights reserved.
009
010 Redistribution and use in source and binary forms, with or without
011 modification, are permitted provided that the following conditions are met: 
012
013 1. Redistributions of source code must retain the above copyright notice, this
014 list of conditions and the following disclaimer. 
015 2. Redistributions in binary form must reproduce the above copyright notice,
016 this list of conditions and the following disclaimer in the documentation
017 and/or other materials provided with the distribution. 
018
019 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
020 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
021 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
022 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
023 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
024 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
025 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
026 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
027 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
028 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029 */
030
031/**
032 * <p>
033 * Defines the calendar system that this iCalendar object uses for all its date
034 * values. If none is specified, then the calendar is assumed to be in
035 * "gregorian" format.
036 * </p>
037 * 
038 * <p>
039 * <b>Code sample (creating):</b>
040 * 
041 * <pre class="brush:java">
042 * ICalendar ical = new ICalendar();
043 * ical.setCalendarScale(CalendarScale.gregorian());
044 * 
045 * ical = new ICalendar();
046 * ical.setCalendarScale(new CalendarScale(&quot;another-calendar-system&quot;));
047 * </pre>
048 * 
049 * </p>
050 * 
051 * <p>
052 * <b>Code sample (retrieving):</b>
053 * 
054 * <pre class="brush:java">
055 * ICalendar ical = ...
056 * CalendarScale calscale = ical.getCalendarscale();
057 * 
058 * if (calscale.isGregorian()) {
059 *       ...
060 * } else {
061 *   String value = calscale.getValue();
062 *   ...
063 * }
064 * </pre>
065 * 
066 * </p>
067 * 
068 * <p>
069 * <b>Examples:</b>
070 * 
071 * <pre class="brush:java">
072 * //creating a new property
073 * CalendarScale calscale = CalendarScale.gregorian();
074 * 
075 * if (calscale.isGregorian()) {
076 *      //its value is &quot;GREGORIAN&quot;
077 * }
078 * </pre>
079 * 
080 * </p>
081 * @author Michael Angstadt
082 * @see <a href="http://tools.ietf.org/html/rfc5545#page-76">RFC 5545 p.76-7</a>
083 */
084public class CalendarScale extends EnumProperty {
085        private static final String GREGORIAN = "GREGORIAN";
086
087        /**
088         * Creates a new calendar scale property. Use of this constructor is
089         * discouraged and may put the property in an invalid state. Use one of the
090         * static factory methods instead.
091         * @param value the value of the property (e.g. "gregorian")
092         */
093        public CalendarScale(String value) {
094                super(value);
095        }
096
097        /**
098         * Creates a new property whose value is set to "gregorian".
099         * @return the new property
100         */
101        public static CalendarScale gregorian() {
102                return new CalendarScale(GREGORIAN);
103        }
104
105        /**
106         * Determines whether the property is set to "gregorian".
107         * @return true if it's set to "gregorian", false if not
108         */
109        public boolean isGregorian() {
110                return is(GREGORIAN);
111        }
112
113        @Override
114        protected Collection<String> getStandardValues() {
115                return Arrays.asList(GREGORIAN);
116        }
117}