You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2016/11/27 18:27:23 UTC

svn commit: r1771624 - in /directory/shared/branches/shared-value/ldap/extras/util/src/main/java/org/apache/directory/api/ldap/util: JndiUtils.java tree/DnNode.java

Author: elecharny
Date: Sun Nov 27 18:27:23 2016
New Revision: 1771624

URL: http://svn.apache.org/viewvc?rev=1771624&view=rev
Log:
Fixed Sonarlint warnings

Modified:
    directory/shared/branches/shared-value/ldap/extras/util/src/main/java/org/apache/directory/api/ldap/util/JndiUtils.java
    directory/shared/branches/shared-value/ldap/extras/util/src/main/java/org/apache/directory/api/ldap/util/tree/DnNode.java

Modified: directory/shared/branches/shared-value/ldap/extras/util/src/main/java/org/apache/directory/api/ldap/util/JndiUtils.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-value/ldap/extras/util/src/main/java/org/apache/directory/api/ldap/util/JndiUtils.java?rev=1771624&r1=1771623&r2=1771624&view=diff
==============================================================================
--- directory/shared/branches/shared-value/ldap/extras/util/src/main/java/org/apache/directory/api/ldap/util/JndiUtils.java (original)
+++ directory/shared/branches/shared-value/ldap/extras/util/src/main/java/org/apache/directory/api/ldap/util/JndiUtils.java Sun Nov 27 18:27:23 2016
@@ -162,17 +162,14 @@ public final class JndiUtils
             throw ( NamingException ) t;
         }
 
-        NamingException ne = null;
+        NamingException ne;
 
-        if ( t instanceof LdapAffectMultipleDsaException )
-        {
-            ne = new NamingException( t.getLocalizedMessage() );
-        }
-        else if ( t instanceof LdapAliasDereferencingException )
-        {
-            ne = new NamingException( t.getLocalizedMessage() );
-        }
-        else if ( t instanceof LdapAliasException )
+        if ( ( t instanceof LdapAffectMultipleDsaException )
+            || ( t instanceof LdapAliasDereferencingException )
+            || ( t instanceof LdapLoopDetectedException )
+            || ( t instanceof LdapAliasException ) 
+            || ( t instanceof LdapOperationErrorException ) 
+            || ( t instanceof LdapOtherException ) )
         {
             ne = new NamingException( t.getLocalizedMessage() );
         }
@@ -212,10 +209,6 @@ public final class JndiUtils
         {
             ne = new InvalidSearchFilterException( t.getLocalizedMessage() );
         }
