Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Boolean Logic

 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this at all interesting? Has it already been done in something I can reuse?

 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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... ).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic