Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGL Development Tools » Array sort(No default implementation? )
Array sort [message #915214] Sun, 16 September 2012 16:52 Go to next message
Dan Darnell is currently offline Dan Darnell
Messages: 145
Registered: November 2011
Location: Arkansas
Senior Member
I am trying to figure out how array sorting is implemented in EDT. I found the sort() function in the List implementation but it takes a user-defined sort function as a parameter. I am familiar with this from the RUILib.sort() implementation in EGL CE but that function would accept null as a parameter to use a default alpha sort. Is the intention in EDT that a developer MUST provide his/her own sort function implementation or are there default implementation(s) tucked away somewhere?

I know in JavaScript that the sort() function accepts a user-defined sort function as a parameter or you can omit the function definition and get an alpha sort. That concept would be nice to have in EDT. (As I say, this is the way it was implemented in RUILib in EGL CE.)

FYI, I'm using the following as sort function implementations of my own devising...is there a better way?

function sortFunctionAlpha (a any in, b any in) returns(int)

	aString string = a as string;
	bString string = b as string;

	if (aString < bString) 
		return -1;
	end 
	
	if (aString > bString)
		return 1;
	end
	 
	return 0;

end 


function sortFunctionInteger (a any in, b any in) returns(int)

	return (a as int - b as int);

end 


Thanks,

Dan
Re: Array sort [message #915558 is a reply to message #915214] Mon, 17 September 2012 10:26 Go to previous messageGo to next message
Matt Heitz is currently offline Matt Heitz
Messages: 36
Registered: July 2009
Member
Dan,

At the moment there's no better way. I imagine that we'll provide something more convenient in the future.

-Matt
Re: Array sort [message #915615 is a reply to message #915558] Mon, 17 September 2012 12:31 Go to previous messageGo to next message
Dan Darnell is currently offline Dan Darnell
Messages: 145
Registered: November 2011
Location: Arkansas
Senior Member
Thanks, Matt. Just making sure I didn't overlook something.

--Dan
Re: Array sort [message #1006846 is a reply to message #915615] Sat, 02 February 2013 14:53 Go to previous message
Richard Moulton is currently offline Richard Moulton
Messages: 92
Registered: August 2011
Location: Devon, UK
Member
I really like this. I was wondering how to deal with array sorting and found this post and then I was wondering how to deal with sorting an array of records, sorting on multiple elements in my array and this worked really well.

	// Portfolio transactions are sorted by transaction type within date; the 
	// earliest BUY transaction would be first 
	function sortTransactions(a any in, b any in) returns(int)
		aTransaction portfolioRecord = a as portfolioRecord;
		bTransaction portfolioRecord = b as portfolioRecord;
		case
			when ( aTransaction.trndate > bTransaction.trndate )
				return 1;
			when ( aTransaction.trndate < bTransaction.trndate )
				return -1;
			otherwise
				case
					when ( aTransaction.trntype > bTransaction.trntype )
						return 1;
					when ( aTransaction.trntype < bTransaction.trntype )
						return -1;
					otherwise
						return 0;
				end
		end
	end


This successfully sorted my array of transactions by transaction type within transaction date. I was pleasantly surprised how easy this was.

Richard
Previous Topic:Widget Instantiability Confusion
Next Topic:develop plugin for rbd
Goto Forum:
  


Current Time: Thu Aug 28 19:18:05 EDT 2014

Powered by FUDForum. Page generated in 0.02405 seconds