Subversion Repository Public Repository

litesoft

Diff Revisions 282 vs 475 for /trunk/Java/GWT/Client/src/com/google/gwt/gen2/table/client/TableModelHelper.java

Diff revisions: vs.
  @@ -15,12 +15,9 @@
15 15 */
16 16 package com.google.gwt.gen2.table.client;
17 17
18 - import com.google.gwt.user.client.rpc.IsSerializable;
18 + import java.util.*;
19 19
20 - import java.util.ArrayList;
21 - import java.util.Collection;
22 - import java.util.Iterator;
23 - import java.util.List;
20 + import com.google.gwt.user.client.rpc.*;
24 21
25 22 /**
26 23 * A helper class that provides all of the inner classes used by
  @@ -28,412 +25,468 @@
28 25 * {@link TableModel} class itself because of a JDT error that prevents the GWT
29 26 * RPC generator from creating implementations of remote services:
30 27 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=243820
31 - *
28 + * <p/>
32 29 * This class should be removed once this bug is fixed.
33 30 */
34 - public final class TableModelHelper {
35 - /**
36 - * Information about the sort order of a specific column in a table.
37 - */
38 - public static class ColumnSortInfo implements IsSerializable {
31 + public final class TableModelHelper
32 + {
39 33 /**
40 - * True if the sort order is ascending.
34 + * Information about the sort order of a specific column in a table.
41 35 */
42 - private boolean ascending;
43 -
44 - /**
45 - * The column index.
46 - */
47 - private int column;
48 -
49 - /**
50 - * Default constructor used for RPC.
51 - */
52 - public ColumnSortInfo() {
53 - this(0, true);
54 - }
36 + public static class ColumnSortInfo implements IsSerializable
37 + {
38 + /**
39 + * True if the sort order is ascending.
40 + */
41 + private boolean ascending;
42 +
43 + /**
44 + * The column index.
45 + */
46 + private int column;
47 +
48 + /**
49 + * Default constructor used for RPC.
50 + */
51 + public ColumnSortInfo()
52 + {
53 + this( 0, true );
54 + }
55 55
56 - /**
57 - * Construct a new {@link ColumnSortInfo}.
58 - *
59 - * @param column the column index
60 - * @param ascending true if sorted ascending
61 - */
62 - public ColumnSortInfo(int column, boolean ascending) {
63 - this.column = column;
64 - this.ascending = ascending;
65 - }
56 + /**
57 + * Construct a new {@link ColumnSortInfo}.
58 + *
59 + * @param column the column index
60 + * @param ascending true if sorted ascending
61 + */
62 + public ColumnSortInfo( int column, boolean ascending )
63 + {
64 + this.column = column;
65 + this.ascending = ascending;
66 + }
66 67
67 - @Override
68 - public boolean equals(Object obj) {
69 - if (obj instanceof ColumnSortInfo) {
70 - return equals((ColumnSortInfo) obj);
71 - }
72 - return false;
73 - }
68 + @Override
69 + public boolean equals( Object obj )
70 + {
71 + if ( obj instanceof ColumnSortInfo )
72 + {
73 + return equals( (ColumnSortInfo) obj );
74 + }
75 + return false;
76 + }
74 77
75 - /**
76 - * Check if this object is equal to another. The objects are equal if the
77 - * column and ascending values are equal.
78 - *
79 - * @param csi the other object
80 - * @return true if objects are the same
81 - */
82 - public boolean equals(ColumnSortInfo csi) {
83 - if (csi == null) {
84 - return false;
85 - }
86 - return getColumn() == csi.getColumn()
87 - && isAscending() == csi.isAscending();
88 - }
78 + /**
79 + * Check if this object is equal to another. The objects are equal if the
80 + * column and ascending values are equal.
81 + *
82 + * @param csi the other object
83 + *
84 + * @return true if objects are the same
85 + */
86 + public boolean equals( ColumnSortInfo csi )
87 + {
88 + if ( csi == null )
89 + {
90 + return false;
91 + }
92 + return getColumn() == csi.getColumn() && isAscending() == csi.isAscending();
93 + }
89 94
90 - /**
91 - * @return the column index
92 - */
93 - public int getColumn() {
94 - return column;
95 - }
95 + /**
96 + * @return the column index
97 + */
98 + public int getColumn()
99 + {
100 + return column;
101 + }
96 102
97 - @Override
98 - public int hashCode() {
99 - return super.hashCode();
100 - }
103 + @Override
104 + public int hashCode()
105 + {
106 + return super.hashCode();
107 + }
101 108
102 - /**
103 - * @return true if ascending, false if descending
104 - */
105 - public boolean isAscending() {
106 - return ascending;
107 - }
109 + /**
110 + * @return true if ascending, false if descending
111 + */
112 + public boolean isAscending()
113 + {
114 + return ascending;
115 + }
108 116
109 - /**
110 - * Set whether or not the sorting is ascending or descending.
111 - *
112 - * @param ascending true if ascending, false if descending
113 - */
114 - public void setAscending(boolean ascending) {
115 - this.ascending = ascending;
116 - }
117 + /**
118 + * Set whether or not the sorting is ascending or descending.
119 + *
120 + * @param ascending true if ascending, false if descending
121 + */
122 + public void setAscending( boolean ascending )
123 + {
124 + this.ascending = ascending;
125 + }
117 126
118 - /**
119 - * Set the column index.
120 - *
121 - * @param column the column index
122 - */
123 - public void setColumn(int column) {
124 - this.column = column;
127 + /**
128 + * Set the column index.
129 + *
130 + * @param column the column index
131 + */
132 + public void setColumn( int column )
133 + {
134 + this.column = column;
135 + }
125 136 }
126 - }
127 137
128 - /**
129 - * An ordered list of sorting info where each entry tells us how to sort a
130 - * single column. The first entry is the primary sort order, the second entry
131 - * is the first tie-breaker, and so on.
132 - */
133 - public static class ColumnSortList implements IsSerializable,
134 - Iterable<ColumnSortInfo> {
135 138 /**
136 - * A List used to manage the insertion/removal of {@link ColumnSortInfo}.
137 - */
138 - private List<ColumnSortInfo> infos = new ArrayList<ColumnSortInfo>();
139 + * An ordered list of sorting info where each entry tells us how to sort a
140 + * single column. The first entry is the primary sort order, the second entry
141 + * is the first tie-breaker, and so on.
142 + */
143 + public static class ColumnSortList implements IsSerializable,
144 + Iterable<ColumnSortInfo>
145 + {
146 + /**
147 + * A List used to manage the insertion/removal of {@link ColumnSortInfo}.
148 + */
149 + private List<ColumnSortInfo> infos = new ArrayList<ColumnSortInfo>();
150 +
151 + /**
152 + * Add a {@link ColumnSortInfo} to this list. If the column already exists,
153 + * it will be removed from its current position and placed at the start of
154 + * the list, becoming the primary sort info.
155 + * <p/>
156 + * This add method inserts an entry at the beginning of the list. It does
157 + * not append the entry to the end of the list.
158 + *
159 + * @param sortInfo the {@link ColumnSortInfo} to add
160 + */
161 + public void add( ColumnSortInfo sortInfo )
162 + {
163 + add( 0, sortInfo );
164 + }
139 165
140 - /**
141 - * Add a {@link ColumnSortInfo} to this list. If the column already exists,
142 - * it will be removed from its current position and placed at the start of
143 - * the list, becoming the primary sort info.
144 - *
145 - * This add method inserts an entry at the beginning of the list. It does
146 - * not append the entry to the end of the list.
147 - *
148 - * @param sortInfo the {@link ColumnSortInfo} to add
149 - */
150 - public void add(ColumnSortInfo sortInfo) {
151 - add(0, sortInfo);
152 - }
166 + /**
167 + * Inserts the specified {@link ColumnSortInfo} at the specified position in
168 + * this list. If the column already exists in the sort info, the index will
169 + * be adjusted to account for any removed entries.
170 + *
171 + * @param sortInfo the {@link ColumnSortInfo} to add
172 + */
173 + public void add( int index, ColumnSortInfo sortInfo )
174 + {
175 + // Remove sort info for duplicate columns
176 + int column = sortInfo.getColumn();
177 + for ( int i = 0; i < infos.size(); i++ )
178 + {
179 + ColumnSortInfo curInfo = infos.get( i );
180 + if ( curInfo.getColumn() == column )
181 + {
182 + infos.remove( i );
183 + i--;
184 + if ( column < index )
185 + {
186 + index--;
187 + }
188 + }
189 + }
153 190
154 - /**
155 - * Inserts the specified {@link ColumnSortInfo} at the specified position in
156 - * this list. If the column already exists in the sort info, the index will
157 - * be adjusted to account for any removed entries.
158 - *
159 - * @param sortInfo the {@link ColumnSortInfo} to add
160 - */
161 - public void add(int index, ColumnSortInfo sortInfo) {
162 - // Remove sort info for duplicate columns
163 - int column = sortInfo.getColumn();
164 - for (int i = 0; i < infos.size(); i++) {
165 - ColumnSortInfo curInfo = infos.get(i);
166 - if (curInfo.getColumn() == column) {
167 - infos.remove(i);
168 - i--;
169 - if (column < index) {
170 - index--;
171 - }
191 + // Insert the new sort info
192 + infos.add( index, sortInfo );
172 193 }
173 - }
174 194
175 - // Insert the new sort info
176 - infos.add(index, sortInfo);
177 - }
195 + /**
196 + * Removes all of the elements from this list.
197 + */
198 + public void clear()
199 + {
200 + infos.clear();
201 + }
178 202
179 - /**
180 - * Removes all of the elements from this list.
181 - */
182 - public void clear() {
183 - infos.clear();
184 - }
203 + @Override
204 + public boolean equals( Object obj )
205 + {
206 + if ( obj instanceof ColumnSortList )
207 + {
208 + return equals( (ColumnSortList) obj );
209 + }
210 + return false;
211 + }
185 212
186 - @Override
187 - public boolean equals(Object obj) {
188 - if (obj instanceof ColumnSortList) {
189 - return equals((ColumnSortList) obj);
190 - }
191 - return false;
192 - }
213 + /**
214 + * Check if this object is equal to another.
215 + *
216 + * @param csl the other object
217 + *
218 + * @return true if objects are equal
219 + */
220 + public boolean equals( ColumnSortList csl )
221 + {
222 + // Object is null
223 + if ( csl == null )
224 + {
225 + return false;
226 + }
227 +
228 + // Check the size of the lists
229 + int size = size();
230 + if ( size != csl.size() )
231 + {
232 + return false;
233 + }
234 +
235 + // Compare the entries
236 + for ( int i = 0; i < size; i++ )
237 + {
238 + if ( !infos.get( i ).equals( csl.infos.get( i ) ) )
239 + {
240 + return false;
241 + }
242 + }
193 243
194 - /**
195 - * Check if this object is equal to another.
196 - *
197 - * @param csl the other object
198 - * @return true if objects are equal
199 - */
200 - public boolean equals(ColumnSortList csl) {
201 - // Object is null
202 - if (csl == null) {
203 - return false;
204 - }
205 -
206 - // Check the size of the lists
207 - int size = size();
208 - if (size != csl.size()) {
209 - return false;
210 - }
211 -
212 - // Compare the entries
213 - for (int i = 0; i < size; i++) {
214 - if (!infos.get(i).equals(csl.infos.get(i))) {
215 - return false;
244 + // Everything is equal
245 + return true;
216 246 }
217 - }
218 -
219 - // Everything is equal
220 - return true;
221 - }
222 247
223 - /**
224 - * Get the primary (first) {@link ColumnSortInfo}'s column index.
225 - *
226 - * @return the primary column or -1 if not sorted
227 - */
228 - public int getPrimaryColumn() {
229 - ColumnSortInfo primaryInfo = getPrimaryColumnSortInfo();
230 - if (primaryInfo == null) {
231 - return -1;
232 - }
233 - return primaryInfo.getColumn();
234 - }
248 + /**
249 + * Get the primary (first) {@link ColumnSortInfo}'s column index.
250 + *
251 + * @return the primary column or -1 if not sorted
252 + */
253 + public int getPrimaryColumn()
254 + {
255 + ColumnSortInfo primaryInfo = getPrimaryColumnSortInfo();
256 + if ( primaryInfo == null )
257 + {
258 + return -1;
259 + }
260 + return primaryInfo.getColumn();
261 + }
235 262
236 - /**
237 - * Get the primary (first) {@link ColumnSortInfo}.
238 - *
239 - * @return the primary column sort info
240 - */
241 - public ColumnSortInfo getPrimaryColumnSortInfo() {
242 - if (infos.size() > 0) {
243 - return infos.get(0);
244 - }
245 - return null;
246 - }
263 + /**
264 + * Get the primary (first) {@link ColumnSortInfo}.
265 + *
266 + * @return the primary column sort info
267 + */
268 + public ColumnSortInfo getPrimaryColumnSortInfo()
269 + {
270 + if ( infos.size() > 0 )
271 + {
272 + return infos.get( 0 );
273 + }
274 + return null;
275 + }
247 276
248 - @Override
249 - public int hashCode() {
250 - return super.hashCode();
251 - }
277 + @Override
278 + public int hashCode()
279 + {
280 + return super.hashCode();
281 + }
252 282
253 - /**
254 - * Get the primary (first) {@link ColumnSortInfo}'s sort order.
255 - *
256 - * @return true if ascending, false if descending
257 - */
258 - public boolean isPrimaryAscending() {
259 - ColumnSortInfo primaryInfo = getPrimaryColumnSortInfo();
260 - if (primaryInfo == null) {
261 - return true;
262 - }
263 - return primaryInfo.isAscending();
264 - }
283 + /**
284 + * Get the primary (first) {@link ColumnSortInfo}'s sort order.
285 + *
286 + * @return true if ascending, false if descending
287 + */
288 + public boolean isPrimaryAscending()
289 + {
290 + ColumnSortInfo primaryInfo = getPrimaryColumnSortInfo();
291 + if ( primaryInfo == null )
292 + {
293 + return true;
294 + }
295 + return primaryInfo.isAscending();
296 + }
265 297
266 - public Iterator<ColumnSortInfo> iterator() {
267 - return new ImmutableIterator<ColumnSortInfo>(infos.iterator());
268 - }
298 + public Iterator<ColumnSortInfo> iterator()
299 + {
300 + return new ImmutableIterator<ColumnSortInfo>( infos.iterator() );
301 + }
269 302
270 - /**
271 - * Remove a {@link ColumnSortInfo} from the list.
272 - *
273 - * @param sortInfo the {@link ColumnSortInfo} to remove
274 - */
275 - public boolean remove(Object sortInfo) {
276 - return infos.remove(sortInfo);
277 - }
303 + /**
304 + * Remove a {@link ColumnSortInfo} from the list.
305 + *
306 + * @param sortInfo the {@link ColumnSortInfo} to remove
307 + */
308 + public boolean remove( Object sortInfo )
309 + {
310 + return infos.remove( sortInfo );
311 + }
278 312
279 - /**
280 - * @return the number of {@link ColumnSortInfo} in the list
281 - */
282 - public int size() {
283 - return infos.size();
284 - }
313 + /**
314 + * @return the number of {@link ColumnSortInfo} in the list
315 + */
316 + public int size()
317 + {
318 + return infos.size();
319 + }
285 320
286 - /**
287 - * @return a duplicate of this list
288 - */
289 - ColumnSortList copy() {
290 - ColumnSortList copy = new ColumnSortList();
291 - for (ColumnSortInfo info : this) {
292 - copy.infos.add(new ColumnSortInfo(info.getColumn(), info.isAscending()));
293 - }
294 - return copy;
321 + /**
322 + * @return a duplicate of this list
323 + */
324 + ColumnSortList copy()
325 + {
326 + ColumnSortList copy = new ColumnSortList();
327 + for ( ColumnSortInfo info : this )
328 + {
329 + copy.infos.add( new ColumnSortInfo( info.getColumn(), info.isAscending() ) );
330 + }
331 + return copy;
332 + }
295 333 }
296 - }
297 334
298 - /**
299 - * A {@link TableModelHelper} request.
300 - */
301 - public static class Request implements IsSerializable {
302 335 /**
303 - * The number of rows to request.
336 + * A {@link TableModelHelper} request.
304 337 */
305 - private int numRows;
306 -
307 - /**
308 - * An ordered list of {@link ColumnSortInfo}.
309 - */
310 - private ColumnSortList columnSortList;
311 -
312 - /**
313 - * The first row of table data to request.
314 - */
315 - private int startRow;
338 + public static class Request implements IsSerializable
339 + {
340 + /**
341 + * The number of rows to request.
342 + */
343 + private int numRows;
344 +
345 + /**
346 + * An ordered list of {@link ColumnSortInfo}.
347 + */
348 + private ColumnSortList columnSortList;
349 +
350 + /**
351 + * The first row of table data to request.
352 + */
353 + private int startRow;
354 +
355 + /**
356 + * Default constructor used for RPC.
357 + */
358 + public Request()
359 + {
360 + this( 0, 0, null );
361 + }
316 362
317 - /**
318 - * Default constructor used for RPC.
319 - */
320 - public Request() {
321 - this(0, 0, null);
322 - }
363 + /**
364 + * Construct a new {@link Request}.
365 + *
366 + * @param startRow the first row to request
367 + * @param numRows the number of rows to request
368 + */
369 + public Request( int startRow, int numRows )
370 + {
371 + this( startRow, numRows, null );
372 + }
323 373
324 - /**
325 - * Construct a new {@link Request}.
326 - *
327 - * @param startRow the first row to request
328 - * @param numRows the number of rows to request
329 - */
330 - public Request(int startRow, int numRows) {
331 - this(startRow, numRows, null);
332 - }
374 + /**
375 + * Construct a new {@link Request} with information about the sort order of
376 + * columns.
377 + *
378 + * @param startRow the first row to request
379 + * @param numRows the number of rows to request
380 + * @param columnSortList a list of {@link ColumnSortInfo}
381 + */
382 + public Request( int startRow, int numRows, ColumnSortList columnSortList )
383 + {
384 + this.startRow = startRow;
385 + this.numRows = numRows;
386 + this.columnSortList = columnSortList;
387 + }
333 388
334 - /**
335 - * Construct a new {@link Request} with information about the sort order of
336 - * columns.
337 - *
338 - * @param startRow the first row to request
339 - * @param numRows the number of rows to request
340 - * @param columnSortList a list of {@link ColumnSortInfo}
341 - */
342 - public Request(int startRow, int numRows, ColumnSortList columnSortList) {
343 - this.startRow = startRow;
344 - this.numRows = numRows;
345 - this.columnSortList = columnSortList;
346 - }
389 + /**
390 + * @return the list of {@link ColumnSortInfo}
391 + */
392 + public ColumnSortList getColumnSortList()
393 + {
394 + return columnSortList;
395 + }
347 396
348 - /**
349 - * @return the list of {@link ColumnSortInfo}
350 - */
351 - public ColumnSortList getColumnSortList() {
352 - return columnSortList;
353 - }
397 + /**
398 + * @return the number of requested rows
399 + */
400 + public int getNumRows()
401 + {
402 + return numRows;
403 + }
354 404
355 - /**
356 - * @return the number of requested rows
357 - */
358 - public int getNumRows() {
359 - return numRows;
405 + /**
406 + * @return the first requested row
407 + */
408 + public int getStartRow()
409 + {
410 + return startRow;
411 + }
360 412 }
361 413
362 414 /**
363 - * @return the first requested row
364 - */
365 - public int getStartRow() {
366 - return startRow;
415 + * A response from the {@link TableModelHelper}.
416 + *
417 + * @param <RowType> the data type of the row values
418 + */
419 + public abstract static class Response<RowType>
420 + {
421 + /**
422 + * Get the objects associated with the retrieved rows.
423 + *
424 + * @return the objects associated with the retrieved row
425 + */
426 + public abstract Iterator<RowType> getRowValues();
367 427 }
368 - }
369 428
370 - /**
371 - * A response from the {@link TableModelHelper}.
372 - *
373 - * @param <RowType> the data type of the row values
374 - */
375 - public abstract static class Response<RowType> {
376 429 /**
377 - * Get the objects associated with the retrieved rows.
378 - *
379 - * @return the objects associated with the retrieved row
380 - */
381 - public abstract Iterator<RowType> getRowValues();
382 - }
430 + * A response from the {@link TableModelHelper} that is serializable, and can
431 + * by used over RPC.
432 + *
433 + * @param <RowType> the serializable data type of the row values
434 + */
435 + public static class SerializableResponse<RowType extends IsSerializable> extends Response<RowType> implements IsSerializable
436 + {
437 + /**
438 + * The {@link Collection} of row values.
439 + */
440 + private Collection<RowType> rowValues;
441 +
442 + /**
443 + * Default constructor used for RPC.
444 + */
445 + public SerializableResponse()
446 + {
447 + this( null );
448 + }
383 449
384 - /**
385 - * A response from the {@link TableModelHelper} that is serializable, and can
386 - * by used over RPC.
387 - *
388 - * @param <RowType> the serializable data type of the row values
389 - */
390 - public static class SerializableResponse<RowType extends IsSerializable>
391 - extends Response<RowType> implements IsSerializable {
392 - /**
393 - * The {@link Collection} of row values.
394 - */
395 - private Collection<RowType> rowValues;
450 + /**
451 + * Create a new {@link SerializableResponse}.
452 + */
453 + public SerializableResponse( Collection<RowType> rowValues )
454 + {
455 + this.rowValues = rowValues;
456 + }
396 457
397 - /**
398 - * Default constructor used for RPC.
399 - */
400 - public SerializableResponse() {
401 - this(null);
458 + @Override
459 + public Iterator<RowType> getRowValues()
460 + {
461 + return rowValues.iterator();
462 + }
402 463 }
403 464
404 465 /**
405 - * Create a new {@link SerializableResponse}.
466 + * Wrap an {@link Iterator} in an immutable iterator.
406 467 */
407 - public SerializableResponse(Collection<RowType> rowValues) {
408 - this.rowValues = rowValues;
409 - }
410 -
411 - @Override
412 - public Iterator<RowType> getRowValues() {
413 - return rowValues.iterator();
414 - }
415 - }
416 -
417 - /**
418 - * Wrap an {@link Iterator} in an immutable iterator.
419 - */
420 - private static class ImmutableIterator<E> implements Iterator<E> {
421 - private Iterator<E> iterator;
422 -
423 - public ImmutableIterator(Iterator<E> iterator) {
424 - this.iterator = iterator;
425 - }
468 + private static class ImmutableIterator<E> implements Iterator<E>
469 + {
470 + private Iterator<E> iterator;
471 +
472 + public ImmutableIterator( Iterator<E> iterator )
473 + {
474 + this.iterator = iterator;
475 + }
426 476
427 - public boolean hasNext() {
428 - return iterator.hasNext();
429 - }
477 + public boolean hasNext()
478 + {
479 + return iterator.hasNext();
480 + }
430 481
431 - public E next() {
432 - return iterator.next();
433 - }
482 + public E next()
483 + {
484 + return iterator.next();
485 + }
434 486
435 - public void remove() {
436 - throw (new UnsupportedOperationException());
487 + public void remove()
488 + {
489 + throw (new UnsupportedOperationException());
490 + }
437 491 }
438 - }
439 492 }