[java-support] branch master updated: IDP-1647 Add helper method to deduplicate UnmodifiableMaps during construction
Rod Widdowson
rdw at steadingsoftware.com
Sun Jul 26 14:42:49 UTC 2020
This is an automated email from the git hooks/post-receive script.
rdw 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=64c8f923610ee001fc1564b8b62ba18b62f42d6e
The following commit(s) were added to refs/heads/master by this push:
new 64c8f92 IDP-1647 Add helper method to deduplicate UnmodifiableMaps during construction
64c8f92 is described below
commit 64c8f923610ee001fc1564b8b62ba18b62f42d6e
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Sun Jul 26 15:42:17 2020 +0100
IDP-1647 Add helper method to deduplicate UnmodifiableMaps during construction
https://issues.shibboleth.net/jira/browse/IDP-1647
---
.../java/support/collection/CollectionSupport.java | 58 ++++++++++++++++++++++
1 file changed, 58 insertions(+)
diff --git a/src/main/java/net/shibboleth/utilities/java/support/collection/CollectionSupport.java b/src/main/java/net/shibboleth/utilities/java/support/collection/CollectionSupport.java
new file mode 100644
index 0000000..13db57d
--- /dev/null
+++ b/src/main/java/net/shibboleth/utilities/java/support/collection/CollectionSupport.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements. See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID 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 net.shibboleth.utilities.java.support.collection;
+
+import java.util.function.BinaryOperator;
+import java.util.stream.Collectors;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Support functions for Collection and Map Management.
+ */
+public final class CollectionSupport {
+
+ /** logger. */
+ private static Logger log = LoggerFactory.getLogger(CollectionSupport.class);
+
+ /** Constructor. */
+ private CollectionSupport() {
+ }
+
+ /** Build something we can plug in into {@link
+ * Collectors#toMap(java.util.function.Function, java.util.function.Function, BinaryOperator)}.
+ * @param <T> the type we'll be looking at
+ * @param what What we are building (i.e. IdpUI)
+ * @param takeFirst do we want the first of the last to win.
+ * @return an appropriate {@link BinaryOperator}
+ */
+ public static <T> BinaryOperator<T> warningMergeFunction(final String what, final boolean takeFirst) {
+
+ return new BinaryOperator<>() {
+
+ public T apply(final T current, final T lookingAt) {
+ log.warn("Duplicate detected building {}", what);
+ log.debug("Values provided are {} and {} taking {}", current, lookingAt,
+ takeFirst ?"first":"last");
+ return takeFirst? current:lookingAt ;
+ }
+
+ };
+ }
+}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list