projects
/
Sone.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
6ddb4da
)
🎨 Use Kotlin arrow type instead of Predicate
author
David ‘Bombe’ Roden
<bombe@pterodactylus.net>
Sun, 28 Jun 2020 19:51:19 +0000
(21:51 +0200)
committer
David ‘Bombe’ Roden
<bombe@pterodactylus.net>
Sun, 28 Jun 2020 19:51:19 +0000
(21:51 +0200)
src/main/java/net/pterodactylus/sone/web/WebInterface.java
patch
|
blob
|
history
src/main/kotlin/net/pterodactylus/sone/notify/PostVisibilityFilter.kt
patch
|
blob
|
history
src/main/kotlin/net/pterodactylus/sone/notify/ReplyVisibilityFilter.kt
patch
|
blob
|
history
src/main/kotlin/net/pterodactylus/sone/web/pages/IndexPage.kt
patch
|
blob
|
history
src/test/kotlin/net/pterodactylus/sone/notify/DefaultPostVisibilityFilterTest.kt
patch
|
blob
|
history
src/test/kotlin/net/pterodactylus/sone/notify/ReplyVisibilityFilterTest.kt
patch
|
blob
|
history
src/test/kotlin/net/pterodactylus/sone/web/pages/IndexPageTest.kt
patch
|
blob
|
history
diff --git
a/src/main/java/net/pterodactylus/sone/web/WebInterface.java
b/src/main/java/net/pterodactylus/sone/web/WebInterface.java
index
69077ed
..
4650625
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/web/WebInterface.java
+++ b/
src/main/java/net/pterodactylus/sone/web/WebInterface.java
@@
-264,7
+264,7
@@
public class WebInterface implements SessionProvider {
.addAll(newPostNotification.getElements())
.addAll(localPostNotification.getElements())
.build();
.addAll(newPostNotification.getElements())
.addAll(localPostNotification.getElements())
.build();
- return allNewPosts.stream().filter(p
ostVisibilityFilter.isVisible(currentSone
)).collect(toSet());
+ return allNewPosts.stream().filter(p
-> postVisibilityFilter.isPostVisible(currentSone, p
)).collect(toSet());
}
@Nonnull
}
@Nonnull
@@
-273,7
+273,7
@@
public class WebInterface implements SessionProvider {
.addAll(newReplyNotification.getElements())
.addAll(localReplyNotification.getElements())
.build();
.addAll(newReplyNotification.getElements())
.addAll(localReplyNotification.getElements())
.build();
- return allNewReplies.stream().filter(r
eplyVisibilityFilter.isVisible(currentSone
)).collect(toSet());
+ return allNewReplies.stream().filter(r
-> replyVisibilityFilter.isReplyVisible(currentSone, r
)).collect(toSet());
}
//
}
//
diff --git
a/src/main/kotlin/net/pterodactylus/sone/notify/PostVisibilityFilter.kt
b/src/main/kotlin/net/pterodactylus/sone/notify/PostVisibilityFilter.kt
index
64df7b8
..
9230862
100644
(file)
--- a/
src/main/kotlin/net/pterodactylus/sone/notify/PostVisibilityFilter.kt
+++ b/
src/main/kotlin/net/pterodactylus/sone/notify/PostVisibilityFilter.kt
@@
-11,7
+11,7
@@
interface PostVisibilityFilter {
fun isPostVisible(sone: Sone?, post: Post): Boolean
@JvmDefault
fun isPostVisible(sone: Sone?, post: Post): Boolean
@JvmDefault
- fun isVisible(currentSone: Sone?)
: Predicate<Post?>
=
-
Predicate
{ p: Post? -> p != null && isPostVisible(currentSone, p) }
+ fun isVisible(currentSone: Sone?) =
+ { p: Post? -> p != null && isPostVisible(currentSone, p) }
}
}
diff --git
a/src/main/kotlin/net/pterodactylus/sone/notify/ReplyVisibilityFilter.kt
b/src/main/kotlin/net/pterodactylus/sone/notify/ReplyVisibilityFilter.kt
index
34018f6
..
785386a
100644
(file)
--- a/
src/main/kotlin/net/pterodactylus/sone/notify/ReplyVisibilityFilter.kt
+++ b/
src/main/kotlin/net/pterodactylus/sone/notify/ReplyVisibilityFilter.kt
@@
-11,7
+11,7
@@
interface ReplyVisibilityFilter {
fun isReplyVisible(sone: Sone?, reply: PostReply): Boolean
@JvmDefault
fun isReplyVisible(sone: Sone?, reply: PostReply): Boolean
@JvmDefault
- fun isVisible(currentSone: Sone?)
: Predicate<PostReply>
=
-
Predicate
{ reply: PostReply -> isReplyVisible(currentSone, reply) }
+ fun isVisible(currentSone: Sone?) =
+ { reply: PostReply -> isReplyVisible(currentSone, reply) }
}
}
diff --git
a/src/main/kotlin/net/pterodactylus/sone/web/pages/IndexPage.kt
b/src/main/kotlin/net/pterodactylus/sone/web/pages/IndexPage.kt
index
5e3f905
..
89d6b93
100644
(file)
--- a/
src/main/kotlin/net/pterodactylus/sone/web/pages/IndexPage.kt
+++ b/
src/main/kotlin/net/pterodactylus/sone/web/pages/IndexPage.kt
@@
-26,7
+26,7
@@
class IndexPage @Inject constructor(webInterface: WebInterface, loaders: Loaders
.flatMap { it.posts } +
soneRequest.core.getDirectedPosts(currentSone.id)
).distinct()
.flatMap { it.posts } +
soneRequest.core.getDirectedPosts(currentSone.id)
).distinct()
- .filter { postVisibilityFilter.isVisible(currentSone).
test
(it) }
+ .filter { postVisibilityFilter.isVisible(currentSone).
invoke
(it) }
.sortedByDescending { it.time }
.let { posts ->
posts.paginate(soneRequest.core.preferences.postsPerPage)
.sortedByDescending { it.time }
.let { posts ->
posts.paginate(soneRequest.core.preferences.postsPerPage)
diff --git
a/src/test/kotlin/net/pterodactylus/sone/notify/DefaultPostVisibilityFilterTest.kt
b/src/test/kotlin/net/pterodactylus/sone/notify/DefaultPostVisibilityFilterTest.kt
index
8a9a699
..
e49b6d4
100644
(file)
--- a/
src/test/kotlin/net/pterodactylus/sone/notify/DefaultPostVisibilityFilterTest.kt
+++ b/
src/test/kotlin/net/pterodactylus/sone/notify/DefaultPostVisibilityFilterTest.kt
@@
-111,13
+111,13
@@
class DefaultPostVisibilityFilterTest {
@Test
fun `predicate will correctly recognize visible post`() {
val post = createPost(sone = localSone)
@Test
fun `predicate will correctly recognize visible post`() {
val post = createPost(sone = localSone)
- assertThat(postVisibilityFilter.isVisible(null).
test
(post), equalTo(true))
+ assertThat(postVisibilityFilter.isVisible(null).
invoke
(post), equalTo(true))
}
@Test
fun `predicate will correctly recognize not visible post`() {
val post = createPost(loaded = false)
}
@Test
fun `predicate will correctly recognize not visible post`() {
val post = createPost(loaded = false)
- assertThat(postVisibilityFilter.isVisible(null).
test
(post), equalTo(false))
+ assertThat(postVisibilityFilter.isVisible(null).
invoke
(post), equalTo(false))
}
}
}
}
diff --git
a/src/test/kotlin/net/pterodactylus/sone/notify/ReplyVisibilityFilterTest.kt
b/src/test/kotlin/net/pterodactylus/sone/notify/ReplyVisibilityFilterTest.kt
index
e91bd42
..
b9f3595
100644
(file)
--- a/
src/test/kotlin/net/pterodactylus/sone/notify/ReplyVisibilityFilterTest.kt
+++ b/
src/test/kotlin/net/pterodactylus/sone/notify/ReplyVisibilityFilterTest.kt
@@
-52,13
+52,13
@@
class ReplyVisibilityFilterTest {
@Test
fun `predicate correctly recognizes visible reply`() {
val postReply = createPostReply(post = post)
@Test
fun `predicate correctly recognizes visible reply`() {
val postReply = createPostReply(post = post)
- assertThat(replyVisibilityFilter.isVisible(localSone).
test
(postReply), equalTo(true))
+ assertThat(replyVisibilityFilter.isVisible(localSone).
invoke
(postReply), equalTo(true))
}
@Test
fun `predicate correctly recognizes not visible reply`() {
val postReply = createPostReply(post = post, time = System.currentTimeMillis() + 100000)
}
@Test
fun `predicate correctly recognizes not visible reply`() {
val postReply = createPostReply(post = post, time = System.currentTimeMillis() + 100000)
- assertThat(replyVisibilityFilter.isVisible(localSone).
test
(postReply), equalTo(false))
+ assertThat(replyVisibilityFilter.isVisible(localSone).
invoke
(postReply), equalTo(false))
}
}
}
}
diff --git
a/src/test/kotlin/net/pterodactylus/sone/web/pages/IndexPageTest.kt
b/src/test/kotlin/net/pterodactylus/sone/web/pages/IndexPageTest.kt
index
8c86365
..
29f4a9c
100644
(file)
--- a/
src/test/kotlin/net/pterodactylus/sone/web/pages/IndexPageTest.kt
+++ b/
src/test/kotlin/net/pterodactylus/sone/web/pages/IndexPageTest.kt
@@
-40,7
+40,7
@@
class IndexPageTest : WebPageTest({ webInterface, loaders, templateRenderer -> I
@Before
fun setupPostVisibilityFilter() {
@Before
fun setupPostVisibilityFilter() {
- whenever(postVisibilityFilter.isVisible(ArgumentMatchers.eq(currentSone))).thenReturn
(Predicate<Post> { true })
+ whenever(postVisibilityFilter.isVisible(ArgumentMatchers.eq(currentSone))).thenReturn
{ true }
}
@Before
}
@Before
@@
-107,7
+107,7
@@
class IndexPageTest : WebPageTest({ webInterface, loaders, templateRenderer -> I
val followedPosts = listOf(createPost(2500, true), createPost(1500))
whenever(followedSone.posts).thenReturn(followedPosts)
whenever(currentSone.friends).thenReturn(listOf("followed1", "followed2"))
val followedPosts = listOf(createPost(2500, true), createPost(1500))
whenever(followedSone.posts).thenReturn(followedPosts)
whenever(currentSone.friends).thenReturn(listOf("followed1", "followed2"))
- whenever(postVisibilityFilter.isVisible(ArgumentMatchers.eq(currentSone))).thenReturn
(Predicate<Post> { (it?.time ?: 10000) < 2500 })
+ whenever(postVisibilityFilter.isVisible(ArgumentMatchers.eq(currentSone))).thenReturn
{ (it?.time ?: 10000) < 2500 }
addSone("followed1", followedSone)
page.processTemplate(freenetRequest, templateContext)
@Suppress("UNCHECKED_CAST")
addSone("followed1", followedSone)
page.processTemplate(freenetRequest, templateContext)
@Suppress("UNCHECKED_CAST")