michael@0: /** michael@0: * Copyright (c) 2012, Ben Fortuna michael@0: * All rights reserved. michael@0: * michael@0: * Redistribution and use in source and binary forms, with or without michael@0: * modification, are permitted provided that the following conditions michael@0: * are met: michael@0: * michael@0: * o Redistributions of source code must retain the above copyright michael@0: * notice, this list of conditions and the following disclaimer. michael@0: * michael@0: * o Redistributions in binary form must reproduce the above copyright michael@0: * notice, this list of conditions and the following disclaimer in the michael@0: * documentation and/or other materials provided with the distribution. michael@0: * michael@0: * o Neither the name of Ben Fortuna nor the names of any other contributors michael@0: * may be used to endorse or promote products derived from this software michael@0: * without specific prior written permission. michael@0: * michael@0: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS michael@0: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT michael@0: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR michael@0: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR michael@0: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, michael@0: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, michael@0: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR michael@0: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF michael@0: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING michael@0: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS michael@0: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. michael@0: */ michael@0: package net.fortuna.ical4j.model.property; michael@0: michael@0: import net.fortuna.ical4j.model.ParameterList; michael@0: import net.fortuna.ical4j.model.Property; michael@0: import net.fortuna.ical4j.model.PropertyFactoryImpl; michael@0: import net.fortuna.ical4j.model.ValidationException; michael@0: michael@0: /** michael@0: * $Id$ michael@0: * michael@0: * Created: [Apr 6, 2004] michael@0: * michael@0: * Defines a PRIORITY iCalendar component property. michael@0: * michael@0: *
michael@0:  *     4.8.1.9 Priority
michael@0:  *     
michael@0:  *        Property Name: PRIORITY
michael@0:  *     
michael@0:  *        Purpose: The property defines the relative priority for a calendar
michael@0:  *        component.
michael@0:  *     
michael@0:  *        Value Type: INTEGER
michael@0:  *     
michael@0:  *        Property Parameters: Non-standard property parameters can be
michael@0:  *        specified on this property.
michael@0:  *     
michael@0:  *        Conformance: The property can be specified in a "VEVENT" or "VTODO"
michael@0:  *        calendar component.
michael@0:  *     
michael@0:  *        Description: The priority is specified as an integer in the range
michael@0:  *        zero to nine. A value of zero (US-ASCII decimal 48) specifies an
michael@0:  *        undefined priority. A value of one (US-ASCII decimal 49) is the
michael@0:  *        highest priority. A value of two (US-ASCII decimal 50) is the second
michael@0:  *        highest priority. Subsequent numbers specify a decreasing ordinal
michael@0:  *        priority. A value of nine (US-ASCII decimal 58) is the lowest
michael@0:  *        priority.
michael@0:  *     
michael@0:  *        A CUA with a three-level priority scheme of "HIGH", "MEDIUM" and
michael@0:  *        "LOW" is mapped into this property such that a property value in the
michael@0:  *        range of one (US-ASCII decimal 49) to four (US-ASCII decimal 52)
michael@0:  *        specifies "HIGH" priority. A value of five (US-ASCII decimal 53) is
michael@0:  *        the normal or "MEDIUM" priority. A value in the range of six (US-
michael@0:  *        ASCII decimal 54) to nine (US-ASCII decimal 58) is "LOW" priority.
michael@0:  *     
michael@0:  *        A CUA with a priority schema of "A1", "A2", "A3",
michael@0:  *         "B1", "B2", ...,
michael@0:  *        "C3" is mapped into this property such that a property value of one
michael@0:  *        (US-ASCII decimal 49) specifies "A1", a property value of two (US-
michael@0:  *        ASCII decimal 50) specifies "A2", a property value of three (US-ASCII
michael@0:  *        decimal 51) specifies "A3", and so forth up to a property value of 9
michael@0:  *        (US-ASCII decimal 58) specifies "C3".
michael@0:  *     
michael@0:  *        Other integer values are reserved for future use.
michael@0:  *     
michael@0:  *        Within a "VEVENT" calendar component, this property specifies a
michael@0:  *        priority for the event. This property may be useful when more than
michael@0:  *        one event is scheduled for a given time period.
michael@0:  *     
michael@0:  *        Within a "VTODO" calendar component, this property specified a
michael@0:  *        priority for the to-do. This property is useful in prioritizing
michael@0:  *        multiple action items for a given time period.
michael@0:  *     
michael@0:  *        Format Definition: The property is specified by the following
michael@0:  *        notation:
michael@0:  *     
michael@0:  *          priority   = "PRIORITY" prioparam ":" privalue CRLF
michael@0:  *          ;Default is zero
michael@0:  *     
michael@0:  *          prioparam  = *(";" xparam)
michael@0:  *     
michael@0:  *          privalue   = integer       ;Must be in the range [0..9]
michael@0:  *             ; All other values are reserved for future use
michael@0:  *     
michael@0:  *        The following is an example of a property with the highest priority:
michael@0:  *     
michael@0:  *          PRIORITY:1
michael@0:  *     
michael@0:  *        The following is an example of a property with a next highest
michael@0:  *        priority:
michael@0:  *     
michael@0:  *          PRIORITY:2
michael@0:  *     
michael@0:  *        Example: The following is an example of a property with no priority.
michael@0:  *        This is equivalent to not specifying the "PRIORITY" property:
michael@0:  *     
michael@0:  *          PRIORITY:0
michael@0:  * 
michael@0: * michael@0: * @author Ben Fortuna michael@0: */ michael@0: public class Priority extends Property { michael@0: michael@0: private static final long serialVersionUID = -5654367843953827397L; michael@0: michael@0: /** michael@0: * Undefined priority. michael@0: */ michael@0: public static final Priority UNDEFINED = new ImmutablePriority(0); michael@0: michael@0: /** michael@0: * High priority. michael@0: */ michael@0: public static final Priority HIGH = new ImmutablePriority(1); michael@0: michael@0: /** michael@0: * Medium priority. michael@0: */ michael@0: public static final Priority MEDIUM = new ImmutablePriority(5); michael@0: michael@0: /** michael@0: * Low priority. michael@0: */ michael@0: public static final Priority LOW = new ImmutablePriority(9); michael@0: michael@0: /** michael@0: * @author Ben Fortuna An immutable instance of Priority. michael@0: */ michael@0: private static final class ImmutablePriority extends Priority { michael@0: michael@0: private static final long serialVersionUID = 5884973714694108418L; michael@0: michael@0: private ImmutablePriority(final int level) { michael@0: super(new ParameterList(true), level); michael@0: } michael@0: michael@0: public void setValue(final String aValue) { michael@0: throw new UnsupportedOperationException( michael@0: "Cannot modify constant instances"); michael@0: } michael@0: michael@0: public void setLevel(final int level) { michael@0: throw new UnsupportedOperationException( michael@0: "Cannot modify constant instances"); michael@0: } michael@0: } michael@0: michael@0: private int level; michael@0: michael@0: /** michael@0: * Default constructor. michael@0: */ michael@0: public Priority() { michael@0: super(PRIORITY, PropertyFactoryImpl.getInstance()); michael@0: level = UNDEFINED.getLevel(); michael@0: } michael@0: michael@0: /** michael@0: * @param aList a list of parameters for this component michael@0: * @param aValue a value string for this component michael@0: */ michael@0: public Priority(final ParameterList aList, final String aValue) { michael@0: super(PRIORITY, aList, PropertyFactoryImpl.getInstance()); michael@0: level = Integer.parseInt(aValue); michael@0: } michael@0: michael@0: /** michael@0: * @param aLevel an int representation of a priority level michael@0: */ michael@0: public Priority(final int aLevel) { michael@0: super(PRIORITY, PropertyFactoryImpl.getInstance()); michael@0: level = aLevel; michael@0: } michael@0: michael@0: /** michael@0: * @param aList a list of parameters for this component michael@0: * @param aLevel an int representation of a priority level michael@0: */ michael@0: public Priority(final ParameterList aList, final int aLevel) { michael@0: super(PRIORITY, aList, PropertyFactoryImpl.getInstance()); michael@0: level = aLevel; michael@0: } michael@0: michael@0: /** michael@0: * @return Returns the level. michael@0: */ michael@0: public final int getLevel() { michael@0: return level; michael@0: } michael@0: michael@0: /** michael@0: * {@inheritDoc} michael@0: */ michael@0: public void setValue(final String aValue) { michael@0: level = Integer.parseInt(aValue); michael@0: } michael@0: michael@0: /** michael@0: * {@inheritDoc} michael@0: */ michael@0: public final String getValue() { michael@0: return String.valueOf(getLevel()); michael@0: } michael@0: michael@0: /** michael@0: * @param level The level to set. michael@0: */ michael@0: public void setLevel(final int level) { michael@0: this.level = level; michael@0: } michael@0: michael@0: /** michael@0: * {@inheritDoc} michael@0: */ michael@0: public final void validate() throws ValidationException { michael@0: // TODO: Auto-generated method stub michael@0: } michael@0: }