?that allows me to 'record' an object
~ Mansukh
Campbell Ritchie wrote:That might not work if you have overridden the equals method. It depends whether two objects returning true from equals count as the same object or not.
~ Mansukh
There are three kinds of actuaries: those who can count, and those who can't.
Campbell Ritchie wrote:What is wrong with the suggestion of a set earlier?
Bartholomew Benson wrote:Well, I wrote that post after reading the first post, and not any of the following posts. Now that I have, I now see that a HashSet is probably a good choice. Oops. Thanks!
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Happens all the time. Just one of those things.Bartholomew Benson wrote: . . . Well, I wrote that post after reading the first post, and not any of the following posts. . . .
Winston Gutkowski wrote:
Bartholomew Benson wrote:Well, I wrote that post after reading the first post, and not any of the following posts. Now that I have, I now see that a HashSet is probably a good choice. Oops. Thanks!
OK, but my question to you is: What type should that HashSet be? I doubt if HashSet<FieldObject> is going to help you much, since what you want to know is if the Robot has seen another FieldObject of the same type.
One thing that might be worth considering is a public Type enum inside your FieldObject class (Google for 'nested') that every FieldObject instance is initialized with.
Your "memory" could then simply be an EnumSet or EnumMap - which is probably even quicker (and much more compact) than a HashSet. You could even set up different 'targets' for each type, allowing the Robot to pick up say 1 of this type, and 3 of another.
HIH
Winston
Why am I so drawn to cherry pie? I can't seem to stop. Save me tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|