78 if (storageManager ==
null) {
79 System.out.println(
"StorageManager not initialized");
85 List<String> storageList = storageManager.getStorageList();
86 System.out.println(
"Existing storages: " + storageList);
91 KeyValueStorage testStorage = storageManager.getStorage(
"test_storage");
92 System.out.println(
"Created test storage");
96 storageManager.getStorage(
"another_storage");
97 List<String> updatedList = storageManager.getStorageList();
98 System.out.println(
"Updated storage list: " + updatedList);
102 storageManager.removeStorage(
"test_storage");
103 System.out.println(
"Removed test storage");
106 List<String> finalList = storageManager.getStorageList();
107 System.out.println(
"Final storage list: " + finalList);
114 if (userStorage ==
null) {
115 System.out.println(
"User storage not initialized");
119 System.out.println(
"\n=== KeyValueStorage Methods Demonstration ===");
123 userStorage.putString(
"user_name",
"John Doe");
124 userStorage.putString(
"user_email",
"john.doe@example.com");
125 System.out.println(
"Stored string values");
130 userStorage.putInt(
"user_age", 25);
131 userStorage.putInt(
"login_count", 42);
132 System.out.println(
"Stored integer values");
137 userStorage.putLong(
"registration_timestamp", 1640995200000L);
138 userStorage.putLong(
"last_login_timestamp", System.currentTimeMillis());
139 System.out.println(
"Stored long values");
144 userStorage.putBool(
"is_premium",
true);
145 userStorage.putBool(
"notifications_enabled",
false);
146 System.out.println(
"Stored boolean values");
151 userStorage.putFloat(
"user_rating", 4.5f);
152 userStorage.putFloat(
"temperature", 23.5f);
153 System.out.println(
"Stored float values");
158 userStorage.putDouble(
"user_location_lat", 55.7558);
159 userStorage.putDouble(
"user_location_lng", 37.6176);
160 System.out.println(
"Stored double values");
165 boolean hasUserName = userStorage.contains(
"user_name");
166 boolean hasNonExistent = userStorage.contains(
"non_existent_key");
167 System.out.println(
"Contains 'user_name': " + hasUserName);
168 System.out.println(
"Contains 'non_existent_key': " + hasNonExistent);
173 List<String> allKeys = userStorage.getKeys();
174 System.out.println(
"All stored keys: " + allKeys);
179 String userName = userStorage.getString(
"user_name",
"Unknown");
180 String userEmail = userStorage.getString(
"user_email",
"");
181 String nonExistent = userStorage.getString(
"non_existent_key",
"default_value");
182 System.out.println(
"User name: " + userName);
183 System.out.println(
"User email: " + userEmail);
184 System.out.println(
"Non-existent key: " + nonExistent);
189 int userAge = userStorage.getInt(
"user_age", 0);
190 int loginCount = userStorage.getInt(
"login_count", 0);
191 int nonExistentInt = userStorage.getInt(
"non_existent_int", -1);
192 System.out.println(
"User age: " + userAge);
193 System.out.println(
"Login count: " + loginCount);
194 System.out.println(
"Non-existent int: " + nonExistentInt);
199 long regTimestamp = userStorage.getLong(
"registration_timestamp", 0);
200 long lastLogin = userStorage.getLong(
"last_login_timestamp", 0);
201 long nonExistentLong = userStorage.getLong(
"non_existent_long", -1);
202 System.out.println(
"Registration timestamp: " + regTimestamp);
203 System.out.println(
"Last login timestamp: " + lastLogin);
204 System.out.println(
"Non-existent long: " + nonExistentLong);
209 boolean isPremium = userStorage.getBool(
"is_premium",
false);
210 boolean notificationsEnabled = userStorage.getBool(
"notifications_enabled",
true);
211 boolean nonExistentBool = userStorage.getBool(
"non_existent_bool",
false);
212 System.out.println(
"Is premium: " + isPremium);
213 System.out.println(
"Notifications enabled: " + notificationsEnabled);
214 System.out.println(
"Non-existent bool: " + nonExistentBool);
219 float userRating = userStorage.getFloat(
"user_rating", 0.0f);
220 float temperature = userStorage.getFloat(
"temperature", 0.0f);
221 float nonExistentFloat = userStorage.getFloat(
"non_existent_float", -1.0f);
222 System.out.println(
"User rating: " + userRating);
223 System.out.println(
"Temperature: " + temperature);
224 System.out.println(
"Non-existent float: " + nonExistentFloat);
229 double userLat = userStorage.getDouble(
"user_location_lat", 0.0);
230 double userLng = userStorage.getDouble(
"user_location_lng", 0.0);
231 double nonExistentDouble = userStorage.getDouble(
"non_existent_double", -1.0);
232 System.out.println(
"User location lat: " + userLat);
233 System.out.println(
"User location lng: " + userLng);
234 System.out.println(
"Non-existent double: " + nonExistentDouble);
239 userStorage.remove(
"user_age");
240 userStorage.remove(
"non_existent_key");
241 System.out.println(
"Removed 'user_age' key");
245 boolean stillHasAge = userStorage.contains(
"user_age");
246 System.out.println(
"Still contains 'user_age': " + stillHasAge);
251 System.out.println(
"Cleared all data from user storage");
255 List<String> keysAfterClear = userStorage.getKeys();
256 System.out.println(
"Keys after clear: " + keysAfterClear);
349 if (storageManager ==
null) {
350 System.out.println(
"StorageManager not initialized");
354 System.out.println(
"\n=== Storage Analytics ===");
357 List<String> allStorages = storageManager.getStorageList();
358 System.out.println(
"Total storages: " + allStorages.size());
360 for (String storageName : allStorages) {
361 KeyValueStorage storage = storageManager.getStorage(storageName);
362 List<String> keys = storage.getKeys();
363 System.out.println(
"Storage '" + storageName +
"' contains " + keys.size() +
" items");
373 for (String key : keys) {
375 String stringValue = storage.getString(key,
"");
376 if (!stringValue.isEmpty()) {
381 int intValue = storage.getInt(key, -999999);
382 if (intValue != -999999) {
387 long longValue = storage.getLong(key, -999999);
388 if (longValue != -999999) {
393 boolean boolValue = storage.getBool(key,
false);
394 if (storage.contains(key)) {
399 float floatValue = storage.getFloat(key, -999999.0f);
400 if (floatValue != -999999.0f) {
405 double doubleValue = storage.getDouble(key, -999999.0);
406 if (doubleValue != -999999.0) {
411 System.out.println(
" - Strings: " + stringCount);
412 System.out.println(
" - Integers: " + intCount);
413 System.out.println(
" - Longs: " + longCount);
414 System.out.println(
" - Booleans: " + boolCount);
415 System.out.println(
" - Floats: " + floatCount);
416 System.out.println(
" - Doubles: " + doubleCount);
424 if (storageManager ==
null) {
425 System.out.println(
"StorageManager not initialized");
429 System.out.println(
"\n=== Data Migration Demonstration ===");
432 KeyValueStorage oldStorage = storageManager.getStorage(
"old_storage");
433 KeyValueStorage newStorage = storageManager.getStorage(
"new_storage");
436 oldStorage.putString(
"name",
"John Doe");
437 oldStorage.putInt(
"age", 25);
438 oldStorage.putBool(
"is_premium",
true);
439 oldStorage.putDouble(
"rating", 4.5);
441 System.out.println(
"Old storage before migration:");
442 demonstrateStorageData(oldStorage);
445 List<String> keys = oldStorage.getKeys();
446 for (String key : keys) {
448 String stringValue = oldStorage.getString(key,
"");
449 if (!stringValue.isEmpty()) {
450 newStorage.putString(key, stringValue);
455 int intValue = oldStorage.getInt(key, -999999);
456 if (intValue != -999999) {
457 newStorage.putInt(key, intValue);
462 long longValue = oldStorage.getLong(key, -999999);
463 if (longValue != -999999) {
464 newStorage.putLong(key, longValue);
469 boolean boolValue = oldStorage.getBool(key,
false);
470 if (oldStorage.contains(key)) {
471 newStorage.putBool(key, boolValue);
476 float floatValue = oldStorage.getFloat(key, -999999.0f);
477 if (floatValue != -999999.0f) {
478 newStorage.putFloat(key, floatValue);
483 double doubleValue = oldStorage.getDouble(key, -999999.0);
484 if (doubleValue != -999999.0) {
485 newStorage.putDouble(key, doubleValue);
489 System.out.println(
"\nNew storage after migration:");
490 demonstrateStorageData(newStorage);
493 storageManager.removeStorage(
"old_storage");
494 System.out.println(
"\nRemoved old storage");
497 List<String> finalStorages = storageManager.getStorageList();
498 System.out.println(
"Final storage list: " + finalStorages);
505 if (storageManager ==
null) {
506 System.out.println(
"StorageManager not initialized");
510 System.out.println(
"\n=== Storage Cleanup Demonstration ===");
513 storageManager.getStorage(
"temp_cache_1");
514 storageManager.getStorage(
"temp_cache_2");
515 storageManager.getStorage(
"permanent_storage");
517 List<String> beforeCleanup = storageManager.getStorageList();
518 System.out.println(
"Storages before cleanup: " + beforeCleanup);
521 List<String> storages = storageManager.getStorageList();
522 for (String storageName : storages) {
523 if (storageName.startsWith(
"temp_")) {
524 storageManager.removeStorage(storageName);
525 System.out.println(
"Removed temporary storage: " + storageName);
529 List<String> afterCleanup = storageManager.getStorageList();
530 System.out.println(
"Storages after cleanup: " + afterCleanup);
537 System.out.println(
"=== StorageManager and KeyValueStorage Examples ===\n");
539 demonstrateStorageManagerMethods();
540 demonstrateKeyValueStorageMethods();
541 demonstrateMultipleStorages();
542 demonstrateStorageAnalytics();
543 demonstrateDataMigration();
544 demonstrateStorageCleanup();
546 System.out.println(
"\n=== All demonstrations completed ===");