KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > mapper > util > BaseTypedList


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 Universite de Versailles Saint-Quentin.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307.
18  * You can also get it at http://www.gnu.org/licenses/lgpl.html
19  *
20  * For more information on this software, see http://www.xquark.org.
21  */

22
23 package org.xquark.mapper.util;
24
25
26 import java.util.*;
27
28 public class BaseTypedList implements Cloneable JavaDoc
29 {
30 private static final String JavaDoc RCSRevision = "$Revision: 1.1 $";
31 private static final String JavaDoc RCSName = "$Name: $";
32     public List list;
33     
34     public BaseTypedList()
35     {
36         this.list = new ArrayList();
37     }
38     
39     public BaseTypedList(int size)
40     {
41         this.list = new ArrayList(size);
42     }
43     
44     public BaseTypedList(List list)
45     {
46         this.list = list;
47     }
48     
49     public int size()
50     {
51         if(list==null)
52             return 0;
53         return list.size();
54     }
55     
56     public void add(Object JavaDoc obj)
57     {
58         list.add(obj);
59     }
60     
61     public void add(int i, Object JavaDoc obj)
62     {
63         list.add(i, obj);
64     }
65     
66     public void clear()
67     {
68         list.clear();
69     }
70     
71     public void remove(int index)
72     {
73         list.remove(index);
74     }
75     
76     public void remove(Object JavaDoc element)
77     {
78         list.remove(element);
79     }
80     
81     public void removeLast()
82     {
83         list.remove(list.size() - 1);
84     }
85     
86     public List getList()
87     {
88         return list;
89     }
90     
91     public void set(int index, Object JavaDoc element)
92     {
93         list.set(index, element);
94     }
95     
96     
97     public BaseTypedList subList(int begin, int end)
98     {
99         return new BaseTypedList(list.subList(begin, end));
100     }
101     
102     public ListIterator listIterator()
103     {
104         return list.listIterator();
105     }
106     
107     public Iterator iterator()
108     {
109         return list.iterator();
110     }
111     
112     public int hashCode()
113     {
114         return list.hashCode();
115     }
116     
117     public boolean equals(Object JavaDoc o)
118     {
119         if (( o != null) && (o instanceof BaseTypedList))
120             return this.list.equals(((BaseTypedList)o).list);
121         else
122             return false;
123     }
124     
125     public String JavaDoc toString()
126     {
127         return list.toString();
128     }
129     
130     public Object JavaDoc clone()
131     {
132         BaseTypedList o = null;
133         try {
134             o = (BaseTypedList)super.clone();
135             o.list = (List)((ArrayList)o.list).clone();
136         }
137         catch (CloneNotSupportedException JavaDoc e) {
138             throw new RuntimeException JavaDoc("The List supplied to build the typed list is not clonable");
139         }
140         return o;
141     }
142 }
143
Popular Tags