-        else if ( t instanceof LdapLoopDetectedException )
-        {
-            ne = new NamingException( t.getLocalizedMessage() );
-        }
         else if ( t instanceof LdapNoPermissionException )
         {
             ne = new NoPermissionException( t.getLocalizedMessage() );
@@ -228,14 +221,6 @@ public final class JndiUtils
         {
             ne = new NameNotFoundException( t.getLocalizedMessage() );
         }
-        else if ( t instanceof LdapOperationErrorException )
-        {
-            ne = new NamingException( t.getLocalizedMessage() );
-        }
-        else if ( t instanceof LdapOtherException )
-        {
-            ne = new NamingException( t.getLocalizedMessage() );
-        }
         else if ( t instanceof LdapProtocolErrorException )
         {
             ne = new CommunicationException( t.getLocalizedMessage() );
@@ -285,9 +270,7 @@ public final class JndiUtils
     {
         try
         {
-            Name name = new LdapName( dn.toString() );
-
-            return name;
+            return new LdapName( dn.toString() );
         }
         catch ( InvalidNameException ine )
         {
@@ -308,9 +291,7 @@ public final class JndiUtils
     {
         try
         {
-            Dn dn = new Dn( name.toString() );
-
-            return dn;
+            return new Dn( name.toString() );
         }
         catch ( LdapInvalidDnException lide )
         {

Modified: directory/shared/branches/shared-value/ldap/extras/util/src/main/java/org/apache/directory/api/ldap/util/tree/DnNode.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-value/ldap/extras/util/src/main/java/org/apache/directory/api/ldap/util/tree/DnNode.java?rev=1771624&r1=1771623&r2=1771624&view=diff
==============================================================================
--- directory/shared/branches/shared-value/ldap/extras/util/src/main/java/org/apache/directory/api/ldap/util/tree/DnNode.java (original)
+++ directory/shared/branches/shared-value/ldap/extras/util/src/main/java/org/apache/directory/api/ldap/util/tree/DnNode.java Sun Nov 27 18:27:23 2016
@@ -47,7 +47,7 @@ import org.slf4j.LoggerFactory;
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @param <N> The type of node we store
  */
-public class DnNode<N> implements Cloneable
+public class DnNode<N>
 {
     /** The logger for this class */
     private static final Logger LOG = LoggerFactory.getLogger( DnNode.class );
@@ -72,6 +72,68 @@ public class DnNode<N> implements Clonea
 
 
     //-------------------------------------------------------------------------
+    // Constructors
+    //-------------------------------------------------------------------------
+    /**
+     * Creates a new instance of DnNode.
+     */
+    public DnNode()
+    {
+        children = new HashMap<>();
+        nodeDn = Dn.EMPTY_DN;
+        nodeRdn = Rdn.EMPTY_RDN;
+    }
+
+
+    /**
+     * Creates a new instance of DnNode.
+     *
+     * @param element the element to store
+     */
+    public DnNode( N element )
+    {
+        this.nodeElement = element;
+        children = new HashMap<>();
+    }
+
+
+    /**
+     * Creates a new instance of DnNode.
+     *
+     * @param dn the node's Dn
+     * @param element the element to store
+     */
+    public DnNode( Dn dn, N element )
+    {
+        if ( ( dn == null ) || ( dn.isEmpty() ) )
+        {
+            children = new HashMap<>();
+            this.nodeDn = Dn.EMPTY_DN;
+
+            return;
+        }
+
+        try
+        {
+            DnNode<N> rootNode = createNode( dn, element, dn.size() );
+
+            // Now copy back the created node into this
+            this.children = rootNode.children;
+            this.depth = rootNode.depth;
+            this.nodeDn = rootNode.nodeDn;
+            this.nodeElement = rootNode.nodeElement;
+            this.nodeRdn = rootNode.nodeRdn;
+            this.parent = null;
+        }
+        catch ( LdapException le )
+        {
+            // Special cas e: the Dn is empty, this is not allowed
+            throw new IllegalArgumentException( le.getMessage(), le );
+        }
+    }
+
+
+    //-------------------------------------------------------------------------
     // Helper methods
     //-------------------------------------------------------------------------
     /**
@@ -108,7 +170,7 @@ public class DnNode<N> implements Clonea
             if ( rootNode == null )
             {
                 // Create the new top node
-                DnNode<N> node = new DnNode<N>( element );
+                DnNode<N> node = new DnNode<>( element );
                 node.nodeRdn = rdn;
                 node.nodeDn = dn;
                 node.depth = dn.size() + depth;
@@ -117,7 +179,7 @@ public class DnNode<N> implements Clonea
             }
             else
             {
-                DnNode<N> node = new DnNode<N>();
+                DnNode<N> node = new DnNode<>();
                 node.nodeRdn = rdn;
                 node.nodeDn = rootNode.nodeDn.getParent();
                 node.depth = node.nodeDn.size() + depth;
@@ -142,68 +204,6 @@ public class DnNode<N> implements Clonea
     }
 
 
-    //-------------------------------------------------------------------------
-    // Constructors
-    //-------------------------------------------------------------------------
-    /**
-     * Creates a new instance of DnNode.
-     */
-    public DnNode()
-    {
-        children = new HashMap<String, DnNode<N>>();
-        nodeDn = Dn.EMPTY_DN;
-        nodeRdn = Rdn.EMPTY_RDN;
-    }
-
-
-    /**
-     * Creates a new instance of DnNode.
-     *
-     * @param element the element to store
-     */
-    public DnNode( N element )
-    {
-        this.nodeElement = element;
-        children = new HashMap<String, DnNode<N>>();
-    }
-
-
-    /**
-     * Creates a new instance of DnNode.
-     *
-     * @param dn the node's Dn
-     * @param element the element to store
-     */
-    public DnNode( Dn dn, N element )
-    {
-        if ( ( dn == null ) || ( dn.isEmpty() ) )
-        {
-            children = new HashMap<String, DnNode<N>>();
-            this.nodeDn = Dn.EMPTY_DN;
-
-            return;
-        }
-
-        try
-        {
-            DnNode<N> rootNode = createNode( dn, element, dn.size() );
-
-            // Now copy back the created node into this
-            this.children = rootNode.children;
-            this.depth = rootNode.depth;
-            this.nodeDn = rootNode.nodeDn;
-            this.nodeElement = rootNode.nodeElement;
-            this.nodeRdn = rootNode.nodeRdn;
-            this.parent = null;
-        }
-        catch ( LdapException le )
-        {
-            // Special cas e: the Dn is empty, this is not allowed
-            throw new IllegalArgumentException( le.getMessage(), le );
-        }
-    }
-
-
     /**
      * Tells if the implementation is a leaf node. If it's a branch node
      * then false is returned.
@@ -409,7 +409,7 @@ public class DnNode<N> implements Clonea
      */
     public synchronized List<N> getDescendantElements( Dn dn )
     {
-        List<N> descendants = new ArrayList<N>();
+        List<N> descendants = new ArrayList<>();
 
         DnNode<N> node = getNode( dn );
 
@@ -534,7 +534,7 @@ public class DnNode<N> implements Clonea
             }
         }
 
-        return ( parentNode != null );
+        return parentNode != null;
     }
 
 
@@ -968,28 +968,6 @@ public class DnNode<N> implements Clonea
     }
 
 
-    /**
-     * {@inheritDoc}
-     */
-    public synchronized DnNode<N> clone()
-    {
-        DnNode<N> clonedDnNode = new DnNode<N>();
-
-        clonedDnNode.nodeElement = nodeElement;
-        clonedDnNode.depth = depth;
-        clonedDnNode.parent = parent;
-        clonedDnNode.nodeRdn = nodeRdn;
-        clonedDnNode.nodeDn = nodeDn;
-
-        for ( DnNode<N> node : children.values() )
-        {
-            clonedDnNode.children.put( node.getRdn().getNormName(), node.clone() );
-        }
-
-        return clonedDnNode;
-    }
-
-
     private String toString( String tabs )
     {
         if ( nodeRdn == null )
@@ -1047,6 +1025,7 @@ public class DnNode<N> implements Clonea
     /**
      * {@inheritDoc}
      */
+    @Override
     public String toString()
     {
         return toString( "" );