View Javadoc

1   /***
2    * ***************************************************************
3    * JADE - Java Agent DEvelopment Framework is a framework to develop
4    * multi-agent systems in compliance with the FIPA specifications.
5    * Copyright (C) 2000 CSELT S.p.A.
6    * 
7    * GNU Lesser General Public License
8    * 
9    * This library is free software; you can redistribute it and/or
10   * modify it under the terms of the GNU Lesser General Public
11   * License as published by the Free Software Foundation,
12   * version 2.1 of the License.
13   * 
14   * This library is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17   * Lesser General Public License for more details.
18   * 
19   * You should have received a copy of the GNU Lesser General Public
20   * License along with this library; if not, write to the
21   * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22   * Boston, MA  02111-1307, USA.
23   * **************************************************************
24   */
25  package JADE_SL;
26  
27  import java.util.*;
28  
29  /***
30   * @author Federico Bergenti - Universita` di Parma
31   */
32  public class ContentElementList implements ContentElement {
33    	private List elements = new ArrayList();
34  	
35    	/***
36     	 * Construct a ContentElementList object 
37     	 */
38    	public ContentElementList() {
39    	}
40    
41      /***
42       * Adds a new element (that must be a content element) to this 
43       * content element list.
44       * @param element The element to add.
45       */
46      public void add(ContentElement element) {
47          elements.add(element);
48      } 
49  
50      /***
51       * Retrieves the number of elements in this content element list.
52       * @return The number of elements.
53       */
54      public int size() {
55          return elements.size();
56      } 
57  
58      /***
59       * Retrieves the <code>i</code>-th element in this content element list.
60       * @param i The index of the element to retrieve.
61       * @return The element.
62       */
63      public ContentElement get(int i) {
64          return (ContentElement) elements.get(i);
65      } 
66  
67      /***
68       * @return An <code>Iterator</code> over the elements of this
69       * content element list.
70       */
71      public Iterator iterator() {
72          return elements.iterator();
73      } 
74  
75      /***
76       * Clear all the elements in this content element list.
77       */
78      public void clear() {
79  			elements.clear();
80      }
81  
82     	/***
83       * Test if a given content element is contained in this 
84       * content element list.
85       * @return <code>true</code> if the given content element is contained
86       * in this content element list.
87       */
88      public boolean contains (ContentElement element) {
89  			return elements.contains(element);
90      }
91  
92     	/***
93       * Returns the position of an element within this content element list.
94       * @return The position of an element within this content element list
95       * or -1 if the given element is not contained in this content element 
96       * list.
97       */
98      public int indexOf (ContentElement element) {
99  			return elements.indexOf(element);
100     }
101 
102    	/***
103      * Removes the element at the given position from this content
104      * element list.
105      * @return The removed element.
106      */
107     public ContentElement remove (int index) {
108 			return (ContentElement)elements.remove(index);
109     }
110 
111    	/***
112      * Test if the content element list is empty.
113      * @return <code>true</code> if this content element list does 
114      * not contain any element.
115      */
116     public boolean isEmpty () {
117 			return elements.isEmpty();
118     }
119 
120    	/***
121      * Retrieve all elements in this content element list in the form of 
122      * an array.
123      * @return An array containing all elements in this content element 
124      * list.
125      */
126     public ContentElement[] toArray () {
127 			int size = elements.size();
128       ContentElement[] tmp = new ContentElement[size];
129       for (int i = 0; i < size; i++)
130       	tmp[i] = (ContentElement)elements.get(i);
131       return tmp;
132     }
133 
134 }