« Return to Thread: Why is FunctionListMap using identity to check values and not equals?
Holger Brands wrote:Phil,
maybe there is a misunderstanding on my side or on your side.
In my opinion, FunctionListMap.put(K key, V value) does the following:
After checking the key-value-agreement it looks into the delegate map
to find the key. If it's not there, it adds the new value to the underlying EventList.
If the key is found, the (old) value is retrieved from the delegate map.
Then it iterates over the underlying EventList to find the *old* value by identity
to replace it with the *new* value. This looks correct to me.
The (new) value that is passed into the put-method is *not* used to compare
anything here.
I think one reason why the old value is searched by identity is,
that it's quite possible to have two equal objects with different keys (according
to the key-maker function).
Hope this helps,
Holger
>
> I have the following situation:
> private final EventList<E> items = GlazedLists.threadSafeList(new
> BasicEventList<E>());
> private final DisposableMap<Key, E> itemsLookup =
> GlazedLists.syncEventListToMap(this.items,
> new FunctionList.Function<E, Key>() {
> public Key evaluate(final E sourceValue) {
> return getKey(sourceValue);
> }
> });
>
> I get updates from an external database that say which object (by key) has
> changed or was removed.
> The removal using the itemsLookup works. However the put() method uses an
> Identity compare to find the item to be replaced. This is of course not
> working, since I am loading a new Object (different identity but same key)
> from the database every time. The object with the same Key should be
> replaced by using the equals method. How could I achieve that?
>
> So when an Update comes in I do an
> itemsLookup.put(key, database.load(key)) which naturally throws an exception
> because the new Object is not found in the base list.
>
> Thanks,
> Phil
> --
> View this message in context: http://www.nabble.com/Why-is-FunctionListMap-using-identity-to-check-values-and-not-equals--tp24066192p24066192.html
> Sent from the GlazedLists - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glazedlists.dev.java.net
> For additional commands, e-mail: users-help@glazedlists.dev.java.net
>
>
___________________________________________________________________
WEB.DE FreeDSL Komplettanschluss mit DSL 6.000 Flatrate und
Telefonanschluss für 17,95 Euro/mtl.! http://produkte.web.de/go/02/
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glazedlists.dev.java.net
For additional commands, e-mail: users-help@glazedlists.dev.java.net
« Return to Thread: Why is FunctionListMap using identity to check values and not equals?
| Free embeddable forum powered by Nabble | Forum Help |