list + equals question ?

N

news.t-com.hr

I have 3 lists, for example ;
List<Test1> list = new ArrayList<Test1>();
List<Test2> list = new ArrayList<Test2>();
List<Test3> list = new ArrayList<Test3>();

I fill them with some data, and show them as three tables on some .jspx
Now i change some data on that three tables, and I want to know how can
I programitically check if some data of those 3 tables is changed, before I
save elements of all 3 lists in DB ( if final values of elements in these 3
tables
is different that the first initaial view) . Using some temp lists ?



Thanks in advance.



__________ Information from ESET NOD32 Antivirus, version of virus signature database 4142 (20090609) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 
N

news.t-com.hr

Good idea, but I also want to find out which element has different value, if
all three lists are fixed size.


I think, that you can store hachCode() of every list before saving
data in DB.

I have 3 lists, for example ;
List<Test1> list = new ArrayList<Test1>();
List<Test2> list = new ArrayList<Test2>();
List<Test3> list = new ArrayList<Test3>();

I fill them with some data, and show them as three tables on some .jspx
Now i change some data on that three tables, and I want to know how can
I programitically check if some data of those 3 tables is changed, before
I
save elements of all 3 lists in DB ( if final values of elements in these
3
tables
is different that the first initaial view) . Using some temp lists ?

Thanks in advance.

__________ Information from ESET NOD32 Antivirus, version of virus
signature database 4142 (20090609) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com


__________ Information from ESET NOD32 Antivirus, version of virus signature
database 4143 (20090610) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com





__________ Information from ESET NOD32 Antivirus, version of virus signature database 4143 (20090610) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 
G

GArlington

I think, that you can store hachCode() of every list before saving
data in DB.

AFAIR: hashcode() implementation does NOT have to return unique values
for unequal objects
So, my solution would be to implement equals() method instead...
 
G

GArlington

Good idea, but I also want to find out which element has different value, if
all three lists are fixed size.


I think, that you can store hachCode() of every list before saving
data in DB.








__________ Information from ESET NOD32 Antivirus, version of virus signature
database 4143 (20090610) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

__________ Information from ESET NOD32 Antivirus, version of virus signature database 4143 (20090610) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

Top posting is BAD...

<quote>
.... to find out which element has different value...
</quote>
You will have to compare EACH element in EACH list...
You can implement ArrayList.compareTo() method to return (first)
unequal element position, but it will not be very helpful in your case
if multiple elements may differ...
 
L

Lew

GArlington said:
AFAIR: hashcode() [sic] implementation does NOT have to return unique values
for unequal objects

It doesn't have to, in fact one generally cannot guarantee different
hash codes for unequal objects, but it does have to return the same
hash code for equal objects. So a different hash code necessarily
implies inequality.
So, my solution would be to implement equals() method instead...

List hashCode()s work by examining each element of the List. All the
fields in each element that participate in hashCode() will participate
in equals() for the element type. Therefore hashCode() is unlikely to
provide any performance advantage for List-to-List comparison,
particularly in the OP's use case of needing to know which elements
differ.
 
D

Daniel Pitts

news.t-com.hr said:
I have 3 lists, for example ;
List<Test1> list = new ArrayList<Test1>();
List<Test2> list = new ArrayList<Test2>();
List<Test3> list = new ArrayList<Test3>();

I fill them with some data, and show them as three tables on some .jspx
Now i change some data on that three tables, and I want to know how can
I programitically check if some data of those 3 tables is changed, before I
save elements of all 3 lists in DB ( if final values of elements in these 3
tables
is different that the first initaial view) . Using some temp lists ?


If you keep track of the old values in a temp list, you can simply use
if (!list.equals(oldList)) save(list);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

pattern question ? 14
sql sort problem ? 4
ArrayList grouping? 2
Save xls file as blob to db ? 2
web application load xls file ? 1
How to set a curses library for DOS with djgpp.. 2
Tables question ? 1
math parser ? 12

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top