From e1cd6c2bc4addf80537e31f929118ac8f908ea63 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Mon, 23 Mar 2015 14:51:59 +0000
Subject: [PATCH] AutoRefactored javadocs + simplified code in equals()

---
 opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/BinaryValue.java |  104 +++++++++++++++++++++++----------------------------
 1 files changed, 47 insertions(+), 57 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/BinaryValue.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/BinaryValue.java
index d3d2623..64835be 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/BinaryValue.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/BinaryValue.java
@@ -167,69 +167,59 @@
     return file;
   }
 
-  /**
-   * {@inheritDoc}
-   */
+  /** {@inheritDoc} */
   public boolean equals(Object o)
   {
-    boolean equals = false;
-    if (o != null)
+    if (this == o)
     {
-      equals = this == o;
-      if (!equals)
-      {
-        equals = o instanceof BinaryValue;
-        if (equals)
-        {
-          BinaryValue candidate = (BinaryValue)o;
-          equals = candidate.getType() == getType();
-          if (equals)
-          {
-            if (file == null)
-            {
-              equals = candidate.getFile() == null;
-            }
-            else if (candidate.getFile() != null)
-            {
-              equals = file.equals(candidate.getFile());
-            }
-            else
-            {
-              equals = false;
-            }
-          }
-          if (equals)
-          {
-            if (type == Type.BASE64_STRING)
-            {
-              equals = candidate.getBase64().equals(getBase64());
-            }
-            else
-            {
-              try
-              {
-                equals = candidate.getBytes().length == getBytes().length;
-                for (int i=0; i<getBytes().length && equals; i++)
-                {
-                  equals = bytes[i] == candidate.getBytes()[i];
-                }
-              }
-              catch (ParseException pe)
-              {
-                throw new RuntimeException(
-                    "Unexpected error getting bytes: "+pe, pe);
-              }
-            }
-          }
-        }
-      }
+      return true;
     }
-    return equals;
+    if (o instanceof BinaryValue)
+    {
+      BinaryValue candidate = (BinaryValue)o;
+      return candidate.getType() == getType()
+          && equal(file, candidate.getFile())
+          && bytesEqual(candidate);
+    }
+    return false;
   }
 
-  /**
-   * {@inheritDoc}
-   */
+  private boolean equal(File o1, File o2)
+  {
+    if (o1 == null)
+    {
+      return o2 == null;
+    }
+    return o1.equals(o2);
+  }
+
+  private boolean bytesEqual(BinaryValue candidate)
+  {
+    if (type == Type.BASE64_STRING)
+    {
+      return candidate.getBase64().equals(getBase64());
+    }
+
+    try
+    {
+      if (candidate.getBytes().length != getBytes().length) {
+        return false;
+      }
+      boolean equals = true;
+      for (int i=0; i<getBytes().length && equals; i++)
+      {
+        equals = bytes[i] == candidate.getBytes()[i];
+      }
+      return equals;
+    }
+    catch (ParseException pe)
+    {
+      throw new RuntimeException(
+          "Unexpected error getting bytes: "+pe, pe);
+    }
+  }
+
+  /** {@inheritDoc} */
   public int hashCode()
   {
     return hashCode;

--
Gitblit v1.10.0