aspose file tools
The moose likes Java in General and the fly likes Commands to Objects Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Commands to Objects" Watch "Commands to Objects" New topic
Author

Commands to Objects

Alex Birmingham
Ranch Hand

Joined: May 22, 2008
Posts: 54
Hey All,

I'm trying to write an object which takes a keyboard-entered string, tokenizes it, creates 'Action-related' objects out of the tokens, and then constructs an Action object with the objects as parameters.

I am going to delete most of this post because my second post is now more relevant.
[ December 09, 2008: Message edited by: Alex Birmingham ]

- SCJA 1.0
Alex Birmingham
Ranch Hand

Joined: May 22, 2008
Posts: 54
Update:

The beginnings are still humble, but the class has been fleshed out a bit. Upon instantiation of CommandFilter, a list of Action sub-classes is created, and that list is used to map a HashMap of strings and their corresponding cued classes. Next step, in theory, is to work on parsing Action-related objects from the rest of the user-entered command, and then to use reflection-built-constructor to instantiate the Action sub-class with those objects.

*Wipes sweat from brow*

What do you guys think, is this the right solution here?

Here's the CommandFilter code:


[ December 09, 2008: Message edited by: Alex Birmingham ]
[ December 09, 2008: Message edited by: Alex Birmingham ]
Alex Birmingham
Ranch Hand

Joined: May 22, 2008
Posts: 54
...if anyone's interested, here's how it turned out.
I feel bad about how clunky it is, and would still appreciate general feedback.

Alex Birmingham
Ranch Hand

Joined: May 22, 2008
Posts: 54
Er, alright.

So it turns out that what I really needed to know was simply the phrase "Regular Expression."
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3268

Hi Alex,

Can you post your final solution, I'm curious


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Alex Birmingham
Ranch Hand

Joined: May 22, 2008
Posts: 54
Well, I haven't coded it yet, but it's looking like the most logical way to do this is to encode a regex or 'regular expression' anything all the Action objects, all the Targetable objects, and anything else that could possibly be invoked via player command.

These regexes will function as 'hooks,' and because of the versatile nature of the Pattern object (or so I'm told, I haven't ever used it myself) it will clean up both the hook code and the parsing code.

so an 'attack' Action object would include something like this:

Pattern hooks = new Pattern("at[tack]|k[ill}|swin[g]");
// Exact syntax unknown

My only issue now is that the targetable hooks have to include adjectives, so that 'a grey door' can be distinguished from 'a blue door.' I believe this is possible with regex, but I'm still looking to figure out how.
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3268

Hmm, interesting . I'm curious because I work on Role Playing software myself (saw some of your variable names). We still tend to use explicit strings for our rule set, but they are not 'actions' like you have.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Commands to Objects
 
Similar Threads
Which are the differences between Component Based and Action Based
Struts - basic form submission -- variable changed values not holding
Who is responsible to create Action object?
ejb client
Struts2: My s:select will not select rows which it should do applicable