mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Jean-Noël Rouvignac
01.49.2016 dbd33f1beb763539ac3b21461765bc43b85f471c
Code cleanup

SchemaConfigManager.java:
Removed unnecessary null checks
Extracted toStrings() method
1 files modified
59 ■■■■■ changed files
opendj-server-legacy/src/main/java/org/opends/server/core/SchemaConfigManager.java 59 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/core/SchemaConfigManager.java
@@ -563,8 +563,6 @@
      String schemaFile, boolean failOnError, List<Attribute> ldapSyntaxList)
      throws ConfigException
  {
    if (ldapSyntaxList != null)
    {
      for (Attribute a : ldapSyntaxList)
      {
        for (ByteString v : a)
@@ -596,31 +594,21 @@
            }
            else
            {
              LocalizableMessage message = WARN_CONFIG_SCHEMA_CANNOT_PARSE_LDAP_SYNTAX.get(
                  schemaFile, de.getMessageObject());
            LocalizableMessage message =
                WARN_CONFIG_SCHEMA_CANNOT_PARSE_LDAP_SYNTAX.get(schemaFile, de.getMessageObject());
              reportError(failOnError, de, message);
            }
          }
        }
      }
    }
  }
  /** Parse the attribute type definitions if there are any. */
  private static void parseAttributeTypeDefinitions(
      Schema schema, String schemaFile, boolean failOnError, List<Attribute> attrList)
          throws ConfigException
  {
    if (attrList != null)
    {
      List<String> definitions = new ArrayList<>();
      for (Attribute a : attrList)
      {
        for (ByteString v : a)
        {
          definitions.add(v.toString());
        }
      }
    List<String> definitions = toStrings(attrList);
      try
      {
        schema.registerAttributeTypes(definitions, schemaFile, !failOnError);
@@ -652,23 +640,13 @@
        }
      }
    }
  }
  /** Parse the objectclass definitions if there are any. */
  private static void parseObjectclassDefinitions(Schema schema,
      String schemaFile, boolean failOnError, List<Attribute> ocList)
      throws ConfigException
  {
    if (ocList != null)
    {
      List<String> definitions = new ArrayList<>();
      for (Attribute a : ocList)
      {
        for (ByteString v : a)
        {
          definitions.add(v.toString());
        }
      }
    List<String> definitions = toStrings(ocList);
      try
      {
        schema.registerObjectClasses(definitions, schemaFile, !failOnError);
@@ -700,6 +678,18 @@
        }
      }
    }
  private static List<String> toStrings(List<Attribute> attributes)
  {
    List<String> results = new ArrayList<>();
    for (Attribute attr : attributes)
    {
      for (ByteString v : attr)
      {
        results.add(v.toString());
      }
    }
    return results;
  }
  /** Parse the name form definitions if there are any. */
@@ -707,8 +697,6 @@
      String schemaFile, boolean failOnError, List<Attribute> nfList)
      throws ConfigException
  {
    if (nfList != null)
    {
      for (Attribute a : nfList)
      {
        for (ByteString v : a)
@@ -740,15 +728,12 @@
        }
      }
    }
  }
  /** Parse the DIT content rule definitions if there are any. */
  private static void parseDITContentRuleDefinitions(Schema schema,
      String schemaFile, boolean failOnError, List<Attribute> dcrList)
      throws ConfigException
  {
    if (dcrList != null)
    {
      for (Attribute a : dcrList)
      {
        for (ByteString v : a)
@@ -777,7 +762,6 @@
        }
      }
    }
  }
  private static void reportError(boolean failOnError, Exception e,
      LocalizableMessage message) throws ConfigException
@@ -794,8 +778,6 @@
      String schemaFile, boolean failOnError, List<Attribute> dsrList)
      throws ConfigException
  {
    if (dsrList != null)
    {
      for (Attribute a : dsrList)
      {
        for (ByteString v : a)
@@ -827,15 +809,12 @@
        }
      }
    }
  }
  /** Parse the matching rule use definitions if there are any. */
  private static void parseMatchingRuleUseDefinitions(Schema schema,
      String schemaFile, boolean failOnError, List<Attribute> mruList)
      throws ConfigException
  {
    if (mruList != null)
    {
      for (Attribute a : mruList)
      {
        for (ByteString v : a)
@@ -843,9 +822,10 @@
          // Register it with the schema.  We will allow duplicates, with the
          // later definition overriding any earlier definition, but we want
          // to trap them and log a warning.
        String definition = v.toString();
          try
          {
            schema.registerMatchingRuleUse(v.toString(), schemaFile, failOnError);
          schema.registerMatchingRuleUse(definition, schemaFile, failOnError);
          }
          catch (DirectoryException de)
          {
@@ -855,7 +835,7 @@
            try
            {
              schema.registerMatchingRuleUse(v.toString(), schemaFile, true);
            schema.registerMatchingRuleUse(definition, schemaFile, true);
            }
            catch (Exception e)
            {
@@ -866,7 +846,6 @@
        }
      }
    }
  }
  /**
   * This method checks if a given attribute is an attribute that