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 type of action to invoke when an alarm is triggered.
034 * </p>
035 * 
036 * <p>
037 * <b>Code sample (creating):</b>
038 * 
039 * <pre class="brush:java">
040 * Action action = Action.audio();
041 * </pre>
042 * 
043 * </p>
044 * 
045 * <p>
046 * <b>Code sample (retrieving):</b>
047 * 
048 * <pre class="brush:java">
049 * ICalendar ical = ...
050 * for (VAlarm alarm : ical.getAlarms()){
051 *   Action action = alarm.getAction();
052 *   if (action.isAudio()) {
053 *         ...
054 *   } else if (action.isEmail()){
055 *     ...
056 *   } else if (action.isDisplay()){
057 *     ...
058 *   }
059 * }
060 * </pre>
061 * 
062 * </p>
063 * @author Michael Angstadt
064 * @see <a href="http://tools.ietf.org/html/rfc5545#page-132">RFC 5545 p.132-3</a>
065 */
066public class Action extends EnumProperty {
067        private static final String AUDIO = "AUDIO";
068        private static final String DISPLAY = "DISPLAY";
069        private static final String EMAIL = "EMAIL";
070
071        /**
072         * Creates an action property. Use of this constructor is discouraged and
073         * may put the property in an invalid state. Use one of the static factory
074         * methods instead.
075         * @param value the value (e.g. "AUDIO")
076         */
077        public Action(String value) {
078                super(value);
079        }
080
081        /**
082         * Creates an "audio" action property.
083         * @return the property
084         */
085        public static Action audio() {
086                return create(AUDIO);
087        }
088
089        /**
090         * Determines if this property is an "audio" action.
091         * @return true if it's an "audio" action, false if not
092         */
093        public boolean isAudio() {
094                return is(AUDIO);
095        }
096
097        /**
098         * Creates an "display" action property.
099         * @return the property
100         */
101        public static Action display() {
102                return create(DISPLAY);
103        }
104
105        /**
106         * Determines if this property is an "display" action.
107         * @return true if it's an "display" action, false if not
108         */
109        public boolean isDisplay() {
110                return is(DISPLAY);
111        }
112
113        /**
114         * Creates an "email" action property.
115         * @return the property
116         */
117        public static Action email() {
118                return create(EMAIL);
119        }
120
121        /**
122         * Determines if this property is an "email" action.
123         * @return true if it's an "email" action, false if not
124         */
125        public boolean isEmail() {
126                return is(EMAIL);
127        }
128
129        private static Action create(String value) {
130                return new Action(value);
131        }
132
133        @Override
134        protected Collection<String> getStandardValues() {
135                return Arrays.asList(AUDIO, DISPLAY, EMAIL);
136        }
137}