@@ -1648,9 +1648,24 @@ public static <V> Map<String, V> entriesWithPrefix(Map<String, V> map, String pr
1648
1648
* @param <V> the type of values stored in the map
1649
1649
*/
1650
1650
public static <V > Map <String , V > entriesWithPrefix (Map <String , V > map , String prefix , boolean strip ) {
1651
+ return entriesWithPrefix (map , prefix , strip , false );
1652
+ }
1653
+
1654
+ /**
1655
+ * Find all key/value pairs whose keys begin with the given prefix, optionally removing that prefix
1656
+ * from all resulting keys.
1657
+ * @param map the map to filter key/value pairs from
1658
+ * @param prefix the prefix to search keys for
1659
+ * @param strip whether the keys of the returned map should not include the prefix
1660
+ * @param allowMatchingLength whether to include keys that are exactly the same length as the prefix
1661
+ * @return a {@link Map} containing a key/value pair for every key/value pair in the {@code map}
1662
+ * parameter whose key begins with the given {@code prefix}; may be empty, but never null
1663
+ * @param <V> the type of values stored in the map
1664
+ */
1665
+ public static <V > Map <String , V > entriesWithPrefix (Map <String , V > map , String prefix , boolean strip , boolean allowMatchingLength ) {
1651
1666
Map <String , V > result = new HashMap <>();
1652
1667
for (Map .Entry <String , V > entry : map .entrySet ()) {
1653
- if (entry .getKey ().startsWith (prefix ) && entry .getKey ().length () > prefix .length ()) {
1668
+ if (entry .getKey ().startsWith (prefix ) && ( allowMatchingLength || entry .getKey ().length () > prefix .length () )) {
1654
1669
if (strip )
1655
1670
result .put (entry .getKey ().substring (prefix .length ()), entry .getValue ());
1656
1671
else
0 commit comments