1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/net/fortuna/ical4j/model/property/Priority.java Tue Feb 10 18:12:00 2015 +0100 1.3 @@ -0,0 +1,239 @@ 1.4 +/** 1.5 + * Copyright (c) 2012, Ben Fortuna 1.6 + * All rights reserved. 1.7 + * 1.8 + * Redistribution and use in source and binary forms, with or without 1.9 + * modification, are permitted provided that the following conditions 1.10 + * are met: 1.11 + * 1.12 + * o Redistributions of source code must retain the above copyright 1.13 + * notice, this list of conditions and the following disclaimer. 1.14 + * 1.15 + * o Redistributions in binary form must reproduce the above copyright 1.16 + * notice, this list of conditions and the following disclaimer in the 1.17 + * documentation and/or other materials provided with the distribution. 1.18 + * 1.19 + * o Neither the name of Ben Fortuna nor the names of any other contributors 1.20 + * may be used to endorse or promote products derived from this software 1.21 + * without specific prior written permission. 1.22 + * 1.23 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.24 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.25 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.26 + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 1.27 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 1.28 + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 1.29 + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 1.30 + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 1.31 + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 1.32 + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 1.33 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.34 + */ 1.35 +package net.fortuna.ical4j.model.property; 1.36 + 1.37 +import net.fortuna.ical4j.model.ParameterList; 1.38 +import net.fortuna.ical4j.model.Property; 1.39 +import net.fortuna.ical4j.model.PropertyFactoryImpl; 1.40 +import net.fortuna.ical4j.model.ValidationException; 1.41 + 1.42 +/** 1.43 + * $Id$ 1.44 + * 1.45 + * Created: [Apr 6, 2004] 1.46 + * 1.47 + * Defines a PRIORITY iCalendar component property. 1.48 + * 1.49 + * <pre> 1.50 + * 4.8.1.9 Priority 1.51 + * 1.52 + * Property Name: PRIORITY 1.53 + * 1.54 + * Purpose: The property defines the relative priority for a calendar 1.55 + * component. 1.56 + * 1.57 + * Value Type: INTEGER 1.58 + * 1.59 + * Property Parameters: Non-standard property parameters can be 1.60 + * specified on this property. 1.61 + * 1.62 + * Conformance: The property can be specified in a "VEVENT" or "VTODO" 1.63 + * calendar component. 1.64 + * 1.65 + * Description: The priority is specified as an integer in the range 1.66 + * zero to nine. A value of zero (US-ASCII decimal 48) specifies an 1.67 + * undefined priority. A value of one (US-ASCII decimal 49) is the 1.68 + * highest priority. A value of two (US-ASCII decimal 50) is the second 1.69 + * highest priority. Subsequent numbers specify a decreasing ordinal 1.70 + * priority. A value of nine (US-ASCII decimal 58) is the lowest 1.71 + * priority. 1.72 + * 1.73 + * A CUA with a three-level priority scheme of "HIGH", "MEDIUM" and 1.74 + * "LOW" is mapped into this property such that a property value in the 1.75 + * range of one (US-ASCII decimal 49) to four (US-ASCII decimal 52) 1.76 + * specifies "HIGH" priority. A value of five (US-ASCII decimal 53) is 1.77 + * the normal or "MEDIUM" priority. A value in the range of six (US- 1.78 + * ASCII decimal 54) to nine (US-ASCII decimal 58) is "LOW" priority. 1.79 + * 1.80 + * A CUA with a priority schema of "A1", "A2", "A3", 1.81 + * "B1", "B2", ..., 1.82 + * "C3" is mapped into this property such that a property value of one 1.83 + * (US-ASCII decimal 49) specifies "A1", a property value of two (US- 1.84 + * ASCII decimal 50) specifies "A2", a property value of three (US-ASCII 1.85 + * decimal 51) specifies "A3", and so forth up to a property value of 9 1.86 + * (US-ASCII decimal 58) specifies "C3". 1.87 + * 1.88 + * Other integer values are reserved for future use. 1.89 + * 1.90 + * Within a "VEVENT" calendar component, this property specifies a 1.91 + * priority for the event. This property may be useful when more than 1.92 + * one event is scheduled for a given time period. 1.93 + * 1.94 + * Within a "VTODO" calendar component, this property specified a 1.95 + * priority for the to-do. This property is useful in prioritizing 1.96 + * multiple action items for a given time period. 1.97 + * 1.98 + * Format Definition: The property is specified by the following 1.99 + * notation: 1.100 + * 1.101 + * priority = "PRIORITY" prioparam ":" privalue CRLF 1.102 + * ;Default is zero 1.103 + * 1.104 + * prioparam = *(";" xparam) 1.105 + * 1.106 + * privalue = integer ;Must be in the range [0..9] 1.107 + * ; All other values are reserved for future use 1.108 + * 1.109 + * The following is an example of a property with the highest priority: 1.110 + * 1.111 + * PRIORITY:1 1.112 + * 1.113 + * The following is an example of a property with a next highest 1.114 + * priority: 1.115 + * 1.116 + * PRIORITY:2 1.117 + * 1.118 + * Example: The following is an example of a property with no priority. 1.119 + * This is equivalent to not specifying the "PRIORITY" property: 1.120 + * 1.121 + * PRIORITY:0 1.122 + * </pre> 1.123 + * 1.124 + * @author Ben Fortuna 1.125 + */ 1.126 +public class Priority extends Property { 1.127 + 1.128 + private static final long serialVersionUID = -5654367843953827397L; 1.129 + 1.130 + /** 1.131 + * Undefined priority. 1.132 + */ 1.133 + public static final Priority UNDEFINED = new ImmutablePriority(0); 1.134 + 1.135 + /** 1.136 + * High priority. 1.137 + */ 1.138 + public static final Priority HIGH = new ImmutablePriority(1); 1.139 + 1.140 + /** 1.141 + * Medium priority. 1.142 + */ 1.143 + public static final Priority MEDIUM = new ImmutablePriority(5); 1.144 + 1.145 + /** 1.146 + * Low priority. 1.147 + */ 1.148 + public static final Priority LOW = new ImmutablePriority(9); 1.149 + 1.150 + /** 1.151 + * @author Ben Fortuna An immutable instance of Priority. 1.152 + */ 1.153 + private static final class ImmutablePriority extends Priority { 1.154 + 1.155 + private static final long serialVersionUID = 5884973714694108418L; 1.156 + 1.157 + private ImmutablePriority(final int level) { 1.158 + super(new ParameterList(true), level); 1.159 + } 1.160 + 1.161 + public void setValue(final String aValue) { 1.162 + throw new UnsupportedOperationException( 1.163 + "Cannot modify constant instances"); 1.164 + } 1.165 + 1.166 + public void setLevel(final int level) { 1.167 + throw new UnsupportedOperationException( 1.168 + "Cannot modify constant instances"); 1.169 + } 1.170 + } 1.171 + 1.172 + private int level; 1.173 + 1.174 + /** 1.175 + * Default constructor. 1.176 + */ 1.177 + public Priority() { 1.178 + super(PRIORITY, PropertyFactoryImpl.getInstance()); 1.179 + level = UNDEFINED.getLevel(); 1.180 + } 1.181 + 1.182 + /** 1.183 + * @param aList a list of parameters for this component 1.184 + * @param aValue a value string for this component 1.185 + */ 1.186 + public Priority(final ParameterList aList, final String aValue) { 1.187 + super(PRIORITY, aList, PropertyFactoryImpl.getInstance()); 1.188 + level = Integer.parseInt(aValue); 1.189 + } 1.190 + 1.191 + /** 1.192 + * @param aLevel an int representation of a priority level 1.193 + */ 1.194 + public Priority(final int aLevel) { 1.195 + super(PRIORITY, PropertyFactoryImpl.getInstance()); 1.196 + level = aLevel; 1.197 + } 1.198 + 1.199 + /** 1.200 + * @param aList a list of parameters for this component 1.201 + * @param aLevel an int representation of a priority level 1.202 + */ 1.203 + public Priority(final ParameterList aList, final int aLevel) { 1.204 + super(PRIORITY, aList, PropertyFactoryImpl.getInstance()); 1.205 + level = aLevel; 1.206 + } 1.207 + 1.208 + /** 1.209 + * @return Returns the level. 1.210 + */ 1.211 + public final int getLevel() { 1.212 + return level; 1.213 + } 1.214 + 1.215 + /** 1.216 + * {@inheritDoc} 1.217 + */ 1.218 + public void setValue(final String aValue) { 1.219 + level = Integer.parseInt(aValue); 1.220 + } 1.221 + 1.222 + /** 1.223 + * {@inheritDoc} 1.224 + */ 1.225 + public final String getValue() { 1.226 + return String.valueOf(getLevel()); 1.227 + } 1.228 + 1.229 + /** 1.230 + * @param level The level to set. 1.231 + */ 1.232 + public void setLevel(final int level) { 1.233 + this.level = level; 1.234 + } 1.235 + 1.236 + /** 1.237 + * {@inheritDoc} 1.238 + */ 1.239 + public final void validate() throws ValidationException { 1.240 + // TODO: Auto-generated method stub 1.241 + } 1.242 +}