Forums Register Login

Iterating through objects?

+Pie Number of slices to send: Send
Hello! I am new to these forums and the Java programming language. Basically, I am trying to create a new object of class Arenas with several variables of different types. This is for a Minecraft plugin for a server (irrelevant), and basically on command /join (arenaName) the code checks to make sure that the arenaName has been defined in config and then is supposed to iterate through all objects of Arenas and check which one has that arenaName. If one doesn't exist, it creates an object and defines the String arenaName to that name. If there isn't a way to do this, could you maybe come up with a better idea on how to organize this? The problem I'm facing is that the number of arenas and name of the arenas is definable by config, so I cannot just name a bunch of objects, because I don't know how many there need to be.





+Pie Number of slices to send: Send
You should (at least) have two classes here, one for Arena, which has a name, and another Arenas to manage a collection of objects of type Arena.
+Pie Number of slices to send: Send
 

Carey Brown wrote:You should (at least) have two classes here, one for Arena, which has a name, and another Arenas to manage a collection of objects of type Arena.



Can you go a bit into more detail. I'm really confused on this, sorry .

Should I make like a map with the arenaName or what am I supposed to do? I understand making hashmaps, and lists, but I don't really get what you're trying to say, or at least how this would solve my problem.
1
+Pie Number of slices to send: Send
Well, you've got "Arenas", plural, where it should be "Arena", singular. Then, sure use a HashMap if you're familiar with that and manage the map outside of the Arena class.
+Pie Number of slices to send: Send
 

Carey Brown wrote:Well, you've got "Arenas", plural, where it should be "Arena", singular. Then, sure use a HashMap if you're familiar with that and manage the map outside of the Arena class.



Like this?



Sorry that I've asked so many questions xD
1
+Pie Number of slices to send: Send
 

John Boland wrote:

Carey Brown wrote:Well, you've got "Arenas", plural, where it should be "Arena", singular. Then, sure use a HashMap if you're familiar with that and manage the map outside of the Arena class.



Like this?



Sorry that I've asked so many questions xD



Exactly.
+Pie Number of slices to send: Send
Welcome to the Ranch

You are not asking too many questions. We are more likely to find people asking too few questions or telling us too little and we have to prise the whole story out of them
Sometimes you feel like a nut. Sometimes you feel like a tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 368 times.
Similar Threads
NullPointerException I dont understand how to fix, Been working on it for 6 hours now
How to iterate thru TreeMap using interator in struts2
Helper classes-Design question
Removing entries from a collection
Use Reflection to "find" classes
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 11:14:45.