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