Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Re: Array objects get changed when sorting the array

Reply
Thread Tools

Re: Array objects get changed when sorting the array

 
 
Roedy Green
Guest
Posts: n/a
 
      06-25-2009
On Thu, 25 Jun 2009 08:39:43 -0700 (PDT), Christian
<(E-Mail Removed)> wrote, quoted or indirectly quoted
someone who said :

>In both cases, when sorting the array, afterwards some of the elements
>are like reset, they contain only default values. E.g. the array
>contains 27 elements. None of the elements entirely contains default
>values anymore. One or the other property is always set to another
>value. After the sort it still contains 27 elements, but the first 4
>items contain only default values. The remaining 23 elements still
>have all their property values and are sorted properly.


All that happens during as sort is the compareTo method gets called.
Presumably your compareTo method is under some circumstances modifying
the fields. See http://mindprod.com/applet/comparatorcutter.html for a
little program to generate you the Comparable or Comparator code.

To analyse just what you did wrong, we need as SSCCE. See
http://mindprod.com/jgloss/sscce.html

--
Roedy Green Canadian Mind Products
http://mindprod.com

If everyone lived the way people do in Vancouver, we would need three more entire planets to support us.
~ Guy Dauncey
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      06-25-2009
On Thu, 25 Jun 2009 12:02:28 -0700, Roedy Green
<(E-Mail Removed)> wrote, quoted or indirectly quoted
someone who said :

>To analyse just what you did wrong, we need as SSCCE. See
>http://mindprod.com/jgloss/sscce.html


If you want to solve this with without writing an sscce, instrument a
setter with some debug code. have it dump a stack trace. See
http://mindprod.com/jgloss/stacktrace.html
Make sure all changes to that field go through the setter.

Then you can find out just when the corruption is happening, and the
call chain that did it. It may well be something that happens before
or after the sort.
--
Roedy Green Canadian Mind Products
http://mindprod.com

If everyone lived the way people do in Vancouver, we would need three more entire planets to support us.
~ Guy Dauncey
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Array objects get changed when sorting the array markspace Java 1 06-25-2009 06:22 PM
class objects, method objects, function objects 7stud Python 11 03-20-2007 06:05 PM
changed state to up changed state to down FastEthernet LINEPROTO-5-UPDOWN surrealarmada@gmail.com Cisco 3 03-07-2007 06:06 PM
scroll position is changed when style is changed? mxbrunet Javascript 1 11-03-2006 03:40 AM
xmlDocument.Save "&#10;" getting changed changed to "&amp;#10" st@jpa.co.jp ASP .Net 1 10-11-2005 01:30 PM



Advertisments