Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Pattern to storage different objects

 
Alex Boole
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3914
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49733
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot put two different objects, nor references to two different objects, into the same memory location.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic