commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject commons-compress git commit: [COMPRESS-368]
Date Wed, 16 Nov 2016 04:49:42 GMT
Repository: commons-compress
Updated Branches:
  refs/heads/master f965bc23b -> adf0f2a79


[COMPRESS-368] 

Allow compressor extensions through a standard JRE ServiceLoader.
Refactor commons code.

Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/adf0f2a7
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/adf0f2a7
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/adf0f2a7

Branch: refs/heads/master
Commit: adf0f2a79124e18577861996014e27098934a83b
Parents: f965bc2
Author: Gary Gregory <ggregory@apache.org>
Authored: Tue Nov 15 20:49:39 2016 -0800
Committer: Gary Gregory <ggregory@apache.org>
Committed: Tue Nov 15 20:49:39 2016 -0800

----------------------------------------------------------------------
 .../compressors/CompressorStreamFactory.java    | 10 ++--
 .../org/apache/commons/compress/utils/Sets.java | 48 ++++++++++++++++++++
 2 files changed, 51 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-compress/blob/adf0f2a7/src/main/java/org/apache/commons/compress/compressors/CompressorStreamFactory.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/compressors/CompressorStreamFactory.java
b/src/main/java/org/apache/commons/compress/compressors/CompressorStreamFactory.java
index 01139d9..e8b4385 100644
--- a/src/main/java/org/apache/commons/compress/compressors/CompressorStreamFactory.java
+++ b/src/main/java/org/apache/commons/compress/compressors/CompressorStreamFactory.java
@@ -25,7 +25,6 @@ import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.util.ArrayList;
 import java.util.Collections;
-import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Locale;
 import java.util.Set;
@@ -51,6 +50,7 @@ import org.apache.commons.compress.compressors.z.ZCompressorInputStream;
 import org.apache.commons.compress.utils.IOUtils;
 import org.apache.commons.compress.utils.Lists;
 import org.apache.commons.compress.utils.ServiceLoaderIterator;
+import org.apache.commons.compress.utils.Sets;
 
 /**
  * <p>
@@ -271,16 +271,12 @@ public class CompressorStreamFactory implements CompressorStreamProvider
{
 
     @Override
     public Set<String> getInputStreamCompressorNames() {
-        HashSet<String> set = new HashSet<>();
-        Collections.addAll(set, GZIP, BZIP2, XZ, LZMA, PACK200, SNAPPY_RAW, SNAPPY_FRAMED,
Z, DEFLATE);
-        return set;
+        return Sets.newHashSet(GZIP, BZIP2, XZ, LZMA, PACK200, SNAPPY_RAW, SNAPPY_FRAMED,
Z, DEFLATE);
     }
 
     @Override
     public Set<String> getOutputStreamCompressorNames() {
-        HashSet<String> set = new HashSet<>();
-        Collections.addAll(set, GZIP, BZIP2, XZ, PACK200, DEFLATE);
-        return set;
+        return Sets.newHashSet(GZIP, BZIP2, XZ, PACK200, DEFLATE);
     }
 
     private static Iterator<CompressorStreamProvider> serviceLoaderIterator() {

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/adf0f2a7/src/main/java/org/apache/commons/compress/utils/Sets.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/utils/Sets.java b/src/main/java/org/apache/commons/compress/utils/Sets.java
new file mode 100644
index 0000000..b8b8578
--- /dev/null
+++ b/src/main/java/org/apache/commons/compress/utils/Sets.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.commons.compress.utils;
+
+import java.util.Collections;
+import java.util.HashSet;
+
+/**
+ * Set utilities
+ *
+ * @since 1.13
+ */
+public class Sets {
+
+    private Sets() {
+        // Do not instantiate
+    }
+
+    /**
+     * Creates a new HashSet filled with the given elements
+     * 
+     * @param elements
+     *            the elements to fill the new set
+     * @return A new HasSet
+     */
+    public static <E> HashSet<E> newHashSet(@SuppressWarnings("unchecked") E...
elements) {
+        final HashSet<E> set = new HashSet<>(elements.length);
+        Collections.addAll(set, elements);
+        return set;
+    }
+}


Mime
View raw message