Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7620041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:50:29+00:00 2026-05-31T03:50:29+00:00

I’m a bit stuck on a project.. Basically, I get a directory to scan

  • 0

I’m a bit stuck on a project..
Basically, I get a directory to scan for files that passes certain filters.

The command files contains lines with filtering (given filters name are stored in an enum file) instructions. like this for example:
suffix%txt
exec%YES

if that’s all, it will return all the files ending with txt (extension) and are executable..
so far no problem.

the problem starts with line like this:
suffix%txt exec%YES (on the same line) in this case, it should return all the files that ends with txt OR executable..

I’m splitting the line using String.split(“%”) and getting it into a map with a key and value, than iterate over each key and checks what filter in the enum it is, and perform the desire checking.

I’m kinda stuck on how to identify that when i have more than 1 filter per line.
I tried doing a HashMap with the 1st filter as the key, and the value is a list that contains all the other (using split(” “) for breaking up the filters..
I can’t rely on the keys being on the even or odd indexes, because a filter may have another %NOT at the end of it (suffix%txt%NOT) which will return all the files that doesn’t end with txt…

Any help would be appreciated!
Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T03:50:31+00:00Added an answer on May 31, 2026 at 3:50 am

    How about this: create a Filter interface, and write a function that parses a file into a single filter based on the contents of the file. You’d have something like:

    interface Filter {
      boolean passesFilter(File file);
    }
    
    class SuffixFilter implements Filter {
      SuffixFilter(String suffix) { ... }
      public boolean passesFilter(File file) {
        // return true if file has the appropriate suffix
      }
    }
    
    class ExecutableFilter implements Filter {
      ...  // filter that returns true if the file is executable
    }
    
    // now for the interesting part ...
    class NegationFilter implements Filter {
      private final Filter subfilter;
      NegationFilter(Filter subfilter) {
        this.subfilter = subfilter;
      }
    
      public boolean passesFilter(File file) {
        return !subfilter.passesFilter(file);
      }
    }
    
    class AndFilter implements Filter {
      private final Collection<Filter> subfilters;
      AndFilter(Collection<Filter> subfilters) {
        this.subfilters = subfilters;
      }
    
      public boolean passesFilter(File file) {
        for (Filter subfilter : subfilters) {
          if (!subfilter.passesFilter(file)) {
            return false;
          }
        }
        return true;
      }
    }
    
    class OrFilter implements Filter {
      private final Collection<Filter> subfilters;
      OrFilter(Collection<Filter> subfilters) {
        this.subfilters = subfilters;
      }
    
      public boolean passesFilter(File file) {
        for (Filter subfilter : subfilters) {
          if (subfilter.passesFilter(file)) {
            return true;
          }
        }
        return false;
      }
    }
    

    With this in place, you just need to build up all the basic filters, and then adjacent elements on the same line get OrFiltered together while filters on separate lines (or-filtered or not) get AndFiltered together. Here’s a sketch:

    Filter readAndFilter(Iterable<String> fileLines) {
      List<Filter> subfilters = new ArrayList<Filter>();
      for (String line : fileLines) {
        subfilters.add(readOrFilter(line));
      }
      return new AndFilter(subfilters);
    }
    
    Filter readOrFilter(String fileLine) {
      List<Filter> subfilters = new ArrayList<Filter>();
      for (String oneFilter : fileLine.split(" ")) {
        Filter filter = buildOneFilter(oneFilter);
        subfilters.add(filter);
      }
      return new OrFilter(subfilters);
    }
    
    Filter buildOneFilter(String oneFilterClause) {
      // parse as you were doing before
    }
    

    You’d call readAndFilter on lines read out from your file, and what you get back is always a single Filter that you can pass files to and it’ll tell you whether they pass the filter. (Note: if you wanted to, you could special-case my readAndFilter and readOrFilter methods to check if the list they’re going to return is of length 1, and if so just return that one filter rather than an And or Or of one element. It doesn’t affect correctness, but it might make debugging output a little easier to read.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I would like to run a str_replace or preg_replace which looks for certain words

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.