From 8289a0b1097f02a99d62f4f7750e6b46a54a54fc Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 9 Feb 2024 16:02:43 +0300 Subject: Append IDEA code suggestions --- src/main/java/com/juick/www/api/Mastodon.java | 2 -- src/main/java/com/juick/www/api/SystemActivity.java | 2 +- src/main/java/com/juick/www/api/activity/Profile.java | 15 ++++++--------- .../java/com/juick/www/api/activity/model/Activity.java | 2 +- src/main/java/com/juick/www/filters/AnythingFilter.java | 1 - 5 files changed, 8 insertions(+), 14 deletions(-) (limited to 'src/main/java/com/juick/www') diff --git a/src/main/java/com/juick/www/api/Mastodon.java b/src/main/java/com/juick/www/api/Mastodon.java index eeca1fda..190ee5ef 100644 --- a/src/main/java/com/juick/www/api/Mastodon.java +++ b/src/main/java/com/juick/www/api/Mastodon.java @@ -182,8 +182,6 @@ public class Mastodon { public record Preferences() { } - ; - @GetMapping("/api/v1/preferences") public Preferences preferences() { return new Preferences(); diff --git a/src/main/java/com/juick/www/api/SystemActivity.java b/src/main/java/com/juick/www/api/SystemActivity.java index 59d5cc73..a75ef3b6 100644 --- a/src/main/java/com/juick/www/api/SystemActivity.java +++ b/src/main/java/com/juick/www/api/SystemActivity.java @@ -72,7 +72,7 @@ public class SystemActivity { follow } - private ActivityType type; + private final ActivityType type; private User from; private List to; private Message message; diff --git a/src/main/java/com/juick/www/api/activity/Profile.java b/src/main/java/com/juick/www/api/activity/Profile.java index aa8f0394..d815c9d6 100644 --- a/src/main/java/com/juick/www/api/activity/Profile.java +++ b/src/main/java/com/juick/www/api/activity/Profile.java @@ -190,7 +190,7 @@ public class Profile { UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUriString(baseUri); uriComponentsBuilder.path(String.format("/u/%s/followers", userName)); List followers = userService.getUserReaders(user.getUid()); - Stream followersPage = followers.stream().skip(20 * page).limit(20); + Stream followersPage = followers.stream().skip(20L * page).limit(20); OrderedCollectionPage result = new OrderedCollectionPage(); result.setId(ServletUriComponentsBuilder.fromCurrentRequestUri().toUriString()); @@ -234,7 +234,7 @@ public class Profile { UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUriString(baseUri); uriComponentsBuilder.path(String.format("/u/%s/following", userName)); List following = userService.getUserFriends(user.getUid()); - Stream followingPage = following.stream().skip(20 * page).limit(20); + Stream followingPage = following.stream().skip(20L * page).limit(20); OrderedCollectionPage result = new OrderedCollectionPage(); result.setId(ServletUriComponentsBuilder.fromCurrentRequestUri().toUriString()); @@ -268,7 +268,7 @@ public class Profile { } private String formatNote(Note note) { - String markdown = remarkConverter.convertFragment((String) note.getContent()); + String markdown = remarkConverter.convertFragment(note.getContent()); // combine note text with attachment urls return note.getAttachment() == null ? markdown : note.getAttachment().stream().map(attachment -> { @@ -289,8 +289,7 @@ public class Profile { if (context instanceof Activity activity) { if ((StringUtils.isNotEmpty(visitor.getUri().toString()) && visitor.getUri().equals(URI.create(activity.getActor()))) || !visitor.isAnonymous()) { - if (activity instanceof Follow) { - Follow followRequest = (Follow) activity; + if (activity instanceof Follow followRequest) { applicationEventPublisher.publishEvent(new FollowEvent(this, followRequest)); return new ResponseEntity<>(CommandResult.fromString("Follow request accepted"), HttpStatus.ACCEPTED); } @@ -309,8 +308,7 @@ public class Profile { } } if (activity instanceof Create) { - if (activity.getObject() instanceof Note) { - Note note = (Note) activity.getObject(); + if (activity.getObject() instanceof Note note) { URI noteId = URI.create(note.getId()); if (messagesService.replyExists(noteId)) { return new ResponseEntity<>(CommandResult.fromString("Reply already exists"), HttpStatus.OK); @@ -386,8 +384,7 @@ public class Profile { logger.info("{} update their profile", activity.getActor()); return new ResponseEntity<>(CommandResult.fromString("Update accepted"), HttpStatus.ACCEPTED); } - if (activity.getObject() instanceof Note) { - Note note = (Note) activity.getObject(); + if (activity.getObject() instanceof Note note) { logger.info("Got update to {}", note.getId()); if (activity.getActor().equals(note.getAttributedTo())) { Message reply = messagesService.getReplyByUri(note.getId()); diff --git a/src/main/java/com/juick/www/api/activity/model/Activity.java b/src/main/java/com/juick/www/api/activity/model/Activity.java index 7cc0b13f..427990c6 100644 --- a/src/main/java/com/juick/www/api/activity/model/Activity.java +++ b/src/main/java/com/juick/www/api/activity/model/Activity.java @@ -38,7 +38,7 @@ public abstract class Activity extends Context { public void setActor(String actor) { this.actor = actor; if (StringUtils.isEmpty(getId())) { - setId(String.format("%s#%s", this.actor, UUID.randomUUID().toString())); + setId(String.format("%s#%s", this.actor, UUID.randomUUID())); } } diff --git a/src/main/java/com/juick/www/filters/AnythingFilter.java b/src/main/java/com/juick/www/filters/AnythingFilter.java index ffd11b29..91422807 100644 --- a/src/main/java/com/juick/www/filters/AnythingFilter.java +++ b/src/main/java/com/juick/www/filters/AnythingFilter.java @@ -73,7 +73,6 @@ public class AnythingFilter extends OncePerRequestFilter { } } } - ; if (userService.getUsernames().stream().anyMatch(name -> name.equals(anything))) { servletResponse.sendRedirect("/" + anything + "/"); } else { -- cgit v1.2.3