wood burning stoves 2.0
The moose likes Java in General and the fly likes Key Class for Products Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Key Class for Products" Watch "Key Class for Products" New topic

Key Class for Products

Pradeep Shankar

Joined: Apr 23, 2011
Posts: 3
How can I change this class so that it is suitable for use as a key in a collection.

All three fields (serialNumber, productName and price) are required to uniquely identify a product.

Instances of this class will be utilized as key values in a JNDI lookup operation

Thank you for taking the time to read this...
Henry Wong

Joined: Sep 28, 2004
Posts: 20359

By "key", I am assuming you want this in a map.... well, then, the answer is "it depends".

If you want it in a hashing map, then you need to implement the equals() and hashCode() method. And if you want it in a treemap, then you either need to make your instance implement Comparable, or write a Comparator class for it.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 45255
. . . and it ought to be immutable, if you ever want to find it again
Pradeep Shankar

Joined: Apr 23, 2011
Posts: 3
Thanks guys...


This interface should be used to retrieve details regarding an payment. A JNDI lookup will result in a suitable implementation being returned (assume that it is bound to the JNDI_NAME supplied below). The interface has been simplified to exclude and remote method invocation concepts.

Interface for retrieving details of an payment:

So it can be used in the front end app, see:

Bind Class to HttpSession Posting

Would appreciate it if someone could help me.
I agree. Here's the link: http://aspose.com/file-tools
subject: Key Class for Products
It's not a secret anymore!