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 status of the component that this property belongs to, such as a
034 * to-do task being "completed".
035 * </p>
036 * 
037 * <p>
038 * <b>Code sample (creating):</b>
039 * 
040 * <pre class="brush:java">
041 * VTodo todo = new VTodo();
042 * 
043 * Status status = Status.completed();
044 * todo.setStatus(status);
045 * </pre>
046 * 
047 * </p>
048 * 
049 * <p>
050 * <b>Code sample (retrieving):</b>
051 * 
052 * <pre class="brush:java">
053 * ICalendar ical = ...
054 * for (VTodo todo : ical.getTodos()){
055 *   Status status = todo.getStatus();
056 *   if (action.isCompleted()) {
057 *         ...
058 *   } else if (action.isDraft()){
059 *     ...
060 *   }
061 *   //etc.
062 * }
063 * </pre>
064 * 
065 * </p>
066 * @author Michael Angstadt
067 * @see <a href="http://tools.ietf.org/html/rfc5545#page-92">RFC 5545 p.92-3</a>
068 */
069public class Status extends EnumProperty {
070        private static final String TENTATIVE = "TENTATIVE";
071        private static final String CONFIRMED = "CONFIRMED";
072        private static final String CANCELLED = "CANCELLED";
073        private static final String NEEDS_ACTION = "NEEDS-ACTION";
074        private static final String COMPLETED = "COMPLETED";
075        private static final String IN_PROGRESS = "IN-PROGRESS";
076        private static final String DRAFT = "DRAFT";
077        private static final String FINAL = "FINAL";
078
079        /**
080         * Creates a status property. Use of this constructor is discouraged and may
081         * put the property in an invalid state. Use one of the static factory
082         * methods instead.
083         * @param status the status (e.g. "TENTATIVE")
084         */
085        public Status(String status) {
086                super(status);
087        }
088
089        /**
090         * Creates a "tentative" status property (only valid for event components).
091         * @return the property
092         */
093        public static Status tentative() {
094                return create(TENTATIVE);
095        }
096
097        /**
098         * Determines if the status is set to "tentative".
099         * @return true if set to "tentative", false if not
100         */
101        public boolean isTentative() {
102                return is(TENTATIVE);
103        }
104
105        /**
106         * Creates a "confirmed" status property (only valid for event components).
107         * @return the property
108         */
109        public static Status confirmed() {
110                return create(CONFIRMED);
111        }
112
113        /**
114         * Determines if the status is set to "confirmed".
115         * @return true if set to "confirmed", false if not
116         */
117        public boolean isConfirmed() {
118                return is(CONFIRMED);
119        }
120
121        /**
122         * Creates a "cancelled" status property (only valid for event, to-do, and
123         * journal components).
124         * @return the property
125         */
126        public static Status cancelled() {
127                return create(CANCELLED);
128        }
129
130        /**
131         * Determines if the status is set to "cancelled".
132         * @return true if set to "cancelled", false if not
133         */
134        public boolean isCancelled() {
135                return is(CANCELLED);
136        }
137
138        /**
139         * Creates a "needs-action" status property (only valid for to-do
140         * components).
141         * @return the property
142         */
143        public static Status needsAction() {
144                return create(NEEDS_ACTION);
145        }
146
147        /**
148         * Determines if the status is set to "needs-action".
149         * @return true if set to "needs-action", false if not
150         */
151        public boolean isNeedsAction() {
152                return is(NEEDS_ACTION);
153        }
154
155        /**
156         * Creates a "completed" status property (only valid for to-do components).
157         * @return the property
158         */
159        public static Status completed() {
160                return create(COMPLETED);
161        }
162
163        /**
164         * Determines if the status is set to "completed".
165         * @return true if set to "completed", false if not
166         */
167        public boolean isCompleted() {
168                return is(COMPLETED);
169        }
170
171        /**
172         * Creates a "in-progress" status property (only valid for to-do
173         * components).
174         * @return the property
175         */
176        public static Status inProgress() {
177                return create(IN_PROGRESS);
178        }
179
180        /**
181         * Determines if the status is set to "in-progress".
182         * @return true if set to "in-progress", false if not
183         */
184        public boolean isInProgress() {
185                return is(IN_PROGRESS);
186        }
187
188        /**
189         * Creates a "draft" status property (only valid for journal components).
190         * @return the property
191         */
192        public static Status draft() {
193                return create(DRAFT);
194        }
195
196        /**
197         * Determines if the status is set to "draft".
198         * @return true if set to "draft", false if not
199         */
200        public boolean isDraft() {
201                return is(DRAFT);
202        }
203
204        /**
205         * Creates a "final" status property (only valid for journal components).
206         * @return the property
207         */
208        public static Status final_() {
209                return create(FINAL);
210        }
211
212        /**
213         * Determines if the status is set to "final".
214         * @return true if set to "final", false if not
215         */
216        public boolean isFinal() {
217                return is(FINAL);
218        }
219
220        private static Status create(String status) {
221                return new Status(status);
222        }
223
224        @Override
225        protected Collection<String> getStandardValues() {
226                return Arrays.asList(TENTATIVE, CONFIRMED, CANCELLED, NEEDS_ACTION, COMPLETED, IN_PROGRESS, DRAFT, FINAL);
227        }
228}