aspose file tools*
The moose likes Beginning Java and the fly likes Pattern to storage different objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Pattern to storage different objects" Watch "Pattern to storage different objects" New topic
Author

Pattern to storage different objects

Alex Boole
Greenhorn

Joined: Aug 20, 2011
Posts: 1
iam searching for a pattern that deals with following problem.

- there is limited number of storage locations, each storage location is able to save only one or no object.
- a specific object (lets say object a) can be stored multiple times in different storage locations (for example storage location 1,3 and 8 are all pointing to the object a, location 2 is empty and location 4,5 are pointing to object b....)
- the number of objects is variable

and these operations should be done very fast:
- i want to know which storage locations are pointing to object a? the result should be an array with the storage location numbers (in this example object a -> [1,3,8])
- an array of storage locations is given and as a result i want an array of objects that are pointed to (example [1,2,4] -> [object a, object b]

any ideas?
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3825

Welcome to CodeRanch, Alex Boole!

I think you are looking for some data structures/algorithms to support your requirement?
there is limited number of storage locations, each storage location is able to save only one or no object. ... the number of objects is variable

I'm not sure what this "storage location" mean here. I think it's the data structure you are talking about? There are many data structures you can use. If you take an array (which can hold references to objects but the length is fixed) or Collection item like a List which can hold any number references and many more are available. Is there any functionality you expect from this "storage location" concept? Is there a MAX amount of objects which the program can assume at the beginning?

i want to know which storage locations are pointing to object a? the result should be an array with the storage location numbers (in this example object a -> [1,3,8])
- an array of storage locations is given and as a result i want an array of objects that are pointed to (example [1,2,4] -> [object a, object b]

These can be achieved by algorithms/methods that you need to be used/called on the data structure you defined earlier. First you have to decide what data structure will be used and for that the real problem need to be identified properly.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38363
    
  23
You cannot put two different objects, nor references to two different objects, into the same memory location.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Pattern to storage different objects