View Javadoc

1   /*
2    * $Id: PropertyList.java [Apr 5, 2004]
3    *
4    * Copyright (c) 2004, Ben Fortuna
5    * All rights reserved.
6    *
7    * Redistribution and use in source and binary forms, with or without
8    * modification, are permitted provided that the following conditions
9    * are met:
10   *
11   * 	o Redistributions of source code must retain the above copyright
12   * notice, this list of conditions and the following disclaimer.
13   *
14   * 	o Redistributions in binary form must reproduce the above copyright
15   * notice, this list of conditions and the following disclaimer in the
16   * documentation and/or other materials provided with the distribution.
17   *
18   * 	o Neither the name of Ben Fortuna nor the names of any other contributors
19   * may be used to endorse or promote products derived from this software
20   * without specific prior written permission.
21   *
22   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25   * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
26   * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27   * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28   * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29   * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30   * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31   * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32   * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33   */
34  package net.fortuna.ical4j.model;
35  
36  import java.util.ArrayList;
37  import java.util.Iterator;
38  import java.util.List;
39  
40  /***
41   * Defines a list of iCalendar properties.
42   *
43   * @author benf
44   */
45  public class PropertyList {
46  
47      private List properties;
48  
49      /***
50       * Constructor.
51       */
52      public PropertyList() {
53          properties = new ArrayList();
54      }
55  
56      /***
57       * @see java.util.AbstractCollection#toString()
58       */
59      public final String toString() {
60  
61          StringBuffer buffer = new StringBuffer();
62  
63          for (Iterator i = properties.iterator(); i.hasNext();) {
64  
65              buffer.append(i.next().toString());
66          }
67  
68          return buffer.toString();
69      }
70  
71      /***
72       * Returns the first property of specified name.
73       * @param aName name of property to return
74       * @return a property or null if no matching property found
75       */
76      public final Property getProperty(final String aName) {
77  
78          for (Iterator i = properties.iterator(); i.hasNext();) {
79              Property p = (Property) i.next();
80  
81              if (p.getName().equals(aName)) {
82                  return p;
83              }
84          }
85  
86          return null;
87      }
88  
89      /***
90       * Returns a list of properties with the specified name.
91       * @param name
92       *            name of properties to return
93       * @return a property list
94       */
95      public final PropertyList getProperties(final String name) {
96          PropertyList list = new PropertyList();
97  
98          for (Iterator i = properties.iterator(); i.hasNext();) {
99              Property p = (Property) i.next();
100 
101             if (p.getName().equals(name)) {
102                 list.add(p);
103             }
104         }
105         return list;
106     }
107 
108     /***
109      * Add a property to the list.
110      * @param property the property to add
111      * @return true
112      * @see List#add(java.lang.Object)
113      */
114     public final boolean add(final Property property) {
115         return properties.add(property);
116     }
117 
118     /***
119      * @return boolean indicates if the list is empty
120      * @see List#isEmpty()
121      */
122     public final boolean isEmpty() {
123         return properties.isEmpty();
124     }
125 
126     /***
127      * @return an iterator
128      * @see List#iterator()
129      */
130     public final Iterator iterator() {
131         return properties.iterator();
132     }
133 
134     /***
135      * Remove a property from the list
136      * @param property the property to remove
137      * @return true if the list contained the specified property
138      * @see List#remove(java.lang.Object)
139      */
140     public final boolean remove(final Property property) {
141         return properties.remove(property);
142     }
143 
144     /***
145      * @return the number of properties in the list
146      * @see List#size()
147      */
148     public final int size() {
149         return properties.size();
150     }
151 }