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

Jean-Noël Rouvignac
06.48.2016 00e59615c33ec795efd9ac0758d56c54a42dbbdc
opendj-server-legacy/src/main/java/org/opends/server/types/Entry.java
@@ -16,6 +16,15 @@
 */
package org.opends.server.types;
import static org.forgerock.opendj.ldap.ResultCode.*;
import static org.opends.messages.CoreMessages.*;
import static org.opends.messages.UtilityMessages.*;
import static org.opends.server.core.DirectoryServer.*;
import static org.opends.server.util.CollectionUtils.*;
import static org.opends.server.util.LDIFWriter.*;
import static org.opends.server.util.ServerConstants.*;
import static org.opends.server.util.StaticUtils.*;
import java.io.BufferedWriter;
import java.io.IOException;
import java.util.ArrayList;
@@ -65,15 +74,6 @@
import org.opends.server.util.LDIFException;
import org.opends.server.util.LDIFWriter;
import static org.forgerock.opendj.ldap.ResultCode.*;
import static org.opends.messages.CoreMessages.*;
import static org.opends.messages.UtilityMessages.*;
import static org.opends.server.core.DirectoryServer.*;
import static org.opends.server.util.CollectionUtils.*;
import static org.opends.server.util.LDIFWriter.*;
import static org.opends.server.util.ServerConstants.*;
import static org.opends.server.util.StaticUtils.*;
/**
 * This class defines a data structure for a Directory Server entry.
 * It includes a DN and a set of attributes.
@@ -773,7 +773,7 @@
   *          attribute type is not present in this entry with the
   *          provided set of options.
   */
  public List<Attribute> getAllAttributes(AttributeDescription attributeDescription)
  public Iterable<Attribute> getAllAttributes(AttributeDescription attributeDescription)
  {
    AttributeType attributeType = attributeDescription.getAttributeType();
opendj-server-legacy/src/main/java/org/opends/server/types/SearchFilter.java
@@ -18,6 +18,7 @@
package org.opends.server.types;
import static org.opends.messages.CoreMessages.*;
import static org.opends.server.util.CollectionUtils.*;
import static org.opends.server.util.ServerConstants.*;
import static org.opends.server.util.StaticUtils.*;
@@ -2569,8 +2570,8 @@
    }
    // See if the entry has an attribute with the requested type.
    List<Attribute> attrs = entry.getAllAttributes(attributeDescription);
    if (attrs.isEmpty())
    Iterable<Attribute> attrs = entry.getAllAttributes(attributeDescription);
    if (isEmpty(attrs))
    {
      if (logger.isTraceEnabled())
      {
@@ -2673,8 +2674,8 @@
    }
    // See if the entry has an attribute with the requested type.
    List<Attribute> attrs = entry.getAllAttributes(attributeDescription);
    if (attrs.isEmpty())
    Iterable<Attribute> attrs = entry.getAllAttributes(attributeDescription);
    if (isEmpty(attrs))
    {
      if (logger.isTraceEnabled())
      {
@@ -2774,8 +2775,8 @@
    }
    // See if the entry has an attribute with the requested type.
    List<Attribute> attrs = entry.getAllAttributes(attributeDescription);
    if (attrs.isEmpty())
    Iterable<Attribute> attrs = entry.getAllAttributes(attributeDescription);
    if (isEmpty(attrs))
    {
      if (logger.isTraceEnabled())
      {
@@ -2872,8 +2873,8 @@
    }
    // See if the entry has an attribute with the requested type.
    List<Attribute> attrs = entry.getAllAttributes(attributeDescription);
    if (attrs.isEmpty())
    Iterable<Attribute> attrs = entry.getAllAttributes(attributeDescription);
    if (isEmpty(attrs))
    {
      if (logger.isTraceEnabled())
      {
@@ -3015,8 +3016,8 @@
    }
    // See if the entry has an attribute with the requested type.
    List<Attribute> attrs = entry.getAllAttributes(attributeDescription);
    if (attrs.isEmpty())
    Iterable<Attribute> attrs = entry.getAllAttributes(attributeDescription);
    if (isEmpty(attrs))
    {
      if (logger.isTraceEnabled())
      {
opendj-server-legacy/src/main/java/org/opends/server/util/CollectionUtils.java
@@ -125,4 +125,16 @@
    }
    return outputCollection;
  }
  /**
   * Returns whether the provided iterable is empty, i.e. whether it has not elements.
   *
   * @param iterable
   *          the iterable for which to omake the determination
   * @return {@code true} if the iterable is empty, {@code false} otherwise.
   */
  public static boolean isEmpty(Iterable<?> iterable)
  {
    return !iterable.iterator().hasNext();
  }
}
opendj-server-legacy/src/main/java/org/opends/server/workflowelement/localbackend/LocalBackendCompareOperation.java
@@ -16,7 +16,13 @@
 */
package org.opends.server.workflowelement.localbackend;
import java.util.List;
import static org.opends.messages.CoreMessages.*;
import static org.opends.server.core.DirectoryServer.*;
import static org.opends.server.types.AbstractOperation.*;
import static org.opends.server.util.CollectionUtils.*;
import static org.opends.server.util.ServerConstants.*;
import static org.opends.server.workflowelement.localbackend.LocalBackendWorkflowElement.*;
import java.util.concurrent.atomic.AtomicBoolean;
import org.forgerock.i18n.LocalizableMessage;
@@ -46,12 +52,6 @@
import org.opends.server.types.operation.PostResponseCompareOperation;
import org.opends.server.types.operation.PreOperationCompareOperation;
import static org.opends.messages.CoreMessages.*;
import static org.opends.server.core.DirectoryServer.*;
import static org.opends.server.types.AbstractOperation.*;
import static org.opends.server.util.ServerConstants.*;
import static org.opends.server.workflowelement.localbackend.LocalBackendWorkflowElement.*;
/**
 * This class defines an operation that may be used to determine whether a
 * specified entry in the Directory Server contains a given attribute-value pair.
@@ -233,8 +233,8 @@
      // Actually perform the compare operation.
      AttributeDescription attrDesc = getAttributeDescription();
      List<Attribute> attrList = entry.getAllAttributes(attrDesc);
      if (attrList.isEmpty())
      Iterable<Attribute> attrList = entry.getAllAttributes(attrDesc);
      if (isEmpty(attrList))
      {
        setResultCode(ResultCode.NO_SUCH_ATTRIBUTE);
        Arg2<Object, Object> errorMsg = attrDesc.hasOptions()
@@ -255,7 +255,7 @@
    }
  }
  private ResultCode matchExists(List<Attribute> attrList, ByteString value)
  private ResultCode matchExists(Iterable<Attribute> attrList, ByteString value)
  {
    for (Attribute a : attrList)
    {
opendj-server-legacy/src/test/java/org/opends/server/core/AddOperationTestCase.java
@@ -357,8 +357,8 @@
    retrieveCompletedOperationElements(addOperation);
    Entry e = DirectoryServer.getEntry(DN.valueOf("ou=People,o=test"));
    List<Attribute> attrList = e.getAllAttributes(a.getAttributeDescription());
    assertFalse(attrList.isEmpty());
    Iterable<Attribute> attrList = e.getAllAttributes(a.getAttributeDescription());
    assertThat(attrList).isNotEmpty();
    boolean foundFoo = false;
    boolean foundBar = false;
opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/AttrHistoricalMultipleTest.java
@@ -429,12 +429,13 @@
    return getValues(entry.getAllAttributes(mod.getAttribute().getAttributeDescription()));
  }
  private List<ByteString> getValues(List<Attribute> attributes)
  private List<ByteString> getValues(Iterable<Attribute> attributes)
  {
    if (!attributes.isEmpty())
    Iterator<Attribute> it = attributes.iterator();
    if (it.hasNext())
    {
      assertThat(attributes).hasSize(1);
      return getValues(attributes.get(0));
      return getValues(it.next());
    }
    return Collections.emptyList();
  }
opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/AttrHistoricalSingleTest.java
@@ -21,7 +21,6 @@
import static org.testng.Assert.*;
import java.util.Iterator;
import java.util.List;
import org.forgerock.i18n.LocalizableMessageBuilder;
import org.forgerock.opendj.ldap.ByteString;
@@ -356,12 +355,13 @@
    return getActualValue(entry.getAllAttributes(mod.getAttribute().getAttributeDescription()));
  }
  private ByteString getActualValue(List<Attribute> attributes)
  private ByteString getActualValue(Iterable<Attribute> attributes)
  {
    if (!attributes.isEmpty())
    Iterator<Attribute> it = attributes.iterator();
    if (it.hasNext())
    {
      assertThat(attributes).hasSize(1);
      Attribute attribute = attributes.get(0);
      Attribute attribute = it.next();
      assertThat(attribute).hasSize(1);
      return attribute.iterator().next();
    }