Created
October 26, 2015 16:15
-
-
Save djalexd/d960f7d5f8a93747e3dc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class T<V> { | |
| private String key; | |
| private Set<V> items; | |
| } | |
| You have a Collection<T> and are required to return a Collection<T> where T objects | |
| that have same 'key' will contains grouped 'items'. | |
| Example: | |
| T t1 = new T("key1", ImmutableSet.of(v1, v2, v3)); | |
| T t2 = new T("key2", ImmutableSet.of(v3, v4)); | |
| T t3 = new T("key1", ImmutableSet.of(v1, v5, v6)); | |
| Collection<T> items = ImmutableSet.of(t1, t2, t3); | |
| Collection<T> items2 = grouByKey(items); | |
| // items2 has this structure: | |
| [ | |
| new T("key1", ImmutableSet.of(v1, v2, v3, v5, v6)), | |
| new T("key2", ImmutableSet.of(v3, v4)) | |
| ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment