From aa81c5f0063887acf2f91f162bc1abe123b57050 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Mon, 27 Apr 2015 12:30:34 +0000
Subject: [PATCH] AutoRefactor'ed use diamond operator

---
 opendj-config/src/main/java/org/forgerock/opendj/config/client/spi/Driver.java                   |   64 +++++++---------
 opendj-config/src/main/java/org/forgerock/opendj/config/LDAPProfile.java                         |   19 ++--
 opendj-config/src/main/java/org/forgerock/opendj/config/ManagedObjectDefinitionI18NResource.java |   38 ++++-----
 opendj-config/src/main/java/org/forgerock/opendj/config/dsconfig/HelpSubCommandHandler.java      |  100 +++++++++---------------
 4 files changed, 91 insertions(+), 130 deletions(-)

diff --git a/opendj-config/src/main/java/org/forgerock/opendj/config/LDAPProfile.java b/opendj-config/src/main/java/org/forgerock/opendj/config/LDAPProfile.java
index 52f18c1..92a1b66 100644
--- a/opendj-config/src/main/java/org/forgerock/opendj/config/LDAPProfile.java
+++ b/opendj-config/src/main/java/org/forgerock/opendj/config/LDAPProfile.java
@@ -22,8 +22,8 @@
  *
  *
  *      Copyright 2008-2009 Sun Microsystems, Inc.
+ *      Portions Copyright 2015 ForgeRock AS.
  */
-
 package org.forgerock.opendj.config;
 
 import java.util.Arrays;
@@ -50,9 +50,7 @@
      */
     public static abstract class Wrapper {
 
-        /**
-         * Default constructor.
-         */
+        /** Default constructor. */
         protected Wrapper() {
             // No implementation required.
         }
@@ -160,7 +158,7 @@
     }
 
     /** The list of profile wrappers. */
-    private final LinkedList<Wrapper> profiles = new LinkedList<Wrapper>();;
+    private final LinkedList<Wrapper> profiles = new LinkedList<>();
 
     /** The LDAP profile property table. */
     private final ManagedObjectDefinitionResource resource = ManagedObjectDefinitionResource.createForProfile("ldap");
