モジュール java.desktop
パッケージ javax.swing

クラスRowFilter<M,​I>

java.lang.Object
javax.swing.RowFilter<M,​I>
型パラメータ:
M - モデルの型。例: PersonModel
I - 識別子の型。TableRowSorterの使用時はInteger

public abstract class RowFilter<M,​I>
extends Object
RowFilterは、エントリをモデルからフィルタ・リングして、ビューに表示されないようにするために使用します。 たとえば、JTableに関連付けられたRowFilterでは、特定の文字列を持つ列が含まれている行しか許可されないことがあります。 エントリの意味は、コンポーネントの型によって異なります。 たとえば、フィルタがJTableに関連付けられている場合、エントリは行を意味します。フィルタがJTreeに関連付けられている場合、エントリはノードを意味します。

サブクラスは、includeメソッドをオーバーライドして、エントリをビューに表示するかどうかを指定する必要があります。 エントリの各列の値を取得するには、Entry引数を使用できます。 次に、例として、文字列「a」で始まる値(複数可)を含むエントリだけを許可するincludeメソッドを示します。

 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の作成を許可する2つの仮パラメータ型が用意されています。 たとえば、次のコードは、Person型のオブジェクトをラップする特定のモデルを示しています。 20歳以上のPersonだけが表示されます。
 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);
 

