323 // Because of the method signature of dateFilter/numberFilter/regexFilter
324 // we can NEVER add a method to RowFilter that returns M,I. If we were
325 // to do so it would be possible to get a ClassCastException during normal
326 // usage.
327 //
328
329 /**
330 * An <code>Entry</code> object is passed to instances of
331 * <code>RowFilter</code>, allowing the filter to get the value of the
332 * entry's data, and thus to determine whether the entry should be shown.
333 * An <code>Entry</code> object contains information about the model
334 * as well as methods for getting the underlying values from the model.
335 *
336 * @param <M> the type of the model; for example <code>PersonModel</code>
337 * @param <I> the type of the identifier; when using
338 * <code>TableRowSorter</code> this will be <code>Integer</code>
339 * @see javax.swing.RowFilter
340 * @see javax.swing.DefaultRowSorter#setRowFilter(javax.swing.RowFilter)
341 * @since 1.6
342 */
343 public static abstract class Entry<M, I> {
344 /**
345 * Creates an <code>Entry</code>.
346 */
347 public Entry() {
348 }
349
350 /**
351 * Returns the underlying model.
352 *
353 * @return the model containing the data that this entry represents
354 */
355 public abstract M getModel();
356
357 /**
358 * Returns the number of values in the entry. For
359 * example, when used with a table this corresponds to the
360 * number of columns.
361 *
362 * @return number of values in the object being filtered
363 */
392 * @throws IndexOutOfBoundsException if index < 0 ||
393 * >= getValueCount
394 */
395 public String getStringValue(int index) {
396 Object value = getValue(index);
397 return (value == null) ? "" : value.toString();
398 }
399
400 /**
401 * Returns the identifer (in the model) of the entry.
402 * For a table this corresponds to the index of the row in the model,
403 * expressed as an <code>Integer</code>.
404 *
405 * @return a model-based (not view-based) identifier for
406 * this entry
407 */
408 public abstract I getIdentifier();
409 }
410
411
412 private static abstract class GeneralFilter<M, I> extends RowFilter<M, I> {
413 private int[] columns;
414
415 GeneralFilter(int[] columns) {
416 checkIndices(columns);
417 this.columns = columns;
418 }
419
420 @Override
421 public boolean include(Entry<? extends M, ? extends I> value){
422 int count = value.getValueCount();
423 if (columns.length > 0) {
424 for (int i = columns.length - 1; i >= 0; i--) {
425 int index = columns[i];
426 if (index < count) {
427 if (include(value, index)) {
428 return true;
429 }
430 }
431 }
432 } else {
|
323 // Because of the method signature of dateFilter/numberFilter/regexFilter
324 // we can NEVER add a method to RowFilter that returns M,I. If we were
325 // to do so it would be possible to get a ClassCastException during normal
326 // usage.
327 //
328
329 /**
330 * An <code>Entry</code> object is passed to instances of
331 * <code>RowFilter</code>, allowing the filter to get the value of the
332 * entry's data, and thus to determine whether the entry should be shown.
333 * An <code>Entry</code> object contains information about the model
334 * as well as methods for getting the underlying values from the model.
335 *
336 * @param <M> the type of the model; for example <code>PersonModel</code>
337 * @param <I> the type of the identifier; when using
338 * <code>TableRowSorter</code> this will be <code>Integer</code>
339 * @see javax.swing.RowFilter
340 * @see javax.swing.DefaultRowSorter#setRowFilter(javax.swing.RowFilter)
341 * @since 1.6
342 */
343 public abstract static class Entry<M, I> {
344 /**
345 * Creates an <code>Entry</code>.
346 */
347 public Entry() {
348 }
349
350 /**
351 * Returns the underlying model.
352 *
353 * @return the model containing the data that this entry represents
354 */
355 public abstract M getModel();
356
357 /**
358 * Returns the number of values in the entry. For
359 * example, when used with a table this corresponds to the
360 * number of columns.
361 *
362 * @return number of values in the object being filtered
363 */
392 * @throws IndexOutOfBoundsException if index < 0 ||
393 * >= getValueCount
394 */
395 public String getStringValue(int index) {
396 Object value = getValue(index);
397 return (value == null) ? "" : value.toString();
398 }
399
400 /**
401 * Returns the identifer (in the model) of the entry.
402 * For a table this corresponds to the index of the row in the model,
403 * expressed as an <code>Integer</code>.
404 *
405 * @return a model-based (not view-based) identifier for
406 * this entry
407 */
408 public abstract I getIdentifier();
409 }
410
411
412 private abstract static class GeneralFilter<M, I> extends RowFilter<M, I> {
413 private int[] columns;
414
415 GeneralFilter(int[] columns) {
416 checkIndices(columns);
417 this.columns = columns;
418 }
419
420 @Override
421 public boolean include(Entry<? extends M, ? extends I> value){
422 int count = value.getValueCount();
423 if (columns.length > 0) {
424 for (int i = columns.length - 1; i >= 0; i--) {
425 int index = columns[i];
426 if (index < count) {
427 if (include(value, index)) {
428 return true;
429 }
430 }
431 }
432 } else {
|