< prev index next >

src/java.desktop/share/classes/javax/swing/RowFilter.java

Print this page

        

*** 32,56 **** import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; /** ! * <code>RowFilter</code> is used to filter out entries from the * model so that they are not shown in the view. For example, a ! * <code>RowFilter</code> associated with a <code>JTable</code> might * only allow rows that contain a column with a specific string. The * meaning of <em>entry</em> depends on the component type. * For example, when a filter is ! * associated with a <code>JTable</code>, an entry corresponds to a ! * row; when associated with a <code>JTree</code>, an entry corresponds * to a node. * <p> ! * Subclasses must override the <code>include</code> method to * indicate whether the entry should be shown in the ! * view. The <code>Entry</code> argument can be used to obtain the values in * each of the columns in that entry. The following example shows an ! * <code>include</code> method that allows only entries containing one or * more values starting with the string "a": * <pre> * RowFilter&lt;Object,Object&gt; startsWithAFilter = new RowFilter&lt;Object,Object&gt;() { * public boolean include(Entry&lt;? extends Object, ? extends Object&gt; entry) { * for (int i = entry.getValueCount() - 1; i &gt;= 0; i--) { --- 32,56 ---- import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; /** ! * {@code RowFilter} is used to filter out entries from the * model so that they are not shown in the view. For example, a ! * {@code RowFilter} associated with a {@code JTable} might * only allow rows that contain a column with a specific string. The * meaning of <em>entry</em> depends on the component type. * For example, when a filter is ! * associated with a {@code JTable}, an entry corresponds to a ! * row; when associated with a {@code JTree}, an entry corresponds * to a node. * <p> ! * Subclasses must override the {@code include} method to * indicate whether the entry should be shown in the ! * view. The {@code Entry} argument can be used to obtain the values in * each of the columns in that entry. The following example shows an ! * {@code include} method that allows only entries containing one or * more values starting with the string "a": * <pre> * RowFilter&lt;Object,Object&gt; startsWithAFilter = new RowFilter&lt;Object,Object&gt;() { * public boolean include(Entry&lt;? extends Object, ? extends Object&gt; entry) { * for (int i = entry.getValueCount() - 1; i &gt;= 0; i--) {
*** 63,76 **** * // entry is not shown * return false; * } * }; * </pre> ! * <code>RowFilter</code> has two formal type parameters that allow ! * you to create a <code>RowFilter</code> for a specific model. For * example, the following assumes a specific model that is wrapping ! * objects of type <code>Person</code>. Only <code>Person</code>s * with an age over 20 will be shown: * <pre> * RowFilter&lt;PersonModel,Integer&gt; ageFilter = new RowFilter&lt;PersonModel,Integer&gt;() { * public boolean include(Entry&lt;? extends PersonModel, ? extends Integer&gt; entry) { * PersonModel personModel = entry.getModel(); --- 63,76 ---- * // entry is not shown * return false; * } * }; * </pre> ! * {@code RowFilter} has two formal type parameters that allow ! * you to create a {@code RowFilter} for a specific model. For * example, the following assumes a specific model that is wrapping ! * objects of type {@code Person}. Only {@code Person}s * with an age over 20 will be shown: * <pre> * RowFilter&lt;PersonModel,Integer&gt; ageFilter = new RowFilter&lt;PersonModel,Integer&gt;() { * public boolean include(Entry&lt;? extends PersonModel, ? extends Integer&gt; entry) { * PersonModel personModel = entry.getModel();
*** 86,105 **** * PersonModel model = createPersonModel(); * TableRowSorter&lt;PersonModel&gt; sorter = new TableRowSorter&lt;PersonModel&gt;(model); * sorter.setRowFilter(ageFilter); * </pre> * ! * @param <M> the type of the model; for example <code>PersonModel</code> * @param <I> the type of the identifier; when using ! * <code>TableRowSorter</code> this will be <code>Integer</code> * @see javax.swing.table.TableRowSorter * @since 1.6 */ public abstract class RowFilter<M,I> { /** * Enumeration of the possible comparison values supported by ! * some of the default <code>RowFilter</code>s. * * @see RowFilter * @since 1.6 */ public enum ComparisonType { --- 86,105 ---- * PersonModel model = createPersonModel(); * TableRowSorter&lt;PersonModel&gt; sorter = new TableRowSorter&lt;PersonModel&gt;(model); * sorter.setRowFilter(ageFilter); * </pre> * ! * @param <M> the type of the model; for example {@code PersonModel} * @param <I> the type of the identifier; when using ! * {@code TableRowSorter} this will be {@code Integer} * @see javax.swing.table.TableRowSorter * @since 1.6 */ public abstract class RowFilter<M,I> { /** * Enumeration of the possible comparison values supported by ! * some of the default {@code RowFilter}s. * * @see RowFilter * @since 1.6 */ public enum ComparisonType {
*** 139,152 **** } } } /** ! * Returns a <code>RowFilter</code> that uses a regular * expression to determine which entries to include. Only entries * with at least one matching value are included. For ! * example, the following creates a <code>RowFilter</code> that * includes entries with at least one value starting with * "a": * <pre> * RowFilter.regexFilter("^a"); * </pre> --- 139,152 ---- } } } /** ! * Returns a {@code RowFilter} that uses a regular * expression to determine which entries to include. Only entries * with at least one matching value are included. For ! * example, the following creates a {@code RowFilter} that * includes entries with at least one value starting with * "a": * <pre> * RowFilter.regexFilter("^a"); * </pre>
*** 162,189 **** * @param <M> the type of the model to which the {@code RowFilter} applies * @param <I> the type of the identifier passed to the {@code RowFilter} * @param regex the regular expression to filter on * @param indices the indices of the values to check. If not supplied all * values are evaluated ! * @return a <code>RowFilter</code> implementing the specified criteria ! * @throws NullPointerException if <code>regex</code> is ! * <code>null</code> ! * @throws IllegalArgumentException if any of the <code>indices</code> * are &lt; 0 ! * @throws PatternSyntaxException if <code>regex</code> is * not a valid regular expression. * @see java.util.regex.Pattern */ public static <M,I> RowFilter<M,I> regexFilter(String regex, int... indices) { return new RegexFilter<M, I>(Pattern.compile(regex), indices); } /** ! * Returns a <code>RowFilter</code> that includes entries that ! * have at least one <code>Date</code> value meeting the specified ! * criteria. For example, the following <code>RowFilter</code> includes * only entries with at least one date value after the current date: * <pre> * RowFilter.dateFilter(ComparisonType.AFTER, new Date()); * </pre> * --- 162,189 ---- * @param <M> the type of the model to which the {@code RowFilter} applies * @param <I> the type of the identifier passed to the {@code RowFilter} * @param regex the regular expression to filter on * @param indices the indices of the values to check. If not supplied all * values are evaluated ! * @return a {@code RowFilter} implementing the specified criteria ! * @throws NullPointerException if {@code regex} is ! * {@code null} ! * @throws IllegalArgumentException if any of the {@code indices} * are &lt; 0 ! * @throws PatternSyntaxException if {@code regex} is * not a valid regular expression. * @see java.util.regex.Pattern */ public static <M,I> RowFilter<M,I> regexFilter(String regex, int... indices) { return new RegexFilter<M, I>(Pattern.compile(regex), indices); } /** ! * Returns a {@code RowFilter} that includes entries that ! * have at least one {@code Date} value meeting the specified ! * criteria. For example, the following {@code RowFilter} includes * only entries with at least one date value after the current date: * <pre> * RowFilter.dateFilter(ComparisonType.AFTER, new Date()); * </pre> *
*** 191,217 **** * @param <I> the type of the identifier passed to the {@code RowFilter} * @param type the type of comparison to perform * @param date the date to compare against * @param indices the indices of the values to check. If not supplied all * values are evaluated ! * @return a <code>RowFilter</code> implementing the specified criteria ! * @throws NullPointerException if <code>date</code> is ! * <code>null</code> ! * @throws IllegalArgumentException if any of the <code>indices</code> ! * are &lt; 0 or <code>type</code> is ! * <code>null</code> * @see java.util.Calendar * @see java.util.Date */ public static <M,I> RowFilter<M,I> dateFilter(ComparisonType type, Date date, int... indices) { return new DateFilter<M, I>(type, date.getTime(), indices); } /** ! * Returns a <code>RowFilter</code> that includes entries that ! * have at least one <code>Number</code> value meeting the * specified criteria. For example, the following * filter will only include entries with at * least one number value equal to 10: * <pre> * RowFilter.numberFilter(ComparisonType.EQUAL, 10); --- 191,217 ---- * @param <I> the type of the identifier passed to the {@code RowFilter} * @param type the type of comparison to perform * @param date the date to compare against * @param indices the indices of the values to check. If not supplied all * values are evaluated ! * @return a {@code RowFilter} implementing the specified criteria ! * @throws NullPointerException if {@code date} is ! * {@code null} ! * @throws IllegalArgumentException if any of the {@code indices} ! * are &lt; 0 or {@code type} is ! * {@code null} * @see java.util.Calendar * @see java.util.Date */ public static <M,I> RowFilter<M,I> dateFilter(ComparisonType type, Date date, int... indices) { return new DateFilter<M, I>(type, date.getTime(), indices); } /** ! * Returns a {@code RowFilter} that includes entries that ! * have at least one {@code Number} value meeting the * specified criteria. For example, the following * filter will only include entries with at * least one number value equal to 10: * <pre> * RowFilter.numberFilter(ComparisonType.EQUAL, 10);
*** 221,245 **** * @param <I> the type of the identifier passed to the {@code RowFilter} * @param type the type of comparison to perform * @param number a {@code Number} value to compare against * @param indices the indices of the values to check. If not supplied all * values are evaluated ! * @return a <code>RowFilter</code> implementing the specified criteria ! * @throws IllegalArgumentException if any of the <code>indices</code> ! * are &lt; 0, <code>type</code> is <code>null</code> ! * or <code>number</code> is <code>null</code> */ public static <M,I> RowFilter<M,I> numberFilter(ComparisonType type, Number number, int... indices) { return new NumberFilter<M, I>(type, number, indices); } /** ! * Returns a <code>RowFilter</code> that includes entries if any * of the supplied filters includes the entry. * <p> ! * The following example creates a <code>RowFilter</code> that will * include any entries containing the string "foo" or the string * "bar": * <pre> * List&lt;RowFilter&lt;Object,Object&gt;&gt; filters = new ArrayList&lt;RowFilter&lt;Object,Object&gt;&gt;(2); * filters.add(RowFilter.regexFilter("foo")); --- 221,245 ---- * @param <I> the type of the identifier passed to the {@code RowFilter} * @param type the type of comparison to perform * @param number a {@code Number} value to compare against * @param indices the indices of the values to check. If not supplied all * values are evaluated ! * @return a {@code RowFilter} implementing the specified criteria ! * @throws IllegalArgumentException if any of the {@code indices} ! * are &lt; 0, {@code type} is {@code null} ! * or {@code number} is {@code null} */ public static <M,I> RowFilter<M,I> numberFilter(ComparisonType type, Number number, int... indices) { return new NumberFilter<M, I>(type, number, indices); } /** ! * Returns a {@code RowFilter} that includes entries if any * of the supplied filters includes the entry. * <p> ! * The following example creates a {@code RowFilter} that will * include any entries containing the string "foo" or the string * "bar": * <pre> * List&lt;RowFilter&lt;Object,Object&gt;&gt; filters = new ArrayList&lt;RowFilter&lt;Object,Object&gt;&gt;(2); * filters.add(RowFilter.regexFilter("foo"));
*** 247,273 **** * RowFilter&lt;Object,Object&gt; fooBarFilter = RowFilter.orFilter(filters); * </pre> * * @param <M> the type of the model to which the {@code RowFilter} applies * @param <I> the type of the identifier passed to the {@code RowFilter} ! * @param filters the <code>RowFilter</code>s to test * @throws IllegalArgumentException if any of the filters ! * are <code>null</code> ! * @throws NullPointerException if <code>filters</code> is null ! * @return a <code>RowFilter</code> implementing the specified criteria * @see java.util.Arrays#asList */ public static <M,I> RowFilter<M,I> orFilter( Iterable<? extends RowFilter<? super M, ? super I>> filters) { return new OrFilter<M,I>(filters); } /** ! * Returns a <code>RowFilter</code> that includes entries if all * of the supplied filters include the entry. * <p> ! * The following example creates a <code>RowFilter</code> that will * include any entries containing the string "foo" and the string * "bar": * <pre> * List&lt;RowFilter&lt;Object,Object&gt;&gt; filters = new ArrayList&lt;RowFilter&lt;Object,Object&gt;&gt;(2); * filters.add(RowFilter.regexFilter("foo")); --- 247,273 ---- * RowFilter&lt;Object,Object&gt; fooBarFilter = RowFilter.orFilter(filters); * </pre> * * @param <M> the type of the model to which the {@code RowFilter} applies * @param <I> the type of the identifier passed to the {@code RowFilter} ! * @param filters the {@code RowFilter}s to test * @throws IllegalArgumentException if any of the filters ! * are {@code null} ! * @throws NullPointerException if {@code filters} is null ! * @return a {@code RowFilter} implementing the specified criteria * @see java.util.Arrays#asList */ public static <M,I> RowFilter<M,I> orFilter( Iterable<? extends RowFilter<? super M, ? super I>> filters) { return new OrFilter<M,I>(filters); } /** ! * Returns a {@code RowFilter} that includes entries if all * of the supplied filters include the entry. * <p> ! * The following example creates a {@code RowFilter} that will * include any entries containing the string "foo" and the string * "bar": * <pre> * List&lt;RowFilter&lt;Object,Object&gt;&gt; filters = new ArrayList&lt;RowFilter&lt;Object,Object&gt;&gt;(2); * filters.add(RowFilter.regexFilter("foo"));
*** 275,320 **** * RowFilter&lt;Object,Object&gt; fooBarFilter = RowFilter.andFilter(filters); * </pre> * * @param <M> the type of the model the {@code RowFilter} applies to * @param <I> the type of the identifier passed to the {@code RowFilter} ! * @param filters the <code>RowFilter</code>s to test ! * @return a <code>RowFilter</code> implementing the specified criteria * @throws IllegalArgumentException if any of the filters ! * are <code>null</code> ! * @throws NullPointerException if <code>filters</code> is null * @see java.util.Arrays#asList */ public static <M,I> RowFilter<M,I> andFilter( Iterable<? extends RowFilter<? super M, ? super I>> filters) { return new AndFilter<M,I>(filters); } /** ! * Returns a <code>RowFilter</code> that includes entries if the * supplied filter does not include the entry. * * @param <M> the type of the model to which the {@code RowFilter} applies * @param <I> the type of the identifier passed to the {@code RowFilter} ! * @param filter the <code>RowFilter</code> to negate ! * @return a <code>RowFilter</code> implementing the specified criteria ! * @throws IllegalArgumentException if <code>filter</code> is ! * <code>null</code> */ public static <M,I> RowFilter<M,I> notFilter(RowFilter<M,I> filter) { return new NotFilter<M,I>(filter); } /** * Returns true if the specified entry should be shown; * returns false if the entry should be hidden. * <p> ! * The <code>entry</code> argument is valid only for the duration of ! * the invocation. Using <code>entry</code> after the call returns * results in undefined behavior. * ! * @param entry a non-<code>null</code> object that wraps the underlying * object from the model * @return true if the entry should be shown */ public abstract boolean include(Entry<? extends M, ? extends I> entry); --- 275,320 ---- * RowFilter&lt;Object,Object&gt; fooBarFilter = RowFilter.andFilter(filters); * </pre> * * @param <M> the type of the model the {@code RowFilter} applies to * @param <I> the type of the identifier passed to the {@code RowFilter} ! * @param filters the {@code RowFilter}s to test ! * @return a {@code RowFilter} implementing the specified criteria * @throws IllegalArgumentException if any of the filters ! * are {@code null} ! * @throws NullPointerException if {@code filters} is null * @see java.util.Arrays#asList */ public static <M,I> RowFilter<M,I> andFilter( Iterable<? extends RowFilter<? super M, ? super I>> filters) { return new AndFilter<M,I>(filters); } /** ! * Returns a {@code RowFilter} that includes entries if the * supplied filter does not include the entry. * * @param <M> the type of the model to which the {@code RowFilter} applies * @param <I> the type of the identifier passed to the {@code RowFilter} ! * @param filter the {@code RowFilter} to negate ! * @return a {@code RowFilter} implementing the specified criteria ! * @throws IllegalArgumentException if {@code filter} is ! * {@code null} */ public static <M,I> RowFilter<M,I> notFilter(RowFilter<M,I> filter) { return new NotFilter<M,I>(filter); } /** * Returns true if the specified entry should be shown; * returns false if the entry should be hidden. * <p> ! * The {@code entry} argument is valid only for the duration of ! * the invocation. Using {@code entry} after the call returns * results in undefined behavior. * ! * @param entry a non-{@code null} object that wraps the underlying * object from the model * @return true if the entry should be shown */ public abstract boolean include(Entry<? extends M, ? extends I> entry);
*** 325,350 **** // to do so it would be possible to get a ClassCastException during normal // usage. // /** ! * An <code>Entry</code> object is passed to instances of ! * <code>RowFilter</code>, allowing the filter to get the value of the * entry's data, and thus to determine whether the entry should be shown. ! * An <code>Entry</code> object contains information about the model * as well as methods for getting the underlying values from the model. * ! * @param <M> the type of the model; for example <code>PersonModel</code> * @param <I> the type of the identifier; when using ! * <code>TableRowSorter</code> this will be <code>Integer</code> * @see javax.swing.RowFilter * @see javax.swing.DefaultRowSorter#setRowFilter(javax.swing.RowFilter) * @since 1.6 */ public abstract static class Entry<M, I> { /** ! * Creates an <code>Entry</code>. */ public Entry() { } /** --- 325,350 ---- // to do so it would be possible to get a ClassCastException during normal // usage. // /** ! * An {@code Entry} object is passed to instances of ! * {@code RowFilter}, allowing the filter to get the value of the * entry's data, and thus to determine whether the entry should be shown. ! * An {@code Entry} object contains information about the model * as well as methods for getting the underlying values from the model. * ! * @param <M> the type of the model; for example {@code PersonModel} * @param <I> the type of the identifier; when using ! * {@code TableRowSorter} this will be {@code Integer} * @see javax.swing.RowFilter * @see javax.swing.DefaultRowSorter#setRowFilter(javax.swing.RowFilter) * @since 1.6 */ public abstract static class Entry<M, I> { /** ! * Creates an {@code Entry}. */ public Entry() { } /**
*** 363,373 **** */ public abstract int getValueCount(); /** * Returns the value at the specified index. This may return ! * <code>null</code>. When used with a table, index * corresponds to the column number in the model. * * @param index the index of the value to get * @return value at the specified index * @throws IndexOutOfBoundsException if index &lt; 0 or --- 363,373 ---- */ public abstract int getValueCount(); /** * Returns the value at the specified index. This may return ! * {@code null}. When used with a table, index * corresponds to the column number in the model. * * @param index the index of the value to get * @return value at the specified index * @throws IndexOutOfBoundsException if index &lt; 0 or
*** 375,391 **** */ public abstract Object getValue(int index); /** * Returns the string value at the specified index. If ! * filtering is being done based on <code>String</code> values ! * this method is preferred to that of <code>getValue</code> ! * as <code>getValue(index).toString()</code> may return a ! * different result than <code>getStringValue(index)</code>. * <p> ! * This implementation calls <code>getValue(index).toString()</code> ! * after checking for <code>null</code>. Subclasses that provide * different string conversion should override this method if * necessary. * * @param index the index of the value to get * @return {@code non-null} string at the specified index --- 375,391 ---- */ public abstract Object getValue(int index); /** * Returns the string value at the specified index. If ! * filtering is being done based on {@code String} values ! * this method is preferred to that of {@code getValue} ! * as {@code getValue(index).toString()} may return a ! * different result than {@code getStringValue(index)}. * <p> ! * This implementation calls {@code getValue(index).toString()} ! * after checking for {@code null}. Subclasses that provide * different string conversion should override this method if * necessary. * * @param index the index of the value to get * @return {@code non-null} string at the specified index
*** 398,408 **** } /** * Returns the identifer (in the model) of the entry. * For a table this corresponds to the index of the row in the model, ! * expressed as an <code>Integer</code>. * * @return a model-based (not view-based) identifier for * this entry */ public abstract I getIdentifier(); --- 398,408 ---- } /** * Returns the identifer (in the model) of the entry. * For a table this corresponds to the index of the row in the model, ! * expressed as an {@code Integer}. * * @return a model-based (not view-based) identifier for * this entry */ public abstract I getIdentifier();
< prev index next >