File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change
1
+ {"students" : {
2
+ "Alex" : 96 ,
3
+ "Simon" : 99 ,
4
+ "Sofia" : 89
5
+ }}
Original file line number Diff line number Diff line change @@ -35,6 +35,42 @@ storage.put("theme", "dark");
35
35
36
36
#### Note: DataStorage.getStorage() ** auto-constructs** the path if it doesn't already exist
37
37
38
+ ### Querying nested data
39
+ DataStorage also allows you to directly access nested objects without needing to use a builder
40
+ form or caching multiple objects.
41
+
42
+ To do so, you just need to call ` DataStorage.query() ` that requires the ordered arrangement of the hierarchy.
43
+
44
+ Example:
45
+ ``` java
46
+
47
+ public class Preferences {
48
+ public static void save (){
49
+ HashMap<String , Integer > map = new HashMap<> ();
50
+ map. put(" Simon" , 99 );
51
+ map. put(" Alex" , 96 );
52
+ map. put(" Sofia" , 89 );
53
+
54
+ DataStorage storage = DataStorage . getStorage(" .config" , " settings.json" );
55
+ storage. put(" students" , map); // Auto-Save
56
+
57
+ System . out. println(storage. query(" students" , " Simon" ));
58
+ // Displays 99
59
+
60
+
61
+ DataStorage storage2 = DataStorage . getStorage(" .config" , " settings.json" );
62
+ storage2. put(" teachers" , 18 ); // Auto-Save
63
+ // storage2 is the same storage object with no object redundancy π
64
+
65
+ }
66
+
67
+ public static void main (String [] args ) {
68
+ save();
69
+ }
70
+ }
71
+
72
+ ```
73
+
38
74
# ![ ] ( https://img.icons8.com/3d-fluency/48/null/smartphone-tablet.png ) Handling Multiple References
39
75
40
76
Now, if there are multiple cases requesting the reference to the same DataStorage object, so instead of
You canβt perform that action at this time.
0 commit comments