導入されたバージョン:
1.6
関連項目:
TableRowSorter
  • ネストされたクラスのサマリー

    ネストされたクラス
    修飾子と型 クラス 説明
    static class  RowFilter.ComparisonType
    一部のデフォルトのRowFilterでサポートされる、値比較に使用可能な値の列挙です。
    static class  RowFilter.Entry<M,​I>
    EntryオブジェクトがRowFilterのインスタンスに渡されると、フィルタはエントリのデータ値を取得し、エントリを表示するかどうかを判断できます。
  • コンストラクタのサマリー

    コンストラクタ
    コンストラクタ 説明
    RowFilter()  
  • メソッドのサマリー

    修飾子と型 メソッド 説明
    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)
    指定された基準を満たすDate値を少なくとも1つ以上持つエントリを含めるRowFilterを返します。
    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)
    指定された基準を満たすNumber値を少なくとも1つ以上持つエントリを含めるRowFilterを返します。
    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を返します。

    クラス java.lang.Objectで宣言されたメソッド

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • コンストラクタの詳細

    • RowFilter

      public RowFilter()
  • メソッドの詳細

    • regexFilter

      public static <M,​ I> RowFilter<M,​I> regexFilter​(String regex, int... indices)
      正規表現を使って含めるエントリを特定するRowFilterを返します。 一致する値を少なくとも1つ以上持つエントリが含められます。 たとえば次のコードは、「a」で始まる値を少なくとも1つ以上持つエントリを含めるRowFilterを作成します。
         RowFilter.regexFilter("^a");
       

      返されるフィルタは、Matcher.find()を使用して取込み内容を確認します。 完全一致の有無を確認するには、文字「^」と「$」を使用して、文字列の先頭と末尾の文字を比較します。 たとえば「^foo$」と指定した場合、「foo」と完全に一致する文字列のある行のみが含まれます。「food」は一致とは見なされません。 サポートされている正規表現の構文の詳細は、Patternを参照してください。

      型パラメータ:
      M - RowFilterが適用されるモデルの型
      I - RowFilterに渡される識別子の型
      パラメータ:
      regex - フィルタを適用する正規表現
      indices - 調べる値のインデックス。 提供されない場合、すべての値が評価される
      戻り値:
      指定された条件を満たすRowFilter
      例外:
      NullPointerException - regexnullである場合
      IllegalArgumentException - indicesに0より小さい値が含まれる場合
      PatternSyntaxException - regexが有効な正規表現でない場合。
      関連項目:
      Pattern
    • dateFilter

      public static <M,​ I> RowFilter<M,​I> dateFilter​(RowFilter.ComparisonType type, Date date, int... indices)
      指定された基準を満たすDate値を少なくとも1つ以上持つエントリを含めるRowFilterを返します。 たとえば次のRowFilterは、現在の日付よりあとの1つ以上の日付の値を持つエントリを含めます。
         RowFilter.dateFilter(ComparisonType.AFTER, new Date());
       
      型パラメータ:
      M - RowFilterが適用されるモデルの型
      I - RowFilterに渡される識別子の型
      パラメータ:
      type - 実行する比較の型
      date - 比較対象の日付
      indices - 調べる値のインデックス。 提供されない場合、すべての値が評価される
      戻り値:
      指定された条件を満たすRowFilter
      例外:
      NullPointerException - datenullである場合
      IllegalArgumentException - indicesに0より小さい値が含まれる場合、またはtypenullの場合
      関連項目:
      Calendar, Date
    • numberFilter

      public static <M,​ I> RowFilter<M,​I> numberFilter​(RowFilter.ComparisonType type, Number number, int... indices)
      指定された基準を満たすNumber値を少なくとも1つ以上持つエントリを含めるRowFilterを返します。 たとえば次のフィルタは、10と等しい値を少なくとも1つ以上持つエントリを含めます。
         RowFilter.numberFilter(ComparisonType.EQUAL, 10);
       
      型パラメータ:
      M - RowFilterが適用されるモデルの型
      I - RowFilterに渡される識別子の型
      パラメータ:
      type - 実行する比較の型
      number - 比較するNumberの値
      indices - 調べる値のインデックス。 提供されない場合、すべての値が評価される
      戻り値:
      指定された条件を満たすRowFilter
      例外:
      IllegalArgumentException - indicesに0より小さい値が含まれる場合、typenullの場合、またはnumbernullの場合
    • orFilter

      public static <M,​ I> RowFilter<M,​I> orFilter​(Iterable<? extends RowFilter<? super M,​? super I>> filters)
      指定されたフィルタ条件のいずれかに一致するエントリがある場合、そのエントリを示すRowFilterを返します。

      次のサンプル・コードは、文字列「foo」または「bar」があるエントリを含めるRowFilterを作成します。

         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);
       

      型パラメータ:
      M - RowFilterが適用されるモデルの型
      I - RowFilterに渡される識別子の型
      パラメータ:
      filters - テストするRowFilter
      戻り値:
      指定された条件を満たすRowFilter
      例外:
      IllegalArgumentException - 次のフィルタが存在する場合: null
      NullPointerException - filtersがnullである場合
      関連項目:
      Arrays.asList(T...)
    • andFilter

      public static <M,​ I> RowFilter<M,​I> andFilter​(Iterable<? extends RowFilter<? super M,​? super I>> filters)
      指定されたすべてのフィルタ条件に一致するエントリがある場合、そのエントリを示すRowFilterを返します。

      次のサンプル・コードは、文字列「foo」と「bar」があるエントリを含めるRowFilterを作成します。

         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);
       

      型パラメータ:
      M - RowFilterが適用されるモデルの型
      I - RowFilterに渡される識別子の型
      パラメータ:
      filters - テストするRowFilter
      戻り値:
      指定された条件を満たすRowFilter
      例外:
      IllegalArgumentException - 次のフィルタが存在する場合: null
      NullPointerException - filtersがnullである場合
      関連項目:
      Arrays.asList(T...)
    • notFilter

      public static <M,​ I> RowFilter<M,​I> notFilter​(RowFilter<M,​I> filter)
      指定されたフィルタ条件にエントリが一致しない場合、一致しないエントリを示すRowFilterを返します。
      型パラメータ:
      M - RowFilterが適用されるモデルの型
      I - RowFilterに渡される識別子の型
      パラメータ:
      filter - 否定するRowFilter
      戻り値:
      指定された条件を満たすRowFilter
      例外:
      IllegalArgumentException - filternullである場合
    • 含む

      public abstract boolean include​(RowFilter.Entry<? extends M,​? extends I> entry)
      指定されたエントリを表示する場合はtrue、表示しない場合はfalseを返します。

      entry引数は、呼出しの間にかぎり有効です。 呼出しの完了後にentryを使用した場合の動作は未定義です。

      パラメータ:
      entry - 配下のモデルからのオブジェクトをラップするnull以外のオブジェクト
      戻り値:
      エントリを表示する場合はtrue