Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Boolean Logic

 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is this at all interesting? Has it already been done in something I can reuse?

 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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... ).
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic