How to create a java Map from iterate

One Star

How to create a java Map from iterate

Hi all,
I need to create a small POC for data migration and I'm only one step away from achieving it.
Basically I need to read a row from a table and create a Map with key column name and value field value. I need the Map because I want to pass it to tXMLRPCInput.
I'm able to read the data and iterate using tFlowToIterate, but I couldn't see a component to create a map from flowToIterate or other components.
The only solution I found is to use tJava and create the map manually and populate it using values from globalMap.
Is there a component to graphically creating a map, and is it easy to create such an extension?
Thanks for creating this great software.
Bilgin Ibryam
Community Manager

Re: How to create a java Map from iterate

Hello
Is there a component to graphically creating a map, and is it easy to create such an extension?

There is not such a component, you must write manually the java code, as workaround, I like to use tJavaFlex to store all records in a map or list.
Best regards

shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: How to create a java Map from iterate

Shong, thanks for your reply. tJavaFlex works fine, but I have to find a solution w/o writing manual code.
What I need seems very similar output talble of tMap component. What would be the easiest way to create the map w/o writing manual code each time (w/o tJavaFlex ) :
- to extend tMap or tFlowToIterate so they put each element in a map and the put the map in globalMap
- or to create a new component which does exactly this: creates map from selected elements
Are there any guidelines or examples how to extend a component or create a new one? I didn't manage to find any.
Any advice how go about it?
Thanks
One Star

Re: How to create a java Map from iterate

I just collect these from book and useful source .The basic operations of Map (put, get, contains Key, contains Value, size, and isEmpty) behave exactly like their counterparts in Hashtable. The following program generates a frequency table of the words found in its argument list. The frequency table maps each word to the number of times it occurs in the argument list.
import java.util.*;
public class Freq {
public static void main(String[] args) {
Map<String, Integer> m = new HashMap<String, Integer>();
// Initialize frequency table from command line
for (String a : args) {
Integer freq = m.get(a);
m.put(a, (freq == null) ? 1 : freq + 1);
}
System.out.println(m.size() + " distinct words:");
System.out.println(m);
}
}
The only tricky thing about this program is the second argument of the put statement. That argument is a conditional expression that has the effect of setting the frequency to one if the word has never been seen before or one more than its current value if the word has already been seen. Try running this program with the command: