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/05/17 07:03:33 UTC
svn commit: r1744193 - in
/directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name:
Ava.java DnUtils.java FastDnParser.java Rdn.java
Author: elecharny
Date: Tue May 17 07:03:33 2016
New Revision: 1744193
URL: http://svn.apache.org/viewvc?rev=1744193&view=rev
Log:
Fixed some Sonar warnings
Modified:
directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Ava.java
directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/DnUtils.java
directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/FastDnParser.java
directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Rdn.java
Modified: directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Ava.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Ava.java?rev=1744193&r1=1744192&r2=1744193&view=diff
==============================================================================
--- directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Ava.java (original)
+++ directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Ava.java Tue May 17 07:03:33 2016
@@ -92,7 +92,7 @@ public class Ava implements Externalizab
private AttributeType attributeType;
/** the schema manager */
- private SchemaManager schemaManager;
+ private transient SchemaManager schemaManager;
/** The computed hashcode */
private volatile int h;
@@ -142,15 +142,15 @@ public class Ava implements Externalizab
{
if ( schemaManager != null )
{
- AttributeType attributeType = schemaManager.getAttributeType( ava.normType );
+ AttributeType attrType = schemaManager.getAttributeType( ava.normType );
- if ( attributeType != null )
+ if ( attrType != null )
{
- normType = attributeType.getOid();
+ normType = attrType.getOid();
try
{
- value = new Value( attributeType, ava.value );
+ value = new Value( attrType, ava.value );
}
catch ( LdapInvalidAttributeValueException e )
{
@@ -404,32 +404,31 @@ public class Ava implements Externalizab
this.upName = upName;
}
-
-
/**
- * Construct a schema aware Ava. The AttributeType and value will be checked accordingly
- * to the SchemaManager.
+ * Construct an Ava. The type and value are normalized :
+ * <li> the type is trimmed and lowercased </li>
+ * <li> the value is trimmed </li>
* <p>
- * Note that the upValue should <b>not</b> be null or empty, or resolve
+ * Note that the upValue should <b>not</b> be null or empty, or resolved
* to an empty string after having trimmed it.
*
- * @param schemaManager The SchemaManager instance
* @param upType The User Provided type
- * @param value The value
+ * @param normType The normalized type
+ * @param value The User Provided value
+ * @param upName The User Provided name (may be escaped)
*
* @throws LdapInvalidDnException If the given type or value are invalid
*/
- private void createAva( SchemaManager schemaManager, String upType, Value value )
+ // WARNING : The protection level is left unspecified intentionally.
+ // We need this method to be visible from the DnParser class, but not
+ // from outside this package.
+ /* Unspecified protection */Ava( String upType, String normType, Value value, String upName )
throws LdapInvalidDnException
{
- normType = attributeType.getOid();
- this.upType = upType;
- this.value = value;
- upName = this.upType + '=' + ( value == null ? "" : Rdn.escapeValue( value.getValue() ) );
- hashCode();
+ this( null, upType, normType, value, upName );
}
-
-
+
+
/**
* Construct an Ava. The type and value are normalized :
* <li> the type is trimmed and lowercased </li>
@@ -438,13 +437,21 @@ public class Ava implements Externalizab
* Note that the upValue should <b>not</b> be null or empty, or resolved
* to an empty string after having trimmed it.
*
+ * @param attributeType The AttributeType for this value
* @param upType The User Provided type
- * @param upValue The User Provided value
+ * @param normType The normalized type
+ * @param value The value
+ * @param upName The User Provided name (may be escaped)
*
* @throws LdapInvalidDnException If the given type or value are invalid
*/
- private void createAva( String upType, Value upValue ) throws LdapInvalidDnException
+ // WARNING : The protection level is left unspecified intentionally.
+ // We need this method to be visible from the DnParser class, but not
+ // from outside this package.
+ /* Unspecified protection */Ava( AttributeType attributeType, String upType, String normType, Value value, String upName )
+ throws LdapInvalidDnException
{
+ this.attributeType = attributeType;
String upTypeTrimmed = Strings.trim( upType );
String normTypeTrimmed = Strings.trim( normType );
@@ -473,12 +480,10 @@ public class Ava implements Externalizab
{
this.normType = Strings.lowerCaseAscii( normTypeTrimmed );
this.upType = upType;
-
}
- value = upValue;
-
- upName = getEscaped();
+ this.value = value;
+ this.upName = upName;
hashCode();
}
@@ -519,30 +524,29 @@ public class Ava implements Externalizab
/**
- * Construct an Ava. The type and value are normalized :
- * <li> the type is trimmed and lowercased </li>
- * <li> the value is trimmed </li>
+ * Construct a schema aware Ava. The AttributeType and value will be checked accordingly
+ * to the SchemaManager.
* <p>
- * Note that the upValue should <b>not</b> be null or empty, or resolved
+ * Note that the upValue should <b>not</b> be null or empty, or resolve
* to an empty string after having trimmed it.
*
+ * @param schemaManager The SchemaManager instance
* @param upType The User Provided type
- * @param normType The normalized type
- * @param value The User Provided value
- * @param upName The User Provided name (may be escaped)
+ * @param value The value
*
* @throws LdapInvalidDnException If the given type or value are invalid
*/
- // WARNING : The protection level is left unspecified intentionally.
- // We need this method to be visible from the DnParser class, but not
- // from outside this package.
- /* Unspecified protection */Ava( String upType, String normType, Value value, String upName )
+ private void createAva( SchemaManager schemaManager, String upType, Value value )
throws LdapInvalidDnException
{
- this( null, upType, normType, value, upName );
+ normType = attributeType.getOid();
+ this.upType = upType;
+ this.value = value;
+ upName = this.upType + '=' + ( value == null ? "" : Rdn.escapeValue( value.getValue() ) );
+ hashCode();
}
-
-
+
+
/**
* Construct an Ava. The type and value are normalized :
* <li> the type is trimmed and lowercased </li>
@@ -551,21 +555,13 @@ public class Ava implements Externalizab
* Note that the upValue should <b>not</b> be null or empty, or resolved
* to an empty string after having trimmed it.
*
- * @param attributeType The AttributeType for this value
* @param upType The User Provided type
- * @param normType The normalized type
- * @param value The value
- * @param upName The User Provided name (may be escaped)
+ * @param upValue The User Provided value
*
* @throws LdapInvalidDnException If the given type or value are invalid
*/
- // WARNING : The protection level is left unspecified intentionally.
- // We need this method to be visible from the DnParser class, but not
- // from outside this package.
- /* Unspecified protection */Ava( AttributeType attributeType, String upType, String normType, Value value, String upName )
- throws LdapInvalidDnException
+ private void createAva( String upType, Value upValue ) throws LdapInvalidDnException
{
- this.attributeType = attributeType;
String upTypeTrimmed = Strings.trim( upType );
String normTypeTrimmed = Strings.trim( normType );
@@ -594,10 +590,12 @@ public class Ava implements Externalizab
{
this.normType = Strings.lowerCaseAscii( normTypeTrimmed );
this.upType = upType;
+
}
- this.value = value;
- this.upName = upName;
+ value = upValue;
+
+ upName = getEscaped();
hashCode();
}
@@ -1404,6 +1402,7 @@ public class Ava implements Externalizab
*
* @return a clone of this object
*/
+ @Override
public Ava clone()
{
try
@@ -1426,6 +1425,7 @@ public class Ava implements Externalizab
* @see java.lang.Object#hashCode()
* @return The instance hash code
*/
+ @Override
public int hashCode()
{
if ( h == 0 )
@@ -1443,6 +1443,7 @@ public class Ava implements Externalizab
/**
* @see Object#equals(Object)
*/
+ @Override
public boolean equals( Object obj )
{
if ( this == obj )
@@ -1799,6 +1800,7 @@ public class Ava implements Externalizab
*
* @throws IoException If the Ava can't be written in the stream
*/
+ @Override
public void writeExternal( ObjectOutput out ) throws IOException
{
if ( Strings.isEmpty( upName )
@@ -1882,6 +1884,7 @@ public class Ava implements Externalizab
* @throws IOException If the Ava can't b written to the stream
* @throws ClassNotFoundException If we can't deserialize an Ava from the stream
*/
+ @Override
public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException
{
boolean hasUpName = in.readBoolean();
@@ -1959,7 +1962,7 @@ public class Ava implements Externalizab
private int compareValues( Ava that )
{
- int comp = 0;
+ int comp;
if ( value.isHumanReadable() )
{
@@ -1969,13 +1972,13 @@ public class Ava implements Externalizab
}
else
{
- byte[] bytes1 = ( byte[] ) value.getBytes();
- byte[] bytes2 = ( byte[] ) that.value.getBytes();
+ byte[] bytes1 = value.getBytes();
+ byte[] bytes2 = that.value.getBytes();
for ( int pos = 0; pos < bytes1.length; pos++ )
{
- int v1 = ( bytes1[pos] & 0x00FF );
- int v2 = ( bytes2[pos] & 0x00FF );
+ int v1 = bytes1[pos] & 0x00FF;
+ int v2 = bytes2[pos] & 0x00FF;
if ( v1 > v2 )
{
@@ -1996,6 +1999,7 @@ public class Ava implements Externalizab
/**
* @see Comparable#compareTo(Object)
*/
+ @Override
public int compareTo( Ava that )
{
if ( that == null )
@@ -2003,7 +2007,7 @@ public class Ava implements Externalizab
return 1;
}
- int comp = 0;
+ int comp;
if ( schemaManager == null )
{
@@ -2035,18 +2039,9 @@ public class Ava implements Externalizab
}
else
{
- if ( value instanceof Value )
- {
- comp = ( ( Value ) value ).compareTo( ( Value ) that.value );
+ comp = value.compareTo( ( Value ) that.value );
- return comp;
- }
- else
- {
- comp = ( ( Value ) value ).compareTo( ( Value ) that.value );
-
- return comp;
- }
+ return comp;
}
}
}
@@ -2108,6 +2103,7 @@ public class Ava implements Externalizab
*
* @return A string representing an Ava
*/
+ @Override
public String toString()
{
return upName;
Modified: directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/DnUtils.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/DnUtils.java?rev=1744193&r1=1744192&r2=1744193&view=diff
==============================================================================
--- directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/DnUtils.java (original)
+++ directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/DnUtils.java Tue May 17 07:03:33 2016
@@ -28,6 +28,14 @@ package org.apache.directory.api.ldap.mo
public final class DnUtils
{
/**
+ * a private constructor
+ */
+ private DnUtils()
+ {
+ }
+
+
+ /**
* Gets the attributeType of a RDN (the left part of the RDN). The RDN is supposed
* to contain only one AVA.
*
@@ -53,9 +61,4 @@ public final class DnUtils
int index = rdn.indexOf( '=' );
return rdn.substring( index + 1, rdn.length() );
}
-
-
- private DnUtils()
- {
- }
}
Modified: directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/FastDnParser.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/FastDnParser.java?rev=1744193&r1=1744192&r2=1744193&view=diff
==============================================================================
--- directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/FastDnParser.java (original)
+++ directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/FastDnParser.java Tue May 17 07:03:33 2016
@@ -486,7 +486,8 @@ import org.apache.directory.api.util.Pos
case '.':
inInnerLoop = false;
dotCount++;
- // no break!
+ break;
+
case '0':
case '1':
case '2':
@@ -561,7 +562,6 @@ import org.apache.directory.api.util.Pos
*/
private static String matchValue( char[] name, Position pos ) throws LdapInvalidDnException
{
- //StringBuilder value = new StringBuilder();
int start = pos.start;
int numTrailingSpaces = 0;
Modified: directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Rdn.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Rdn.java?rev=1744193&r1=1744192&r2=1744193&view=diff
==============================================================================
--- directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Rdn.java (original)
+++ directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Rdn.java Tue May 17 07:03:33 2016
@@ -138,13 +138,13 @@ public class Rdn implements Cloneable, E
* because we want the Avas to be sorted. An Ava may contain more than one
* value. In this case, the values are String stored in a List.
*/
- private List<Ava> avas = null;
+ private transient List<Ava> avas = null;
/**
* We also keep a set of types, in order to use manipulations. A type is
* connected with the Ava it represents.
*/
- private Map<String, List<Ava>> avaTypes;
+ private transient Map<String, List<Ava>> avaTypes;
/**
* We keep the type for a single valued Rdn, to avoid the creation of an HashMap
@@ -180,7 +180,7 @@ public class Rdn implements Cloneable, E
private boolean normalized = false;
/** the schema manager */
- private SchemaManager schemaManager;
+ private transient SchemaManager schemaManager;
/** The computed hashcode */
private volatile int h;
@@ -369,8 +369,8 @@ public class Rdn implements Cloneable, E
default:
// We must duplicate the treeSet and the hashMap
- avas = new ArrayList<Ava>();
- avaTypes = new HashMap<String, List<Ava>>();
+ avas = new ArrayList<>();
+ avaTypes = new HashMap<>();
for ( Ava currentAva : rdn.avas )
{
@@ -380,7 +380,7 @@ public class Rdn implements Cloneable, E
if ( avaList == null )
{
- avaList = new ArrayList<Ava>();
+ avaList = new ArrayList<>();
avaList.add( currentAva );
avaTypes.put( currentAva.getNormType(), avaList );
avas.add( currentAva );
@@ -430,8 +430,8 @@ public class Rdn implements Cloneable, E
default:
// We must duplicate the treeSet and the hashMap
- avas = new ArrayList<Ava>();
- avaTypes = new HashMap<String, List<Ava>>();
+ avas = new ArrayList<>();
+ avaTypes = new HashMap<>();
for ( Ava currentAva : rdn.avas )
{
@@ -446,7 +446,7 @@ public class Rdn implements Cloneable, E
if ( avaList == null )
{
- avaList = new ArrayList<Ava>();
+ avaList = new ArrayList<>();
avaList.add( tmpAva );
avaTypes.put( tmpAva.getNormType(), avaList );
avas.add( tmpAva );
@@ -481,7 +481,7 @@ public class Rdn implements Cloneable, E
private void addAVA( SchemaManager schemaManager, String type, Value value ) throws LdapInvalidDnException
{
// First, let's normalize the type
- AttributeType attributeType = null;
+ AttributeType attributeType;
String normalizedType = Strings.lowerCaseAscii( type );
this.schemaManager = schemaManager;
@@ -534,9 +534,9 @@ public class Rdn implements Cloneable, E
}
// First, create the List and the HashMap
- avas = new ArrayList<Ava>();
- avaTypes = new HashMap<String, List<Ava>>();
- List<Ava> avaList = new ArrayList<Ava>();
+ avas = new ArrayList<>();
+ avaTypes = new HashMap<>();
+ List<Ava> avaList = new ArrayList<>();
// and store the existing Ava into it.
avas.add( ava );
@@ -556,7 +556,7 @@ public class Rdn implements Cloneable, E
if ( avaList == null )
{
// Not present, we can add it
- avaList = new ArrayList<Ava>();
+ avaList = new ArrayList<>();
avaList.add( newAva );
avaTypes.put( newAva.getNormType(), avaList );
avas.add( newAva );
@@ -618,9 +618,9 @@ public class Rdn implements Cloneable, E
}
// First, create the List and the hashMap
- avas = new ArrayList<Ava>();
- avaTypes = new HashMap<String, List<Ava>>();
- List<Ava> avaList = new ArrayList<Ava>();
+ avas = new ArrayList<>();
+ avaTypes = new HashMap<>();
+ List<Ava> avaList = new ArrayList<>();
// and store the existing Ava into it.
avas.add( ava );
@@ -639,7 +639,7 @@ public class Rdn implements Cloneable, E
if ( avaList == null )
{
// Not present, we can add it
- avaList = new ArrayList<Ava>();
+ avaList = new ArrayList<>();
avaList.add( addedAva );
avaTypes.put( addedAva.getNormType(), avaList );
avas.add( addedAva );
@@ -798,6 +798,7 @@ public class Rdn implements Cloneable, E
*
* @return an iterator of the components of this Rdn, each an Ava
*/
+ @Override
public Iterator<Ava> iterator()
{
if ( nbAvas < 2 )
@@ -807,12 +808,14 @@ public class Rdn implements Cloneable, E
private boolean hasMoreElement = nbAvas == 1;
+ @Override
public boolean hasNext()
{
return hasMoreElement;
}
+ @Override
public Ava next()
{
Ava obj = ava;
@@ -821,6 +824,7 @@ public class Rdn implements Cloneable, E
}
+ @Override
public void remove()
{
// nothing to do
@@ -839,6 +843,7 @@ public class Rdn implements Cloneable, E
*
* @return A clone of the current Rdn
*/
+ @Override
public Rdn clone()
{
try
@@ -860,13 +865,13 @@ public class Rdn implements Cloneable, E
default:
// We must duplicate the treeSet and the hashMap
- rdn.avaTypes = new HashMap<String, List<Ava>>();
- rdn.avas = new ArrayList<Ava>();
+ rdn.avaTypes = new HashMap<>();
+ rdn.avas = new ArrayList<>();
for ( Ava currentAva : this.avas )
{
rdn.avas.add( currentAva.clone() );
- List<Ava> avaList = new ArrayList<Ava>();
+ List<Ava> avaList = new ArrayList<>();
for ( Ava elem : avaTypes.get( currentAva.getNormType() ) )
{
@@ -1182,7 +1187,7 @@ public class Rdn implements Cloneable, E
if ( Chars.isHex( chars, i ) )
{
isHex = true;
- pair = ( ( byte ) ( Hex.getHexValue( chars[i] ) << 4 ) );
+ pair = ( byte ) ( Hex.getHexValue( chars[i] ) << 4 );
}
break;
@@ -1398,7 +1403,7 @@ public class Rdn implements Cloneable, E
default:
boolean isFirst = true;
- for ( Ava ava : avas )
+ for ( Ava atav : avas )
{
if ( isFirst )
{
@@ -1409,7 +1414,7 @@ public class Rdn implements Cloneable, E
sb.append( '+' );
}
- sb.append( ava.getEscaped() );
+ sb.append( atav.getEscaped() );
}
break;
@@ -1536,6 +1541,7 @@ public class Rdn implements Cloneable, E
* @see java.lang.Object#hashCode()
* @return the instance's hash code
*/
+ @Override
public int hashCode()
{
if ( h == 0 )
@@ -1661,8 +1667,8 @@ public class Rdn implements Cloneable, E
break;
default:
- avas = new ArrayList<Ava>();
- avaTypes = new HashMap<String, List<Ava>>();
+ avas = new ArrayList<>();
+ avaTypes = new HashMap<>();
for ( int i = 0; i < nbAvas; i++ )
{
@@ -1674,7 +1680,7 @@ public class Rdn implements Cloneable, E
if ( avaList == null )
{
- avaList = new ArrayList<Ava>();
+ avaList = new ArrayList<>();
avaTypes.put( newAva.getNormType(), avaList );
}
@@ -1731,6 +1737,7 @@ public class Rdn implements Cloneable, E
* @param out The stream into which the serialized Rdn will be put
* @throws IOException If the stream can't be written
*/
+ @Override
public void writeExternal( ObjectOutput out ) throws IOException
{
out.writeInt( nbAvas );
@@ -1770,6 +1777,7 @@ public class Rdn implements Cloneable, E
* @throws IOException If we can't read from the input stream
* @throws ClassNotFoundException If we can't create a new Rdn
*/
+ @Override
public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException
{
// Read the Ava number
@@ -1792,8 +1800,8 @@ public class Rdn implements Cloneable, E
break;
default:
- avas = new ArrayList<Ava>();
- avaTypes = new HashMap<String, List<Ava>>();
+ avas = new ArrayList<>();
+ avaTypes = new HashMap<>();
for ( int i = 0; i < nbAvas; i++ )
{
@@ -1805,7 +1813,7 @@ public class Rdn implements Cloneable, E
if ( avaList == null )
{
- avaList = new ArrayList<Ava>();
+ avaList = new ArrayList<>();
avaTypes.put( newAva.getNormType(), avaList );
}
@@ -1829,6 +1837,7 @@ public class Rdn implements Cloneable, E
* @return a negative value if the current RDN is below the provided one, a positive value
* if it's above and 0 if they are equal.
*/
+ @Override
public int compareTo( Rdn otherRdn )
{
if ( otherRdn == null )
@@ -1891,11 +1900,11 @@ public class Rdn implements Cloneable, E
int pos = 0;
- for ( Ava ava : avas )
+ for ( Ava atav : avas )
{
Ava otherAva = otherRdn.avas.get( pos );
- comp = ava.compareTo( otherAva );
+ comp = atav.compareTo( otherAva );
if ( comp != 0 )
{
@@ -1921,6 +1930,7 @@ public class Rdn implements Cloneable, E
* @return a String representation of the Rdn. The caller will get back the user
* provided Rdn
*/
+ @Override
public String toString()
{
return upName == null ? "" : upName;