473,657 Members | 2,707 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.ICompara ble.CompareTo
If TypeOf obj Is glcobject Then
Dim tmp As glcobject = DirectCast(obj, glcobject)
Return m_datetime.Comp areTo(tmp.m_dat etime)
End If
End Function

???

Thanks!
Derek
Nov 21 '05 #1
4 2046
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*****@DONTSP AMMEokstateDOT. edu> wrote in message
news:%2******** ********@TK2MSF TNGP09.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.ICompara ble.CompareTo
If TypeOf obj Is glcobject Then
Dim tmp As glcobject = DirectCast(obj, glcobject)
Return m_datetime.Comp areTo(tmp.m_dat etime)
End If
End Function

???

Thanks!
Derek

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

"Derek Martin" <dm*****@DONTSP AMMEokstateDOT. edu> wrote in message
news:%2******** ********@TK2MSF TNGP09.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.ICompara ble.CompareTo
If TypeOf obj Is glcobject Then
Dim tmp As glcobject = DirectCast(obj, glcobject)
Return m_datetime.Comp areTo(tmp.m_dat etime)
End If
End Function

???

Thanks!
Derek

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

Derek

"Russell Jones" <ar**@nospam.no rthstate.net> wrote in message
news:uS******** ******@TK2MSFTN GP12.phx.gbl...
Call Sort, and then ArrayList.Rever se.

"Derek Martin" <dm*****@DONTSP AMMEokstateDOT. edu> wrote in message
news:%2******** ********@TK2MSF TNGP09.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.ICompara ble.CompareTo
If TypeOf obj Is glcobject Then
Dim tmp As glcobject = DirectCast(obj, glcobject)
Return m_datetime.Comp areTo(tmp.m_dat etime)
End If
End Function

???

Thanks!
Derek


Nov 21 '05 #4
If m_ascending Then
If Not v_CaseSensitive Then Return New
CaseInsensitive Comparer().Comp are(x, y) Else Return New
Comparer(ci).Co mpare(x, y)
Else
If Not v_CaseSensitive Then Return New
CaseInsensitive Comparer().Comp are(y, x) Else Return New
Comparer(ci).Co mpare(y, x)
End If

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

Derek

"Russell Jones" <ar**@nospam.no rthstate.net> wrote in message
news:uS******** ******@TK2MSFTN GP12.phx.gbl...
Call Sort, and then ArrayList.Rever se.

"Derek Martin" <dm*****@DONTSP AMMEokstateDOT. edu> wrote in message
news:%2******** ********@TK2MSF TNGP09.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.ICompara ble.CompareTo
If TypeOf obj Is glcobject Then
Dim tmp As glcobject = DirectCast(obj, glcobject)
Return m_datetime.Comp areTo(tmp.m_dat etime)
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
6433
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. Simple code: Dim y As New ArrayList y.Add("Abc") y.Add("abc") y.Add("_bc")
19
2444
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 would like to sort the arraylist based on object.name - is that possible? Thanks! Derek
20
5968
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 arraylist then I have to handle this with a sort method that uses comparer. I can reference the properties of the Arraylist directly such as dim mylist as new FrameList mylist.Add(new FrameStructure) mylist(0).first = "blabla..." mylist(0).second...
10
9678
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 al.add("one") al.add("two") dim x as integer = al.indexof("ONE") I would like this to find the match and return 0
0
1672
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 investigate any further but there was nothing about it when googling the newsgroups so I am posting a note in case it helps somebody else out. The problem was in a system with a web front end calling through to a chain of 3 webservices i.e.
16
6414
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 sorting (because it's ultimately being consumed in a GridView). I can't simply sort the ArrayList (because it only knows it's holding a bunch of objects). So I need a way to sort the ArrayList, based on the data - that is within the objects that...
48
4455
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 lot faster with both methods using .NET 1.1, that's why I am pretty sure its a (rather serious) bug. Below you can find C# test case that should allow you to reproduce this error, to run it you will need to put 2 data files into current directory...
4
13291
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
6969
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, "Standard UTM")) aSystem.Add(New PickList(-2, "UTM-NAD83")) aSystem.Add(New PickList(-3, "UTM-NAD27"))
0
8394
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8306
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8825
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7327
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1615
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.