jdk/src/java.base/share/classes/java/util/stream/Collectors.java
changeset 28419 361e3aa27cb5
parent 25859 3317bb8137f4
child 29218 a2c7a365dde4
equal deleted inserted replaced
28418:7593914c0304 28419:361e3aa27cb5
   988      * elements, and whose corresponding values are {@code List}s containing the
   988      * elements, and whose corresponding values are {@code List}s containing the
   989      * input elements which map to the associated key under the classification
   989      * input elements which map to the associated key under the classification
   990      * function.
   990      * function.
   991      *
   991      *
   992      * <p>There are no guarantees on the type, mutability, or serializability
   992      * <p>There are no guarantees on the type, mutability, or serializability
   993      * of the {@code Map} or {@code List} objects returned, or of the
   993      * of the {@code ConcurrentMap} or {@code List} objects returned, or of the
   994      * thread-safety of the {@code List} objects returned.
   994      * thread-safety of the {@code List} objects returned.
   995      * @implSpec
   995      * @implSpec
   996      * This produces a result similar to:
   996      * This produces a result similar to:
   997      * <pre>{@code
   997      * <pre>{@code
   998      *     groupingByConcurrent(classifier, toList());
   998      *     groupingByConcurrent(classifier, toList());
  1025      *
  1025      *
  1026      * <p>The classification function maps elements to some key type {@code K}.
  1026      * <p>The classification function maps elements to some key type {@code K}.
  1027      * The downstream collector operates on elements of type {@code T} and
  1027      * The downstream collector operates on elements of type {@code T} and
  1028      * produces a result of type {@code D}. The resulting collector produces a
  1028      * produces a result of type {@code D}. The resulting collector produces a
  1029      * {@code Map<K, D>}.
  1029      * {@code Map<K, D>}.
       
  1030      *
       
  1031      * <p>There are no guarantees on the type, mutability, or serializability
       
  1032      * of the {@code ConcurrentMap} returned.
  1030      *
  1033      *
  1031      * <p>For example, to compute the set of last names of people in each city,
  1034      * <p>For example, to compute the set of last names of people in each city,
  1032      * where the city names are sorted:
  1035      * where the city names are sorted:
  1033      * <pre>{@code
  1036      * <pre>{@code
  1034      *     ConcurrentMap<City, Set<String>> namesByCity
  1037      *     ConcurrentMap<City, Set<String>> namesByCity
  1141      * Returns a {@code Collector} which partitions the input elements according
  1144      * Returns a {@code Collector} which partitions the input elements according
  1142      * to a {@code Predicate}, and organizes them into a
  1145      * to a {@code Predicate}, and organizes them into a
  1143      * {@code Map<Boolean, List<T>>}.
  1146      * {@code Map<Boolean, List<T>>}.
  1144      *
  1147      *
  1145      * There are no guarantees on the type, mutability,
  1148      * There are no guarantees on the type, mutability,
  1146      * serializability, or thread-safety of the {@code Map} returned.
  1149      * serializability, or thread-safety of the {@code Map} or {@code List}
       
  1150      * returned.
  1147      *
  1151      *
  1148      * @param <T> the type of the input elements
  1152      * @param <T> the type of the input elements
  1149      * @param predicate a predicate used for classifying input elements
  1153      * @param predicate a predicate used for classifying input elements
  1150      * @return a {@code Collector} implementing the partitioning operation
  1154      * @return a {@code Collector} implementing the partitioning operation
  1151      *
  1155      *
  1210      * {@link Object#equals(Object)}), an {@code IllegalStateException} is
  1214      * {@link Object#equals(Object)}), an {@code IllegalStateException} is
  1211      * thrown when the collection operation is performed.  If the mapped keys
  1215      * thrown when the collection operation is performed.  If the mapped keys
  1212      * may have duplicates, use {@link #toMap(Function, Function, BinaryOperator)}
  1216      * may have duplicates, use {@link #toMap(Function, Function, BinaryOperator)}
  1213      * instead.
  1217      * instead.
  1214      *
  1218      *
       
  1219      * <p>There are no guarantees on the type, mutability, serializability,
       
  1220      * or thread-safety of the {@code Map} returned.
       
  1221      *
  1215      * @apiNote
  1222      * @apiNote
  1216      * It is common for either the key or the value to be the input elements.
  1223      * It is common for either the key or the value to be the input elements.
  1217      * In this case, the utility method
  1224      * In this case, the utility method
  1218      * {@link java.util.function.Function#identity()} may be helpful.
  1225      * {@link java.util.function.Function#identity()} may be helpful.
  1219      * For example, the following produces a {@code Map} mapping
  1226      * For example, the following produces a {@code Map} mapping
  1268      *
  1275      *
  1269      * <p>If the mapped
  1276      * <p>If the mapped
  1270      * keys contains duplicates (according to {@link Object#equals(Object)}),
  1277      * keys contains duplicates (according to {@link Object#equals(Object)}),
  1271      * the value mapping function is applied to each equal element, and the
  1278      * the value mapping function is applied to each equal element, and the
  1272      * results are merged using the provided merging function.
  1279      * results are merged using the provided merging function.
       
  1280      *
       
  1281      * <p>There are no guarantees on the type, mutability, serializability,
       
  1282      * or thread-safety of the {@code Map} returned.
  1273      *
  1283      *
  1274      * @apiNote
  1284      * @apiNote
  1275      * There are multiple ways to deal with collisions between multiple elements
  1285      * There are multiple ways to deal with collisions between multiple elements
  1276      * mapping to the same key.  The other forms of {@code toMap} simply use
  1286      * mapping to the same key.  The other forms of {@code toMap} simply use
  1277      * a merge function that throws unconditionally, but you can easily write
  1287      * a merge function that throws unconditionally, but you can easily write
  1380      * {@link Object#equals(Object)}), an {@code IllegalStateException} is
  1390      * {@link Object#equals(Object)}), an {@code IllegalStateException} is
  1381      * thrown when the collection operation is performed.  If the mapped keys
  1391      * thrown when the collection operation is performed.  If the mapped keys
  1382      * may have duplicates, use
  1392      * may have duplicates, use
  1383      * {@link #toConcurrentMap(Function, Function, BinaryOperator)} instead.
  1393      * {@link #toConcurrentMap(Function, Function, BinaryOperator)} instead.
  1384      *
  1394      *
       
  1395      * <p>There are no guarantees on the type, mutability, or serializability
       
  1396      * of the {@code ConcurrentMap} returned.
       
  1397      *
  1385      * @apiNote
  1398      * @apiNote
  1386      * It is common for either the key or the value to be the input elements.
  1399      * It is common for either the key or the value to be the input elements.
  1387      * In this case, the utility method
  1400      * In this case, the utility method
  1388      * {@link java.util.function.Function#identity()} may be helpful.
  1401      * {@link java.util.function.Function#identity()} may be helpful.
  1389      * For example, the following produces a {@code Map} mapping
  1402      * For example, the following produces a {@code Map} mapping
  1433      * the provided mapping functions to the input elements.
  1446      * the provided mapping functions to the input elements.
  1434      *
  1447      *
  1435      * <p>If the mapped keys contains duplicates (according to {@link Object#equals(Object)}),
  1448      * <p>If the mapped keys contains duplicates (according to {@link Object#equals(Object)}),
  1436      * the value mapping function is applied to each equal element, and the
  1449      * the value mapping function is applied to each equal element, and the
  1437      * results are merged using the provided merging function.
  1450      * results are merged using the provided merging function.
       
  1451      *
       
  1452      * <p>There are no guarantees on the type, mutability, or serializability
       
  1453      * of the {@code ConcurrentMap} returned.
  1438      *
  1454      *
  1439      * @apiNote
  1455      * @apiNote
  1440      * There are multiple ways to deal with collisions between multiple elements
  1456      * There are multiple ways to deal with collisions between multiple elements
  1441      * mapping to the same key.  The other forms of {@code toConcurrentMap} simply use
  1457      * mapping to the same key.  The other forms of {@code toConcurrentMap} simply use
  1442      * a merge function that throws unconditionally, but you can easily write
  1458      * a merge function that throws unconditionally, but you can easily write