src/net/fortuna/ical4j/model/property/Priority.java

Tue, 10 Feb 2015 18:12:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 10 Feb 2015 18:12:00 +0100
changeset 0
fb9019fb1bf7
permissions
-rw-r--r--

Import initial revisions of existing project AndroidCaldavSyncAdapater,
forked from upstream repository at 27e8a0f8495c92e0780d450bdf0c7cec77a03a55.

michael@0 1 /**
michael@0 2 * Copyright (c) 2012, Ben Fortuna
michael@0 3 * All rights reserved.
michael@0 4 *
michael@0 5 * Redistribution and use in source and binary forms, with or without
michael@0 6 * modification, are permitted provided that the following conditions
michael@0 7 * are met:
michael@0 8 *
michael@0 9 * o Redistributions of source code must retain the above copyright
michael@0 10 * notice, this list of conditions and the following disclaimer.
michael@0 11 *
michael@0 12 * o Redistributions in binary form must reproduce the above copyright
michael@0 13 * notice, this list of conditions and the following disclaimer in the
michael@0 14 * documentation and/or other materials provided with the distribution.
michael@0 15 *
michael@0 16 * o Neither the name of Ben Fortuna nor the names of any other contributors
michael@0 17 * may be used to endorse or promote products derived from this software
michael@0 18 * without specific prior written permission.
michael@0 19 *
michael@0 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
michael@0 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
michael@0 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
michael@0 23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
michael@0 24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
michael@0 25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
michael@0 26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
michael@0 27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
michael@0 28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
michael@0 29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
michael@0 30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
michael@0 31 */
michael@0 32 package net.fortuna.ical4j.model.property;
michael@0 33
michael@0 34 import net.fortuna.ical4j.model.ParameterList;
michael@0 35 import net.fortuna.ical4j.model.Property;
michael@0 36 import net.fortuna.ical4j.model.PropertyFactoryImpl;
michael@0 37 import net.fortuna.ical4j.model.ValidationException;
michael@0 38
michael@0 39 /**
michael@0 40 * $Id$
michael@0 41 *
michael@0 42 * Created: [Apr 6, 2004]
michael@0 43 *
michael@0 44 * Defines a PRIORITY iCalendar component property.
michael@0 45 *
michael@0 46 * <pre>
michael@0 47 * 4.8.1.9 Priority
michael@0 48 *
michael@0 49 * Property Name: PRIORITY
michael@0 50 *
michael@0 51 * Purpose: The property defines the relative priority for a calendar
michael@0 52 * component.
michael@0 53 *
michael@0 54 * Value Type: INTEGER
michael@0 55 *
michael@0 56 * Property Parameters: Non-standard property parameters can be
michael@0 57 * specified on this property.
michael@0 58 *
michael@0 59 * Conformance: The property can be specified in a &quot;VEVENT&quot; or &quot;VTODO&quot;
michael@0 60 * calendar component.
michael@0 61 *
michael@0 62 * Description: The priority is specified as an integer in the range
michael@0 63 * zero to nine. A value of zero (US-ASCII decimal 48) specifies an
michael@0 64 * undefined priority. A value of one (US-ASCII decimal 49) is the
michael@0 65 * highest priority. A value of two (US-ASCII decimal 50) is the second
michael@0 66 * highest priority. Subsequent numbers specify a decreasing ordinal
michael@0 67 * priority. A value of nine (US-ASCII decimal 58) is the lowest
michael@0 68 * priority.
michael@0 69 *
michael@0 70 * A CUA with a three-level priority scheme of &quot;HIGH&quot;, &quot;MEDIUM&quot; and
michael@0 71 * &quot;LOW&quot; is mapped into this property such that a property value in the
michael@0 72 * range of one (US-ASCII decimal 49) to four (US-ASCII decimal 52)
michael@0 73 * specifies &quot;HIGH&quot; priority. A value of five (US-ASCII decimal 53) is
michael@0 74 * the normal or &quot;MEDIUM&quot; priority. A value in the range of six (US-
michael@0 75 * ASCII decimal 54) to nine (US-ASCII decimal 58) is &quot;LOW&quot; priority.
michael@0 76 *
michael@0 77 * A CUA with a priority schema of &quot;A1&quot;, &quot;A2&quot;, &quot;A3&quot;,
michael@0 78 * &quot;B1&quot;, &quot;B2&quot;, ...,
michael@0 79 * &quot;C3&quot; is mapped into this property such that a property value of one
michael@0 80 * (US-ASCII decimal 49) specifies &quot;A1&quot;, a property value of two (US-
michael@0 81 * ASCII decimal 50) specifies &quot;A2&quot;, a property value of three (US-ASCII
michael@0 82 * decimal 51) specifies &quot;A3&quot;, and so forth up to a property value of 9
michael@0 83 * (US-ASCII decimal 58) specifies &quot;C3&quot;.
michael@0 84 *
michael@0 85 * Other integer values are reserved for future use.
michael@0 86 *
michael@0 87 * Within a &quot;VEVENT&quot; calendar component, this property specifies a
michael@0 88 * priority for the event. This property may be useful when more than
michael@0 89 * one event is scheduled for a given time period.
michael@0 90 *
michael@0 91 * Within a &quot;VTODO&quot; calendar component, this property specified a
michael@0 92 * priority for the to-do. This property is useful in prioritizing
michael@0 93 * multiple action items for a given time period.
michael@0 94 *
michael@0 95 * Format Definition: The property is specified by the following
michael@0 96 * notation:
michael@0 97 *
michael@0 98 * priority = &quot;PRIORITY&quot; prioparam &quot;:&quot; privalue CRLF
michael@0 99 * ;Default is zero
michael@0 100 *
michael@0 101 * prioparam = *(&quot;;&quot; xparam)
michael@0 102 *
michael@0 103 * privalue = integer ;Must be in the range [0..9]
michael@0 104 * ; All other values are reserved for future use
michael@0 105 *
michael@0 106 * The following is an example of a property with the highest priority:
michael@0 107 *
michael@0 108 * PRIORITY:1
michael@0 109 *
michael@0 110 * The following is an example of a property with a next highest
michael@0 111 * priority:
michael@0 112 *
michael@0 113 * PRIORITY:2
michael@0 114 *
michael@0 115 * Example: The following is an example of a property with no priority.
michael@0 116 * This is equivalent to not specifying the &quot;PRIORITY&quot; property:
michael@0 117 *
michael@0 118 * PRIORITY:0
michael@0 119 * </pre>
michael@0 120 *
michael@0 121 * @author Ben Fortuna
michael@0 122 */
michael@0 123 public class Priority extends Property {
michael@0 124
michael@0 125 private static final long serialVersionUID = -5654367843953827397L;
michael@0 126
michael@0 127 /**
michael@0 128 * Undefined priority.
michael@0 129 */
michael@0 130 public static final Priority UNDEFINED = new ImmutablePriority(0);
michael@0 131
michael@0 132 /**
michael@0 133 * High priority.
michael@0 134 */
michael@0 135 public static final Priority HIGH = new ImmutablePriority(1);
michael@0 136
michael@0 137 /**
michael@0 138 * Medium priority.
michael@0 139 */
michael@0 140 public static final Priority MEDIUM = new ImmutablePriority(5);
michael@0 141
michael@0 142 /**
michael@0 143 * Low priority.
michael@0 144 */
michael@0 145 public static final Priority LOW = new ImmutablePriority(9);
michael@0 146
michael@0 147 /**
michael@0 148 * @author Ben Fortuna An immutable instance of Priority.
michael@0 149 */
michael@0 150 private static final class ImmutablePriority extends Priority {
michael@0 151
michael@0 152 private static final long serialVersionUID = 5884973714694108418L;
michael@0 153
michael@0 154 private ImmutablePriority(final int level) {
michael@0 155 super(new ParameterList(true), level);
michael@0 156 }
michael@0 157
michael@0 158 public void setValue(final String aValue) {
michael@0 159 throw new UnsupportedOperationException(
michael@0 160 "Cannot modify constant instances");
michael@0 161 }
michael@0 162
michael@0 163 public void setLevel(final int level) {
michael@0 164 throw new UnsupportedOperationException(
michael@0 165 "Cannot modify constant instances");
michael@0 166 }
michael@0 167 }
michael@0 168
michael@0 169 private int level;
michael@0 170
michael@0 171 /**
michael@0 172 * Default constructor.
michael@0 173 */
michael@0 174 public Priority() {
michael@0 175 super(PRIORITY, PropertyFactoryImpl.getInstance());
michael@0 176 level = UNDEFINED.getLevel();
michael@0 177 }
michael@0 178
michael@0 179 /**
michael@0 180 * @param aList a list of parameters for this component
michael@0 181 * @param aValue a value string for this component
michael@0 182 */
michael@0 183 public Priority(final ParameterList aList, final String aValue) {
michael@0 184 super(PRIORITY, aList, PropertyFactoryImpl.getInstance());
michael@0 185 level = Integer.parseInt(aValue);
michael@0 186 }
michael@0 187
michael@0 188 /**
michael@0 189 * @param aLevel an int representation of a priority level
michael@0 190 */
michael@0 191 public Priority(final int aLevel) {
michael@0 192 super(PRIORITY, PropertyFactoryImpl.getInstance());
michael@0 193 level = aLevel;
michael@0 194 }
michael@0 195
michael@0 196 /**
michael@0 197 * @param aList a list of parameters for this component
michael@0 198 * @param aLevel an int representation of a priority level
michael@0 199 */
michael@0 200 public Priority(final ParameterList aList, final int aLevel) {
michael@0 201 super(PRIORITY, aList, PropertyFactoryImpl.getInstance());
michael@0 202 level = aLevel;
michael@0 203 }
michael@0 204
michael@0 205 /**
michael@0 206 * @return Returns the level.
michael@0 207 */
michael@0 208 public final int getLevel() {
michael@0 209 return level;
michael@0 210 }
michael@0 211
michael@0 212 /**
michael@0 213 * {@inheritDoc}
michael@0 214 */
michael@0 215 public void setValue(final String aValue) {
michael@0 216 level = Integer.parseInt(aValue);
michael@0 217 }
michael@0 218
michael@0 219 /**
michael@0 220 * {@inheritDoc}
michael@0 221 */
michael@0 222 public final String getValue() {
michael@0 223 return String.valueOf(getLevel());
michael@0 224 }
michael@0 225
michael@0 226 /**
michael@0 227 * @param level The level to set.
michael@0 228 */
michael@0 229 public void setLevel(final int level) {
michael@0 230 this.level = level;
michael@0 231 }
michael@0 232
michael@0 233 /**
michael@0 234 * {@inheritDoc}
michael@0 235 */
michael@0 236 public final void validate() throws ValidationException {
michael@0 237 // TODO: Auto-generated method stub
michael@0 238 }
michael@0 239 }

mercurial