You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ma...@apache.org on 2019/11/12 21:37:26 UTC
[james-project] 04/15: [Refactoring] initiliazed available charset
names with a stream pipeline
This is an automated email from the ASF dual-hosted git repository.
matthieu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 3033780d8741145bd5b35498ffb8cc7cbdc41a1e
Author: Matthieu Baechler <ma...@apache.org>
AuthorDate: Thu Nov 7 22:07:26 2019 +0100
[Refactoring] initiliazed available charset names with a stream pipeline
---
.../apache/james/imap/api/display/CharsetUtil.java | 32 ++++++++--------------
1 file changed, 12 insertions(+), 20 deletions(-)
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/api/display/CharsetUtil.java b/protocols/imap/src/main/java/org/apache/james/imap/api/display/CharsetUtil.java
index c001c6f..8f47d62 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/api/display/CharsetUtil.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/api/display/CharsetUtil.java
@@ -20,11 +20,11 @@ package org.apache.james.imap.api.display;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
-import java.util.Collections;
-import java.util.HashSet;
import java.util.Set;
+import java.util.stream.Stream;
import com.beetstra.jutf7.CharsetProvider;
+import com.github.steveash.guavate.Guavate;
/**
* Utility class which can be used to get a list of supported {@link Charset}'s
@@ -33,31 +33,23 @@ import com.beetstra.jutf7.CharsetProvider;
*/
public class CharsetUtil {
- private static final Set<String> charsetNames;
+ private static final Set<String> CHARSET_NAMES =
+ Charset.availableCharsets()
+ .values()
+ .stream()
+ .flatMap(charset -> Stream.concat(
+ Stream.of(charset.name()),
+ charset.aliases().stream()))
+ .collect(Guavate.toImmutableSet());
+
private static final String X_MODIFIED_UTF_7 = "X-MODIFIED-UTF-7";
private static final Charset X_MODIFIED_UTF_7_CHARSET = new CharsetProvider().charsetForName(X_MODIFIED_UTF_7);
-
- // build the sets which holds the charsets and names
- static {
- Set<String> cNames = new HashSet<>();
-
- for (Charset charset : Charset.availableCharsets().values()) {
- final Set<String> aliases = charset.aliases();
- cNames.add(charset.name());
- cNames.addAll(aliases);
- }
-
- charsetNames = Collections.unmodifiableSet(cNames);
- }
-
/**
* Return an unmodifiable {@link Set} which holds the names (and aliases) of all supported Charsets
- *
- * @return supportedCharsetNames
*/
public static final Set<String> getAvailableCharsetNames() {
- return charsetNames;
+ return CHARSET_NAMES;
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org