You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avalon.apache.org by do...@apache.org on 2001/03/26 11:15:07 UTC

cvs commit: jakarta-avalon/src/java/org/apache/avalon/util/io OrFileFilter.java InvertedFileFilter.java AndFileFilter.java

donaldp     01/03/26 01:15:07

  Added:       src/java/org/apache/avalon/util/io OrFileFilter.java
                        InvertedFileFilter.java AndFileFilter.java
  Log:
  Extra file filters
  
  Submitted By: "Harmeet Bedi" <hb...@yahoo.com>
  
  Revision  Changes    Path
  1.1                  jakarta-avalon/src/java/org/apache/avalon/util/io/OrFileFilter.java
  
  Index: OrFileFilter.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.avalon.util.io;
  
  import java.io.File;
  import java.io.FilenameFilter;
  
  /**
   * This takes two file fiters as input. Accepts a selection if it is 
   * accpetable to either input filter
   *
   * @author  Harmeet Bedi <ha...@kodemuse.com>
   */
  public class OrFileFilter 
      implements FilenameFilter
  {
      private final FilenameFilter m_filter1;
      private final FilenameFilter m_filter2;
  
      public OrFileFilter( final FilenameFilter filter1, final FilenameFilter filter2 ) 
      {
          m_filter1 = filter1;
          m_filter2 = filter2;
      }
  
      public boolean accept( final File file, final String name ) 
      {
          return m_filter1.accept( file, name ) || m_filter2.accept( file, name );
      }
  }
  
      
  
  
  
  
  1.1                  jakarta-avalon/src/java/org/apache/avalon/util/io/InvertedFileFilter.java
  
  Index: InvertedFileFilter.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.avalon.util.io;
  
  import java.io.File;
  import java.io.FilenameFilter;
  
  /**
   * This takes a file filter as input and inverts the selection.
   * This is used in retrieving files that are not accepted by a filter.
   *
   * @author  Harmeet Bedi <ha...@kodemuse.com>
   */
  public class InvertedFileFilter implements FilenameFilter
  {
      private final FilenameFilter origFilter;
      public InvertedFileFilter( FilenameFilter origFilter ) 
      {
          this.origFilter = origFilter;
      }
  
      public boolean accept( File file, final String name ) 
      {
          return !origFilter.accept(file,name);
      }
  }
  
      
  
  
  
  1.1                  jakarta-avalon/src/java/org/apache/avalon/util/io/AndFileFilter.java
  
  Index: AndFileFilter.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.avalon.util.io;
  
  import java.io.File;
  import java.io.FilenameFilter;
  
  /**
   * This takes two file fiters as input. Accepts a selection only if it is 
   * accpetable to both the input filters
   *
   * @author  Harmeet Bedi <ha...@kodemuse.com>
   */
  public class AndFileFilter 
      implements FilenameFilter
  {
      private final FilenameFilter m_filter1;
      private final FilenameFilter m_filter2;
  
      public AndFileFilter( FilenameFilter filter1, FilenameFilter filter2 ) 
      {
          m_filter1 = filter1;
          m_filter2 = filter2;
      }
  
      public boolean accept( final File file, final String name ) 
      {
          return m_filter1.accept( file, name ) && m_filter2.accept( file, name );
      }
  }
  
      
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org