on 07-06-2017 12:05 PM
Hello all,
I have a requirement where I need to sort one queue which contains multiple contexts and each context is having multiple values.
As per attached screenshot, I need to sort the output based on the value that is occurring before '+' symbol and publish the output in ascending order. My output should ideally look like follows:
15112371+98.83
15112371+0.43
.
.
.
15112371+
-Context Change-
15112372+98.84
15112372+0.50
.
.
.
15112372+
Looking forward to your kind inputs.
Best regards,
Aman
Hi Aman,
Try following
Do a remove context --> sort --> UDF with all values in queue.
CODE:
String s1="";
String s2="";
try{
for(int i=0;i<input.length;i++)
{
s1=input[i].substring(0,input[i].indexOf("+"));
s2=input[i+1].substring(0,input[i+1].indexOf("+"));
if (s1.equals(s2))
{
result.addValue(input[i]);
}
else
{
result.addValue(input[i]);
result.addValue(ResultList.CC);
}
}
}
catch(Exception e)
{
}
Thanks,
Avinash B
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry My bad. Try this. It should work fine.
String s1="";
String s2="";
for(int i=0;i<input.length;i++)
{
if(i!=input.length-1)
{
s1=input[i].substring(0,input[i].indexOf("+"));
s2=input[i+1].substring(0,input[i+1].indexOf("+"));
if (s1.equals(s2))
{
result.addValue(input[i]);
}
else
{
result.addValue(input[i]);
result.addValue(ResultList.CC);
}
}
else
{
result.addValue(input[i]);
}
}
Thanks,
Avinash B
Hello avinash.avi,
Thanks a lot for the update. The logic and code that you have provided are working perfectly fine for below input (LHS) and I am getting RHS as output. This is perfect.
However, this code is not working for the following input. Could you please suggest the changes that needs to be done to this code in order to make it work similar to the above?
Best regards,
Aman
Hello Avinash,
Here is the output that I am expecting here:
15112371+CU+
15112371+CR+
15112371+ZN+
15112371+TI+
15112371+MN+0.03
15112371+FE+0.20
15112371+SI+0.43
15112371+MG+0.46
15112371+AL+98.83
- Context Change-
15112372+CU+
15112372+ZN+
15112372+TI+
15112372+CR+0.01
15112372+MN+0.03
15112372+FE+0.19
15112372+MG+0.38
15112372+SI+0.50
15112372+AL+98.84
Hello avinash.avi,,
I just realised, even if I do not get a ContextChange, that will serve the purpose for me. Requesting you to kindly suggest on the logic. Below is the input (screenshot) that I am getting and below that is the desired output.
15112371+CU+
15112371+CR+
15112371+ZN+
15112371+TI+
15112371+MN+0.03
15112371+FE+0.20
15112371+SI+0.43
15112371+MG+0.46
15112371+AL+98.83
15112372+CU+
15112372+ZN+
15112372+TI+
15112372+CR+0.01
15112372+MN+0.03
15112372+FE+0.19
15112372+MG+0.38
15112372+SI+0.50
15112372+AL+98.84
Thanks in advance.
-Aman
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.