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 can be used to build java.util.function.Predicate<FileNode> when searching through a file-system. The class FileNode uses these to allow a programmer to decide which file-names should be read from disk when building file-trees into Java Memory. This class is in accordance with Java's Functional Interface rules, so a simple "lambda-expression" will almost always do the trick.

    WRAPPING class StrFilter: Using the class StrFilter to quickly build FileNodeFilter instances can (on occasion) make the task of testing and filtering the file-name and directory strings easier - if it looks like similar tasks are being repeated over and over again.
    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)
        FUNCTIONAL-INTERFACE BOOLEAN METHOD: This is the method that fulfils this Functional-Interface 'test(...)' method.
        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.

        StrFilter NOTE: The class 'StrFilter' can be used in conjunction with the class-specific filters, for instance, this class FileNodeFilter
        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);