473,406 Members | 2,843 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Invert an Arraylist.Sort()

Hi List, I have an arraylist of objects. I have created my own IComparable
in the object to return the sort on datetime. This works great! Now, I'd
like to invert the sort. Currently, it gives me 4/1/05 before 4/5/05
(good), but I'd like to have 4/5/05 before 4/1/05 (better!) for my
application.

Public Function CompareTo(ByVal obj As Object) As Integer Implements + _
System.IComparable.CompareTo
If TypeOf obj Is glcobject Then
Dim tmp As glcobject = DirectCast(obj, glcobject)
Return m_datetime.CompareTo(tmp.m_datetime)
End If
End Function

???

Thanks!
Derek
Nov 21 '05 #1
4 2035
Maybe create a property which tells your object which way to sort. Then in
CompareTo look at that property, and return the appropriate result.

"Derek Martin" <dm*****@DONTSPAMMEokstateDOT.edu> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi List, I have an arraylist of objects. I have created my own
IComparable in the object to return the sort on datetime. This works
great! Now, I'd like to invert the sort. Currently, it gives me 4/1/05
before 4/5/05 (good), but I'd like to have 4/5/05 before 4/1/05 (better!)
for my application.

Public Function CompareTo(ByVal obj As Object) As Integer Implements + _
System.IComparable.CompareTo
If TypeOf obj Is glcobject Then
Dim tmp As glcobject = DirectCast(obj, glcobject)
Return m_datetime.CompareTo(tmp.m_datetime)
End If
End Function

???

Thanks!
Derek

Nov 21 '05 #2
Call Sort, and then ArrayList.Reverse.

"Derek Martin" <dm*****@DONTSPAMMEokstateDOT.edu> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi List, I have an arraylist of objects. I have created my own
IComparable in the object to return the sort on datetime. This works
great! Now, I'd like to invert the sort. Currently, it gives me 4/1/05
before 4/5/05 (good), but I'd like to have 4/5/05 before 4/1/05 (better!)
for my application.

Public Function CompareTo(ByVal obj As Object) As Integer Implements + _
System.IComparable.CompareTo
If TypeOf obj Is glcobject Then
Dim tmp As glcobject = DirectCast(obj, glcobject)
Return m_datetime.CompareTo(tmp.m_datetime)
End If
End Function

???

Thanks!
Derek

Nov 21 '05 #3
Ooooh - good idea!!!! Thanks Russell...

Derek

"Russell Jones" <ar**@nospam.northstate.net> wrote in message
news:uS**************@TK2MSFTNGP12.phx.gbl...
Call Sort, and then ArrayList.Reverse.

"Derek Martin" <dm*****@DONTSPAMMEokstateDOT.edu> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi List, I have an arraylist of objects. I have created my own
IComparable in the object to return the sort on datetime. This works
great! Now, I'd like to invert the sort. Currently, it gives me 4/1/05
before 4/5/05 (good), but I'd like to have 4/5/05 before 4/1/05 (better!)
for my application.

Public Function CompareTo(ByVal obj As Object) As Integer Implements + _
System.IComparable.CompareTo
If TypeOf obj Is glcobject Then
Dim tmp As glcobject = DirectCast(obj, glcobject)
Return m_datetime.CompareTo(tmp.m_datetime)
End If
End Function

???

Thanks!
Derek


Nov 21 '05 #4
If m_ascending Then
If Not v_CaseSensitive Then Return New
CaseInsensitiveComparer().Compare(x, y) Else Return New
Comparer(ci).Compare(x, y)
Else
If Not v_CaseSensitive Then Return New
CaseInsensitiveComparer().Compare(y, x) Else Return New
Comparer(ci).Compare(y, x)
End If

"Derek Martin" wrote:
Ooooh - good idea!!!! Thanks Russell...

Derek

"Russell Jones" <ar**@nospam.northstate.net> wrote in message
news:uS**************@TK2MSFTNGP12.phx.gbl...
Call Sort, and then ArrayList.Reverse.

"Derek Martin" <dm*****@DONTSPAMMEokstateDOT.edu> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi List, I have an arraylist of objects. I have created my own
IComparable in the object to return the sort on datetime. This works
great! Now, I'd like to invert the sort. Currently, it gives me 4/1/05
before 4/5/05 (good), but I'd like to have 4/5/05 before 4/1/05 (better!)
for my application.

Public Function CompareTo(ByVal obj As Object) As Integer Implements + _
System.IComparable.CompareTo
If TypeOf obj Is glcobject Then
Dim tmp As glcobject = DirectCast(obj, glcobject)
Return m_datetime.CompareTo(tmp.m_datetime)
End If
End Function

???

Thanks!
Derek



Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Adam J. Schaff | last post by:
Hello. I recently noticed that the Sort method of the .NET ArrayList class does not behave as I expected. I expect 'A' < '_' < 'a' (as per their ascii values) but what I got was the opposite....
19
by: Derek Martin | last post by:
Hi there, I have been playing with sorting my arraylist and having some troubles. Maybe just going about it wrong. My arraylist contains objects and one of the members of the object is 'name.' I...
20
by: Dennis | last post by:
I use the following code for a strongly typed arraylist and it works great. However, I was wondering if this is the proper way to do it. I realize that if I want to implement sorting of the...
10
by: JohnR | last post by:
I have an arraylist of string values. I would like to search the arraylist to find the index of a particular string and I would like the search to be case insensitive. dim al as new arraylist...
0
by: Grant Wickman | last post by:
Our team has just fixed a really nasty problem that appears to be caused by an obscure bug in the sort method of Arraylist and daisy-chained webservice stubs. We've fixed the bug so I'll not...
16
by: RCS | last post by:
So I have an ArrayList that gets populated with objects like: myAL.Add(new CustomObject(parm1,parm2)); I'm consuming this ArrayList from an ObjectDataSource and would like to have this support...
48
by: Alex Chudnovsky | last post by:
I have come across with what appears to be a significant performance bug in ..NET 2.0 ArrayList.Sort method when compared with Array.Sort on the same data. Same data on the same CPU gets sorted a...
4
by: M Harvey | last post by:
I have an arraylist that contains datetime values. What is the best way to sort this arraylist by date ascending? Thanks, Matt
3
by: Stuart | last post by:
I am using Visual Basic 2005. I have created a two dimensional ArrayList named aSystem that is populated as follows:- aSystem.Add(New PickList(0, "Undefined")) aSystem.Add(New PickList(-1,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.