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