Question

i've got a question. I'm making a sort of addon for a game and i need to create a data structure for store informations with this organization:
Data
   - Player
     - items
        - item1
        - item2
        - item3
  - logs
    - log1
    - log2
    - log3
  - Buildings
     - monuments
        - monument1
        - monument2
        - monument3
  - cities
     - city1
     - city2
     - city3
[...]

I did a complex hashmap

public Save<HashMap<String,HashMap<String,HashMap<String,List<String>>>>> data;

Where Save is

public class Save<T> {
 public final T object;

 public Save(T object){
     this.object = object;
 }

}

In this hierarchy there will be only strings and it will be loaded at start and saved in intervals of 5 minutes.

My question is if there is a more confortable and manaegable(it is very closed) way to do this Thanks

Pas de solution correcte

Autres conseils

A freeform hierarchy will lead to complex, unreadable, and unmaintainable Java code.

Use OOP. Figure out what your data model really is and what the entities are (e.g., players, monuments, etc.). Then define actual classes for them. Each of them can then be easily serialized - you could even have them serialized into a database with things like Hibernate if you needed.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top