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