aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/juick/util')
-rw-r--r--src/main/java/com/juick/util/DateFormatter.java1
-rw-r--r--src/main/java/com/juick/util/MessageUtils.java13
-rw-r--r--src/main/java/com/juick/util/PrettyTimeFormatter.java14
3 files changed, 11 insertions, 17 deletions
diff --git a/src/main/java/com/juick/util/DateFormatter.java b/src/main/java/com/juick/util/DateFormatter.java
index 8f569562..0a14f3dc 100644
--- a/src/main/java/com/juick/util/DateFormatter.java
+++ b/src/main/java/com/juick/util/DateFormatter.java
@@ -20,7 +20,6 @@ package com.juick.util;
import org.apache.commons.lang3.StringUtils;
import java.time.Instant;
-import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
diff --git a/src/main/java/com/juick/util/MessageUtils.java b/src/main/java/com/juick/util/MessageUtils.java
index 9b668b7c..b922d980 100644
--- a/src/main/java/com/juick/util/MessageUtils.java
+++ b/src/main/java/com/juick/util/MessageUtils.java
@@ -28,6 +28,7 @@ import org.springframework.web.util.UriComponentsBuilder;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -270,16 +271,12 @@ public class MessageUtils {
// TODO: check if it is really needed
public static String percentEncode(final String s) {
- String ret = StringUtils.EMPTY;
- try {
- ret = URLEncoder.encode(s, CharEncoding.UTF_8).replace("+", "%20").replace("*", "%2A").replace("%7E", "~");
- } catch (UnsupportedEncodingException e) {
- }
- return ret;
+ return URLEncoder.encode(s, StandardCharsets.UTF_8).replace("+", "%20")
+ .replace("*", "%2A").replace("%7E", "~");
}
public static String formatMarkdownText(final Message msg) {
- String s = StringUtils.defaultString(msg.getText()).replaceAll(replyNumberRegex, String.format("$1[/$2](https://juick.com/m/%d#$2)$3", msg.getMid()));
- return escapeMarkdown(s);
+ return StringUtils.defaultString(msg.getText())
+ .replaceAll(replyNumberRegex, String.format("$1[/$2](https://juick.com/m/%d#$2)$3", msg.getMid()));
}
public static String escapeMarkdown(final String s) {
return s.replace("_", "\\_").replace("*", "\\*")
diff --git a/src/main/java/com/juick/util/PrettyTimeFormatter.java b/src/main/java/com/juick/util/PrettyTimeFormatter.java
index 383f4d9a..792d185d 100644
--- a/src/main/java/com/juick/util/PrettyTimeFormatter.java
+++ b/src/main/java/com/juick/util/PrettyTimeFormatter.java
@@ -32,14 +32,12 @@ public class PrettyTimeFormatter {
// Cache PrettyTime per locale. LRU cache to prevent memory leak.
private static final Map<Locale, PrettyTime> PRETTY_TIME_LOCALE_MAP =
- new LinkedHashMap<Locale, PrettyTime>(MAX_CACHE_SIZE + 1, 1.1F, true)
- {
- @Override
- protected boolean removeEldestEntry(Map.Entry<Locale, PrettyTime> eldest)
- {
- return size() > MAX_CACHE_SIZE;
- }
- };
+ new LinkedHashMap<>(MAX_CACHE_SIZE + 1, 1.1F, true) {
+ @Override
+ protected boolean removeEldestEntry(Map.Entry<Locale, PrettyTime> eldest) {
+ return size() > MAX_CACHE_SIZE;
+ }
+ };
public String format(final Locale locale, final Date value)
{