Using List Interface
All i am trying to understand how to check elements are valid on a list interface. I have the following setup using the glazedlists API which uses BasicEventList which is like the standard java.util.list
Now i have setup my getters and settings and i have setup the list object
final EventList trades = new BasicEventList();
So when i add my elements onto the list i do
trades.add(new Tradeslist(clordid,acc,sym,odtype,odprice,odside,odtradid,odstat,oddate));
And what i want to be able to do is say, first check the list does not have the entry that contains clordid in it, if it does not add it, if it does then i want to set some params on that list entry.
So i setup an Iterator
Iterator myIterator = trades.iterator();
while(myIterator.hasNext()){
Object item = myIterator.next();
System.out.println("Sys = "+item.hashCode());
}
But what i don't understand is that with this Iterator i get back the objects value in memory and i want to say okay does this object contain a value that looks like clordid if so then the list contains the clordid already and update it. But how do i go about that.
Cast to a Tradeslist, then use the methods in that.Please use code tags. http://forum.java.sun.com/help.jspa?sec=formatting
mlka at 2007-7-14 17:49:12 >

Cast to ? Do you have a snipit of code ?
> Cast to ? Do you have a snipit of code ?
Iterator myIterator = trades.iterator();
while(myIterator.hasNext()){
Tradeslist item = (Tradeslist)myIterator.next();
System.out.println("Sys = "+item.hashCode());
}
If you need examples showing Casting, then maybe should you read some of the below:
[url=http://java.sun.com/docs/books/tutorial/ ]Sun's basic Java tutorial[/url]
[url=http://java.sun.com/learning/new2java/index.html ]Sun's New To Java Center[/url]. Includes an overview of what Java is, instructions for setting up Java, an intro to programming (that includes links to the above tutorial or to parts of it), quizzes, a list of resources, and info on certification and courses.
[url=http://javaalmanac.com ]http://javaalmanac.com [/url]. A couple dozen code examples that supplement [url=http://www.amazon.com/exec/obidos/tg/detail/-/0201752808?v=glance ]The Java Developers Almanac[/url].
[url=http://www.jguru.com ]jGuru[/url]. A general Java resource site. Includes FAQs, forums, courses, more.
[url=http://www.javaranch.com ]JavaRanch[/url]. To quote the tagline on their homepage: "a friendly place for Java greenhorns." FAQs, forums (moderated, I believe), sample code, all kinds of goodies for newbies. From what I've heard, they live up to the "friendly" claim.
Bruce Eckel's [url=http://mindview.net/Books/DownloadSites ]Thinking in Java[/url] (Available online.)
Joshua Bloch's [url=http://www.amazon.co.uk/exec/obidos/Author=Bloch,%20Josh ]Effective Java[/url]
Bert Bates and Kathy Sierra's [url=http://www.amazon.com/exec/obidos/tg/detail/-/0596004656?v=glance ]Head First Java[/url].
James Gosling's [url=http://www.bookpool.com/sm/0321349806 ]The Java Programming Language[/url]. Gosling is
the creator of Java. It doesn't get much more authoratative than this.
Message was edited by:
mlk
mlka at 2007-7-14 17:49:12 >

To prevent future questions:No, casting does not convert any objects to anything. It just changes the type of a reference.
I have looked at some of those and they talk abotu finding elments in sorted lists but these are all arrays, and i know that you can do searchs on them for elements but what i have above is a hashref which references what ?
Is there not a simple way to just say trades.contains("value i am looking for");
would that not be the simple way ?
> Is there not a simple way to just say> trades.contains("value i am looking for");> Did I not show you how to do this in your other thread?
If EventList implements List, then it HAS a contains method.
But I though you were looking for something in one of the Tradeslist in the EventList.
If so EventList can not know about what is inside it. You will have to then call contains (assuming Tradeslist is also a java.util.List) on each of the elements with the EventList.
mlka at 2007-7-14 17:49:12 >

Well what i am trying to look for is, when i get these events in that are passed in from a ResultsSet query i want to check the list to make sure they are
not on the list before trying to add them, that way i stop duplicates
i am not sure from what i have seen how to implement the indexof to find a certain value i know each element passed from from the Iterator is a ref to the value on the list, but how do i take that iterator ref and then lookup then value in the list and say okay so
iteratorref = valueinlist
> not on the list before trying to add them, that way i> stop duplicatesUse a java.util.Set. A Set dows not allow duplicates.
Wicked i shall have a look at set. What about if i have an entry in the list which i need to update which is what my orig post was about how do i go about finding and updating the entry.
> Wicked i shall have a look at set. What about if i> have an entry in the list which i need to update> which is what my orig post was about how do i go> about finding and updating the entry.Did you not read my last response in your other thread?
Yes but i did not understand it, hence posting again..... No worries i shall do some searching on the web.
> Yes but i did not understand it, hence posting> again..... No worries i shall do some searching on> the web.Next time please post "I don't understand it", rather than spawning a new thread.
mlka at 2007-7-14 17:49:12 >

> Yes but i did not understand it, hence posting> again..... http://java.sun.com/docs/books/tutorial/collections/index.html