diff --git a/jOOQ/src/main/java/org/jooq/Result.java b/jOOQ/src/main/java/org/jooq/Result.java index 5f6ea158a7..5657a44528 100644 --- a/jOOQ/src/main/java/org/jooq/Result.java +++ b/jOOQ/src/main/java/org/jooq/Result.java @@ -1440,6 +1440,148 @@ public interface Result extends List, Attachable { Map, E> intoMap(Name[] keyFieldNames, RecordMapper mapper) throws IllegalArgumentException, InvalidResultException, MappingException; + /** + * Return a {@link Map} with results grouped by the given key entity. + *

+ * The grouping semantics is governed by the key type's + * {@link Object#equals(Object)} and {@link Object#hashCode()} + * implementation, not necessarily the values as fetched from the database. + *

+ * An {@link InvalidResultException} is thrown, if the keys are non-unique + * in the result set. Use {@link #intoGroups(Class)} instead, if your keys + * are non-unique. + * + * @param keyType The key type. If this is null, the resulting + * map will contain at most one entry. + * @return A Map containing grouped results + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @throws InvalidResultException if the keys are non-unique in the result + * set. + * @see DefaultRecordMapper + */ + Map intoMap(Class keyType) throws MappingException, InvalidResultException; + + /** + * Return a {@link Map} with results grouped by the given key entity and + * mapped into the given entity type. + *

+ * The grouping semantics is governed by the key type's + * {@link Object#equals(Object)} and {@link Object#hashCode()} + * implementation, not necessarily the values as fetched from the database. + *

+ * An {@link InvalidResultException} is thrown, if the keys are non-unique + * in the result set. Use {@link #intoGroups(Class, Class)} instead, if your + * keys are non-unique. + * + * @param keyType The key type. If this is null, the resulting + * map will contain at most one entry. + * @param valueType The value type. + * @return A Map containing grouped results + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @throws InvalidResultException if the keys are non-unique in the result + * set. + * @see DefaultRecordMapper + */ + Map intoMap(Class keyType, Class valueType) + throws MappingException, InvalidResultException; + + /** + * Return a {@link Map} with results grouped by the given key entity and + * mapped into the given entity type. + *

+ * The grouping semantics is governed by the key type's + * {@link Object#equals(Object)} and {@link Object#hashCode()} + * implementation, not necessarily the values as fetched from the database. + *

+ * An {@link InvalidResultException} is thrown, if the keys are non-unique + * in the result set. Use {@link #intoGroups(Class, RecordMapper)} instead, + * if your keys are non-unique. + * + * @param keyType The key type. If this is null, the resulting + * map will contain at most one entry. + * @param valueMapper The value mapper. + * @return A Map containing grouped results + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @throws InvalidResultException if the keys are non-unique in the result + * set. + * @see DefaultRecordMapper + */ + Map intoMap(Class keyType, RecordMapper valueMapper) + throws InvalidResultException, MappingException; + + /** + * Return a {@link Map} with results grouped by the given key entity and + * mapped into the given entity type. + *

+ * The grouping semantics is governed by the key type's + * {@link Object#equals(Object)} and {@link Object#hashCode()} + * implementation, not necessarily the values as fetched from the database. + *

+ * An {@link InvalidResultException} is thrown, if the keys are non-unique + * in the result set. Use {@link #intoGroups(RecordMapper)} instead, if your + * keys are non-unique. + * + * @param keyMapper The key mapper. + * @return A Map containing grouped results + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @throws InvalidResultException if the keys are non-unique in the result + * set. + * @see DefaultRecordMapper + */ + Map intoMap(RecordMapper keyMapper) throws InvalidResultException, MappingException; + + /** + * Return a {@link Map} with results grouped by the given key entity and + * mapped into the given entity type. + *

+ * The grouping semantics is governed by the key type's + * {@link Object#equals(Object)} and {@link Object#hashCode()} + * implementation, not necessarily the values as fetched from the database. + *

+ * An {@link InvalidResultException} is thrown, if the keys are non-unique + * in the result set. Use {@link #intoGroups(RecordMapper, Class)} instead, + * if your keys are non-unique. + * + * @param keyMapper The key mapper. + * @param valueType The value type. + * @return A Map containing grouped results + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @throws InvalidResultException if the keys are non-unique in the result + * set. + * @see DefaultRecordMapper + */ + Map intoMap(RecordMapper keyMapper, Class valueType) + throws InvalidResultException, MappingException; + + /** + * Return a {@link Map} with results grouped by the given key entity and + * mapped into the given entity type. + *

+ * The grouping semantics is governed by the key type's + * {@link Object#equals(Object)} and {@link Object#hashCode()} + * implementation, not necessarily the values as fetched from the database. + *

+ * An {@link InvalidResultException} is thrown, if the keys are non-unique + * in the result set. Use {@link #intoGroups(RecordMapper, RecordMapper)} + * instead, if your keys are non-unique. + * + * @param keyMapper The key mapper. + * @param valueMapper The value mapper. + * @return A Map containing grouped results + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @throws InvalidResultException if the keys are non-unique in the result + * set. + * @see DefaultRecordMapper + */ + Map intoMap(RecordMapper keyMapper, RecordMapper valueMapper) + throws InvalidResultException, MappingException; + /** * Return a {@link Map} with the given key table as a map key and the * corresponding record as value. @@ -1963,6 +2105,128 @@ public interface Result extends List, Attachable { Map> intoGroups(Name[] keyFieldNames, RecordMapper mapper) throws IllegalArgumentException, MappingException; + /** + * Return a {@link Map} with results grouped by the given key entity. + *

+ * The grouping semantics is governed by the key type's + * {@link Object#equals(Object)} and {@link Object#hashCode()} + * implementation, not necessarily the values as fetched from the database. + *

+ * Unlike {@link #intoMap(Class)}, this method allows for non-unique keys in + * the result set. + * + * @param keyType The key type. If this is null, the resulting + * map will contain at most one entry. + * @return A Map containing grouped results + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @see DefaultRecordMapper + */ + Map> intoGroups(Class keyType) throws MappingException; + + /** + * Return a {@link Map} with results grouped by the given key entity and + * mapped into the given entity type. + *

+ * The grouping semantics is governed by the key type's + * {@link Object#equals(Object)} and {@link Object#hashCode()} + * implementation, not necessarily the values as fetched from the database. + *

+ * Unlike {@link #intoMap(Class, Class)}, this method allows for non-unique + * keys in the result set. + * + * @param keyType The key type. If this is null, the resulting + * map will contain at most one entry. + * @param valueType The value type. + * @return A Map containing grouped results + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @see DefaultRecordMapper + */ + Map> intoGroups(Class keyType, Class valueType) throws MappingException; + + /** + * Return a {@link Map} with results grouped by the given key entity and + * mapped into the given entity type. + *

+ * The grouping semantics is governed by the key type's + * {@link Object#equals(Object)} and {@link Object#hashCode()} + * implementation, not necessarily the values as fetched from the database. + *

+ * Unlike {@link #intoMap(Class, RecordMapper)}, this method allows for + * non-unique keys in the result set. + * + * @param keyType The key type. If this is null, the resulting + * map will contain at most one entry. + * @param valueMapper The value mapper. + * @return A Map containing grouped results + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @see DefaultRecordMapper + */ + Map> intoGroups(Class keyType, RecordMapper valueMapper) + throws MappingException; + + /** + * Return a {@link Map} with results grouped by the given key entity and + * mapped into the given entity type. + *

+ * The grouping semantics is governed by the key type's + * {@link Object#equals(Object)} and {@link Object#hashCode()} + * implementation, not necessarily the values as fetched from the database. + *

+ * Unlike {@link #intoMap(RecordMapper, RecordMapper)}, this method allows + * for non-unique keys in the result set. + * + * @param keyMapper The key mapper. + * @return A Map containing grouped results + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @see DefaultRecordMapper + */ + Map> intoGroups(RecordMapper keyMapper) throws MappingException; + + /** + * Return a {@link Map} with results grouped by the given key entity and + * mapped into the given entity type. + *

+ * The grouping semantics is governed by the key type's + * {@link Object#equals(Object)} and {@link Object#hashCode()} + * implementation, not necessarily the values as fetched from the database. + *

+ * Unlike {@link #intoMap(RecordMapper, Class)}, this method allows for + * non-unique keys in the result set. + * + * @param keyMapper The key mapper. + * @param valueType The value type. + * @return A Map containing grouped results + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @see DefaultRecordMapper + */ + Map> intoGroups(RecordMapper keyMapper, Class valueType) throws MappingException; + + /** + * Return a {@link Map} with results grouped by the given key entity and + * mapped into the given entity type. + *

+ * The grouping semantics is governed by the key type's + * {@link Object#equals(Object)} and {@link Object#hashCode()} + * implementation, not necessarily the values as fetched from the database. + *

+ * Unlike {@link #intoMap(RecordMapper, RecordMapper)}, this method allows + * for non-unique keys in the result set. + * + * @param keyMapper The key mapper. + * @param valueMapper The value mapper. + * @return A Map containing grouped results + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @see DefaultRecordMapper + */ + Map> intoGroups(RecordMapper keyMapper, RecordMapper valueMapper) + throws MappingException; + /** * Return a {@link Map} with the result grouped by the given key table. *

diff --git a/jOOQ/src/main/java/org/jooq/ResultQuery.java b/jOOQ/src/main/java/org/jooq/ResultQuery.java index 59c3b7ad79..360aa91ca8 100644 --- a/jOOQ/src/main/java/org/jooq/ResultQuery.java +++ b/jOOQ/src/main/java/org/jooq/ResultQuery.java @@ -1596,12 +1596,163 @@ public interface ResultQuery extends Query, Iterable { MappingException; /** - * Execute the query and return a {@link Map} with table as a map key and the - * corresponding record as value. + * Execute the query and return a {@link Map} with results grouped by the + * given key entity. *

- * An exception is thrown, if the keys turn out to be non-unique in the - * result set. Use {@link #fetchGroups(Table)} instead, if your keys are - * non-unique. + * The grouping semantics is governed by the key type's + * {@link Object#equals(Object)} and {@link Object#hashCode()} + * implementation, not necessarily the values as fetched from the database. + *

+ * An {@link InvalidResultException} is thrown, if the keys are non-unique + * in the result set. Use {@link #fetchGroups(Class)} instead, if your keys + * are non-unique. + * + * @param keyType The key type. If this is null, the resulting + * map will contain at most one entry. + * @return A Map containing grouped results + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @throws InvalidResultException if the key list is non-unique in the + * result set. + * @see Result#intoMap(Class) + * @see DefaultRecordMapper + */ + Map fetchMap(Class keyType) + throws DataAccessException, MappingException, InvalidResultException; + + /** + * Execute the query and return a {@link Map} with results grouped by the + * given key entity and mapped into the given entity type. + *

+ * The grouping semantics is governed by the key type's + * {@link Object#equals(Object)} and {@link Object#hashCode()} + * implementation, not necessarily the values as fetched from the database. + *

+ * An {@link InvalidResultException} is thrown, if the keys are non-unique + * in the result set. Use {@link #fetchGroups(Class, Class)} instead, if + * your keys are non-unique. + * + * @param keyType The key type. If this is null, the resulting + * map will contain at most one entry. + * @param valueType The value type. + * @return A Map containing grouped results + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @throws InvalidResultException if the key list is non-unique in the + * result set. + * @see Result#intoMap(Class, Class) + * @see DefaultRecordMapper + */ + Map fetchMap(Class keyType, Class valueType) + throws DataAccessException, MappingException, InvalidResultException; + + /** + * Execute the query and return a {@link Map} with results grouped by the + * given key entity and mapped into the given entity type. + *

+ * The grouping semantics is governed by the key type's + * {@link Object#equals(Object)} and {@link Object#hashCode()} + * implementation, not necessarily the values as fetched from the database. + *

+ * An {@link InvalidResultException} is thrown, if the keys are non-unique + * in the result set. Use {@link #fetchGroups(Class, RecordMapper)} instead, + * if your keys are non-unique. + * + * @param keyType The key type. If this is null, the resulting + * map will contain at most one entry. + * @param valueMapper The value mapper. + * @return A Map containing grouped results + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @throws InvalidResultException if the key list is non-unique in the + * result set. + * @see Result#intoMap(Class, RecordMapper) + * @see DefaultRecordMapper + */ + Map fetchMap(Class keyType, RecordMapper valueMapper) + throws DataAccessException, InvalidResultException, MappingException; + + /** + * Execute the query and return a {@link Map} with results grouped by the + * given key entity and mapped into the given entity type. + *

+ * The grouping semantics is governed by the key type's + * {@link Object#equals(Object)} and {@link Object#hashCode()} + * implementation, not necessarily the values as fetched from the database. + *

+ * An {@link InvalidResultException} is thrown, if the keys are non-unique + * in the result set. Use {@link #fetchGroups(RecordMapper)} instead, if + * your keys are non-unique. + * + * @param keyMapper The key mapper. + * @return A Map containing grouped results + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @throws InvalidResultException if the key list is non-unique in the + * result set. + * @see Result#intoMap(RecordMapper) + * @see DefaultRecordMapper + */ + Map fetchMap(RecordMapper keyMapper) throws DataAccessException, + InvalidResultException, MappingException; + + /** + * Execute the query and return a {@link Map} with results grouped by the + * given key entity and mapped into the given entity type. + *

+ * The grouping semantics is governed by the key type's + * {@link Object#equals(Object)} and {@link Object#hashCode()} + * implementation, not necessarily the values as fetched from the database. + *

+ * An {@link InvalidResultException} is thrown, if the keys are non-unique + * in the result set. Use {@link #fetchGroups(RecordMapper, Class)} instead, + * if your keys are non-unique. + * + * @param keyMapper The key mapper. + * @param valueType The value type. + * @return A Map containing grouped results + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @throws InvalidResultException if the key list is non-unique in the + * result set. + * @see Result#intoMap(RecordMapper, Class) + * @see DefaultRecordMapper + */ + Map fetchMap(RecordMapper keyMapper, Class valueType) throws DataAccessException, + InvalidResultException, MappingException; + + /** + * Execute the query and return a {@link Map} with results grouped by the + * given key entity and mapped into the given entity type. + *

+ * The grouping semantics is governed by the key type's + * {@link Object#equals(Object)} and {@link Object#hashCode()} + * implementation, not necessarily the values as fetched from the database. + *

+ * An {@link InvalidResultException} is thrown, if the keys are non-unique + * in the result set. Use {@link #fetchGroups(RecordMapper, RecordMapper)} + * instead, if your keys are non-unique. + * + * @param keyMapper The key mapper. + * @param valueMapper The value mapper. + * @return A Map containing grouped results + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @throws InvalidResultException if the key list is non-unique in the + * result set. + * @see Result#intoMap(RecordMapper, RecordMapper) + * @see DefaultRecordMapper + */ + Map fetchMap(RecordMapper keyMapper, RecordMapper valueMapper) + throws DataAccessException, InvalidResultException, MappingException; + + /** + * Execute the query and return a {@link Map} with table as a map key and + * the corresponding record as value. + *

+ * An {@link InvalidResultException} is thrown, if the keys turn out to be + * non-unique in the result set. Use {@link #fetchGroups(Table)} instead, if + * your keys are non-unique. * * @param table The key table. Client code must assure that keys are unique * in the result set. May not be null. @@ -2165,6 +2316,131 @@ public interface ResultQuery extends Query, Iterable { Map> fetchGroups(Name[] keyFieldNames, RecordMapper mapper) throws MappingException; + /** + * Execute the query and return a {@link Map} with results grouped by the + * given key entity. + *

+ * The grouping semantics is governed by the key type's + * {@link Object#equals(Object)} and {@link Object#hashCode()} + * implementation, not necessarily the values as fetched from the database. + *

+ * Unlike {@link #fetchMap(Class)}, this method allows for non-unique keys + * in the result set. + * + * @param keyType The key type. If this is null, the resulting + * map will contain at most one entry. + * @return A Map containing grouped results + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @see DefaultRecordMapper + */ + Map> fetchGroups(Class keyType) throws MappingException; + + /** + * Execute the query and return a {@link Map} with results grouped by the + * given key entity and mapped into the given entity type. + *

+ * The grouping semantics is governed by the key type's + * {@link Object#equals(Object)} and {@link Object#hashCode()} + * implementation, not necessarily the values as fetched from the database. + *

+ * Unlike {@link #fetchMap(Class, Class)}, this method allows for non-unique + * keys in the result set. + * + * @param keyType The key type. If this is null, the resulting + * map will contain at most one entry. + * @param valueType The value type. + * @return A Map containing grouped results + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @see DefaultRecordMapper + */ + Map> fetchGroups(Class keyType, Class valueType) + throws MappingException; + + /** + * Execute the query and return a {@link Map} with results grouped by the + * given key entity and mapped into the given entity type. + *

+ * The grouping semantics is governed by the key type's + * {@link Object#equals(Object)} and {@link Object#hashCode()} + * implementation, not necessarily the values as fetched from the database. + *

+ * Unlike {@link #fetchMap(Class, RecordMapper)}, this method allows for + * non-unique keys in the result set. + * + * @param keyType The key type. If this is null, the resulting + * map will contain at most one entry. + * @param valueMapper The value mapper. + * @return A Map containing grouped results + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @see DefaultRecordMapper + */ + Map> fetchGroups(Class keyType, RecordMapper valueMapper) + throws MappingException; + + /** + * Execute the query and return a {@link Map} with results grouped by the + * given key entity and mapped into the given entity type. + *

+ * The grouping semantics is governed by the key type's + * {@link Object#equals(Object)} and {@link Object#hashCode()} + * implementation, not necessarily the values as fetched from the database. + *

+ * Unlike {@link #fetchMap(RecordMapper, RecordMapper)}, this method allows + * for non-unique keys in the result set. + * + * @param keyMapper The key mapper. + * @return A Map containing grouped results + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @see DefaultRecordMapper + */ + Map> fetchGroups(RecordMapper keyMapper) throws MappingException; + + /** + * Execute the query and return a {@link Map} with results grouped by the + * given key entity and mapped into the given entity type. + *

+ * The grouping semantics is governed by the key type's + * {@link Object#equals(Object)} and {@link Object#hashCode()} + * implementation, not necessarily the values as fetched from the database. + *

+ * Unlike {@link #fetchMap(RecordMapper, Class)}, this method allows for + * non-unique keys in the result set. + * + * @param keyMapper The key mapper. + * @param valueType The value type. + * @return A Map containing grouped results + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @see DefaultRecordMapper + */ + Map> fetchGroups(RecordMapper keyMapper, Class valueType) + throws MappingException; + + /** + * Execute the query and return a {@link Map} with results grouped by the + * given key entity and mapped into the given entity type. + *

+ * The grouping semantics is governed by the key type's + * {@link Object#equals(Object)} and {@link Object#hashCode()} + * implementation, not necessarily the values as fetched from the database. + *

+ * Unlike {@link #fetchMap(RecordMapper, RecordMapper)}, this method allows + * for non-unique keys in the result set. + * + * @param keyMapper The key mapper. + * @param valueMapper The value mapper. + * @return A Map containing grouped results + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @see DefaultRecordMapper + */ + Map> fetchGroups(RecordMapper keyMapper, RecordMapper valueMapper) + throws MappingException; + /** * Execute the query and return a {@link Map} with the result grouped by the * given table. diff --git a/jOOQ/src/main/java/org/jooq/impl/AbstractResultQuery.java b/jOOQ/src/main/java/org/jooq/impl/AbstractResultQuery.java index 8ac1b7a7f3..29aedf1689 100644 --- a/jOOQ/src/main/java/org/jooq/impl/AbstractResultQuery.java +++ b/jOOQ/src/main/java/org/jooq/impl/AbstractResultQuery.java @@ -861,6 +861,36 @@ abstract class AbstractResultQuery extends AbstractQuery imple return fetch().intoMap(keyFieldNames, mapper); } + @Override + public final Map fetchMap(Class keyType) { + return fetch().intoMap(keyType); + } + + @Override + public final Map fetchMap(Class keyType, Class valueType) { + return fetch().intoMap(keyType, valueType); + } + + @Override + public final Map fetchMap(Class keyType, RecordMapper valueMapper) { + return fetch().intoMap(keyType, valueMapper); + } + + @Override + public final Map fetchMap(RecordMapper keyMapper) { + return fetch().intoMap(keyMapper); + } + + @Override + public final Map fetchMap(RecordMapper keyMapper, Class valueType) { + return fetch().intoMap(keyMapper, valueType); + } + + @Override + public final Map fetchMap(RecordMapper keyMapper, RecordMapper valueMapper) { + return fetch().intoMap(keyMapper, valueMapper); + } + @Override public final Map fetchMap(Table table) { return fetch().intoMap(table); @@ -1021,6 +1051,36 @@ abstract class AbstractResultQuery extends AbstractQuery imple return fetch().intoGroups(keys, mapper); } + @Override + public final Map> fetchGroups(Class keyType) { + return fetch().intoGroups(keyType); + } + + @Override + public final Map> fetchGroups(Class keyType, Class valueType) { + return fetch().intoGroups(keyType, valueType); + } + + @Override + public final Map> fetchGroups(Class keyType, RecordMapper valueMapper) { + return fetch().intoGroups(keyType, valueMapper); + } + + @Override + public final Map> fetchGroups(RecordMapper keyMapper) { + return fetch().intoGroups(keyMapper); + } + + @Override + public final Map> fetchGroups(RecordMapper keyMapper, Class valueType) { + return fetch().intoGroups(keyMapper, valueType); + } + + @Override + public final Map> fetchGroups(RecordMapper keyMapper, RecordMapper valueMapper) { + return fetch().intoGroups(keyMapper, valueMapper); + } + @Override public final Map> fetchGroups(Table table) { return fetch().intoGroups(table); diff --git a/jOOQ/src/main/java/org/jooq/impl/ResultImpl.java b/jOOQ/src/main/java/org/jooq/impl/ResultImpl.java index 7bd846e2da..b3142922d2 100644 --- a/jOOQ/src/main/java/org/jooq/impl/ResultImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/ResultImpl.java @@ -1254,6 +1254,58 @@ class ResultImpl implements Result, AttachableInternal { return map; } + @Override + public final Map intoMap(Class keyType) { + return intoMap(Utils.configuration(this).recordMapperProvider().provide(fields, keyType)); + } + + @Override + public final Map intoMap(Class keyType, Class valueType) { + return intoMap( + Utils.configuration(this).recordMapperProvider().provide(fields, keyType), + Utils.configuration(this).recordMapperProvider().provide(fields, valueType) + ); + } + + @Override + public final Map intoMap(Class keyType, RecordMapper valueMapper) { + return intoMap(Utils.configuration(this).recordMapperProvider().provide(fields, keyType), valueMapper); + } + + @Override + public final Map intoMap(RecordMapper keyMapper) { + Map map = new LinkedHashMap(); + + for (R record : this) { + K key = keyMapper.map(record); + + if (map.put(key, record) != null) + throw new InvalidResultException("Key list " + key + " is not unique in Result for " + this); + } + + return map; + } + + @Override + public final Map intoMap(RecordMapper keyMapper, Class valueType) { + return intoMap(keyMapper, Utils.configuration(this).recordMapperProvider().provide(fields, valueType)); + } + + @Override + public final Map intoMap(RecordMapper keyMapper, RecordMapper valueMapper) { + Map map = new LinkedHashMap(); + + for (R record : this) { + K key = keyMapper.map(record); + V value = valueMapper.map(record); + + if (map.put(key, value) != null) + throw new InvalidResultException("Key list " + key + " is not unique in Result for " + this); + } + + return map; + } + @Override public final Map intoMap(Table table) { Map map = new LinkedHashMap(); @@ -1261,9 +1313,8 @@ class ResultImpl implements Result, AttachableInternal { for (R record : this) { S key = record.into(table); - if (map.put(key, record) != null) { + if (map.put(key, record) != null) throw new InvalidResultException("Key list " + key + " is not unique in Result for " + this); - } } return map; @@ -1281,9 +1332,8 @@ class ResultImpl implements Result, AttachableInternal { for (R record : this) { S key = record.into(table); - if (map.put(key, mapper.map(record)) != null) { + if (map.put(key, mapper.map(record)) != null) throw new InvalidResultException("Key list " + key + " is not unique in Result for " + this); - } } return map; @@ -1579,6 +1629,67 @@ class ResultImpl implements Result, AttachableInternal { return map; } + @Override + public final Map> intoGroups(Class keyType) { + return intoGroups(Utils.configuration(this).recordMapperProvider().provide(fields, keyType)); + } + + @Override + public final Map> intoGroups(Class keyType, Class valueType) { + return intoGroups( + Utils.configuration(this).recordMapperProvider().provide(fields, keyType), + Utils.configuration(this).recordMapperProvider().provide(fields, valueType) + ); + } + + @Override + public final Map> intoGroups(Class keyType, RecordMapper valueMapper) { + return intoGroups(Utils.configuration(this).recordMapperProvider().provide(fields, keyType), valueMapper); + } + + @Override + public final Map> intoGroups(RecordMapper keyMapper) { + Map> map = new LinkedHashMap>(); + + for (R record : this) { + K key = keyMapper.map(record); + + Result result = map.get(key); + if (result == null) { + result = new ResultImpl(configuration(), fields()); + map.put(key, result); + } + + result.add(record); + } + + return map; + } + + @Override + public final Map> intoGroups(RecordMapper keyMapper, Class valueType) { + return intoGroups(keyMapper, Utils.configuration(this).recordMapperProvider().provide(fields, valueType)); + } + + @Override + public final Map> intoGroups(RecordMapper keyMapper, RecordMapper valueMapper) { + Map> map = new LinkedHashMap>(); + + for (R record : this) { + K key = keyMapper.map(record); + + List list = map.get(key); + if (list == null) { + list = new ArrayList(); + map.put(key, list); + } + + list.add(valueMapper.map(record)); + } + + return map; + } + @Override public final Map> intoGroups(Table table) { Map> map = new LinkedHashMap>();