From 79939daec3c4722257470383d928fd13bd93306d Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Tue, 28 Apr 2015 09:33:43 +0000
Subject: [PATCH] AutoRefactor'ed use diamond operator

---
 opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/NameForm.java       |   67 +++++++++-------------
 opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/DITContentRule.java |   80 +++++++++-----------------
 2 files changed, 56 insertions(+), 91 deletions(-)

diff --git a/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/DITContentRule.java b/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/DITContentRule.java
index 595056a..7f08834 100644
--- a/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/DITContentRule.java
+++ b/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/DITContentRule.java
@@ -24,15 +24,13 @@
  *      Copyright 2009 Sun Microsystems, Inc.
  *      Portions copyright 2011-2015 ForgeRock AS
  */
-
 package org.forgerock.opendj.ldap.schema;
 
+import static com.forgerock.opendj.ldap.CoreMessages.*;
 import static java.util.Arrays.*;
 
 import static org.forgerock.opendj.ldap.schema.SchemaUtils.*;
 
-import static com.forgerock.opendj.ldap.CoreMessages.*;
-
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
@@ -44,6 +42,7 @@
 import java.util.Set;
 
 import org.forgerock.i18n.LocalizableMessage;
+import org.forgerock.i18n.LocalizableMessageDescriptor.Arg2;
 import org.forgerock.util.Reject;
 
 /**
@@ -57,12 +56,12 @@
     /** A fluent API for incrementally constructing DIT content rule. */
     public static final class Builder extends SchemaElementBuilder<Builder> {
         private String structuralClassOID;
-        private final List<String> names = new LinkedList<String>();
+        private final List<String> names = new LinkedList<>();
         private boolean isObsolete;
-        private final Set<String> auxiliaryClassOIDs = new LinkedHashSet<String>();
-        private final Set<String> optionalAttributeOIDs = new LinkedHashSet<String>();
-        private final Set<String> prohibitedAttributeOIDs = new LinkedHashSet<String>();
-        private final Set<String> requiredAttributeOIDs = new LinkedHashSet<String>();
+        private final Set<String> auxiliaryClassOIDs = new LinkedHashSet<>();
+        private final Set<String> optionalAttributeOIDs = new LinkedHashSet<>();
+        private final Set<String> prohibitedAttributeOIDs = new LinkedHashSet<>();
+        private final Set<String> requiredAttributeOIDs = new LinkedHashSet<>();
 
         Builder(final DITContentRule contentRule, final SchemaBuilder schemaBuilder) {
             super(schemaBuilder, contentRule);
@@ -786,7 +785,7 @@
         }
 
         if (!auxiliaryClassOIDs.isEmpty()) {
-            auxiliaryClasses = new HashSet<ObjectClass>(auxiliaryClassOIDs.size());
+            auxiliaryClasses = new HashSet<>(auxiliaryClassOIDs.size());
             ObjectClass objectClass;
             for (final String oid : auxiliaryClassOIDs) {
                 try {
@@ -810,54 +809,18 @@
         }
 
         if (!requiredAttributeOIDs.isEmpty()) {
-            requiredAttributes = new HashSet<AttributeType>(requiredAttributeOIDs.size());
-            AttributeType attributeType;
-            for (final String oid : requiredAttributeOIDs) {
-                try {
-                    attributeType = schema.getAttributeType(oid);
-                } catch (final UnknownSchemaElementException e) {
-                    // This isn't good because it means that the DIT content rule
-                    // requires an attribute type that we don't know anything about.
-                    final LocalizableMessage message =
-                            ERR_ATTR_SYNTAX_DCR_UNKNOWN_REQUIRED_ATTR1.get(getNameOrOID(), oid);
-                    throw new SchemaException(message, e);
-                }
-                requiredAttributes.add(attributeType);
-            }
+            requiredAttributes =
+                getAttributeTypes(schema, requiredAttributeOIDs, ERR_ATTR_SYNTAX_DCR_UNKNOWN_REQUIRED_ATTR1);
         }
 
         if (!optionalAttributeOIDs.isEmpty()) {
-            optionalAttributes = new HashSet<AttributeType>(optionalAttributeOIDs.size());
-            AttributeType attributeType;
-            for (final String oid : optionalAttributeOIDs) {
-                try {
-                    attributeType = schema.getAttributeType(oid);
-                } catch (final UnknownSchemaElementException e) {
-                    // This isn't good because it means that the DIT content rule
-                    // requires an attribute type that we don't know anything about.
-                    final LocalizableMessage message =
-                            ERR_ATTR_SYNTAX_DCR_UNKNOWN_OPTIONAL_ATTR1.get(getNameOrOID(), oid);
-                    throw new SchemaException(message, e);
-                }
-                optionalAttributes.add(attributeType);
-            }
+            optionalAttributes =
+                getAttributeTypes(schema, optionalAttributeOIDs, ERR_ATTR_SYNTAX_DCR_UNKNOWN_OPTIONAL_ATTR1);
         }
 
         if (!prohibitedAttributeOIDs.isEmpty()) {
-            prohibitedAttributes = new HashSet<AttributeType>(prohibitedAttributeOIDs.size());
-            AttributeType attributeType;
-            for (final String oid : prohibitedAttributeOIDs) {
-                try {
-                    attributeType = schema.getAttributeType(oid);
-                } catch (final UnknownSchemaElementException e) {
-                    // This isn't good because it means that the DIT content rule
-                    // requires an attribute type that we don't know anything about.
-                    final LocalizableMessage message =
-                            ERR_ATTR_SYNTAX_DCR_UNKNOWN_PROHIBITED_ATTR1.get(getNameOrOID(), oid);
-                    throw new SchemaException(message, e);
-                }
-                prohibitedAttributes.add(attributeType);
-            }
+            prohibitedAttributes =
+                getAttributeTypes(schema, prohibitedAttributeOIDs, ERR_ATTR_SYNTAX_DCR_UNKNOWN_PROHIBITED_ATTR1);
         }
 
         // Make sure that none of the prohibited attributes is required by
@@ -885,4 +848,19 @@
         prohibitedAttributes = Collections.unmodifiableSet(prohibitedAttributes);
         requiredAttributes = Collections.unmodifiableSet(requiredAttributes);
     }
+
+    private Set<AttributeType> getAttributeTypes(final Schema schema, Set<String> oids, Arg2<Object, Object> errorMsg)
+            throws SchemaException {
+        Set<AttributeType> attrTypes = new HashSet<>(oids.size());
+        for (final String oid : oids) {
+            try {
+                attrTypes.add(schema.getAttributeType(oid));
+            } catch (final UnknownSchemaElementException e) {
+                // This isn't good because it means that the DIT content rule
+                // requires an attribute type that we don't know anything about.
+                throw new SchemaException(errorMsg.get(getNameOrOID(), oid), e);
+            }
+        }
+        return attrTypes;
+    }
 }
diff --git a/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/NameForm.java b/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/NameForm.java
index 4eec7ba..592eaf1 100644
--- a/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/NameForm.java
+++ b/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/NameForm.java
@@ -22,9 +22,8 @@
  *
  *
  *      Copyright 2009 Sun Microsystems, Inc.
- *      Portions copyright 2011-2013 ForgeRock AS
+ *      Portions copyright 2011-2015 ForgeRock AS
  */
-
 package org.forgerock.opendj.ldap.schema;
 
 import static com.forgerock.opendj.ldap.CoreMessages.ERR_ATTR_SYNTAX_NAME_FORM_STRUCTURAL_CLASS_NOT_STRUCTURAL1;
@@ -44,6 +43,7 @@
 import java.util.Set;
 
 import org.forgerock.i18n.LocalizableMessage;
+import org.forgerock.i18n.LocalizableMessageDescriptor.Arg2;
 
 /**
  * This class defines a data structure for storing and interacting with a name
@@ -55,10 +55,10 @@
     /** A fluent API for incrementally constructing name forms. */
     public static final class Builder extends SchemaElementBuilder<Builder> {
         private boolean isObsolete;
-        private final List<String> names = new LinkedList<String>();
+        private final List<String> names = new LinkedList<>();
         private String oid;
-        private final Set<String> optionalAttributes = new LinkedHashSet<String>();
-        private final Set<String> requiredAttributes = new LinkedHashSet<String>();
+        private final Set<String> optionalAttributes = new LinkedHashSet<>();
+        private final Set<String> requiredAttributes = new LinkedHashSet<>();
         private String structuralObjectClassOID;
 
         Builder(final NameForm nf, final SchemaBuilder builder) {
@@ -589,8 +589,7 @@
         }
     }
 
-    void validate(final Schema schema, final List<LocalizableMessage> warnings)
-            throws SchemaException {
+    void validate(final Schema schema, final List<LocalizableMessage> warnings) throws SchemaException {
         try {
             structuralClass = schema.getObjectClass(structuralClassOID);
         } catch (final UnknownSchemaElementException e) {
@@ -600,49 +599,37 @@
             throw new SchemaException(message, e);
         }
         if (structuralClass.getObjectClassType() != ObjectClassType.STRUCTURAL) {
-            // This is bad because the associated structural class type is not
-            // structural.
+            // This is bad because the associated structural class type is not structural.
             final LocalizableMessage message =
                     ERR_ATTR_SYNTAX_NAME_FORM_STRUCTURAL_CLASS_NOT_STRUCTURAL1.get(getNameOrOID(),
-                            structuralClass.getNameOrOID(), String.valueOf(structuralClass
-                                    .getObjectClassType()));
+                            structuralClass.getNameOrOID(), structuralClass.getObjectClassType());
             throw new SchemaException(message);
         }
 
-        requiredAttributes = new HashSet<AttributeType>(requiredAttributeOIDs.size());
-        AttributeType attributeType;
-        for (final String oid : requiredAttributeOIDs) {
-            try {
-                attributeType = schema.getAttributeType(oid);
-            } catch (final UnknownSchemaElementException e) {
-                // This isn't good because it means that the name form requires
-                // an attribute type that we don't know anything about.
-                final LocalizableMessage message =
-                        ERR_ATTR_SYNTAX_NAME_FORM_UNKNOWN_REQUIRED_ATTR1.get(getNameOrOID(), oid);
-                throw new SchemaException(message, e);
-            }
-            requiredAttributes.add(attributeType);
-        }
+        requiredAttributes =
+              getAttributeTypes(schema, requiredAttributeOIDs, ERR_ATTR_SYNTAX_NAME_FORM_UNKNOWN_REQUIRED_ATTR1);
 
         if (!optionalAttributeOIDs.isEmpty()) {
-            optionalAttributes = new HashSet<AttributeType>(optionalAttributeOIDs.size());
-            for (final String oid : optionalAttributeOIDs) {
-                try {
-                    attributeType = schema.getAttributeType(oid);
-                } catch (final UnknownSchemaElementException e) {
-                    // This isn't good because it means that the name form
-                    // requires an attribute type that we don't know anything
-                    // about.
-                    final LocalizableMessage message =
-                            ERR_ATTR_SYNTAX_NAME_FORM_UNKNOWN_OPTIONAL_ATTR1.get(getNameOrOID(),
-                                    oid);
-                    throw new SchemaException(message, e);
-                }
-                optionalAttributes.add(attributeType);
-            }
+            optionalAttributes =
+                    getAttributeTypes(schema, optionalAttributeOIDs, ERR_ATTR_SYNTAX_NAME_FORM_UNKNOWN_OPTIONAL_ATTR1);
         }
 
         optionalAttributes = Collections.unmodifiableSet(optionalAttributes);
         requiredAttributes = Collections.unmodifiableSet(requiredAttributes);
     }
+
+    private Set<AttributeType> getAttributeTypes(final Schema schema, Set<String> oids, Arg2<Object, Object> errorMsg)
+            throws SchemaException {
+        Set<AttributeType> attrTypes = new HashSet<>(oids.size());
+        for (final String oid : oids) {
+            try {
+                attrTypes.add(schema.getAttributeType(oid));
+            } catch (final UnknownSchemaElementException e) {
+                // This isn't good because it means that the name form requires
+                // an attribute type that we don't know anything about.
+                throw new SchemaException(errorMsg.get(getNameOrOID(), oid), e);
+            }
+        }
+        return attrTypes;
+    }
 }

--
Gitblit v1.10.0