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

Tue, 10 Feb 2015 19:58:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 10 Feb 2015 19:58:00 +0100
changeset 4
45d57ecba757
permissions
-rw-r--r--

Upgrade the upgraded ical4j component to use org.apache.commons.lang3.

     1 /**
     2  * Copyright (c) 2012, Ben Fortuna
     3  * All rights reserved.
     4  *
     5  * Redistribution and use in source and binary forms, with or without
     6  * modification, are permitted provided that the following conditions
     7  * are met:
     8  *
     9  *  o Redistributions of source code must retain the above copyright
    10  * notice, this list of conditions and the following disclaimer.
    11  *
    12  *  o Redistributions in binary form must reproduce the above copyright
    13  * notice, this list of conditions and the following disclaimer in the
    14  * documentation and/or other materials provided with the distribution.
    15  *
    16  *  o Neither the name of Ben Fortuna nor the names of any other contributors
    17  * may be used to endorse or promote products derived from this software
    18  * without specific prior written permission.
    19  *
    20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
    24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
    27  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
    28  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
    29  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    31  */
    32 package net.fortuna.ical4j.model.property;
    34 import java.text.ParseException;
    36 import net.fortuna.ical4j.model.Parameter;
    37 import net.fortuna.ical4j.model.ParameterList;
    38 import net.fortuna.ical4j.model.PeriodList;
    39 import net.fortuna.ical4j.model.Property;
    40 import net.fortuna.ical4j.model.PropertyFactoryImpl;
    41 import net.fortuna.ical4j.model.ValidationException;
    42 import net.fortuna.ical4j.util.ParameterValidator;
    44 /**
    45  * $Id$
    46  * 
    47  * Created: [Apr 14, 2004]
    48  *
    49  * Defines a FREEBUSY iCalendar component property.
    50  * 
    51  * <pre>
    52  *     4.8.2.6 Free/Busy Time
    53  *     
    54  *        Property Name: FREEBUSY
    55  *     
    56  *        Purpose: The property defines one or more free or busy time
    57  *        intervals.
    58  *     
    59  *        Value Type: PERIOD. The date and time values MUST be in an UTC time
    60  *        format.
    61  *     
    62  *        Property Parameters: Non-standard or free/busy time type property
    63  *        parameters can be specified on this property.
    64  *     
    65  *        Conformance: The property can be specified in a &quot;VFREEBUSY&quot; calendar
    66  *        component.
    67  *     
    68  *        Property Parameter: &quot;FBTYPE&quot; and non-standard parameters can be
    69  *        specified on this property.
    70  *     
    71  *        Description: These time periods can be specified as either a start
    72  *        and end date-time or a start date-time and duration. The date and
    73  *        time MUST be a UTC time format.
    74  *     
    75  *        &quot;FREEBUSY&quot; properties within the &quot;VFREEBUSY&quot; calendar component
    76  *        SHOULD be sorted in ascending order, based on start time and then end
    77  *        time, with the earliest periods first.
    78  *     
    79  *        The &quot;FREEBUSY&quot; property can specify more than one value, separated by
    80  *        the COMMA character (US-ASCII decimal 44). In such cases, the
    81  *        &quot;FREEBUSY&quot; property values SHOULD all be of the same &quot;FBTYPE&quot;
    82  *        property parameter type (e.g., all values of a particular &quot;FBTYPE&quot;
    83  *        listed together in a single property).
    84  *     
    85  *        Format Definition: The property is defined by the following notation:
    86  *     
    87  *          freebusy   = &quot;FREEBUSY&quot; fbparam &quot;:&quot; fbvalue
    88  *                       CRLF
    89  *     
    90  *          fbparam    = *(
    91  *                     ; the following is optional,
    92  *                     ; but MUST NOT occur more than once
    93  *     
    94  *                     (&quot;;&quot; fbtypeparam) /
    95  *     
    96  *                     ; the following is optional,
    97  *                     ; and MAY occur more than once
    98  *     
    99  *                     (&quot;;&quot; xparam)
   100  *     
   101  *                     )
   102  *     
   103  *          fbvalue    = period *[&quot;,&quot; period]
   104  *          ;Time value MUST be in the UTC time format.
   105  * </pre>
   106  * 
   107  * @author Ben Fortuna
   108  */
   109 public class FreeBusy extends Property {
   111     private static final long serialVersionUID = -6415954847619338567L;
   113     private PeriodList periods;
   115     /**
   116      * Default constructor.
   117      */
   118     public FreeBusy() {
   119         super(FREEBUSY, PropertyFactoryImpl.getInstance());
   120         periods = new PeriodList();
   121     }
   123     /**
   124      * @param aValue a freebusy value
   125      * @throws ParseException where the specified string is not a valid freebusy value
   126      */
   127     public FreeBusy(final String aValue) throws ParseException {
   128         super(FREEBUSY, PropertyFactoryImpl.getInstance());
   129         setValue(aValue);
   130     }
   132     /**
   133      * @param aList a list of parameters for this component
   134      * @param aValue a value string for this component
   135      * @throws ParseException when the specified string is not a valid list of periods
   136      */
   137     public FreeBusy(final ParameterList aList, final String aValue)
   138             throws ParseException {
   139         super(FREEBUSY, aList, PropertyFactoryImpl.getInstance());
   140         setValue(aValue);
   141     }
   143     /**
   144      * @param pList a list of periods
   145      */
   146     public FreeBusy(final PeriodList pList) {
   147         super(FREEBUSY, PropertyFactoryImpl.getInstance());
   148         if (!pList.isUtc()) {
   149             throw new IllegalArgumentException("Periods must be in UTC format");
   150         }
   151         periods = pList;
   152     }
   154     /**
   155      * @param aList a list of parameters for this component
   156      * @param pList a list of periods
   157      */
   158     public FreeBusy(final ParameterList aList, final PeriodList pList) {
   159         super(FREEBUSY, aList, PropertyFactoryImpl.getInstance());
   160         if (!pList.isUtc()) {
   161             throw new IllegalArgumentException("Periods must be in UTC format");
   162         }
   163         periods = pList;
   164     }
   166     /**
   167      * {@inheritDoc}
   168      */
   169     public final void validate() throws ValidationException {
   171         /*
   172          * ; the following is optional, ; but MUST NOT occur more than once (";" fbtypeparam) /
   173          */
   174         ParameterValidator.getInstance().assertOneOrLess(Parameter.FBTYPE,
   175                 getParameters());
   177         /*
   178          * ; the following is optional, ; and MAY occur more than once (";" xparam)
   179          */
   181         if (!periods.isUtc()) {
   182             throw new ValidationException("Periods must be in UTC format");
   183         }
   184     }
   186     /**
   187      * @return Returns the periods.
   188      */
   189     public final PeriodList getPeriods() {
   190         return periods;
   191     }
   193     /**
   194      * {@inheritDoc}
   195      */
   196     public final void setValue(final String aValue) throws ParseException {
   197         periods = new PeriodList(aValue);
   198     }
   200     /**
   201      * {@inheritDoc}
   202      */
   203     public final String getValue() {
   204         return getPeriods().toString();
   205     }
   206 }

mercurial