山ごとに小分けの関数にする
This file contains 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
List<Tweet> tweets(String uid, List<Follow> follows, List<Tweet> tweets, | |
List<ReTweet>reTweets) { | |
var result = <Tweet>[]; | |
// フォローしているユーザのUserIDを抽出 | |
var followUserIDs = getFollowUserIDs(follows, uid); | |
// フォローしているユーザのTweetを抽出 | |
result.addAll(getTweets(followUserIDs, tweets)); | |
// フォローしているユーザーのReTweetを抽出 | |
result.addAll(getReTweets(followUserIDs, reTweets, tweets)); | |
return result; | |
} | |
List<Tweet> getReTweets(List<String> followUserIDs, List<ReTweet> reTweets, | |
List<Tweet> tweets) { | |
var list = <Tweet>[]; | |
for (var followUserID in followUserIDs) { | |
for (var reTweet in reTweets) { | |
if (reTweet.uid != followUserID) { | |
continue; | |
} | |
for (var tweet in tweets) { | |
if (reTweet.tweetID == tweet.tweetID) { | |
list.add(tweet); | |
} | |
} | |
} | |
} | |
return list; | |
} | |
List<Tweet> getTweets(followUserIDs, List<Tweet> tweets) { | |
var list = <Tweet>[]; | |
for (var followUserID in followUserIDs) { | |
for (var tweet in tweets) { | |
if (tweet.uid == followUserID) { | |
list.add(tweet); | |
} | |
} | |
} | |
return tweets; | |
} | |
List<String> getFollowUserIDs(List<Follow> follows, String uid) { | |
var followUserIDs = <String>[]; | |
for (var follow in follows) { | |
if (follow.from != uid) { | |
followUserIDs.add(follow.to); | |
} | |
} | |
return followUserIDs; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment