|
29 | 29 | import java.util.Map; |
30 | 30 | import java.util.SortedMap; |
31 | 31 | import java.util.TreeMap; |
| 32 | +import java.util.WeakHashMap; |
32 | 33 | import java.util.concurrent.ConcurrentHashMap; |
33 | 34 | import java.util.concurrent.ConcurrentMap; |
34 | 35 | import java.util.concurrent.ConcurrentNavigableMap; |
@@ -1255,6 +1256,189 @@ static Map<String, Object> extraProperties(Map<String, Object> map) { |
1255 | 1256 | return properties; |
1256 | 1257 | } |
1257 | 1258 |
|
| 1259 | + /** |
| 1260 | + * Creates a new empty {@link ConcurrentSkipListMap} instance. |
| 1261 | + * |
| 1262 | + * <p>This method provides a convenient way to create an empty concurrent skip list map. |
| 1263 | + * The returned map is thread-safe and allows for efficient concurrent operations.</p> |
| 1264 | + * |
| 1265 | + * <h3>Example Usage</h3> |
| 1266 | + * <pre>{@code |
| 1267 | + * Map<String, String> map = MapUtils.newConcurrentSkipListMap(); |
| 1268 | + * System.out.println(map.isEmpty()); // Output: true |
| 1269 | + * |
| 1270 | + * map.put("key", "value"); |
| 1271 | + * System.out.println(map); // Output: {key=value} |
| 1272 | + * }</pre> |
| 1273 | + * |
| 1274 | + * @param <K> the type of keys in the map |
| 1275 | + * @param <V> the type of values in the map |
| 1276 | + * @return a new, empty {@link ConcurrentSkipListMap} |
| 1277 | + */ |
| 1278 | + @Nonnull |
| 1279 | + public static <K, V> ConcurrentSkipListMap<K, V> newConcurrentSkipListMap() { |
| 1280 | + return new ConcurrentSkipListMap<>(); |
| 1281 | + } |
| 1282 | + |
| 1283 | + /** |
| 1284 | + * Creates a new {@link ConcurrentSkipListMap} instance from the specified {@link Map}. |
| 1285 | + * |
| 1286 | + * <p>This method converts the given {@link Map} into a {@link ConcurrentSkipListMap}.</p> |
| 1287 | + * |
| 1288 | + * <h3>Example Usage</h3> |
| 1289 | + * <pre>{@code |
| 1290 | + * Map<String, String> original = new HashMap<>(); |
| 1291 | + * original.put("key", "value"); |
| 1292 | + * Map<String, String> map = MapUtils.newConcurrentSkipListMap(original); |
| 1293 | + * System.out.println(map); // Output: {key=value} |
| 1294 | + * }</pre> |
| 1295 | + * |
| 1296 | + * @param map the map whose entries are to be copied, may be null or empty |
| 1297 | + * @param <K> the type of keys in the map |
| 1298 | + * @param <V> the type of values in the map |
| 1299 | + * @return a new {@link ConcurrentSkipListMap} containing all entries from the map |
| 1300 | + */ |
| 1301 | + @Nonnull |
| 1302 | + public static <K, V> ConcurrentSkipListMap<K, V> newConcurrentSkipListMap(Map<? extends K, ? extends V> map) { |
| 1303 | + return new ConcurrentSkipListMap<>(map); |
| 1304 | + } |
| 1305 | + |
| 1306 | + /** |
| 1307 | + * Creates a new empty {@link WeakHashMap} instance. |
| 1308 | + * |
| 1309 | + * <p>This method provides a convenient way to create an empty weak hash map. |
| 1310 | + * The returned map allows weak reference keys that can be garbage collected.</p> |
| 1311 | + * |
| 1312 | + * <h3>Example Usage</h3> |
| 1313 | + * <pre>{@code |
| 1314 | + * Map<String, String> map = MapUtils.newWeakHashMap(); |
| 1315 | + * System.out.println(map.isEmpty()); // Output: true |
| 1316 | + * |
| 1317 | + * map.put("key", "value"); |
| 1318 | + * System.out.println(map); // Output: {key=value} |
| 1319 | + * }</pre> |
| 1320 | + * |
| 1321 | + * @param <K> the type of keys in the map |
| 1322 | + * @param <V> the type of values in the map |
| 1323 | + * @return a new, empty {@link WeakHashMap} |
| 1324 | + */ |
| 1325 | + @Nonnull |
| 1326 | + public static <K, V> WeakHashMap<K, V> newWeakHashMap() { |
| 1327 | + return new WeakHashMap<>(); |
| 1328 | + } |
| 1329 | + |
| 1330 | + /** |
| 1331 | + * Creates a new {@link WeakHashMap} instance with the specified initial capacity. |
| 1332 | + * |
| 1333 | + * <p>This method provides a convenient way to create a weak hash map with a predefined initial size.</p> |
| 1334 | + * |
| 1335 | + * <h3>Example Usage</h3> |
| 1336 | + * <pre>{@code |
| 1337 | + * Map<String, String> map = MapUtils.newWeakHashMap(16); |
| 1338 | + * System.out.println(map.isEmpty()); // Output: true |
| 1339 | + * }</pre> |
| 1340 | + * |
| 1341 | + * @param initialCapacity the initial capacity of the weak hash map |
| 1342 | + * @param <K> the type of keys in the map |
| 1343 | + * @param <V> the type of values in the map |
| 1344 | + * @return a new, empty {@link WeakHashMap} with the specified initial capacity |
| 1345 | + */ |
| 1346 | + @Nonnull |
| 1347 | + public static <K, V> WeakHashMap<K, V> newWeakHashMap(int initialCapacity) { |
| 1348 | + return new WeakHashMap<>(initialCapacity); |
| 1349 | + } |
| 1350 | + |
| 1351 | + /** |
| 1352 | + * Creates a new {@link WeakHashMap} instance from the specified {@link Map}. |
| 1353 | + * |
| 1354 | + * <p>This method converts the given {@link Map} into a {@link WeakHashMap}.</p> |
| 1355 | + * |
| 1356 | + * <h3>Example Usage</h3> |
| 1357 | + * <pre>{@code |
| 1358 | + * Map<String, String> original = new HashMap<>(); |
| 1359 | + * original.put("key", "value"); |
| 1360 | + * Map<String, String> map = MapUtils.newWeakHashMap(original); |
| 1361 | + * System.out.println(map); // Output: {key=value} |
| 1362 | + * }</pre> |
| 1363 | + * |
| 1364 | + * @param map the map whose entries are to be copied, may be null or empty |
| 1365 | + * @param <K> the type of keys in the map |
| 1366 | + * @param <V> the type of values in the map |
| 1367 | + * @return a new {@link WeakHashMap} containing all entries from the map |
| 1368 | + */ |
| 1369 | + @Nonnull |
| 1370 | + public static <K, V> WeakHashMap<K, V> newWeakHashMap(Map<? extends K, ? extends V> map) { |
| 1371 | + return new WeakHashMap<>(map); |
| 1372 | + } |
| 1373 | + |
| 1374 | + /** |
| 1375 | + * Creates a new empty {@link IdentityHashMap} instance. |
| 1376 | + * |
| 1377 | + * <p>This method provides a convenient way to create an empty identity hash map. |
| 1378 | + * The returned map uses reference equality instead of object equality for key comparisons.</p> |
| 1379 | + * |
| 1380 | + * <h3>Example Usage</h3> |
| 1381 | + * <pre>{@code |
| 1382 | + * Map<String, String> map = MapUtils.newIdentityHashMap(); |
| 1383 | + * System.out.println(map.isEmpty()); // Output: true |
| 1384 | + * |
| 1385 | + * map.put("key", "value"); |
| 1386 | + * System.out.println(map); // Output: {key=value} |
| 1387 | + * }</pre> |
| 1388 | + * |
| 1389 | + * @param <K> the type of keys in the map |
| 1390 | + * @param <V> the type of values in the map |
| 1391 | + * @return a new, empty {@link IdentityHashMap} |
| 1392 | + */ |
| 1393 | + @Nonnull |
| 1394 | + public static <K, V> IdentityHashMap<K, V> newIdentityHashMap() { |
| 1395 | + return new IdentityHashMap<>(); |
| 1396 | + } |
| 1397 | + |
| 1398 | + /** |
| 1399 | + * Creates a new {@link IdentityHashMap} instance with the specified expected maximum size. |
| 1400 | + * |
| 1401 | + * <p>This method provides a convenient way to create an identity hash map with a predefined initial size.</p> |
| 1402 | + * |
| 1403 | + * <h3>Example Usage</h3> |
| 1404 | + * <pre>{@code |
| 1405 | + * Map<String, String> map = MapUtils.newIdentityHashMap(16); |
| 1406 | + * System.out.println(map.isEmpty()); // Output: true |
| 1407 | + * }</pre> |
| 1408 | + * |
| 1409 | + * @param expectedMaxSize the expected maximum size of the map |
| 1410 | + * @param <K> the type of keys in the map |
| 1411 | + * @param <V> the type of values in the map |
| 1412 | + * @return a new, empty {@link IdentityHashMap} with the expected maximum size |
| 1413 | + */ |
| 1414 | + @Nonnull |
| 1415 | + public static <K, V> IdentityHashMap<K, V> newIdentityHashMap(int expectedMaxSize) { |
| 1416 | + return new IdentityHashMap<>(expectedMaxSize); |
| 1417 | + } |
| 1418 | + |
| 1419 | + /** |
| 1420 | + * Creates a new {@link IdentityHashMap} instance from the specified {@link Map}. |
| 1421 | + * |
| 1422 | + * <p>This method converts the given {@link Map} into an {@link IdentityHashMap}.</p> |
| 1423 | + * |
| 1424 | + * <h3>Example Usage</h3> |
| 1425 | + * <pre>{@code |
| 1426 | + * Map<String, String> original = new HashMap<>(); |
| 1427 | + * original.put("key", "value"); |
| 1428 | + * Map<String, String> map = MapUtils.newIdentityHashMap(original); |
| 1429 | + * System.out.println(map); // Output: {key=value} |
| 1430 | + * }</pre> |
| 1431 | + * |
| 1432 | + * @param map the map whose entries are to be copied, may be null or empty |
| 1433 | + * @param <K> the type of keys in the map |
| 1434 | + * @param <V> the type of values in the map |
| 1435 | + * @return a new {@link IdentityHashMap} containing all entries from the map |
| 1436 | + */ |
| 1437 | + @Nonnull |
| 1438 | + public static <K, V> IdentityHashMap<K, V> newIdentityHashMap(Map<? extends K, ? extends V> map) { |
| 1439 | + return new IdentityHashMap<>(map); |
| 1440 | + } |
| 1441 | + |
1258 | 1442 | private MapUtils() { |
1259 | 1443 | } |
1260 | 1444 |
|
|
0 commit comments