By Atif Khan (
April 16, 2007 at 6:46 pm)
· Filed under Java, Programming, Software
Sometime back I proposed a reversible enum pattern in my post. One thing missing from that implementation was the ability to successfully lookup the enum constants in cases where enum constants can have multiple values. To accomplish this, I utilized another feature introduced in Java 5, namely varargs or variable argument support. This way while building the key for the map, we utilize all the values for a constant and use the varargs in the reverse() method of the enum.
Let’s look at the interface MultiValueReversibleEnum that denotes an enum as reversible and that an enum should implement.
The things to notice in this interface are:
getAllCode() method - It returns an array of all the possible values for an enum constant
reverse( E ... code ) method - You can see the usage of varargs here. You basically give all the possible values for the enum constant you want to lookup in the right order
Next we need to look at the map
MultiValueReverseEnumMap that will store the enum constants and their value mappings.
As you can see, the getAllCodes() defined in the interface is used to build the key for the map. Also, the get( final K ... enumValues ) method that looks up the value in map uses varargs.
Now it’s time to glue everything together and see how to use the interface and map to build a multi-valued reversible enum. We will write a test class
MultiValuedEnumTest.
If you run this class, you should see following getting printed:
Reverse for [1, 11]: ONE
Reverse for [2, 22]: TWO
It’s all very simple and straightforward. If you have any suggestions or feedback to improve this, please leave me a comment.
Permalink
By Atif Khan (
April 10, 2007 at 3:05 pm)
· Filed under Java, Programming, Software, Web
I have been spending time on and off looking at various web frameworks available for a little more than a year. A lot of this has to do with keeping track of what’s going on in the web framework arena and keep in sync with the technologies. Another focus of mine is to see how the new (at least for me) frameworks affect the productivity of a developer.
I first looked at RIFE last year and I have been very impressed by the concepts.The developers of RIFE, Geert Bevin and others have been very helpful when I had some questions. I was even able to get answers on the IRC channel for RIFE. It was not until recently that I tried to write an application using RIFE that I really got a feel of it.
Here are some of the good and bad that I encountered:
Pros
- A complete framework. It includes basic web framework, ORM, Content Management, Validations, Templates etc.
- Good support from developers
- A nice quick start application to get you running quickly
- Good support for constraints for adding validations
- Continuations - ability to pause, rewind, jump through transaction steps
Cons
- Templates are really weird to work with. The syntax for the templates really did me. It is not really designer friendly like Tapestry or Wicket
- The concept of flowlink and datalink is just too verbose and not clear
- Using annotation didn’t do me any good as well for defining the flow and data links. There isn’t enough documentation for annotations
- The only way for form validations I could find was to define the a MetaData class equivalent to the domain object representing the form and define the validations in there. This just seems like way too much of work for simple validations.
- I could not figure out how to customize the error messages for form validations
In the end, I feel that it’s the lack of documentation that prevented me from really exploring it. I know Geert is a very sharp guy and if he ever gets to read my blog, I welcome his comments. I think the learning curve is too much for RIFE and lack of documentation adds to it and I am not sure if the return is proportional to the effort compared to other frameworks.
Permalink