M - 模型的类型; 
        例如PersonModel 
       I - I的类型; 
        当使用TableRowSorter这将是Integer 
       public abstract class RowFilter<M,I> extends Object
RowFilter用于过滤模型中的条目,以便它们不会显示在视图中。 
       例如,与RowFilter关联的JTable可能只允许包含具有特定字符串的列的行。 
       条目的含义取决于组件类型。 
       例如,当过滤器与JTable时,条目对应于一行; 
       当与JTree时,条目对应于节点。 
        子类必须覆盖include方法来指示条目是否应该在视图中显示。 Entry参数可用于获取该条目中每个列中的值。 以下示例显示了一个include方法,它只允许以字符串“a”开头的包含一个或多个值的条目: 
  RowFilter<Object,Object> startsWithAFilter = new RowFilter<Object,Object>() {
   public boolean include(Entry<? extends Object, ? extends Object> entry) {
     for (int i = entry.getValueCount() - 1; i >= 0; i--) {
       if (entry.getStringValue(i).startsWith("a")) {
         // The value starts with "a", include it
         return true;
       }
     }
     // None of the columns start with "a"; return false so that this
     // entry is not shown
     return false;
   }
 };  
       RowFilter有两个正式类型参数,允许您为特定型号创建RowFilter 。 
       例如,以下假设是包装类型为Person对象的特定模型。 
       只有Person年龄超过20岁将显示: 
         RowFilter<PersonModel,Integer> ageFilter = new RowFilter<PersonModel,Integer>() {
   public boolean include(Entry<? extends PersonModel, ? extends Integer> entry) {
     PersonModel personModel = entry.getModel();
     Person person = personModel.getPerson(entry.getIdentifier());
     if (person.getAge() > 20) {
       // Returning true indicates this row should be shown.
       return true;
     }
     // Age is <= 20, don't show it.
     return false;
   }
 };
 PersonModel model = createPersonModel();
 TableRowSorter<PersonModel> sorter = new TableRowSorter<PersonModel>(model);
 sorter.setRowFilter(ageFilter);  
      TableRowSorter 
       | Modifier and Type | Class and Description | 
|---|---|
| static class  | RowFilter.ComparisonType
              枚举可能的比较值,由某些默认的 
              RowFilter。 | 
| static class  | RowFilter.Entry<M,I>Entry对象传递给RowFilter的RowFilter,允许过滤器获取条目数据的值,从而确定条目是否应该显示。 | 
| Constructor and Description | 
|---|
| RowFilter() | 
| Modifier and Type | Method and Description | 
|---|---|
| static <M,I> RowFilter<M,I> | andFilter(Iterable<? extends RowFilter<? super M,? super I>> filters)
              如果所有提供的过滤器都包含条目,则返回一个包含条目的 
              RowFilter。 | 
| static <M,I> RowFilter<M,I> | dateFilter(RowFilter.ComparisonType type, Date date, int... indices)
              返回一个 
              RowFilter,其中包含符合指定条件的值至少有一个Date的条目。 | 
| abstract boolean | include(RowFilter.Entry<? extends M,? extends I> entry) 
             如果指定的条目应该显示,则返回true; 
             如果条目应该隐藏,则返回false。 
             | 
| static <M,I> RowFilter<M,I> | notFilter(RowFilter<M,I> filter)
              如果提供的过滤器不包含条目,则返回一个包含条目的 
              RowFilter。 | 
| static <M,I> RowFilter<M,I> | numberFilter(RowFilter.ComparisonType type, Number number, int... indices)
              返回一个 
              RowFilter,其中包含符合指定条件的值至少有一个Number的条目。 | 
| static <M,I> RowFilter<M,I> | orFilter(Iterable<? extends RowFilter<? super M,? super I>> filters)
              返回一个 
              RowFilter,如果任何提供的过滤器包含条目,则包含条目。 | 
| static <M,I> RowFilter<M,I> | regexFilter(String regex, int... indices)
              返回一个 
              RowFilter,它使用正则表达式来确定要包括的条目。 | 
