Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (736)
Games in Android Showcase (223)
games submitted by our members
Games in WIP (813)
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 1616 times)
0 Members and 1 Guest are viewing this topic.
Offline Fokusas

Senior Devvie

Medals: 3
Projects: 1

« Posted 2011-10-17 18:20:20 »

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

Senior Devvie

Medals: 3
Projects: 1

« 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.

cybrmynd (124 views)
2017-08-02 12:28:51

cybrmynd (147 views)
2017-08-02 12:19:43

cybrmynd (142 views)
2017-08-02 12:18:09

Sralse (158 views)
2017-07-25 17:13:48

Archive (629 views)
2017-04-27 17:45:51

buddyBro (737 views)
2017-04-05 03:38:00

CopyableCougar4 (1266 views)
2017-03-24 15:39:42

theagentd (1246 views)
2017-03-24 15:32:08

Rule (1221 views)
2017-03-19 12:43:22

Rule (1274 views)
2017-03-19 12:42:17
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51 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‑
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!