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

Jean-Noel Rouvignac
16.36.2015 be124cd7df8df56616279461f01ef8baea150056
Use Objects.equals() throughout
12 files modified
232 ■■■■ changed files
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/BackendDescriptor.java 12 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/BinaryValue.java 12 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/ConnectionHandlersMonitoringTableModel.java 23 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/ObjectClassValue.java 12 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/pdb/PDBStorage.java 13 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/protocols/http/HTTPConnectionHandler.java 40 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/replication/common/DSInfo.java 12 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/replication/server/changelog/file/Record.java 11 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/replication/service/ReplicationBroker.java 13 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/ReplicationCliMain.java 12 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/util/StaticUtils.java 15 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/types/SearchFilterTests.java 57 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/BackendDescriptor.java
@@ -26,6 +26,7 @@
 */
package org.opends.guitools.controlpanel.datamodel;
import java.util.Objects;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
@@ -157,20 +158,11 @@
          && desc.getBaseDns().equals(getBaseDns())
          && desc.getIndexes().equals(getIndexes())
          && desc.getVLVIndexes().equals(getVLVIndexes())
          && equal(getMonitoringEntry(), desc.getMonitoringEntry());
          && Objects.equals(getMonitoringEntry(), desc.getMonitoringEntry());
    }
    return false;
  }
  private boolean equal(CustomSearchResult m1, CustomSearchResult m2)
  {
    if (m1 == null)
    {
      return m2 == null;
    }
    return m1.equals(m2);
  }
  /**
   * Returns the monitoring entry information.
   * @return the monitoring entry information.
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/BinaryValue.java
@@ -29,6 +29,7 @@
import java.io.File;
import java.text.ParseException;
import java.util.Objects;
import org.opends.server.util.Base64;
@@ -178,21 +179,12 @@
    {
      BinaryValue candidate = (BinaryValue)o;
      return candidate.getType() == getType()
          && equal(file, candidate.getFile())
          && Objects.equals(file, candidate.getFile())
          && bytesEqual(candidate);
    }
    return false;
  }
  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)
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/ConnectionHandlersMonitoringTableModel.java
@@ -29,6 +29,7 @@
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import org.forgerock.i18n.LocalizableMessage;
@@ -105,7 +106,7 @@
  private int compareNames(AddressConnectionHandlerDescriptor ach1,
      AddressConnectionHandlerDescriptor ach2)
  {
    if (equal(ach1.getAddress(), ach2.getAddress()))
    if (Objects.equals(ach1.getAddress(), ach2.getAddress()))
    {
      Integer port1 = Integer.valueOf(ach1.getConnectionHandler().getPort());
      Integer port2 = Integer.valueOf(ach2.getConnectionHandler().getPort());
@@ -114,24 +115,6 @@
    return getName(ach1).compareTo(getName(ach2));
  }
  /**
   * Returns whether two addresses are equal.
   *
   * @param address1
   *          the first address
   * @param address2
   *          the second address
   * @return true if both are equal, false otherwise
   */
  static boolean equal(InetAddress address1, InetAddress address2)
  {
    if (address1 != null)
    {
      return address1.equals(address2);
    }
    return address2 == null;
  }
  /** {@inheritDoc} */
  @Override
  protected CustomSearchResult getMonitoringEntry(
@@ -287,7 +270,7 @@
      return false;
    }
    AddressConnectionHandlerDescriptor ach = (AddressConnectionHandlerDescriptor) o;
    return ConnectionHandlersMonitoringTableModel.equal(getAddress(), ach.getAddress())
    return Objects.equals(getAddress(), ach.getAddress())
        && ach.getConnectionHandler().equals(getConnectionHandler());
  }
}
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/ObjectClassValue.java
@@ -26,6 +26,7 @@
 */
