A Java FileFilter example

Summary: A Java FileFilter example, including a complete implementation of a Java FileFilter class.

I don't have much time for discussion today, but here's the source code for a Java FileFilter example I created in a text editor I wrote named "Jelly":

package com.devdaily.jelly.model;

import java.io.File;
import javax.swing.*;
import javax.swing.filechooser.*;

public class RGAFileFilter extends FileFilter
{

  // Accept all directories and all .tex and .latex files.
  public boolean accept(File f)
  {
    if (f.isDirectory())
    {
        return true;
    }

    String extension = getExtension(f);
    if (extension != null)
    {
      //if (extension.equals("tex") || extension.equals("latex") || extension.equals("rga") )
      if ( extension.equals("rga") )
      {
          return true;
      }
      else
      {
          return false;
      }
    }

    return false;
  }

  // The description of this filter
  public String getDescription()
  {
    return "RGA Files (.rga)";
  }

  public static String getExtension(File f)
  {
    String ext = null;
    String s = f.getName();
    int i = s.lastIndexOf('.');

    if (i > 0 &&  i < s.length() - 1) {
        ext = s.substring(i+1).toLowerCase();
    }
    return ext;
  }
}

As you can see from the code, I currently use a filename extension of ".rga", but I also used to use file extensions like ".tex" and ".latex".

Sorry, no other discussion here today ... if you're here, I hope you know why you need a Java FileFilter example, and just wanted to see an implementation like this.