Author |
Message
|
siva1431202 |
Posted: Wed May 04, 2011 3:15 am Post subject: Sorting and Removing Duplicates |
|
|
Novice
Joined: 04 May 2011 Posts: 20
|
If i have some data and i am using in aggregate flow. I am combining two replies coming from two systems.
1)Now I have to sort the data
2)Remove the duplicates
I want to do this using the following Languages
1)ESQL
2)PHP
3)ESQL
4)JAVA.
If any one have some idea please reply me with the logic |
|
Back to top |
|
 |
mqjeff |
Posted: Wed May 04, 2011 3:54 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
There is an old post around here somewhere that has an ESQL implementation of the quicksort algorithm.
There should be similar that you can find on the internet for PHP or otherwise is part of the PHP language.
then the question of removing duplicates is just a question of seeing if the next element is the same as the current element.
Or you could stick the data into a database and ask the database to sort and remove duplicates for you.
Happy Searching! |
|
Back to top |
|
 |
siva1431202 |
Posted: Wed May 04, 2011 4:32 am Post subject: |
|
|
Novice
Joined: 04 May 2011 Posts: 20
|
ok...Thank you. But where as here we are not using Database. So can u suggest someother thing to remove duplicates. |
|
Back to top |
|
 |
mqjeff |
Posted: Wed May 04, 2011 4:34 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
I already suggested something to remove duplicates.
Check to see if the next item is the same as the current item, if it is, delete one. |
|
Back to top |
|
 |
smdavies99 |
Posted: Wed May 04, 2011 5:11 am Post subject: |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
|
Back to top |
|
 |
siva1431202 |
Posted: Wed May 04, 2011 6:21 am Post subject: |
|
|
Novice
Joined: 04 May 2011 Posts: 20
|
Ok. THank You. I am trying on the code which you had given.
Because i have to do it using java compute node and Php compute node.
so i am trying to build the logic and syntax based on those examples. |
|
Back to top |
|
 |
khudania |
Posted: Wed May 04, 2011 6:39 am Post subject: |
|
|
 Apprentice
Joined: 30 Nov 2004 Posts: 43
|
|
Back to top |
|
 |
siva1431202 |
Posted: Wed May 04, 2011 7:00 am Post subject: |
|
|
Novice
Joined: 04 May 2011 Posts: 20
|
I had already seen that code and i want to try in java and PHP.
I have the code for sorting array but i want to sort the tree structure in java and PHP. |
|
Back to top |
|
 |
khudania |
Posted: Wed May 04, 2011 7:09 am Post subject: |
|
|
 Apprentice
Joined: 30 Nov 2004 Posts: 43
|
siva1431202 wrote: |
I had already seen that code and i want to try in java and PHP.
I have the code for sorting array but i want to sort the tree structure in java and PHP. |
java would be really simple.
Quote: |
import java.util.*;
ArrayList arrayList = new ArrayList();
arrayList.add("ACB");
arrayList.add("ABE");
arrayList.add("ABC");
arrayList.add("AB1");
Collections.sort(arrayList);
|
The resultant arrayList is sorted one. _________________ If the doors of perception were cleansed, everything would appear as it is - infinite |
|
Back to top |
|
 |
Vitor |
Posted: Wed May 04, 2011 7:11 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
khudania wrote: |
siva1431202 wrote: |
I had already seen that code and i want to try in java and PHP.
I have the code for sorting array but i want to sort the tree structure in java and PHP. |
java would be really simple.
Quote: |
import java.util.*;
ArrayList arrayList = new ArrayList();
arrayList.add("ACB");
arrayList.add("ABE");
arrayList.add("ABC");
arrayList.add("AB1");
Collections.sort(arrayList);
|
The resultant arrayList is sorted one. |
And how would you apply this to a message tree, as the OP has indicated is the requirement? _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
mqjeff |
Posted: Wed May 04, 2011 7:11 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
khudania wrote: |
siva1431202 wrote: |
I had already seen that code and i want to try in java and PHP.
I have the code for sorting array but i want to sort the tree structure in java and PHP. |
java would be really simple.
Quote: |
import java.util.*;
ArrayList arrayList = new ArrayList();
arrayList.add("ACB");
arrayList.add("ABE");
arrayList.add("ABC");
arrayList.add("AB1");
Collections.sort(arrayList);
|
The resultant arrayList is sorted one. |
Oddly enough, the Java Collections interface doesn't provide a version of sort() that accepts an MbElement or MbMessage object... |
|
Back to top |
|
 |
khudania |
Posted: Wed May 04, 2011 7:20 am Post subject: Re: Sorting and Removing Duplicates |
|
|
 Apprentice
Joined: 30 Nov 2004 Posts: 43
|
siva1431202 wrote: |
If i have some data and i am using in aggregate flow. I am combining two replies coming from two systems.
1)Now I have to sort the data
If any one have some idea please reply me with the logic |
Siva wants to sort just the data and he has to at least create a java collection object of the that data, sorting part is handled by the sort function.
for eg.
Quote: |
arrayList.add("ACB"); |
ie an array, or any other descendant of collection class. _________________ If the doors of perception were cleansed, everything would appear as it is - infinite |
|
Back to top |
|
 |
Vitor |
Posted: Wed May 04, 2011 7:25 am Post subject: Re: Sorting and Removing Duplicates |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
khudania wrote: |
Siva wants to sort just the data and he has to at least create a java collection object of the that data, sorting part is handled by the sort function. |
So your solution (if I grasp it correctly) is to unload the message tree into a collection object and sort that? _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
siva1431202 |
Posted: Wed May 04, 2011 7:29 am Post subject: |
|
|
Novice
Joined: 04 May 2011 Posts: 20
|
So your solution (if I grasp it correctly) is to unload the message tree into a collection object and sort that?
Yes you are right and i have to do it using PHP and JAVA compute nodes. |
|
Back to top |
|
 |
khudania |
Posted: Wed May 04, 2011 7:33 am Post subject: |
|
|
 Apprentice
Joined: 30 Nov 2004 Posts: 43
|
From what I understand, Siva wants to sort the data(some list) and not the entire message tree and if my understanding is right, this is how the values can be sorted in java.
Siva, for filtering duplicates, use HashSet instead of ArrayList and then add , only the uniques will be added.
Code: |
Set hashSet = new HashSet();
hashSet.add('ABC');
hashSet.add('ABD');
//and then
arrayList = new ArrayList(hashSet );
Collections.sort(arrayList);
|
_________________ If the doors of perception were cleansed, everything would appear as it is - infinite |
|
Back to top |
|
 |
|