One Star

[resolved] How to create a java Map from iterate ?

Hello,
I need to read a row from input and create a new Map in output.
Can tJavaFlex do this, and how can I forword the new flow map for output ? :/
My java code is like this:

java.util.List<String> fibres= new java.util.ArrayList<String>();
String Id_cable=input_row.Noeud.trim();
Integer Nb_tube=input_row.TUBES;
Integer Compositio=input_row.COMPOSITIO;
String Id_tube=input_row.Id_tube;
if (Nb_tube>0)
{ // only one tube input
for (int i=1;i<=Nb_tube; i++) {
Id_tube=Id_cable+"T"+i;
if(Compositio>0)
{
String Id_fibre="";
for(int j=1;j<=Compositio;j++){
//a new calculated row,for one input row of tube
// I will have many rows of calculated fibres.
Id_fibre= Id_tube.trim()+"F"+j;
fibres.add(Id_fibre,Id_fibre);
fibres.add(Id_tube,Id_tube);
}
}
}
}

May I use tJavaFlex+tFlowtoIterate+tFixedFlow, and how can I use tJavaFlex with 2* for loop ? :/
Thank you in advance .
1 ACCEPTED SOLUTION

Accepted Solutions
Community Manager

Re: [resolved] How to create a java Map from iterate ?

Hello
Yes, tJavaFlex component fix your need. See my screenshots.
code on begin part:
// start part of your Java code
java.util.Map<String,String> fibres= new java.util.HashMap<String,String>();
String Id_cable;
Integer Nb_tube;
Integer Compositio;
String Id_tube;

code on main part:
			  Id_cable=row1.Noeud.trim();
Nb_tube=row1.TUBES;
Compositio=row1.COMPOSITIO;
Id_tube=row1.Id_tube;
if (Nb_tube>0)
{ // only one tube input
for (int i=1;i<=Nb_tube; i++) {
Id_tube=Id_cable+"T"+i;
if(Compositio>0)
{
String Id_fibre="";
for(int j=1;j<=Compositio;j++){
//a new calculated row,for one input row of tube
// I will have many rows of calculated fibres.
Id_fibre= Id_tube.trim()+"F"+j;
fibres.put(Id_fibre,Id_fibre);
fibres.put(Id_tube,Id_tube);
}
}
}
}

code on end part:
// end of the component, outside/closing the loop
globalMap.put("fibres",fibres);

Best regards

shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
2 REPLIES
Community Manager

Re: [resolved] How to create a java Map from iterate ?

Hello
Yes, tJavaFlex component fix your need. See my screenshots.
code on begin part:
// start part of your Java code
java.util.Map<String,String> fibres= new java.util.HashMap<String,String>();
String Id_cable;
Integer Nb_tube;
Integer Compositio;
String Id_tube;

code on main part:
			  Id_cable=row1.Noeud.trim();
Nb_tube=row1.TUBES;
Compositio=row1.COMPOSITIO;
Id_tube=row1.Id_tube;
if (Nb_tube>0)
{ // only one tube input
for (int i=1;i<=Nb_tube; i++) {
Id_tube=Id_cable+"T"+i;
if(Compositio>0)
{
String Id_fibre="";
for(int j=1;j<=Compositio;j++){
//a new calculated row,for one input row of tube
// I will have many rows of calculated fibres.
Id_fibre= Id_tube.trim()+"F"+j;
fibres.put(Id_fibre,Id_fibre);
fibres.put(Id_tube,Id_tube);
}
}
}
}

code on end part:
// end of the component, outside/closing the loop
globalMap.put("fibres",fibres);

Best regards

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

Re: [resolved] How to create a java Map from iterate ?

It's work, thank you shong. :cool: