Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
lab_reactive_java
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
rtbdp
labs
lab_reactive_java
Commits
2315cef5
Commit
2315cef5
authored
8 years ago
by
Stuart Marks
Browse files
Options
Downloads
Patches
Plain Diff
Minor fix to, and improved description of, map inversion exercise.
parent
a5c57e2b
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
LambdaLab/test/exercises/G_Challenges.java
+19
-1
19 additions, 1 deletion
LambdaLab/test/exercises/G_Challenges.java
LambdaLab/test/solutions/G_Challenges.java
+19
-1
19 additions, 1 deletion
LambdaLab/test/solutions/G_Challenges.java
with
38 additions
and
2 deletions
LambdaLab/test/exercises/G_Challenges.java
+
19
−
1
View file @
2315cef5
...
...
@@ -117,6 +117,24 @@ public class G_Challenges {
* Invert a "multi-map". (From an idea by Paul Sandoz)
*
* Given a Map<X, Set<Y>>, convert it to Map<Y, Set<X>>.
* Each set member of the input map's values becomes a key in
* the result map. Each key in the input map becomes a set member
* of the values of the result map. In the input map, an item
* may appear in the value set of multiple keys. In the result
* map, that item will be a key, and its value set will be
* its corresopnding keys from the input map.
*
* In this case the input is Map<String, Set<Integer>>
* and the result is Map<Integer, Set<String>>.
*
* For example, if the input map is
* {p=[10, 20], q=[20, 30]}
* then the result map should be
* {10=[p], 20=[p, q], 30=[q]}
* irrespective of ordering. Note that the Integer 20 appears
* in the value sets for both p and q in the input map. Therefore,
* in the result map, there should be a mapping with 20 as the key
* and p and q as its value set.
*/
@Test
@Ignore
public
void
ex27_invertMultiMap
()
{
...
...
@@ -128,7 +146,7 @@ public class G_Challenges {
input
.
put
(
"e"
,
new
HashSet
<>(
Arrays
.
asList
(
2
,
4
)));
input
.
put
(
"f"
,
new
HashSet
<>(
Arrays
.
asList
(
3
,
4
)));
Map
<
Integer
,
Lis
t
<
String
>>
result
=
null
;
// TODO
Map
<
Integer
,
Se
t
<
String
>>
result
=
null
;
// TODO
assertEquals
(
new
HashSet
<>(
Arrays
.
asList
(
"a"
,
"c"
,
"d"
)),
result
.
get
(
1
));
assertEquals
(
new
HashSet
<>(
Arrays
.
asList
(
"a"
,
"b"
,
"e"
)),
result
.
get
(
2
));
...
...
This diff is collapsed.
Click to expand it.
LambdaLab/test/solutions/G_Challenges.java
+
19
−
1
View file @
2315cef5
...
...
@@ -139,6 +139,24 @@ public class G_Challenges {
* Invert a "multi-map". (From an idea by Paul Sandoz)
*
* Given a Map<X, Set<Y>>, convert it to Map<Y, Set<X>>.
* Each set member of the input map's values becomes a key in
* the result map. Each key in the input map becomes a set member
* of the values of the result map. In the input map, an item
* may appear in the value set of multiple keys. In the result
* map, that item will be a key, and its value set will be
* its corresopnding keys from the input map.
*
* In this case the input is Map<String, Set<Integer>>
* and the result is Map<Integer, Set<String>>.
*
* For example, if the input map is
* {p=[10, 20], q=[20, 30]}
* then the result map should be
* {10=[p], 20=[p, q], 30=[q]}
* irrespective of ordering. Note that the Integer 20 appears
* in the value sets for both p and q in the input map. Therefore,
* in the result map, there should be a mapping with 20 as the key
* and p and q as its value set.
*/
@Test
public
void
ex27_invertMultiMap
()
{
...
...
@@ -150,7 +168,7 @@ public class G_Challenges {
input
.
put
(
"e"
,
new
HashSet
<>(
Arrays
.
asList
(
2
,
4
)));
input
.
put
(
"f"
,
new
HashSet
<>(
Arrays
.
asList
(
3
,
4
)));
//TODO//Map<Integer,
Lis
t<String>> result = null;
//TODO//Map<Integer,
Se
t<String>> result = null;
//BEGINREMOVE
Map
<
Integer
,
Set
<
String
>>
result
=
input
.
entrySet
().
stream
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment