Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java Programmer > Set and .equals...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 33 Topic 52590 of 55345
Post > Topic >>

Set and .equals() semantics

by Rex Mottram <rexm@[EMAIL PROTECTED] > May 8, 2008 at 12:00 PM

I must be missing something involving the lack of a 'get' method for Sets.

Briefly, my app maintains a Collection of unique Foo() objects derived 
by reading and parsing an InputStream. The objects being stored have an
equals() method which compares the im****tant attributes. So far, very 
basic and simple.

It seemed to me the obvious type for holding this collection of
unique objects was a Set, so that's how I did it. The input-reading 
method grabs a line of input, parses it, and creates a "Foo foo = new 
Foo()". If an equivalent instance (as determined by equals()) is already 
present in the set, I want to let the new one go out of scope. If not 
already present, I want to add it. Still, simple and basic.

Here's where things go sideways: I also need to store a reference to 
'foo' in another new object. If this is the first time I've seen it, 
everything is fine because I already have the reference and can add it 
to both places, e.g.

	fooSet.add(foo);
	bar.addFoo(foo);

But if it was already present in the Set, I'm left holding a reference 
to the "tem****ary" copy which is about to go out of scope. I know 
there's an identical copy already in the Set but there's no way to 
retrieve it in order to add it to the Bar object.

I've switched over to using

	Map<Foo, Foo>

which can both look up and retrieve a reference. But I hope I'm 
misunderstanding something which would allow me to use the more natural 
Set design.

Thanks,
RM
 




 33 Posts in Topic:
Set and .equals() semantics
Rex Mottram <rexm@[EMA  2008-05-08 12:00:52 
Re: Set and .equals() semantics
Lasse Reichstein Nielsen   2008-05-08 18:12:15 
Re: Set and .equals() semantics
Rex Mottram <rexm@[EMA  2008-05-08 12:42:29 
Re: Set and .equals() semantics
Tom Anderson <twic@[EM  2008-05-08 18:39:13 
Re: Set and .equals() semantics
"Mike Schilling&quo  2008-05-08 10:44:14 
Re: Set and .equals() semantics
Mark Space <markspace@  2008-05-08 13:08:16 
Re: Set and .equals() semantics
"Mike Schilling&quo  2008-05-08 15:56:22 
Re: Set and .equals() semantics
Rex Mottram <rexm@[EMA  2008-05-08 19:04:16 
Re: Set and .equals() semantics
"Mike Schilling&quo  2008-05-08 16:52:33 
Re: Set and .equals() semantics
Mark Space <markspace@  2008-05-08 17:30:03 
Re: Set and .equals() semantics
Lew <lew@[EMAIL PROTEC  2008-05-09 01:32:32 
Re: Set and .equals() semantics
Lasse Reichstein Nielsen   2008-05-09 07:15:36 
Re: Set and .equals() semantics
Lew <lew@[EMAIL PROTEC  2008-05-09 01:39:23 
Re: Set and .equals() semantics
Rex Mottram <rexm@[EMA  2008-05-09 06:33:17 
Re: Set and .equals() semantics
Patricia Shanahan <pat  2008-05-09 06:24:35 
Re: Set and .equals() semantics
Lasse Reichstein Nielsen   2008-05-09 22:17:10 
Re: Set and .equals() semantics
Lew <lew@[EMAIL PROTEC  2008-05-09 20:41:20 
Re: Set and .equals() semantics
Tom Anderson <twic@[EM  2008-05-09 01:15:42 
Re: Set and .equals() semantics
"Mike Schilling&quo  2008-05-08 17:58:34 
Re: Set and .equals() semantics
Mark Space <markspace@  2008-05-08 18:44:07 
Re: Set and .equals() semantics
Rex Mottram <rexm@[EMA  2008-05-08 22:04:54 
Re: Set and .equals() semantics
Jaakko Kangasharju <jk  2008-05-09 10:22:12 
Re: Set and .equals() semantics
Patricia Shanahan <pat  2008-05-09 07:41:57 
Re: Set and .equals() semantics
Mark Space <markspace@  2008-05-09 16:53:49 
Re: Set and .equals() semantics
Tom Anderson <twic@[EM  2008-05-09 11:07:51 
Re: Set and .equals() semantics
Lew <lew@[EMAIL PROTEC  2008-05-09 09:34:20 
Re: Set and .equals() semantics
Rex Mottram <rexm@[EMA  2008-05-09 10:07:23 
Re: Set and .equals() semantics
Patricia Shanahan <pat  2008-05-09 08:12:26 
Re: Set and .equals() semantics
RedGrittyBrick <RedGri  2008-05-09 17:04:45 
Re: Set and .equals() semantics
Jaakko Kangasharju <jk  2008-05-09 19:38:26 
Re: Set and .equals() semantics
Tom Anderson <twic@[EM  2008-05-09 18:21:42 
Re: Set and .equals() semantics
Lew <lew@[EMAIL PROTEC  2008-05-09 20:55:03 
Re: Set and .equals() semantics
Tom Anderson <twic@[EM  2008-05-09 18:24:56 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Nov 21 14:08:54 CST 2008.