Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Key Class for Products

 
Pradeep Shankar
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author
Marshal
Pie
Posts: 20835
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.

Henry
 
Campbell Ritchie
Sheriff
Pie
Posts: 47270
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . and it ought to be immutable, if you ever want to find it again
 
Pradeep Shankar
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys...

Requirements:

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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic