@@ -23,27 +23,18 @@ public class DataPackage implements Serializable {
23
23
public String uuid = UUID .randomUUID ().toString ();
24
24
25
25
public String getItem (long itemID ) {
26
- for (Map .Entry <String , Game > game : games .entrySet ()) {
27
- for (Map .Entry <String , Long > item : game .getValue ().itemNameToId .entrySet ()) {
28
- if (item .getValue () == itemID )
29
- return item .getKey ();
30
- }
26
+ if (!itemIdToName .containsKey (itemID )) {
27
+ return String .format ("Unknown Item [%d]" , itemID );
31
28
}
32
- return String .format ("Unknown Item [%d]" , itemID );
29
+
30
+ return itemIdToName .get (itemID );
33
31
}
34
32
35
33
public String getLocation (long locationID ) {
36
- if (locationIdToName .containsKey (locationID ))
37
- return locationIdToName .get (locationID );
38
- for (Map .Entry <String , Game > game : games .entrySet ()) {
39
- for (Map .Entry <String , Long > location : game .getValue ().locationNameToId .entrySet ()) {
40
- if (location .getValue () == locationID ) {
41
- locationIdToName .put (locationID , location .getKey ());
42
- return location .getKey ();
43
- }
44
- }
45
- }
46
- return String .format ("Unknown Location [%d]" , locationID );
34
+ if (!locationIdToName .containsKey (locationID ))
35
+ return String .format ("Unknown Location [%d]" , locationID );
36
+
37
+ return locationIdToName .get (locationID );
47
38
}
48
39
49
40
public Map <String , Integer > getVersions () {
@@ -57,13 +48,6 @@ public HashMap<String, Game> getGames() {
57
48
}
58
49
59
50
public HashMap <Long , String > getItems () {
60
- if (itemIdToName .isEmpty ()) {
61
- for (Map .Entry <String , Game > gameEntry : games .entrySet ()) {
62
- for (Map .Entry <String , Long > items : gameEntry .getValue ().itemNameToId .entrySet ()) {
63
- itemIdToName .put (items .getValue (), items .getKey ());
64
- }
65
- }
66
- }
67
51
return itemIdToName ;
68
52
}
69
53
@@ -79,14 +63,7 @@ public HashMap<Long, String> getItemsForGame(String game) {
79
63
}
80
64
81
65
public HashMap <Long , String > getLocations () {
82
- if (locationIdToName .isEmpty ()) {
83
- for (Map .Entry <String , Game > gameEntry : games .entrySet ()) {
84
- for (Map .Entry <String , Long > locations : gameEntry .getValue ().locationNameToId .entrySet ()) {
85
- itemIdToName .put (locations .getValue (), locations .getKey ());
86
- }
87
- }
88
- }
89
- return itemIdToName ;
66
+ return locationIdToName ;
90
67
}
91
68
92
69
public HashMap <Long , String > getLocationsForGame (String game ) {
@@ -110,6 +87,26 @@ public String getUUID() {
110
87
111
88
public void update (DataPackage newData ) {
112
89
games .putAll (newData .getGames ());
90
+ buildItemsMap ();
91
+ buildLocationsMap ();
113
92
version = newData .version ;
114
93
}
94
+
95
+ private void buildItemsMap () {
96
+ for (Map .Entry <String , Game > gameEntry : games .entrySet ()) {
97
+ for (Map .Entry <String , Long > items : gameEntry .getValue ().itemNameToId .entrySet ()) {
98
+ itemIdToName .put (items .getValue (), items .getKey ());
99
+ }
100
+ }
101
+ }
102
+
103
+ private void buildLocationsMap () {
104
+ locationIdToName .clear ();
105
+
106
+ for (Map .Entry <String , Game > gameEntry : games .entrySet ()) {
107
+ for (Map .Entry <String , Long > locations : gameEntry .getValue ().locationNameToId .entrySet ()) {
108
+ locationIdToName .put (locations .getValue (), locations .getKey ());
109
+ }
110
+ }
111
+ }
115
112
}
0 commit comments