| | |
Question about indexing objects
![]() |
•
•
Join Date: Nov 2004
Posts: 189
Reputation:
Solved Threads: 0
Hello everyone,
I want to use indexing technology to speed up searching operation of my application. I have found that Java built-in type Hashtable can only have one key for each object. But my requirement is that an object can have multiple keys for an object. For example, the objects may be arranged in the following model,
Object (key1, key2, value)
and the related instances maybe
John ("male", "single", <personal information of John>)
Smith ("male", "married", <personal information of Smith>)
When given key1 (or key2, or key1 and key2 altogether), I want to find out matched objects. For example, when given "male", John and Smith are both matched. When given "single", only John is matched. When given "female" and "single", no records are matched.
Thanks in advance,
George
I want to use indexing technology to speed up searching operation of my application. I have found that Java built-in type Hashtable can only have one key for each object. But my requirement is that an object can have multiple keys for an object. For example, the objects may be arranged in the following model,
Object (key1, key2, value)
and the related instances maybe
John ("male", "single", <personal information of John>)
Smith ("male", "married", <personal information of Smith>)
When given key1 (or key2, or key1 and key2 altogether), I want to find out matched objects. For example, when given "male", John and Smith are both matched. When given "single", only John is matched. When given "female" and "single", no records are matched.
Thanks in advance,
George
•
•
Join Date: Mar 2005
Posts: 53
Reputation:
Solved Threads: 1
•
•
•
•
Originally Posted by George2
Hello everyone,
I want to use indexing technology to speed up searching operation of my application. I have found that Java built-in type Hashtable can only have one key for each object. But my requirement is that an object can have multiple keys for an object. For example, the objects may be arranged in the following model,
Object (key1, key2, value)
and the related instances maybe
John ("male", "single", <personal information of John>)
Smith ("male", "married", <personal information of Smith>)
When given key1 (or key2, or key1 and key2 altogether), I want to find out matched objects. For example, when given "male", John and Smith are both matched. When given "single", only John is matched. When given "female" and "single", no records are matched.
Thanks in advance,
George
cheers,
aj.wh.ca
•
•
Join Date: Nov 2004
Posts: 189
Reputation:
Solved Threads: 0
Thanks aj.wh.ca,
Your ideas are great! I am very interested in the extending HashMap class solution in your reply. Could you provide more information to this solution? Especially how to define "key" class and "equal" function to be flexible to be reusable in other applications.
Another question is, what class of jakarta Collection should I use to meet my requirements? I have studied the document of jakarta Collection but can not find a suitable one. Could you help?
regards,
George
•
•
•
•
Originally Posted by aj.wh.ca
Yeah Java does not provide MultiKey Map kind of a thing. So you are left with 2 choices. Use some third party class (jakarta collections package has what you are looking for) or implement your own. You can do this by extending the HashMap class or simply defining a custom "equals" function for your "key" class instead of using default String class for key.
cheers,
aj.wh.ca
Another question is, what class of jakarta Collection should I use to meet my requirements? I have studied the document of jakarta Collection but can not find a suitable one. Could you help?
regards,
George
•
•
Join Date: Mar 2005
Posts: 53
Reputation:
Solved Threads: 1
•
•
•
•
Originally Posted by George2
Thanks aj.wh.ca,
Your ideas are great! I am very interested in the extending HashMap class solution in your reply. Could you provide more information to this solution? Especially how to define "key" class and "equal" function to be flexible to be reusable in other applications.
Another question is, what class of jakarta Collection should I use to meet my requirements? I have studied the document of jakarta Collection but can not find a suitable one. Could you help?
regards,
George
For the 3rd party API consider following link.
http://jakarta.apache.org/commons/co.../MultiMap.html
A simpler solution would be as I said earlier to make a new class.
e.g.
public class MyKey // you may want to extend an existing class say String
{
String[] keys ;
MyKey(String[] k){....}
public boolean equals(MyKey k){//simply compare the keys here as per your conditions}
}
Now in the hashmap for key,value pair insert object of MyKey and the associated value.
This may not be best in performance but this is clean and simple.
regards,
aj.wh.ca
•
•
Join Date: Nov 2004
Posts: 189
Reputation:
Solved Threads: 0
Thanks aj.wh.ca,
You are too kind and too great!
regards,
George
•
•
•
•
Originally Posted by aj.wh.ca
Thanks George.
For the 3rd party API consider following link.
http://jakarta.apache.org/commons/co.../MultiMap.html
A simpler solution would be as I said earlier to make a new class.
e.g.
public class MyKey // you may want to extend an existing class say String
{
String[] keys ;
MyKey(String[] k){....}
public boolean equals(MyKey k){//simply compare the keys here as per your conditions}
}
Now in the hashmap for key,value pair insert object of MyKey and the associated value.
This may not be best in performance but this is clean and simple.
regards,
aj.wh.ca
regards,
George
![]() |
Similar Threads
- Question about array of objects.... (C++)
- declaring objects within objects from main (C++)
- hijackthis log on a dev computer (Viruses, Spyware and other Nasties)
Other Threads in the Java Forum
- Previous Thread: Best Java Project
- Next Thread: JMenu ...Can't remember
| Thread Tools | Search this Thread |
-xlint add android api applet application array automation bank bi binary blackberry block bluetooth class client code compile compiler component database developmenthelp dice eclipse equation error event fractal functiontesting game gameprogramming givemetehcodez graphics gui health html hyper ide idea image infinite int j2me j2seprojects java javac javame javaprojects jetbrains jni jpanel jtable julia learningresources lego linux mac main map method mobile myregfun netbeans notdisplaying number online openjavafx pearl problem program project qt scanner screen scrollbar server set singleton sms sort sorting spamblocker sql sqlserver storm string superclass swing system textfields thread threads time title tree tutorial-sample update variablebinding windows xor





