The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Joined: Jan 29, 2003
I was planning to make something to copy files with some selection rules and thought "Why not make this the last time I ever write a recursive file.list()?" Then, "It will need some way to filter files, and my first application is going to need some and/or combinations of filters."
RuleNode is an interface. A BaseNode implements and() and or() methods. RuleAnd and RuleOr extend the BaseNode to do evaluate sets of nodes. My file copy program nodes would implement RuleNode or maybe extend BaseNode.
The result of something like "a.and( b.or( c ) )" is a tree. A FilenameFilter would pass the filespec to all filter nodes in the tree so they can set their internal boolean. Then isTrue() would evaluate them with appropriate short circuits.
This is all very fuzzy so far. I'd like to eliminate the two passes through the tree to set the booleans and call the isTrue() method. Maybe overload isTrue() to pass the File along. Looks like the Apache predicate does that. It might do the whole job for me.
Joined: Jul 11, 2001
Yes, sounds I'd go with the Jakarta Predicate.
In fact I use it quite often for similar situations (or actually more often for much simpler situations... ).