Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi everyone,
i have this situation
Key
A
A
B
C
D
D
I want compute the rowId, mantaining the same value for the same key. Sample of expected output value
Key RowId
A 1
A 1
B 2
C 3
D 4
D 4
Any idea?
thank you
You can do this with a tJavaFlex component. The code you will need looks like below....
Start Code
// start part of your Java code int rowNum = 0;
Main Code
// here is the main part of the component,
// a piece of code executed in the row
// loop
String value = row1.Key;
if(globalMap.get(value)==null){
rowNum = rowNum+1;
globalMap.put(value, rowNum);
}
row2.RowId = ((Integer)globalMap.get(value)).intValue();
What the above is doing is keeping a track of the RowId count using the "rowNum" created in the Start Code section. Then, it is creating a globalMap key/value pair for every "Key" in your data. Once the "Key" is created once, it is assigned the current "rowNum" which is appended by 1. Every time that "Key" is seen again, it is assigned the value stored in the globalMap.
You can do this with a tJavaFlex component. The code you will need looks like below....
Start Code
// start part of your Java code int rowNum = 0;
Main Code
// here is the main part of the component,
// a piece of code executed in the row
// loop
String value = row1.Key;
if(globalMap.get(value)==null){
rowNum = rowNum+1;
globalMap.put(value, rowNum);
}
row2.RowId = ((Integer)globalMap.get(value)).intValue();
What the above is doing is keeping a track of the RowId count using the "rowNum" created in the Start Code section. Then, it is creating a globalMap key/value pair for every "Key" in your data. Once the "Key" is created once, it is assigned the current "rowNum" which is appended by 1. Every time that "Key" is seen again, it is assigned the value stored in the globalMap.
I should point out that I used the globalMap because it was easy. It might be better to create your own HashMap object to store these values in. This will protect against you accidentally affecting other key/value pairs that the globalMap might hold.
I assume that you posted this to show how you got you job to work?