Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (517)
Games in Android Showcase (123)
games submitted by our members
Games in WIP (578)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Question about collections  (Read 963 times)
0 Members and 1 Guest are viewing this topic.
Offline Fokusas
« Posted 2011-10-17 18:20:20 »

Hello,
I am creating simple (for now Cheesy) game (for learning purpose) and would like to ask you for advise.
I would like to ask you which collection type should i use.
I have LinkedList named Isradimai (Inventions) which contains all Isradimas (Invention) type objects. (For now it only contains 20 but later it could contain 100-400 objects). Also there is another LinkedList named Ismintis (Wisdom) which contains only discovered inventions (Isradimas objects). And there also is 2 more LinkedLists named galimiIsradimai (available inventions) and galimiDarbai(available jobs). GalimiIsradimai contains only new discoverable Isradimas object and are show to player to pick new invention. GalimiIsradimai are populated by cloning Isradimai and then removing all that are contained in Ismintis. Then i iterate over it and examine each object to see if it fits needed requirements. If it fails it is removed. Each time player "invents" new invention i clear and repopulate galimiIsradimai and player have a new list of possible inventions it also clears and repopulates galimiDarbai.  
GalimiDarbai contains all available actions for player. Sometimes inventing new inventions unlocks new actions for player to perform.That list is populated by iterating over Ismintis "and" Darbai (HashMap). If Isradimas object (contained in Ismintis) unlocks new action i look in HashMap and put received Darbas object in galimiDarbai.
Everything works very well. But one day i got idea that it could be better to replace all LinkedList to HashMap. So what do you think?
If you see some flaws in my design please post them too

Thanks in advance.
P.S. Sorry if i made some mistakes
Offline aazimon
« Reply #1 - Posted 2011-10-17 18:35:41 »

I don't see any flaws. The main advantage of a HashMap to a LinkedList, is that you can retrieve the object faster when you have the key. I would make the Isradimai a HashMap for faster retrieval.
For the Discoverable list, I would create a HashMap, the key being the discovering event (a level or whatever), and the value to be a list of Isradimai keys.
Offline sproingie

JGO Kernel


Medals: 202



« Reply #2 - Posted 2011-10-17 20:13:20 »

Your choice should really be down to HashMap or ArrayList.  Other Map implementations are for specialty purposes, and there is hardly any circumstance whatsoever where LinkedList is a better option than ArrayList; LinkedList  even fails for functional data structures, since it isn't recursively defined.

Edit: naturally, the choice between HashMap and ArrayList wouldn't be down to which performs better, but which operations you actually need.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Fokusas
« Reply #3 - Posted 2011-10-19 05:53:22 »

Thanks for your answers.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

DarkCart (18 views)
2014-10-31 21:44:48

DarkCart (23 views)
2014-10-31 21:43:57

TehJavaDev (40 views)
2014-10-27 03:28:38

TehJavaDev (31 views)
2014-10-27 03:27:51

DarkCart (45 views)
2014-10-26 19:37:11

Luminem (27 views)
2014-10-26 10:17:50

Luminem (31 views)
2014-10-26 10:14:04

theagentd (36 views)
2014-10-25 15:46:29

Longarmx (64 views)
2014-10-17 03:59:02

Norakomi (62 views)
2014-10-16 15:22:06
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!