the problem with implementing an equals and hashCode function for the Product 
object is that it is not always created from db data... many of the objects in 
the structs package are 'fill what I know at the moment'... no guarantee that 
any one member variable in the object will always be set... for instance when a 
Product is created on the client side for an ingest the productId is not set 
until after ingestion... also the current trunk filemgr's Product object 
doesn't have an ingested or received time attach to it... at least the last 
time I checked it didn't... lol... so an equals method which say just checked 
against productId and productName could give a false positive in some cases... 
for example making two sequential calls to getProductById() then calling equals 
(assuming we implemented it) on the 2 Product objects returned would return 
true... but if the Product was updated between the 2 calls, equals really 
should return false because the first Product object is out of date... and 
doing a deep equals on the Product object would make the operation expensive... 
the Product object is more meant to be an information carrier... I would 
recommend storing your Products in a Map<String,Product> where the String key 
is ProductId

-Brian

On Oct 11, 2011, at 4:46 PM, "Starch, Michael D (388L)" 
<[email protected]> wrote:

> Chris et all,
> 
> Do you see any problems overriding the default equals, and hashCode methods 
> in the Product class (checking by memory address/reference) to something that 
> checks to see if the products logically represent the same thing (same id, 
> name, etc)?
> 
> My issue is the following, I receive data back from the database, with 
> multiple lines representing a single product (this is a database thing, and 
> the desired behavior).  Thus if I iterate across the results, I will get 
> multiple Product objects that represent one real Product (and contain 
> equivalent member variables).  In essence they are the same "Product".  I can 
> write cleaner, faster, code to combine the results, if I can test them for 
> equality and hash them directly, without first pulling out the productName, 
> or Id.
> 
> This will be a problem if there is some code that expects two "Products" that 
> have identical member variables to fail the equality test if they are 
> distinct objects.
> 
> Thanks,
> 
> -Michael
> 
> 
> 
> 
> 

Reply via email to