public static <M,I> RowFilter<M,I> regexFilter(String regex, int... indices)
RowFilter ,它使用正则表达式来确定要包括哪些条目。 
           仅包含具有至少一个匹配值的条目。 
           例如,以下内容创建一个RowFilter ,其中包含以“a”开头的至少一个值的条目: 
             RowFilter.regexFilter("^a");  
            返回的过滤器使用Matcher.find()测试包含。 要测试完全匹配,使用字符'^'和'$'分别匹配字符串的开头和结尾。 例如,“^ foo $”仅包括其字符串完全为“foo”而不是“food”的行。 有关支持的正则表达式构造的完整说明,请参见Pattern。 
regex - 要过滤的正则表达式 
           indices - 要检查的值的索引。 
            如果不提供,则评估所有值 
           RowFilter实现指定标准 
           NullPointerException - 如果 
            regex是 
            null 
           IllegalArgumentException - 如果 
            indices中有任何一个是<0 
           PatternSyntaxException - 如果 
            regex不是有效的正则表达式。 
           Pattern 
           public static <M,I> RowFilter<M,I> dateFilter(RowFilter.ComparisonType type, Date date, int... indices)
RowFilter ,其中包含符合指定条件的值至少有一个Date的条目。 
           例如,以下RowFilter RowFilter包括在当前日期之后至少有一个日期值的条目: 
             RowFilter.dateFilter(ComparisonType.AFTER, new Date());  
          type - 要执行的比较类型 
           date - 与之比较的日期 
           indices - 要检查的值的索引。 
            如果不提供,则评估所有值 
           RowFilter实现指定标准 
           NullPointerException - 如果 
            date是 
            null 
           IllegalArgumentException - 如果任何 
            indices是<0或 
            type是 
            null 
           Calendar , Date 
           public static <M,I> RowFilter<M,I> numberFilter(RowFilter.ComparisonType type, Number number, int... indices)
RowFilter ,其中包含符合指定条件的值至少有一个Number的条目。 
           例如,以下过滤器将仅包含至少一个数值等于10的条目: 
             RowFilter.numberFilter(ComparisonType.EQUAL, 10);  
          type - 要执行的比较类型 
           indices - 要检查的值的索引。 
            如果不提供,则评估所有值 
           RowFilter实现指定的条件 
           IllegalArgumentException - 如果 
            indices中的任何一个是< 
            type是 
            null或 
            number是 
            null 
           public static <M,I> RowFilter<M,I> orFilter(Iterable<? extends RowFilter<? super M,? super I>> filters)
RowFilter ,如果任何提供的过滤器包含条目,则包含条目。 
            以下示例创建一个RowFilter ,它将包含任何包含字符串“foo”或字符串“bar”的条目: 
  List<RowFilter<Object,Object>> filters = new ArrayList<RowFilter<Object,Object>>(2);
   filters.add(RowFilter.regexFilter("foo"));
   filters.add(RowFilter.regexFilter("bar"));
   RowFilter<Object,Object> fooBarFilter = RowFilter.orFilter(filters);  
          filters - 
            RowFilter的测试 
           RowFilter实现指定的条件 
           IllegalArgumentException - 如果任何一个过滤器是 
            null 
           NullPointerException - 如果 
            filters为空 
           Arrays.asList(T...) 
           public static <M,I> RowFilter<M,I> andFilter(Iterable<? extends RowFilter<? super M,? super I>> filters)
RowFilter 。 
            以下示例创建一个RowFilter ,它将包含任何包含字符串“foo”和字符串“bar”的条目: 
  List<RowFilter<Object,Object>> filters = new ArrayList<RowFilter<Object,Object>>(2);
   filters.add(RowFilter.regexFilter("foo"));
   filters.add(RowFilter.regexFilter("bar"));
   RowFilter<Object,Object> fooBarFilter = RowFilter.andFilter(filters);  
          filters - 要测试的 
            RowFilter 
           RowFilter实现指定的标准 
           IllegalArgumentException - 如果任何一个过滤器是 
            null 
           NullPointerException - 如果 
            filters为空 
           Arrays.asList(T...) 
           public static <M,I> RowFilter<M,I> notFilter(RowFilter<M,I> filter)
RowFilter ,其中包含条目。 
          filter - 否定的 
            RowFilter 
           RowFilter实现指定的条件 
           IllegalArgumentException - 如果 
            filter是 
            null 
           public abstract boolean include(RowFilter.Entry<? extends M,? extends I> entry)
 entry参数仅在调用期间有效。 调用后使用entry返回未定义的行为。 
entry - 从模型中包装底层对象的非 
            null对象 
            Submit a bug or feature 
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
 Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.