Skip to main content


Showing posts from December, 2011

Guava: Multimap, Bimap

Multimap Multimap   is a collection similar to a Map, but which may associate multiple values with a single key. So if you put the two value with the same key then multimap will map both value with the same key. Multimap   has some very useful extension like ListMultimap , SetMultimap ArrayListMultimap implements the ListMultimap interface and uses an ArrayList to store the values for a given key. And  HashMultimap implements the SetMultimap interface and it will not store the duplicate key-value pairs, same as Set behave. Here is the ArrayListMultimap example. Multimap<String, String> map1 = ArrayListMultimap.create(); map1.put("A", "Test1"); map1.put("B", "Test2"); map1.put("B", "Test3"); map1.put("A", "Test4"); map1.put("C", "Test5"); map1.put("X", "Test6"); Multimap<String, String> map2 = ArrayListMultimap.create(); map2.put(&quo

JavaScript [ExtJs3]: Loading complex data in EditorGridPanel with Dynamic Combo Box

Grid is always an important widget of any project and many time we find a situation where we have to render the complex data in grid panel. And another use-case of dynamic combo box where the combo data comes with the record. To handle a complex object we have to define a new data type. = { convert: function(v){ v.toString = function(){ return v.display; }; return v; }, sortType:, type: 'complexdata' }; This extended class will take care of dynamic combo box loading. It’s a plugin class so after creating the object we have to add this to “plugins” property of grid panel. Ext.ux.ComplexDataColumn = Ext.extend(Ext.grid.Column, { dataField: 'options', displayField: 'display', valueField: 'id', constructor: function (c) { c.editor = this.buildComboEditor();, c); }, init: function(grid){ g

Java: Create message with MessageFormat class

Creating a message string is very easy, but creating it with more effective way that's matter. Most of time when we write the code for message string, we use "+" operator on string. But it become complex when we have to deal with lots of pieces of string. It can be worse when we have to deal with number, date and currency type data with locale setting. Below are few test data which use common way of creating the message string. DateFormat df = DateFormat.getDateInstance(DateFormat.DEFAULT); DateFormat tf = DateFormat.getTimeInstance(DateFormat.DEFAULT); Date today = new Date(); String text = "Work"; int num = 7; String meesage1 = "Time= " + tf.format(today) + ", Date= " + df.format(today) + ", Text= " + text + ", Number= " + num + "."; System.out.println(meesage1); String message2 = new StringBuffer("Time= ").append(tf.format(today)) .append(", Date= ").append(df.form