[java-metadata-aggregator] branch main updated: Rework per SpotBugs to iterate over entries, not keys

Ian Young ian at iay.org.uk
Thu Apr 20 09:14:27 UTC 2023


This is an automated email from the git hooks/post-receive script.

iay pushed a commit to branch main
in repository java-metadata-aggregator.

View the commit online:
http://git.shibboleth.net/view/?p=java-metadata-aggregator.git;a=commit;h=943754a2177e807571a2f3deb568960e413a883a

The following commit(s) were added to refs/heads/main by this push:
     new 943754a  Rework per SpotBugs to iterate over entries, not keys
943754a is described below

commit 943754a2177e807571a2f3deb568960e413a883a
Author: Ian Young <ian at iay.org.uk>
AuthorDate: Thu Apr 20 10:13:32 2023 +0100

    Rework per SpotBugs to iterate over entries, not keys
    
    Also change some nullability annotations and simplify accordingly.
---
 .../metadata/dom/SimpleNamespaceContext.java       | 33 +++++++++-------------
 1 file changed, 13 insertions(+), 20 deletions(-)

diff --git a/mda-framework/src/main/java/net/shibboleth/metadata/dom/SimpleNamespaceContext.java b/mda-framework/src/main/java/net/shibboleth/metadata/dom/SimpleNamespaceContext.java
index 308e12e..30b3d69 100644
--- a/mda-framework/src/main/java/net/shibboleth/metadata/dom/SimpleNamespaceContext.java
+++ b/mda-framework/src/main/java/net/shibboleth/metadata/dom/SimpleNamespaceContext.java
@@ -26,13 +26,13 @@ import javax.annotation.Nullable;
 import javax.annotation.concurrent.ThreadSafe;
 import javax.xml.namespace.NamespaceContext;
 
-import net.shibboleth.shared.annotation.constraint.NullableElements;
-import net.shibboleth.shared.primitive.StringSupport;
-import net.shibboleth.shared.xml.XMLConstants;
-
 import com.google.common.collect.ImmutableBiMap;
 import com.google.common.collect.ImmutableBiMap.Builder;
 
+import net.shibboleth.shared.annotation.constraint.NonnullElements;
+import net.shibboleth.shared.primitive.StringSupport;
+import net.shibboleth.shared.xml.XMLConstants;
+
 /**
  * Simple implementation of {@link NamespaceContext} based on a map from prefix values to corresponding URIs. This
  * implementation only supports a single mapping for a given prefix, that is {@link #getPrefixes(String)} will always
@@ -56,23 +56,16 @@ public class SimpleNamespaceContext implements NamespaceContext {
      * 
      * @param prefixToUriMappings Maps prefix values to the corresponding namespace URIs.
      */
-    public SimpleNamespaceContext(@Nullable @NullableElements final Map<String, String> prefixToUriMappings) {
+    public SimpleNamespaceContext(final @Nonnull @NonnullElements Map<String, String> prefixToUriMappings) {
         final Builder<String,String> mappingBuilder = getMappingsBuilder();
 
-        if (prefixToUriMappings == null || prefixToUriMappings.isEmpty()) {
-            mappings = mappingBuilder.build();
-            return;
-        }
-
-        String trimmedPrefix;
-        String trimmedUri;
-        for (final String key : prefixToUriMappings.keySet()) {
-            trimmedPrefix = StringSupport.trimOrNull(key);
+        for (final var entry : prefixToUriMappings.entrySet()) {
+            final var trimmedPrefix = StringSupport.trimOrNull(entry.getKey());
             if (trimmedPrefix == null) {
                 continue;
             }
 
-            trimmedUri = StringSupport.trimOrNull(prefixToUriMappings.get(key));
+            final var trimmedUri = StringSupport.trimOrNull(entry.getValue());
             if (trimmedUri != null) {
                 mappingBuilder.put(trimmedPrefix, trimmedUri);
             }
@@ -81,8 +74,8 @@ public class SimpleNamespaceContext implements NamespaceContext {
         mappings = mappingBuilder.build();
     }
 
-    /** {@inheritDoc} */
-    @Nullable public String getNamespaceURI(final String prefix) {
+    @Override
+    public @Nullable String getNamespaceURI(final String prefix) {
         if (prefix == null) {
             throw new IllegalArgumentException("Prefix can not be null");
         }
@@ -94,8 +87,8 @@ public class SimpleNamespaceContext implements NamespaceContext {
         return uri;
     }
 
-    /** {@inheritDoc} */
-    @Nullable public String getPrefix(final String namespaceURI) {
+    @Override
+    public @Nullable String getPrefix(final String namespaceURI) {
         if (namespaceURI == null) {
             throw new IllegalArgumentException("Namespace URI can not be null");
         }
@@ -121,7 +114,7 @@ public class SimpleNamespaceContext implements NamespaceContext {
      * 
      * @return initial set of mappings
      */
-    @Nonnull private Builder<String, String> getMappingsBuilder(){
+    private @Nonnull Builder<String, String> getMappingsBuilder() {
         final Builder<String,String> mappingBuilder = new Builder<>();
         
         mappingBuilder.put(XMLConstants.XML_PREFIX, XMLConstants.XML_NS);

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list