package org.opends.guitools.controlpanel.datamodel;
import java.util.Objects;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
@@ -95,18 +96,9 @@
    if (o instanceof ObjectClassValue)
    {
      ObjectClassValue oc = (ObjectClassValue)o;
      return equal(structural, oc.getStructural())
      return Objects.equals(structural, oc.getStructural())
          && auxiliary.equals(oc.getAuxiliary());
    }
    return false;
  }
  private boolean equal(String s1, String s2)
  {
    if (s1 == null)
    {
      return s2 == null;
    }
    return s1.equals(s2);
  }
}
opendj-server-legacy/src/main/java/org/opends/server/backends/pdb/PDBStorage.java
@@ -27,6 +27,7 @@
import static com.persistit.Transaction.CommitPolicy.*;
import static java.util.Arrays.*;
import static org.opends.messages.BackendMessages.*;
import static org.opends.messages.ConfigMessages.*;
import static org.opends.messages.UtilityMessages.*;
@@ -47,6 +48,7 @@
import java.util.ListIterator;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.ConcurrentLinkedDeque;
@@ -509,7 +511,7 @@
        ex.fetch();
        final ByteSequence oldValue = valueToBytes(ex.getValue());
        final ByteSequence newValue = f.computeNewValue(oldValue);
        if (!equals(newValue, oldValue))
        if (!Objects.equals(newValue, oldValue))
        {
          if (newValue == null)
          {
@@ -530,15 +532,6 @@
      }
    }
    private boolean equals(ByteSequence b1, ByteSequence b2)
    {
      if (b1 == null)
      {
        return b2 == null;
      }
      return b1.equals(b2);
    }
    private Exchange getExchangeFromCache(final TreeName treeName) throws PersistitException
    {
      Exchange exchange = exchanges.get(treeName);
opendj-server-legacy/src/main/java/org/opends/server/protocols/http/HTTPConnectionHandler.java
@@ -255,39 +255,21 @@
  private boolean anyChangeRequiresRestart(HTTPConnectionHandlerCfg newCfg)
  {
    return !equals(newCfg.getListenPort(), initConfig.getListenPort())
        || !equals(newCfg.getListenAddress(), initConfig.getListenAddress())
        || !equals(newCfg.getMaxRequestSize(), currentConfig
            .getMaxRequestSize())
        || !equals(newCfg.isAllowTCPReuseAddress(), currentConfig
            .isAllowTCPReuseAddress())
        || !equals(newCfg.isUseTCPKeepAlive(), currentConfig
            .isUseTCPKeepAlive())
        || !Objects.equals(newCfg.getListenAddress(), initConfig.getListenAddress())
        || !equals(newCfg.getMaxRequestSize(), currentConfig.getMaxRequestSize())
        || !equals(newCfg.isAllowTCPReuseAddress(), currentConfig.isAllowTCPReuseAddress())
        || !equals(newCfg.isUseTCPKeepAlive(), currentConfig.isUseTCPKeepAlive())
        || !equals(newCfg.isUseTCPNoDelay(), currentConfig.isUseTCPNoDelay())
        || !equals(newCfg.getMaxBlockedWriteTimeLimit(), currentConfig
            .getMaxBlockedWriteTimeLimit())
        || !equals(newCfg.getMaxBlockedWriteTimeLimit(), currentConfig.getMaxBlockedWriteTimeLimit())
        || !equals(newCfg.getBufferSize(), currentConfig.getBufferSize())
        || !equals(newCfg.getAcceptBacklog(), currentConfig.getAcceptBacklog())
        || !equals(newCfg.isUseSSL(), currentConfig.isUseSSL())
        || !equals(newCfg.getKeyManagerProviderDN(), currentConfig
            .getKeyManagerProviderDN())
        || !equals(newCfg.getSSLCertNickname(), currentConfig
            .getSSLCertNickname())
        || !equals(newCfg.getTrustManagerProviderDN(), currentConfig
            .getTrustManagerProviderDN())
        || !equals(newCfg.getSSLProtocol(), currentConfig.getSSLProtocol())
        || !equals(newCfg.getSSLCipherSuite(), currentConfig
            .getSSLCipherSuite())
        || !equals(newCfg.getSSLClientAuthPolicy(), currentConfig
            .getSSLClientAuthPolicy());
  }
  private boolean equals(Object o1, Object o2)
  {
    if (o1 == null)
    {
      return o2 == null;
    }
    return o1.equals(o2);
        || !Objects.equals(newCfg.getKeyManagerProviderDN(), currentConfig.getKeyManagerProviderDN())
        || !Objects.equals(newCfg.getSSLCertNickname(), currentConfig.getSSLCertNickname())
        || !Objects.equals(newCfg.getTrustManagerProviderDN(), currentConfig.getTrustManagerProviderDN())
        || !Objects.equals(newCfg.getSSLProtocol(), currentConfig.getSSLProtocol())
        || !Objects.equals(newCfg.getSSLCipherSuite(), currentConfig.getSSLCipherSuite())
        || !Objects.equals(newCfg.getSSLClientAuthPolicy(), currentConfig.getSSLClientAuthPolicy());
  }
  private boolean equals(long l1, long l2)
opendj-server-legacy/src/main/java/org/opends/server/replication/common/DSInfo.java
@@ -22,7 +22,7 @@
 *
 *
 *      Copyright 2008-2010 Sun Microsystems, Inc.
 *      Portions copyright 2011-2014 ForgeRock AS
 *      Portions copyright 2011-2015 ForgeRock AS
 */
package org.opends.server.replication.common;
@@ -38,7 +38,6 @@
 */
public final class DSInfo
{
  /** DS server id. */
  private final int dsId;
  /** DS server url. */
@@ -279,13 +278,8 @@
        && groupId == dsInfo.getGroupId()
        && protocolVersion == dsInfo.getProtocolVersion()
        && refUrls.equals(dsInfo.getRefUrls())
        && equals(eclIncludes, dsInfo.getEclIncludes())
        && equals(eclIncludesForDeletes, dsInfo.getEclIncludesForDeletes());
  }
  private boolean equals(Object o1, Object o2)
  {
    return o1 == null ? o2 == null : o1.equals(o2);
        && Objects.equals(eclIncludes, dsInfo.getEclIncludes())
        && Objects.equals(eclIncludesForDeletes, dsInfo.getEclIncludesForDeletes());
  }
  /**
opendj-server-legacy/src/main/java/org/opends/server/replication/server/changelog/file/Record.java
@@ -25,6 +25,8 @@
 */
package org.opends.server.replication.server.changelog.file;
import java.util.Objects;
/**
 * Represents a record, which is a pair of key-value.
 *
@@ -125,13 +127,8 @@
      return false;
    }
    Record<?, ?> other = (Record<?, ?>) that;
    return equals(key, other.key)
        && equals(value, other.value);
  }
  private boolean equals(Object o1, Object o2)
  {
    return o1 == null ? o2 == null : o1.equals(o2);
    return Objects.equals(key, other.key)
        && Objects.equals(value, other.value);
  }
  /** {@inheritDoc} */
opendj-server-legacy/src/main/java/org/opends/server/replication/service/ReplicationBroker.java
@@ -3116,24 +3116,19 @@
      }
      final Topology other = (Topology) obj;
      return rsServerId == other.rsServerId
          && equals(replicaInfos, other.replicaInfos)
          && equals(rsInfos, other.rsInfos)
          && Objects.equals(replicaInfos, other.replicaInfos)
          && Objects.equals(rsInfos, other.rsInfos)
          && urlsEqual1(replicaInfos, other.replicaInfos)
          && urlsEqual2(rsInfos, other.rsInfos);
    }
    private boolean equals(Object o1, Object o2)
    {
      return o1 == null ? o2 == null : o1.equals(o2);
    }
    private boolean urlsEqual1(Map<Integer, DSInfo> replicaInfos1,
        Map<Integer, DSInfo> replicaInfos2)
    {
      for (Entry<Integer, DSInfo> entry : replicaInfos1.entrySet())
      {
        DSInfo dsInfo = replicaInfos2.get(entry.getKey());
        if (!equals(entry.getValue().getDsUrl(), dsInfo.getDsUrl()))
        if (!Objects.equals(entry.getValue().getDsUrl(), dsInfo.getDsUrl()))
        {
          return false;
        }
@@ -3147,7 +3142,7 @@
      for (Entry<Integer, ReplicationServerInfo> entry : rsInfos1.entrySet())
      {
        ReplicationServerInfo rsInfo = rsInfos2.get(entry.getKey());
        if (!equals(entry.getValue().getServerURL(), rsInfo.getServerURL()))
        if (!Objects.equals(entry.getValue().getServerURL(), rsInfo.getServerURL()))
        {
          return false;
        }
opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/ReplicationCliMain.java
@@ -46,6 +46,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
@@ -8018,7 +8019,7 @@
  {
    for (ServerProperty prop : propertiesToCompare)
    {
      if (!equals(server1.get(prop), server2.get(prop)))
      if (!Objects.equals(server1.get(prop), server2.get(prop)))
      {
        return false;
      }
@@ -8026,15 +8027,6 @@
    return true;
  }
  private boolean equals(Object o1, Object o2)
  {
    if (o1 != null)
    {
      return o1.equals(o2);
    }
    return o2 == null;
  }
  /**
   * Tells whether we are trying to disable all the replicated suffixes.
   * @param uData the disable replication data provided by the user.
opendj-server-legacy/src/main/java/org/opends/server/util/StaticUtils.java
@@ -1540,21 +1540,6 @@
    return true;
  }
  /**
   * Return true if and only if o1 and o2 are both null or o1.equals(o2).
   *
   * @param o1 the first object to compare
   * @param o2 the second object to compare
   * @return true iff o1 and o2 are equal
   */
  public static boolean objectsAreEqual(Object o1, Object o2)
  {
    return Objects.equals(o1, o2);
  }
  /**
   * Retrieves the best human-readable message for the provided exception.  For
   * exceptions defined in the OpenDJ project, it will attempt to use the
opendj-server-legacy/src/test/java/org/opends/server/types/SearchFilterTests.java
@@ -46,7 +46,6 @@
import static java.util.Arrays.*;
import static org.opends.server.util.StaticUtils.*;
import static org.testng.Assert.*;
/**
@@ -500,55 +499,23 @@
    private String matchingRuleId;
    private boolean dnAttributes;
    public void validateFilterFields() throws AssertionError {
      if (!searchFilter.getFilterType().equals(filterType)) {
        throwUnequalError("filterTypes");
      }
      if (!searchFilter.getFilterComponents().equals(filterComponents)) {
        throwUnequalError("filterComponents");
      }
      if (!objectsAreEqual(searchFilter.getNotComponent(), notComponent)) {
        throwUnequalError("notComponent");
      }
      if (!objectsAreEqual(searchFilter.getAssertionValue(), assertionValue)) {
        throwUnequalError("assertionValue");
      }
      if (!objectsAreEqual(searchFilter.getAttributeType(), attributeType)) {
        throwUnequalError("attributeType");
      }
      if (!objectsAreEqual(searchFilter.getSubInitialElement(), subInitialElement)) {
        throwUnequalError("subInitial");
      }
      if (!objectsAreEqual(searchFilter.getSubAnyElements(), subAnyElements)) {
        throwUnequalError("subAny");
      }
      if (!objectsAreEqual(searchFilter.getSubFinalElement(), subFinalElement)) {
        throwUnequalError("subFinal");
      }
      if (!objectsAreEqual(searchFilter.getMatchingRuleID(), matchingRuleId)) {
        throwUnequalError("matchingRuleId");
      }
      if (searchFilter.getDNAttributes() != dnAttributes) {
        throwUnequalError("dnAttributes");
      }
      assertEquals(searchFilter.getFilterType(), filterType, errorMsg("filterTypes"));
      assertEquals(searchFilter.getFilterComponents(), filterComponents, errorMsg("filterComponents"));
      assertEquals(searchFilter.getNotComponent(), notComponent, "notComponent");
      assertEquals(searchFilter.getAssertionValue(), assertionValue, "assertionValue");
      assertEquals(searchFilter.getAttributeType(), attributeType, errorMsg("attributeType"));
      assertEquals(searchFilter.getSubInitialElement(), subInitialElement, errorMsg("subInitial"));
      assertEquals(searchFilter.getSubAnyElements(), subAnyElements, errorMsg("subAny"));
      assertEquals(searchFilter.getSubFinalElement(), subFinalElement, errorMsg("subFinal"));
      assertEquals(searchFilter.getMatchingRuleID(), matchingRuleId, errorMsg("matchingRuleId"));
      assertEquals(searchFilter.getDNAttributes(), dnAttributes, errorMsg("dnAttributes"));
    }
    private void throwUnequalError(String message) throws AssertionError {
      throw new AssertionError("Filter differs from what is expected '" + message + "' differ.\n" + toString());
    private String errorMsg(String message) {
      return "Filter differs from what is expected '" + message + "' differ.\n" + toString();
    }
    @Override
    public String toString() {
      return "FilterDescription: \n" +