Package Torello.Java

Interface FileNodeFilter

  • All Superinterfaces:
    java.util.function.Predicate<FileNode>, java.io.Serializable
    Functional Interface:
    This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

    @FunctionalInterface
    public interface FileNodeFilter
    extends java.util.function.Predicate<FileNode>, java.io.Serializable
    A simple functional-interface (lambda) for filtering lists of FileNode.

    This class is used to filter FileNode-instances when searching through a File-System. Class FileNode uses these filters to allow a programmer to decide which File-Names to include or reject when building many of the containers and / or trees utilized by that class.

    Since this class is a Functional-Interface, it is also (therefore) a Lambda-Target, meaning that any Java Lambda-Expression may be passed to a method that receives this class as a parameter (in place of an actual instance of this class).

    Using StrFilter:
    This class may also be built from an instance of class StrFilter. This allows a programmer to leverage the constructors written for class StrFilter into this class as well.

    Using the class StrFilter to quickly build FileNodeFilter instances can (on occasion) make the task of testing and filtering the file-name and directory String's easier. The example provided below should hilite the advantages.

    Example:
    String[] myFilesList    = { "file.java", "file2.java", ... };
    FileNodeFilter myFilter = FileNodeFilter.fromStrFilter(StrFilter.strListKEEP(myFilesList));
    
    String[] foundFilesList = FileNode
        .createRoot("src/main/java/")
        .loadTree(-1, myFilter, null));
        .flattenJustFiles(SORTED_FILENAME_ARRAY);
    
    See Also:
    StrFilter


    • Field Detail

      • serialVersionUID

        🡇     🗕  🗗  🗖
        static final long serialVersionUID
        This fulfils the SerialVersion UID requirement for all classes that implement Java's interface java.io.Serializable. Using the Serializable Implementation offered by java is very easy, and can make saving program state when debugging a lot easier. It can also be used in place of more complicated systems like "hibernate" to store data as well.

        Functional Interfaces are usually not thought of as Data Objects that need to be saved, stored and retrieved; however, having the ability to store intermediate results along with the lambda-functions that helped get those results can make debugging easier.
        See Also:
        Constant Field Values
        Code:
        Exact Field Declaration Expression:
         public static final long serialVersionUID = 1;
        
    • Method Detail

      • test

        🡅  🡇     🗕  🗗  🗖
        boolean test​(FileNode fn)
        FunctionalInterface Target-Method:
        This method corresponds to the @FunctionalInterface Annotation's method requirement. It is the only non-default, non-static method in this interface, and may be the target of a Lambda-Expression or '::' (double-colon) Function-Pointer.
        Specified by:
        test in interface java.util.function.Predicate<FileNode>
        Parameters:
        fn - Any file node
        Returns:
        A TRUE value should mean that the FileNode has passed the test (will be kept / retained). A return value of FALSE should indicate that the FileNode needs to be filtered.
      • and

        🡅  🡇     🗕  🗗  🗖
        default FileNodeFilter and​(FileNodeFilter other)
        Standard Java-Predicate, Java Functional-Interface AND routine.

        Logically AND's 'this' FileNodeFilter with the filter parameter 'other'
        Parameters:
        other - A 2nd FileNodeFilter with which 'this' filter may be AND'ed.
        Returns:
        A new FileNodeFilter that is the logical-and of 'this' filter and 'other'
        Code:
        Exact Method Body:
         // FAIL-FAST: Check that the lambda will not throw a null pointer exception prior to
         // creating the lambda.
        
         if (other == null) throw new NullPointerException
             ("The parameter 'other' to FileNodeFilter.and(other) was null.");
        
         return (FileNode f) -> this.test(f) && other.test(f);
        
      • or

        🡅  🡇     🗕  🗗  🗖
        default FileNodeFilter or​(FileNodeFilter other)
        Standard Java-Predicate, Java Functional-Interface OR routine.

        Logically OR's 'this' FileNodeFilter with the filter parameter 'other'
        Parameters:
        other - A 2nd FileNodeFilter with which 'this' filter may be or'ed.
        Returns:
        A new FileNodeFilter that is the logical-or of 'this' filter and "other"
        Code:
        Exact Method Body:
         // FAIL-FAST: Check that the lambda will not throw a null pointer exception prior to
         // creating the lambda.
        
         if (other == null) throw new NullPointerException
             ("The parameter 'other' to FileNodeFilter.or(other) was null..");
        
         return (FileNode f) -> this.test(f) || other.test(f);
        
      • negate

        🡅  🡇     🗕  🗗  🗖
        default FileNodeFilter negate()
        Standard Java-Predicate, Java Functional-Interface NEGATE routine.

        Generates 's a FileNodeFilter that is the "logical-not" of 'this' filter.
        Specified by:
        negate in interface java.util.function.Predicate<FileNode>
        Returns:
        A new FileNodeFilter that would return TRUE whenever 'this' would return FALSE, and vice-versa.
        Code:
        Exact Method Body:
         return (FileNode f) -> ! this.test(f);
        
      • filter

        🡅  🡇     🗕  🗗  🗖
        default int filter​(java.lang.Iterable<FileNode> fileNodes)
        This is similar to the java streams function filter(Predicate<>). Elements that do not meet the criteria specified by this FileNodeFilter - specifically, if an element of the input-parameter 'urlList' would evaluate to FALSE - then that element shall be removed from the list.
        Parameters:
        fileNodes - An Iterable of FileNode's which the user would like filtered using 'this' filter.
        Returns:
        The number of elements that were removed from parameter 'fileNodes' based on the results of the 'test(FileNode)' lambda-method FileNodeFilter.test() of 'this' instance.
        Code:
        Exact Method Body:
         int                 removeCount = 0;
         Iterator<FileNode>  iter        = fileNodes.iterator();
        
         // If the filter test returns FALSE, then remove the URL from the collection.
         // Increment the removeCount Counter.
        
         while (iter.hasNext()) if (! test(iter.next())) { removeCount++; iter.remove(); }
        
         return removeCount;
        
      • fromStrFilter

        🡅     🗕  🗗  🗖
        static FileNodeFilter fromStrFilter​(StrFilter sf)
        This wraps a StrFilter inside of a FileNodeFilter. The String-comparison that is performed will use the full-path-name of the FileNode.
        Parameters:
        sf - This is a "String Predicate" that has (usually, but not required) been built by one of the many String-Filter Factory-Build static-methods of class StrFilter. The Predicate's that are constructed via the build methods of StrFilter call the Object.toString() method on the objects they receive for testing.
        Returns:
        FileNodeFilter This will return an instance of a FileNodeFilter that will test the full-path-name as a String.
        See Also:
        StrFilter
        Code:
        Exact Method Body:
         if (sf == null) throw new NullPointerException(
             "The String-Filter Predicate Parameter 'sf' in static-factory builder method " +
             "'fromStrFilter' was passed a null value."
         );
        
         return (FileNode fn) -> sf.test(fn);