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
public interface IAccessProfileInfo { | |
Future<Iterable<ProfileId>> friendsOf(ProfileId profileId); | |
Future<Set<Topic>> favoriteTopicsOf(ProfileId profileId); | |
Future<Iterable<PostSummary>> lastPostsOf(ProfileId profileId); | |
} |
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
public Iterable<PostSummary> suggestedPostsFor(ProfileId profileId) { | |
try { | |
Future<Iterable<ProfileId>> friendIds = friendsOf(profileId); | |
Set<Topic> topics = favoriteTopicsOf(profileId).get(); | |
Stream<PostSummary> interestingPosts = stream(friendIds.get()) | |
.parallel() // Stream parallelization | |
.flatMap(friendId -> lastPostsOf(friendId)) | |
.filter(post -> post.isAbout(topics)); | |
return mostLiked(3, interestingPosts); | |
} catch (Exception e) { // InterruptedException and ExecutionException |
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
public Iterable<PostSummary> suggestedPostsFor(ProfileId profileId) { | |
Iterable<ProfileId> friendIds = friendsOf(profileId); | |
Set<Topic> topics = favoriteTopicsOf(profileId); | |
Stream<PostSummary> interestingPosts = stream(friendIds) | |
.flatMap(friendId -> lastPostsOf(friendId)) | |
.filter(post -> post.isAbout(topics)); | |
return mostLiked(3, interestingPosts); | |
} |
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 RestInfrastructure { | |
@Bean | |
@Autowired | |
public static IAccessProfileInfo getProfileInfoAccess(/* ... */) { | |
return new /*...*/; | |
} | |
} |
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 SuggestPopularFriendPost { | |
private final IAccessProfileInfo profileInfo; // Injected with constructor | |
public Iterable<PostSummary> suggestedPostsFor(ProfileId profileId) { | |
// Same code as before, calling `friendsOf`, `favoriteTopicsOf` and `lastPostsOf` | |
} | |
private Iterable<ProfileId> friendsOf(ProfileId profileId) { | |
return profileInfo.friendsOf(profileId); // Rerouting to `IAccessProfileInfo` | |
} |
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
public interface ISuggestPosts { | |
Iterable<PostSummary> suggestedPostsFor(ProfileId profileId); | |
void resetSuggestionOf(ProfileId profileId); | |
} |
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
public interface ICacheSuggestions { | |
void saveSuggestions(ProfileId profileId, Iterable<PostSummary> suggestions); | |
Iterable<PostSummary> loadSuggestions(ProfileId profileId); | |
} |
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
public static ISuggestPosts suggestPosts(IAccessProfileInfo profileInfo, ICacheSuggestions cache) { | |
return new PostSuggestions(cache, new SuggestPopularFriendPost(profileInfo)); | |
} |
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
public interface IAccessProfileInfo { | |
Iterable<ProfileId> friendsOf(ProfileId profileId); | |
Set<Topic> favoriteTopicsOf(ProfileId profileId); | |
Iterable<PostSummary> lastPostsOf(ProfileId profileId); | |
} |
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
public interface ISuggestPosts { | |
Iterable<PostSummary> suggestedPostsFor(ProfileId profileId); | |
} |