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     * Defines the status of the component that this property belongs to.
030     * @author Michael Angstadt
031     * @see <a href="http://tools.ietf.org/html/rfc5545#page-92">RFC 5545 p.92-3</a>
032     */
033    public class Status extends TextProperty {
034            //TODO create separate classes for each component?
035            private static final String TENTATIVE = "TENTATIVE";
036            private static final String CONFIRMED = "CONFIRMED";
037            private static final String CANCELLED = "CANCELLED";
038            private static final String NEEDS_ACTION = "NEEDS-ACTION";
039            private static final String COMPLETED = "COMPLETED";
040            private static final String IN_PROGRESS = "IN-PROGRESS";
041            private static final String DRAFT = "DRAFT";
042            private static final String FINAL = "FINAL";
043    
044            /**
045             * Creates a status property. Use of this constructor is discouraged and may
046             * put the property in an invalid state. Use one of the static factory
047             * methods instead.
048             * @param status the status (e.g. "TENTATIVE")
049             */
050            public Status(String status) {
051                    super(status);
052            }
053    
054            /**
055             * Creates a "tentative" status property (only valid for event components).
056             * @return the property
057             */
058            public static Status tentative() {
059                    return create(TENTATIVE);
060            }
061    
062            /**
063             * Determines if the status is set to "tentative".
064             * @return true if set to "tentative", false if not
065             */
066            public boolean isTentative() {
067                    return is(TENTATIVE);
068            }
069    
070            /**
071             * Creates a "confirmed" status property (only valid for event components).
072             * @return the property
073             */
074            public static Status confirmed() {
075                    return create(CONFIRMED);
076            }
077    
078            /**
079             * Determines if the status is set to "confirmed".
080             * @return true if set to "confirmed", false if not
081             */
082            public boolean isConfirmed() {
083                    return is(CONFIRMED);
084            }
085    
086            /**
087             * Creates a "cancelled" status property (only valid for event, to-do, and
088             * journal components).
089             * @return the property
090             */
091            public static Status cancelled() {
092                    return create(CANCELLED);
093            }
094    
095            /**
096             * Determines if the status is set to "cancelled".
097             * @return true if set to "cancelled", false if not
098             */
099            public boolean isCancelled() {
100                    return is(CANCELLED);
101            }
102    
103            /**
104             * Creates a "needs-action" status property (only valid for to-do
105             * components).
106             * @return the property
107             */
108            public static Status needsAction() {
109                    return create(NEEDS_ACTION);
110            }
111    
112            /**
113             * Determines if the status is set to "needs-action".
114             * @return true if set to "needs-action", false if not
115             */
116            public boolean isNeedsAction() {
117                    return is(NEEDS_ACTION);
118            }
119    
120            /**
121             * Creates a "completed" status property (only valid for to-do components).
122             * @return the property
123             */
124            public static Status completed() {
125                    return create(COMPLETED);
126            }
127    
128            /**
129             * Determines if the status is set to "completed".
130             * @return true if set to "completed", false if not
131             */
132            public boolean isCompleted() {
133                    return is(COMPLETED);
134            }
135    
136            /**
137             * Creates a "in-progress" status property (only valid for to-do components).
138             * @return the property
139             */
140            public static Status inProgress() {
141                    return create(IN_PROGRESS);
142            }
143    
144            /**
145             * Determines if the status is set to "in-progress".
146             * @return true if set to "in-progress", false if not
147             */
148            public boolean isInProgress() {
149                    return is(IN_PROGRESS);
150            }
151    
152            /**
153             * Creates a "draft" status property (only valid for journal components).
154             * @return the property
155             */
156            public static Status draft() {
157                    return create(DRAFT);
158            }
159    
160            /**
161             * Determines if the status is set to "draft".
162             * @return true if set to "draft", false if not
163             */
164            public boolean isDraft() {
165                    return is(DRAFT);
166            }
167    
168            /**
169             * Creates a "final" status property (only valid for journal components).
170             * @return the property
171             */
172            public static Status final_() {
173                    return create(FINAL);
174            }
175    
176            /**
177             * Determines if the status is set to "final".
178             * @return true if set to "final", false if not
179             */
180            public boolean isFinal() {
181                    return is(FINAL);
182            }
183    
184            private static Status create(String status) {
185                    return new Status(status);
186            }
187    
188            private boolean is(String status) {
189                    return status.equalsIgnoreCase(value);
190            }
191    }