[java-support] branch master updated: More Guava cleanup.
Scott Cantor
cantor.2 at osu.edu
Thu Nov 14 20:43:47 EST 2019
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch master
in repository java-support.
View the commit online:
http://git.shibboleth.net/view/?p=java-support.git;a=commit;h=10dadc9a4148bebfb58312cff39efa126e0d50f1
The following commit(s) were added to refs/heads/master by this push:
new 10dadc9 More Guava cleanup.
10dadc9 is described below
commit 10dadc9a4148bebfb58312cff39efa126e0d50f1
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Thu Nov 14 20:43:42 2019 -0500
More Guava cleanup.
---
.../httpclient/TLSSocketFactoryBuilder.java | 8 +++---
.../java/support/net/HttpServletSupport.java | 3 +--
.../java/support/net/MediaTypeSupport.java | 9 +------
.../java/support/net/MediaTypeSupportTest.java | 31 +++++++++++-----------
4 files changed, 21 insertions(+), 30 deletions(-)
diff --git a/src/main/java/net/shibboleth/utilities/java/support/httpclient/TLSSocketFactoryBuilder.java b/src/main/java/net/shibboleth/utilities/java/support/httpclient/TLSSocketFactoryBuilder.java
index f7ebd17..5a1ee18 100644
--- a/src/main/java/net/shibboleth/utilities/java/support/httpclient/TLSSocketFactoryBuilder.java
+++ b/src/main/java/net/shibboleth/utilities/java/support/httpclient/TLSSocketFactoryBuilder.java
@@ -23,6 +23,7 @@ import java.security.NoSuchProviderException;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.List;
+import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@@ -34,9 +35,6 @@ import net.shibboleth.utilities.java.support.primitive.StringSupport;
import org.apache.http.conn.ssl.X509HostnameVerifier;
-import com.google.common.base.Predicates;
-import com.google.common.collect.Collections2;
-
/**
* A builder for instances of {@link TLSSocketFactory} which allows easy specification
* of the full range of supported factory inputs.
@@ -146,7 +144,7 @@ public class TLSSocketFactoryBuilder {
if (managers == null) {
keyManagers = null;
} else {
- keyManagers = new ArrayList<>(Collections2.filter(managers, Predicates.notNull()));
+ keyManagers = managers.stream().filter(m -> m != null).collect(Collectors.toList());
if (keyManagers.isEmpty()) {
keyManagers = null;
}
@@ -176,7 +174,7 @@ public class TLSSocketFactoryBuilder {
if (managers == null) {
trustManagers = null;
} else {
- trustManagers = new ArrayList<>(Collections2.filter(managers, Predicates.notNull()));
+ trustManagers = managers.stream().filter(m -> m != null).collect(Collectors.toList());
if (trustManagers.isEmpty()) {
trustManagers = null;
}
diff --git a/src/main/java/net/shibboleth/utilities/java/support/net/HttpServletSupport.java b/src/main/java/net/shibboleth/utilities/java/support/net/HttpServletSupport.java
index 7b90ea1..6bf32f7 100644
--- a/src/main/java/net/shibboleth/utilities/java/support/net/HttpServletSupport.java
+++ b/src/main/java/net/shibboleth/utilities/java/support/net/HttpServletSupport.java
@@ -28,7 +28,6 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.google.common.annotations.Beta;
-import com.google.common.collect.ImmutableList;
import com.google.common.net.MediaType;
import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElements;
@@ -154,7 +153,7 @@ public final class HttpServletSupport {
if (languages == null) {
return Collections.EMPTY_LIST;
}
- return ImmutableList.copyOf(LanguageRange.parse(languages));
+ return List.copyOf(LanguageRange.parse(languages));
}
}
\ No newline at end of file
diff --git a/src/main/java/net/shibboleth/utilities/java/support/net/MediaTypeSupport.java b/src/main/java/net/shibboleth/utilities/java/support/net/MediaTypeSupport.java
index d029828..5d4f68b 100644
--- a/src/main/java/net/shibboleth/utilities/java/support/net/MediaTypeSupport.java
+++ b/src/main/java/net/shibboleth/utilities/java/support/net/MediaTypeSupport.java
@@ -17,12 +17,9 @@
package net.shibboleth.utilities.java.support.net;
-import java.util.HashSet;
import java.util.Set;
import java.util.function.Function;
-import com.google.common.base.Predicates;
-import com.google.common.collect.Collections2;
import com.google.common.net.MediaType;
import net.shibboleth.utilities.java.support.primitive.StringSupport;
@@ -80,11 +77,7 @@ public final class MediaTypeSupport {
}
final MediaType mediaType = MediaType.parse(contentTypeValue).withoutParameters();
- final Set<MediaType> validTypesWithoutParameters = new HashSet<>();
- validTypesWithoutParameters.addAll(Collections2.filter(
- Collections2.transform(validTypes, STRIP_PARAMS::apply),
- Predicates.notNull()));
- return validTypesWithoutParameters.contains(mediaType);
+ return validTypes.stream().map(STRIP_PARAMS).filter(t -> t != null).anyMatch(mediaType::equals);
}
return noContentTypeIsValid;
diff --git a/src/test/java/net/shibboleth/utilities/java/support/net/MediaTypeSupportTest.java b/src/test/java/net/shibboleth/utilities/java/support/net/MediaTypeSupportTest.java
index 30cfa3a..d21694a 100644
--- a/src/test/java/net/shibboleth/utilities/java/support/net/MediaTypeSupportTest.java
+++ b/src/test/java/net/shibboleth/utilities/java/support/net/MediaTypeSupportTest.java
@@ -17,10 +17,11 @@
package net.shibboleth.utilities.java.support.net;
+import java.util.Set;
+
import org.testng.Assert;
import org.testng.annotations.Test;
-import com.google.common.collect.Sets;
import com.google.common.net.MediaType;
/**
@@ -33,12 +34,12 @@ public class MediaTypeSupportTest {
// No Content-type
Assert.assertTrue(MediaTypeSupport.validateContentType(contentType,
- Sets.newHashSet(MediaType.XML_UTF_8),
+ Set.of(MediaType.XML_UTF_8),
true,
false));
Assert.assertFalse(MediaTypeSupport.validateContentType(contentType,
- Sets.newHashSet(MediaType.XML_UTF_8),
+ Set.of(MediaType.XML_UTF_8),
false,
false));
@@ -46,32 +47,32 @@ public class MediaTypeSupportTest {
contentType = "text/xml; charset=utf-8";
Assert.assertFalse(MediaTypeSupport.validateContentType(contentType,
- Sets.newHashSet(MediaType.create("application", "foobar")),
+ Set.of(MediaType.create("application", "foobar")),
true,
false));
Assert.assertTrue(MediaTypeSupport.validateContentType(contentType,
- Sets.newHashSet(MediaType.XML_UTF_8, MediaType.create("application", "foobar")),
+ Set.of(MediaType.XML_UTF_8, MediaType.create("application", "foobar")),
true,
false));
Assert.assertTrue(MediaTypeSupport.validateContentType(contentType,
- Sets.newHashSet(MediaType.XML_UTF_8, MediaType.create("application", "foobar")),
+ Set.of(MediaType.XML_UTF_8, MediaType.create("application", "foobar")),
true,
true));
Assert.assertTrue(MediaTypeSupport.validateContentType(contentType,
- Sets.newHashSet(MediaType.XML_UTF_8.withoutParameters(), MediaType.create("application", "foobar")),
+ Set.of(MediaType.XML_UTF_8.withoutParameters(), MediaType.create("application", "foobar")),
true,
true));
Assert.assertTrue(MediaTypeSupport.validateContentType(contentType,
- Sets.newHashSet(MediaType.ANY_TEXT_TYPE, MediaType.create("application", "foobar")),
+ Set.of(MediaType.ANY_TEXT_TYPE, MediaType.create("application", "foobar")),
true,
true));
Assert.assertTrue(MediaTypeSupport.validateContentType(contentType,
- Sets.newHashSet(MediaType.ANY_TYPE, MediaType.create("application", "foobar")),
+ Set.of(MediaType.ANY_TYPE, MediaType.create("application", "foobar")),
true,
true));
@@ -79,33 +80,33 @@ public class MediaTypeSupportTest {
contentType = "text/xml";
Assert.assertFalse(MediaTypeSupport.validateContentType(contentType,
- Sets.newHashSet(MediaType.create("application", "foobar")),
+ Set.of(MediaType.create("application", "foobar")),
true,
false));
Assert.assertTrue(MediaTypeSupport.validateContentType(contentType,
- Sets.newHashSet(MediaType.XML_UTF_8, MediaType.create("application", "foobar")),
+ Set.of(MediaType.XML_UTF_8, MediaType.create("application", "foobar")),
true,
false));
// Not valid, because the text/xml valid type includes parameters
Assert.assertFalse(MediaTypeSupport.validateContentType(contentType,
- Sets.newHashSet(MediaType.XML_UTF_8, MediaType.create("application", "foobar")),
+ Set.of(MediaType.XML_UTF_8, MediaType.create("application", "foobar")),
true,
true));
Assert.assertTrue(MediaTypeSupport.validateContentType(contentType,
- Sets.newHashSet(MediaType.XML_UTF_8.withoutParameters(), MediaType.create("application", "foobar")),
+ Set.of(MediaType.XML_UTF_8.withoutParameters(), MediaType.create("application", "foobar")),
true,
true));
Assert.assertTrue(MediaTypeSupport.validateContentType(contentType,
- Sets.newHashSet(MediaType.ANY_TEXT_TYPE, MediaType.create("application", "foobar")),
+ Set.of(MediaType.ANY_TEXT_TYPE, MediaType.create("application", "foobar")),
true,
true));
Assert.assertTrue(MediaTypeSupport.validateContentType(contentType,
- Sets.newHashSet(MediaType.ANY_TYPE, MediaType.create("application", "foobar")),
+ Set.of(MediaType.ANY_TYPE, MediaType.create("application", "foobar")),
true,
true));
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list