Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » EGL Development Tools » Array sort(No default implementation? )
Array sort [message #915214] Sun, 16 September 2012 20:52 Go to next message
Dan Darnell is currently offline Dan DarnellFriend
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 14:26 Go to previous messageGo to next message
Matt Heitz is currently offline Matt HeitzFriend
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 16:31 Go to previous messageGo to next message
Dan Darnell is currently offline Dan DarnellFriend
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 19:53 Go to previous message
Richard Moulton is currently offline Richard MoultonFriend
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: Fri Mar 29 02:09:35 GMT 2024

Powered by FUDForum. Page generated in 0.02179 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top