@@ -295,15 +293,14 @@
      *             provided managed object definition could not be loaded.
      */
     public List<String> getObjectClasses(AbstractManagedObjectDefinition<?, ?> d) {
-        LinkedList<String> objectClasses = new LinkedList<String>();
-        Set<String> s = new HashSet<String>();
+        LinkedList<String> objectClasses = new LinkedList<>();
+        Set<String> s = new HashSet<>();
 
         // Add the object classes from the parent hierarchy.
         while (d != null) {
             String oc = getObjectClass(d);
-            if (!s.contains(oc)) {
+            if (s.add(oc)) {
                 objectClasses.addFirst(oc);
-                s.add(oc);
             }
             d = d.getParent();
         }
@@ -316,11 +313,11 @@
     }
 
     /**
-     * Get an LDAP RDN sequence associatied with a relation.
+     * Get an LDAP RDN sequence associated with a relation.
      *
      * @param r
      *            The relation.
-     * @return Returns the LDAP RDN sequence associatied with a relation.
+     * @return Returns the LDAP RDN sequence associated with a relation.
      * @throws MissingResourceException
      *             If the LDAP profile properties file associated with the
      *             provided managed object definition could not be loaded.
diff --git a/opendj-config/src/main/java/org/forgerock/opendj/config/ManagedObjectDefinitionI18NResource.java b/opendj-config/src/main/java/org/forgerock/opendj/config/ManagedObjectDefinitionI18NResource.java
index 557950f..75fe793 100644
--- a/opendj-config/src/main/java/org/forgerock/opendj/config/ManagedObjectDefinitionI18NResource.java
+++ b/opendj-config/src/main/java/org/forgerock/opendj/config/ManagedObjectDefinitionI18NResource.java
@@ -22,6 +22,7 @@
  *
  *
  *      Copyright 2008 Sun Microsystems, Inc.
+ *      Portions Copyright 2015 ForgeRock AS.
  */
 package org.forgerock.opendj.config;
 
@@ -42,8 +43,7 @@
 public final class ManagedObjectDefinitionI18NResource {
 
     /** Application-wide set of instances. */
-    private static final Map<String, ManagedObjectDefinitionI18NResource> INSTANCES =
-        new HashMap<String, ManagedObjectDefinitionI18NResource>();
+    private static final Map<String, ManagedObjectDefinitionI18NResource> INSTANCES = new HashMap<>();
 
     /**
      * Gets the internationalized resource instance which can be used to
@@ -80,14 +80,13 @@
     }
 
     /** Mapping from definition to locale-based resource bundle. */
-    private final Map<AbstractManagedObjectDefinition<?, ?>, Map<Locale, ResourceBundle>> resources;
+    private final Map<AbstractManagedObjectDefinition<?, ?>, Map<Locale, ResourceBundle>> resources = new HashMap<>();
 
     /** The resource name prefix. */
     private final String prefix;
 
     /** Private constructor. */
     private ManagedObjectDefinitionI18NResource(String prefix) {
-        this.resources = new HashMap<AbstractManagedObjectDefinition<?, ?>, Map<Locale, ResourceBundle>>();
         this.prefix = prefix;
     }
 
@@ -247,16 +246,8 @@
      */
     synchronized void setResourceBundle(AbstractManagedObjectDefinition<?, ?> d, Locale locale,
         ResourceBundle resoureBundle) {
-        // First get the locale-resource mapping, creating it if
-        // necessary.
-        Map<Locale, ResourceBundle> map = resources.get(d);
-        if (map == null) {
-            map = new HashMap<Locale, ResourceBundle>();
-            resources.put(d, map);
-        }
-
         // Add the resource bundle.
-        map.put(locale, resoureBundle);
+        getMapping(d).put(locale, resoureBundle);
     }
 
     /**
@@ -269,16 +260,9 @@
                 + "Top configuration definition");
         }
 
-        // First get the locale-resource mapping, creating it if
-        // necessary.
-        Map<Locale, ResourceBundle> map = resources.get(d);
-        if (map == null) {
-            map = new HashMap<Locale, ResourceBundle>();
-            resources.put(d, map);
-        }
+        Map<Locale, ResourceBundle> map = getMapping(d);
 
-        // Now get the resource based on the locale, loading it if
-        // necessary.
+        // Now get the resource based on the locale, loading it if necessary.
         ResourceBundle resourceBundle = map.get(locale);
         if (resourceBundle == null) {
             String baseName = prefix + "." + d.getClass().getName();
@@ -289,4 +273,14 @@
 
         return resourceBundle;
     }
+
+    private Map<Locale, ResourceBundle> getMapping(AbstractManagedObjectDefinition<?, ?> d) {
+        // First get the locale-resource mapping, creating it if necessary.
+        Map<Locale, ResourceBundle> map = resources.get(d);
+        if (map == null) {
+            map = new HashMap<>();
+            resources.put(d, map);
+        }
+        return map;
+    }
 }
diff --git a/opendj-config/src/main/java/org/forgerock/opendj/config/client/spi/Driver.java b/opendj-config/src/main/java/org/forgerock/opendj/config/client/spi/Driver.java
index b5ee6d0..43c0677 100644
--- a/opendj-config/src/main/java/org/forgerock/opendj/config/client/spi/Driver.java
+++ b/opendj-config/src/main/java/org/forgerock/opendj/config/client/spi/Driver.java
@@ -22,12 +22,11 @@
  *
  *
  *      Copyright 2008-2009 Sun Microsystems, Inc.
- *      Portions Copyright 2014 ForgeRock AS
+ *      Portions Copyright 2014-2015 ForgeRock AS
  */
 package org.forgerock.opendj.config.client.spi;
 
-import static org.forgerock.opendj.config.PropertyException.defaultBehaviorException;
-import static org.forgerock.opendj.config.PropertyException.propertyIsSingleValuedException;
+import static org.forgerock.opendj.config.PropertyException.*;
 
 import java.util.ArrayList;
 import java.util.Collection;
@@ -37,29 +36,28 @@
 import java.util.SortedSet;
 
 import org.forgerock.i18n.LocalizableMessage;
-import org.forgerock.opendj.server.config.client.RootCfgClient;
 import org.forgerock.opendj.config.AbsoluteInheritedDefaultBehaviorProvider;
 import org.forgerock.opendj.config.AbstractManagedObjectDefinition;
 import org.forgerock.opendj.config.AliasDefaultBehaviorProvider;
 import org.forgerock.opendj.config.Configuration;
 import org.forgerock.opendj.config.ConfigurationClient;
 import org.forgerock.opendj.config.Constraint;
-import org.forgerock.opendj.config.PropertyException;
 import org.forgerock.opendj.config.DefaultBehaviorProviderVisitor;
 import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider;
 import org.forgerock.opendj.config.DefinitionDecodingException;
+import org.forgerock.opendj.config.DefinitionDecodingException.Reason;
 import org.forgerock.opendj.config.InstantiableRelationDefinition;
 import org.forgerock.opendj.config.ManagedObjectNotFoundException;
 import org.forgerock.opendj.config.ManagedObjectPath;
 import org.forgerock.opendj.config.OptionalRelationDefinition;
 import org.forgerock.opendj.config.PropertyDefinition;
+import org.forgerock.opendj.config.PropertyException;
 import org.forgerock.opendj.config.PropertyNotFoundException;
 import org.forgerock.opendj.config.PropertyOption;
 import org.forgerock.opendj.config.RelationDefinition;
 import org.forgerock.opendj.config.RelativeInheritedDefaultBehaviorProvider;
 import org.forgerock.opendj.config.SetRelationDefinition;
 import org.forgerock.opendj.config.UndefinedDefaultBehaviorProvider;
-import org.forgerock.opendj.config.DefinitionDecodingException.Reason;
 import org.forgerock.opendj.config.client.ClientConstraintHandler;
 import org.forgerock.opendj.config.client.ManagedObject;
 import org.forgerock.opendj.config.client.ManagedObjectDecodingException;
@@ -67,6 +65,7 @@
 import org.forgerock.opendj.config.client.OperationRejectedException;
 import org.forgerock.opendj.config.client.OperationRejectedException.OperationType;
 import org.forgerock.opendj.ldap.LdapException;
+import org.forgerock.opendj.server.config.client.RootCfgClient;
 
 /**
  * An abstract management connection context driver which should form the basis
@@ -129,7 +128,7 @@
         @Override
         public Collection<T> visitDefined(DefinedDefaultBehaviorProvider<T> d, Void p) {
             Collection<String> stringValues = d.getDefaultValues();
-            List<T> values = new ArrayList<T>(stringValues.size());
+            List<T> values = new ArrayList<>(stringValues.size());
 
             for (String stringValue : stringValues) {
                 try {
@@ -217,17 +216,15 @@
                 if (isCreate && firstPath.equals(target)) {
                     // Recursively retrieve this property's default values.
                     Collection<T> tmp = find(target, pd2);
-                    Collection<T> values = new ArrayList<T>(tmp.size());
+                    Collection<T> values = new ArrayList<>(tmp.size());
                     for (T value : tmp) {
                         pd1.validateValue(value);
                         values.add(value);
                     }
                     return values;
                 } else {
-                    // FIXME: issue 2481 - this is broken if the referenced
-                    // property
-                    // inherits its defaults from the newly created managed
-                    // object.
+                    // FIXME: issue 2481 - this is broken if the referenced property
+                    // inherits its defaults from the newly created managed object.
                     return getPropertyValues(target, pd2);
                 }
             } catch (PropertyException e) {
@@ -243,18 +240,14 @@
                 throw PropertyException.defaultBehaviorException(pd1, e);
             }
         }
-    };
+    }
 
-    /**
-     * Creates a new abstract driver.
-     */
+    /** Creates a new abstract driver. */
     protected Driver() {
        // Do nothing.
     }
 
-    /**
-     * Closes any context associated with this management context driver.
-     */
+    /** Closes any context associated with this management context driver. */
     public void close() {
         // do nothing by default
     }
@@ -579,7 +572,7 @@
      */
     protected final <P> Collection<P> findDefaultValues(ManagedObjectPath<?, ?> p, PropertyDefinition<P> pd,
         boolean isCreate) {
-        DefaultValueFinder<P> v = new DefaultValueFinder<P>(p, isCreate);
+        DefaultValueFinder<P> v = new DefaultValueFinder<>(p, isCreate);
         return v.find(p, pd);
     }
 
@@ -632,22 +625,8 @@
         // The targeted managed object is guaranteed to exist, so enforce
         // any constraints.
         AbstractManagedObjectDefinition<?, ?> d = path.getManagedObjectDefinition();
-        List<LocalizableMessage> messages = new LinkedList<LocalizableMessage>();
-        boolean isAcceptable = true;
-
-        for (Constraint constraint : d.getAllConstraints()) {
-            for (ClientConstraintHandler handler : constraint.getClientConstraintHandlers()) {
-                ManagementContext context = getManagementContext();
-                if (!handler.isDeleteAcceptable(context, path, messages)) {
-                    isAcceptable = false;
-                }
-            }
-            if (!isAcceptable) {
-                break;
-            }
-        }
-
-        if (!isAcceptable) {
+        List<LocalizableMessage> messages = new LinkedList<>();
+        if (!isAcceptable(path, d, messages)) {
             throw new OperationRejectedException(OperationType.DELETE, d.getUserFriendlyName(), messages);
         }
 
@@ -655,4 +634,17 @@
         return true;
     }
 
+    private <C extends ConfigurationClient, S extends Configuration>
+    boolean isAcceptable(ManagedObjectPath<C, S> path, AbstractManagedObjectDefinition<?, ?> d,
+            List<LocalizableMessage> messages) throws LdapException {
+        for (Constraint constraint : d.getAllConstraints()) {
+            for (ClientConstraintHandler handler : constraint.getClientConstraintHandlers()) {
+                ManagementContext context = getManagementContext();
+                if (!handler.isDeleteAcceptable(context, path, messages)) {
+                    return false;
+                }
+            }
+        }
+        return true;
+    }
 }
diff --git a/opendj-config/src/main/java/org/forgerock/opendj/config/dsconfig/HelpSubCommandHandler.java b/opendj-config/src/main/java/org/forgerock/opendj/config/dsconfig/HelpSubCommandHandler.java
index 63bbb3c..ac2441c 100644
--- a/opendj-config/src/main/java/org/forgerock/opendj/config/dsconfig/HelpSubCommandHandler.java
+++ b/opendj-config/src/main/java/org/forgerock/opendj/config/dsconfig/HelpSubCommandHandler.java
@@ -22,7 +22,7 @@
  *
  *
  *      Copyright 2007-2008 Sun Microsystems, Inc.
- *      Portions Copyright 2011-2014 ForgeRock AS
+ *      Portions Copyright 2011-2015 ForgeRock AS
  */
 package org.forgerock.opendj.config.dsconfig;
 
@@ -81,9 +81,7 @@
  */
 final class HelpSubCommandHandler extends SubCommandHandler {
 
-    /**
-     * This class is used to print the default behavior of a property.
-     */
+    /** This class is used to print the default behavior of a property. */
     private static class DefaultBehaviorPrinter {
 
         /**
@@ -160,19 +158,15 @@
          * @return Returns the user-friendly description of a property's default behavior.
          */
         public <T> LocalizableMessage print(PropertyDefinition<T> pd) {
-            DefaultVisitor<T> v = new DefaultVisitor<T>();
+            DefaultVisitor<T> v = new DefaultVisitor<>();
             return pd.getDefaultBehaviorProvider().accept(v, pd);
         }
     }
 
-    /**
-     * This class is used to print detailed syntax information about a property.
-     */
+    /** This class is used to print detailed syntax information about a property. */
     private static class SyntaxPrinter {
 
-        /**
-         * The syntax printer visitor implementation.
-         */
+        /** The syntax printer visitor implementation. */
         private static final class Visitor extends PropertyDefinitionVisitor<Void, PrintStream> {
 
             /** Private constructor. */
@@ -609,11 +603,9 @@
     /**
      * A table listing all the available types of managed object indexed on their parent type.
      */
-    private final Map<String, Map<String, AbstractManagedObjectDefinition<?, ?>>> categoryMap;
+    private final Map<String, Map<String, AbstractManagedObjectDefinition<?, ?>>> categoryMap = new TreeMap<>();
 
-    /**
-     * The argument which should be used to display inherited properties.
-     */
+    /** The argument which should be used to display inherited properties. */
     private BooleanArgument inheritedModeArgument;
 
     /** The sub-command associated with this handler. */
@@ -622,7 +614,7 @@
     /**
      * A table listing all the available types of managed object indexed on their tag(s).
      */
-    private final Map<Tag, Map<String, AbstractManagedObjectDefinition<?, ?>>> tagMap;
+    private final Map<Tag, Map<String, AbstractManagedObjectDefinition<?, ?>>> tagMap = new HashMap<>();
 
     /**
      * The argument which should be used to specify the sub-type of managed object to be retrieved.
@@ -652,9 +644,6 @@
         // Register common arguments.
         registerPropertyNameArgument(this.subCommand);
 
-        this.categoryMap = new TreeMap<String, Map<String, AbstractManagedObjectDefinition<?, ?>>>();
-        this.tagMap = new HashMap<Tag, Map<String, AbstractManagedObjectDefinition<?, ?>>>();
-
         setCommandBuilderUseful(false);
     }
 
@@ -696,7 +685,7 @@
         // Get the sub-type mapping, creating it if necessary.
         Map<String, AbstractManagedObjectDefinition<?, ?>> subTypes = categoryMap.get(baseName);
         if (subTypes == null) {
-            subTypes = new TreeMap<String, AbstractManagedObjectDefinition<?, ?>>();
+            subTypes = new TreeMap<>();
             categoryMap.put(baseName, subTypes);
         }
 
@@ -706,7 +695,7 @@
         for (Tag tag : d.getAllTags()) {
             subTypes = tagMap.get(tag);
             if (subTypes == null) {
-                subTypes = new TreeMap<String, AbstractManagedObjectDefinition<?, ?>>();
+                subTypes = new TreeMap<>();
                 tagMap.put(tag, subTypes);
             }
             subTypes.put(typeName, d);
@@ -729,7 +718,7 @@
         // Update the command builder.
         updateCommandBuilderWithSubCommand();
 
-        List<AbstractManagedObjectDefinition<?, ?>> dlist = new LinkedList<AbstractManagedObjectDefinition<?, ?>>();
+        List<AbstractManagedObjectDefinition<?, ?>> dlist = new LinkedList<>();
         AbstractManagedObjectDefinition<?, ?> tmp = null;
 
         if (categoryName != null) {
@@ -881,18 +870,7 @@
                     continue;
                 }
 
-                Set<PropertyDefinition<?>> pds = new TreeSet<PropertyDefinition<?>>();
-                if (inheritedModeArgument.isPresent()) {
-                    pds.addAll(mod.getAllPropertyDefinitions());
-                } else {
-                    pds.addAll(mod.getPropertyDefinitions());
-
-                    // The list will still contain overridden properties.
-                    if (mod.getParent() != null) {
-                        pds.removeAll(mod.getParent().getAllPropertyDefinitions());
-                    }
-                }
-
+                Set<PropertyDefinition<?>> pds = getPropertyDefinitions(mod);
                 for (PropertyDefinition<?> pd : pds) {
                     if (pd.hasOption(PropertyOption.HIDDEN)) {
                         continue;
@@ -941,19 +919,8 @@
     private void displayVerbose(ConsoleApplication app, String categoryName, String typeName, Tag tag,
             Set<String> propertyNames) {
         // Construct line used to separate consecutive sections.
-        LocalizableMessageBuilder mb;
-
-        mb = new LocalizableMessageBuilder();
-        for (int i = 0; i < MAX_LINE_WIDTH; i++) {
-            mb.append('=');
-        }
-        LocalizableMessage c1 = mb.toMessage();
-
-        mb = new LocalizableMessageBuilder();
-        for (int i = 0; i < MAX_LINE_WIDTH; i++) {
-            mb.append('-');
-        }
-        LocalizableMessage c2 = mb.toMessage();
+        LocalizableMessage c1 = buildLine('=', MAX_LINE_WIDTH);
+        LocalizableMessage c2 = buildLine('-', MAX_LINE_WIDTH);
 
         // Display help for each managed object.
         boolean isFirstManagedObject = true;
@@ -989,17 +956,7 @@
                     continue;
                 }
 
-                Set<PropertyDefinition<?>> pds = new TreeSet<PropertyDefinition<?>>();
-                if (inheritedModeArgument.isPresent()) {
-                    pds.addAll(mod.getAllPropertyDefinitions());
-                } else {
-                    pds.addAll(mod.getPropertyDefinitions());
-
-                    // The list will still contain overridden properties.
-                    if (mod.getParent() != null) {
-                        pds.removeAll(mod.getParent().getAllPropertyDefinitions());
-                    }
-                }
+                Set<PropertyDefinition<?>> pds = getPropertyDefinitions(mod);
 
                 boolean isFirstProperty = true;
                 for (PropertyDefinition<?> pd : pds) {
@@ -1017,9 +974,7 @@
 
                     if (isFirstProperty) {
                         // User has requested properties relating to this managed
-                        // object definition, so display the summary of the
-                        // managed
-                        // object.
+                        // object definition, so display the summary of the managed object.
                         if (!isFirstManagedObject) {
                             app.println();
                             app.println(c1);
@@ -1049,4 +1004,27 @@
             }
         }
     }
+
+    private LocalizableMessage buildLine(char c, int length) {
+        LocalizableMessageBuilder mb = new LocalizableMessageBuilder();
+        for (int i = 0; i < length; i++) {
+            mb.append(c);
+        }
+        return mb.toMessage();
+    }
+
+    private Set<PropertyDefinition<?>> getPropertyDefinitions(AbstractManagedObjectDefinition<?, ?> mod) {
+        Set<PropertyDefinition<?>> pds = new TreeSet<>();
+        if (inheritedModeArgument.isPresent()) {
+            pds.addAll(mod.getAllPropertyDefinitions());
+        } else {
+            pds.addAll(mod.getPropertyDefinitions());
+
+            // The list will still contain overridden properties.
+            if (mod.getParent() != null) {
+                pds.removeAll(mod.getParent().getAllPropertyDefinitions());
+            }
+        }
+        return pds;
+    }
 }

--
Gitblit v1.10.0