File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes OO, Patterns, UML and Refactoring and the fly likes Boolean Logic Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Boolean Logic" Watch "Boolean Logic" New topic
Author

Boolean Logic

Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Is this at all interesting? Has it already been done in something I can reuse?



A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Looks a little bit similar to how Smalltalk Booleans are implemented. And to http://jakarta.apache.org/commons/collections/api-release/org/apache/commons/collections/functors/package-summary.html

But what exactly are you trying to accomplish?


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
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
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.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
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... ).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Boolean Logic