check differnet pattern match then perform an action

M

mike

Hi,

I will read output lines ( text strings) from another program. I have
about, at the moment, 30 different ( text strings) to look for in the
output and each match will result in an action from my program.

Any ideas on how I can make the pattern matching design so that each
line will be matched against each pattern?

cheers,

//mike
 
J

John B. Matthews

mike said:
Hi,

I will read output lines ( text strings) from another program. I have
about, at the moment, 30 different ( text strings) to look for in the
output and each match will result in an action from my program.

Any ideas on how I can make the pattern matching design so that each
line will be matched against each pattern?

Are you considering the command pattern?

<http://www.google.com/search?q=java+command+pattern>
 
J

John B. Matthews

"John B. Matthews said:
Are you considering the command pattern?

<http://www.google.com/search?q=java+command+pattern>

On closer reading, you may be more interested in pattern matching than
command dispatching. I'm not sure if you mean to match any of 30 literal
strings or any of 30 regular expressions. In either case, you may be
better off using StreamTokenizer to parse the input text (output from
another program) into a HashMap of unique, non-trivial words. A literal
match would then be constant-time. A regex match will take longer, but
pre-compiling is especially beneficial for short target strings. If
misspelling is a problem, consider a variation of Knuth's soundex
algorithm:

<http://www.java2s.com/Code/Java/Collections-Data-Structure/SoundextheSou
ndexAlgorithmasdescribedbyKnuth.htm>
 
M

mike

On closer reading, you may be more interested in pattern matching than
command dispatching. I'm not sure if you mean to match any of 30 literal
strings or any of 30 regular expressions. In either case, you may be
better off using StreamTokenizer to parse the input text (output from
another program) into a HashMap of unique, non-trivial words. A literal
match would then be constant-time. A regex match will take longer, but
pre-compiling is especially beneficial for short target strings. If
misspelling is a problem, consider a variation of Knuth's soundex
algorithm:

<http://www.java2s.com/Code/Java/Collections-Data-Structure/SoundextheSou
ndexAlgorithmasdescribedbyKnuth.htm>

--
John B. Matthews
trashgod at gmail dot com
home dot woh dot rr dot com slash jbmatthews- Dölj citerad text -

- Visa citerad text -

Hi,

You led me to look at patterns. So I decided to test an implementaion
using Composite pattern.
http://pclc.pace.edu/~bergin/patterns/strategydecorator.html

I will have a class for each scenario of output. Then the class will
return a State object.

I appreciated you leading me into patterns.

cheers,

//mike


I will try using
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top