001 /*
002 * Copyright (C) 2008-2009 Holger Arndt, A. Naegele and M. Bundschus
003 *
004 * This file is part of the Java Data Mining Package (JDMP).
005 * See the NOTICE file distributed with this work for additional
006 * information regarding copyright ownership and licensing.
007 *
008 * JDMP is free software; you can redistribute it and/or modify
009 * it under the terms of the GNU Lesser General Public License as
010 * published by the Free Software Foundation; either version 2
011 * of the License, or (at your option) any later version.
012 *
013 * JDMP is distributed in the hope that it will be useful,
014 * but WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016 * GNU Lesser General Public License for more details.
017 *
018 * You should have received a copy of the GNU Lesser General Public
019 * License along with JDMP; if not, write to the
020 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
021 * Boston, MA 02110-1301 USA
022 */
023
024 package org.jdmp.jetty.collections;
025
026 import java.net.URL;
027 import java.util.Collection;
028 import java.util.Iterator;
029 import java.util.List;
030 import java.util.ListIterator;
031
032 import org.jdmp.jetty.JettyObjectClient;
033 import org.ujmp.core.exceptions.MatrixException;
034
035 public class JettyListClient<V> implements List<V> {
036
037 private JettyObjectClient client = null;
038
039 public JettyListClient(URL url) {
040 client = new JettyObjectClient(url);
041 }
042
043 @Override
044 public boolean add(V e) {
045 try {
046 return (Boolean) client.execute("add", e);
047 } catch (Exception ex) {
048 throw new MatrixException(ex);
049 }
050 }
051
052 @Override
053 public void add(int index, V element) {
054 try {
055 client.execute("add", index, element);
056 } catch (Exception e) {
057 throw new MatrixException(e);
058 }
059 }
060
061 @Override
062 public boolean addAll(Collection<? extends V> c) {
063 try {
064 return (Boolean) client.execute("addAll", c);
065 } catch (Exception e) {
066 throw new MatrixException(e);
067 }
068 }
069
070 @Override
071 public boolean addAll(int index, Collection<? extends V> c) {
072 try {
073 return (Boolean) client.execute("addAll", index, c);
074 } catch (Exception e) {
075 throw new MatrixException(e);
076 }
077 }
078
079 @Override
080 public boolean contains(Object o) {
081 try {
082 return (Boolean) client.execute("contains", o);
083 } catch (Exception e) {
084 throw new MatrixException(e);
085 }
086 }
087
088 @Override
089 public boolean containsAll(Collection<?> c) {
090 try {
091 return (Boolean) client.execute("containsAll", c);
092 } catch (Exception e) {
093 throw new MatrixException(e);
094 }
095 }
096
097 @SuppressWarnings("unchecked")
098 @Override
099 public V get(int index) {
100 try {
101 return (V) client.execute("get", index);
102 } catch (Exception e) {
103 throw new MatrixException(e);
104 }
105 }
106
107 @Override
108 public int indexOf(Object o) {
109 try {
110 return (Integer) client.execute("indexOf", o);
111 } catch (Exception e) {
112 throw new MatrixException(e);
113 }
114 }
115
116 @Override
117 public Iterator<V> iterator() {
118 try {
119 return (Iterator<V>) client.execute("iterator");
120 } catch (Exception e) {
121 throw new MatrixException(e);
122 }
123 }
124
125 @Override
126 public int lastIndexOf(Object o) {
127 try {
128 return (Integer) client.execute("lastIndexOf", o);
129 } catch (Exception e) {
130 throw new MatrixException(e);
131 }
132 }
133
134 @SuppressWarnings("unchecked")
135 @Override
136 public ListIterator<V> listIterator() {
137 try {
138 return (ListIterator<V>) client.execute("listIterator");
139 } catch (Exception e) {
140 throw new MatrixException(e);
141 }
142 }
143
144 @SuppressWarnings("unchecked")
145 @Override
146 public ListIterator<V> listIterator(int index) {
147 try {
148 return (ListIterator<V>) client.execute("listIterator", index);
149 } catch (Exception e) {
150 throw new MatrixException(e);
151 }
152 }
153
154 @SuppressWarnings("unchecked")
155 @Override
156 public V remove(int index) {
157 try {
158 return (V) client.execute("remove", index);
159 } catch (Exception e) {
160 throw new MatrixException(e);
161 }
162 }
163
164 @Override
165 public boolean removeAll(Collection<?> c) {
166 try {
167 return (Boolean) client.execute("removeAll", c);
168 } catch (Exception e) {
169 throw new MatrixException(e);
170 }
171 }
172
173 @Override
174 public boolean retainAll(Collection<?> c) {
175 try {
176 return (Boolean) client.execute("retainAll", c);
177 } catch (Exception e) {
178 throw new MatrixException(e);
179 }
180 }
181
182 @SuppressWarnings("unchecked")
183 @Override
184 public V set(int index, V element) {
185 try {
186 return (V) client.execute("set", index, element);
187 } catch (Exception e) {
188 throw new MatrixException(e);
189 }
190 }
191
192 @SuppressWarnings("unchecked")
193 @Override
194 public List<V> subList(int fromIndex, int toIndex) {
195 try {
196 return (List<V>) client.execute("subList", fromIndex, toIndex);
197 } catch (Exception e) {
198 throw new MatrixException(e);
199 }
200 }
201
202 @Override
203 public Object[] toArray() {
204 try {
205 return (Object[]) client.execute("toArray");
206 } catch (Exception e) {
207 throw new MatrixException(e);
208 }
209 }
210
211 @SuppressWarnings("unchecked")
212 @Override
213 public <T> T[] toArray(T[] a) {
214 try {
215 return (T[]) client.execute("toArray", a);
216 } catch (Exception e) {
217 throw new MatrixException(e);
218 }
219 }
220
221 @Override
222 public void clear() {
223 try {
224 client.execute("clear");
225 } catch (Exception e) {
226 throw new MatrixException(e);
227 }
228 }
229
230 @Override
231 public boolean isEmpty() {
232 try {
233 return (Boolean) client.execute("isEmpty");
234 } catch (Exception e) {
235 throw new MatrixException(e);
236 }
237 }
238
239 @Override
240 public int size() {
241 try {
242 return (Integer) client.execute("size");
243 } catch (Exception e) {
244 throw new MatrixException(e);
245 }
246 }
247
248 @Override
249 public boolean remove(Object o) {
250 try {
251 return (Boolean) client.execute("remove", o);
252 } catch (Exception e) {
253 throw new MatrixException(e);
254 }
255 }
256
257 }