For Programmers: Free Programming Magazines  


Home > Archive > Cobol > March 2006 > Re: Java compatibility issues (WAS: MF having issues?)









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Java compatibility issues (WAS: MF having issues?)
Oliver Wong

2006-03-09, 6:55 pm


"James J. Gavan" <jgavandeletethis@shaw.ca> wrote in message
news:uJNPf.128728$B94.114109@pd7tw3no...
>
> Can't have a duplicate Key in a collection anymore than you can have a
> duplicate key in a COBOL file. Try to add an element creating a duplicate
> key - it just gets ignored. I can have :
>
> Key---> then Data
> -----------------
> 12345 Micro Focus Ltd
> 12347 Micro Focus Ltd
>
> but I can't have :
>
> Micro Focus Ltd 12345
> Micro Focus Ltd 12347
>
> Wasn't too clear about your reference to Pairs - but the following example
> from Adele Goldberg (Smalltalk 80) is allowable to find 'Opposites' from
> the Key :-
>
> Key---> then Data
> -----------------
> hot cold
> push pull
> stop go
> come go
> front back
> top bottom
>
> I think 'Pairs' you are possibly referring to something slightly different
> ?


Yes, I meant something different.

In Java as well, you can't have a dictionary (though it's called a "Map"
in Java) where two objects have the same key. I was saying you could "fake"
it by having a "Pair" object whose sole purpose is to contain references to
the two objects you *do* want to store.

Key --> Data
123 (Hot, Cold)
124 (push, pull)
125 (stop, go)
etc.

The idea is that only one object, the "pair" object, is associate with a
given key. But the pair object is like a collection whose size is guaranteed
to always be 2. Obviously, you can extend this idea if you wanted to
simulate 3 objects per key:

Key --> Data
123 (Hot, Warm, Cold)
124 (push, rest, pull)
125 (red, green, blue)
etc.

- Oliver

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com