com.unboundid.ldap.sdk.unboundidds.jsonfilter
Class ORJSONObjectFilter

java.lang.Object
  extended by com.unboundid.ldap.sdk.unboundidds.jsonfilter.JSONObjectFilter
      extended by com.unboundid.ldap.sdk.unboundidds.jsonfilter.ORJSONObjectFilter
All Implemented Interfaces:
java.io.Serializable

@Mutable
@ThreadSafety(level=NOT_THREADSAFE)
public final class ORJSONObjectFilter
extends JSONObjectFilter

NOTE: This class is part of the Commercial Edition of the UnboundID LDAP SDK for Java. It is not available for use in applications that include only the Standard Edition of the LDAP SDK, and is not supported for use in conjunction with non-UnboundID products.
This class provides an implementation of a JSON object filter that can perform a logical OR across the result obtained from a number of filters. The OR filter will match an object only if at least one (and optionally, exactly one) of the filters contained in it matches that object. An OR filter with an empty set of embedded filters will never match any object.

The fields that are required to be included in an "OR" filter are: The fields that may optionally be included in an "OR" filter are:

Examples

The following is an example of an OR filter that will never match any JSON object:
   { "filterType" : "or",
     "orFilters" : [ ] }
 
The above filter can be created with the code:
   ORJSONObjectFilter filter = new ORJSONObjectFilter();
 


The following is an example of an OR filter that will match any JSON object that contains either a top-level field named "homePhone" or a top-level field named "workPhone":
   { "filterType" : "or",
     "orFilters" : [
       { "filterType" : "containsField",
          "field" : "homePhone" },
       { "filterType" : "containsField",
          "field" : "workPhone" } ] }
 
The above filter can be created with the code:
   ORJSONObjectFilter filter = new ORJSONObjectFilter(
        new ContainsFieldJSONObjectFilter("homePhone"),
        new EqualsJSONObjectFilter("workPhone"));
 

See Also:
Serialized Form

Field Summary
static java.lang.String FIELD_EXCLUSIVE
          The name of the JSON field that is used to indicate whether this should be an exclusive OR.
static java.lang.String FIELD_OR_FILTERS
          The name of the JSON field that is used to specify the set of filters to include in this OR filter.
static java.lang.String FILTER_TYPE
          The value that should be used for the filterType element of the JSON object that represents an "OR" filter.
 
Fields inherited from class com.unboundid.ldap.sdk.unboundidds.jsonfilter.JSONObjectFilter
FIELD_FILTER_TYPE, JSON_OBJECT_FILTER_MATCHING_RULE_NAME, JSON_OBJECT_FILTER_MATCHING_RULE_OID
 
Constructor Summary
ORJSONObjectFilter(java.util.Collection<JSONObjectFilter> orFilters)
          Creates a new instance of this filter type with the provided information.
ORJSONObjectFilter(JSONObjectFilter... orFilters)
          Creates a new instance of this filter type with the provided information.
 
Method Summary
protected  ORJSONObjectFilter decodeFilter(JSONObject filterObject)
          Decodes the provided JSON object as a filter of this type.
 boolean exclusive()
          Indicates whether this filter should be treated as an exclusive OR, in which it will only match a JSON object if exactly one of the embedded filters matches that object.
 java.lang.String getFilterType()
          Retrieves the value that must appear in the filterType field for this filter.
protected  java.util.Set<java.lang.String> getOptionalFieldNames()
          Retrieves the names of all fields that may optionally be present but are not required in the JSON object representing a filter of this type.
 java.util.List<JSONObjectFilter> getORFilters()
          Retrieves the set of filters for this OR filter.
protected  java.util.Set<java.lang.String> getRequiredFieldNames()
          Retrieves the names of all fields (excluding the filterType field) that must be present in the JSON object representing a filter of this type.
 boolean matchesJSONObject(JSONObject o)
          Indicates whether this JSON object filter matches the provided JSON object.
 void setExclusive(boolean exclusive)
          Specifies whether this filter should be treated as an exclusive OR, in which it will only match a JSON object if exactly one of the embedded filters matches that object.
 void setORFilters(java.util.Collection<JSONObjectFilter> orFilters)
          Specifies the set of filters for this OR filter.
 void setORFilters(JSONObjectFilter... orFilters)
          Specifies the set of filters for this OR filter.
 JSONObject toJSONObject()
          Retrieves a JSON object that represents this filter.
 
Methods inherited from class com.unboundid.ldap.sdk.unboundidds.jsonfilter.JSONObjectFilter
decode, equals, getBoolean, getFilters, getString, getStrings, getValues, hashCode, registerFilterType, toLDAPFilter, toString, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

FILTER_TYPE

public static final java.lang.String FILTER_TYPE
The value that should be used for the filterType element of the JSON object that represents an "OR" filter.

See Also:
Constant Field Values

FIELD_OR_FILTERS

public static final java.lang.String FIELD_OR_FILTERS
The name of the JSON field that is used to specify the set of filters to include in this OR filter.

See Also:
Constant Field Values

FIELD_EXCLUSIVE

public static final java.lang.String FIELD_EXCLUSIVE
The name of the JSON field that is used to indicate whether this should be an exclusive OR.

See Also:
Constant Field Values
Constructor Detail

ORJSONObjectFilter

public ORJSONObjectFilter(JSONObjectFilter... orFilters)
Creates a new instance of this filter type with the provided information.

Parameters:
orFilters - The set of filters for this OR filter. At least one of these filters must match a JSON object in order for this OR filter to match that object. If this is null or empty, then this OR filter will never match any JSON object.

ORJSONObjectFilter

public ORJSONObjectFilter(java.util.Collection<JSONObjectFilter> orFilters)
Creates a new instance of this filter type with the provided information.

Parameters:
orFilters - The set of filters for this OR filter. At least one of these filters must match a JSON object in order for this OR filter to match that object. If this is null or empty, then this OR filter will never match any JSON object.
Method Detail

getORFilters

public java.util.List<JSONObjectFilter> getORFilters()
Retrieves the set of filters for this OR filter. At least one of these filters must match a JSON object in order fro this OR filter to match that object.

Returns:
The set of filters for this OR filter.

setORFilters

public void setORFilters(JSONObjectFilter... orFilters)
Specifies the set of filters for this OR filter. At least one of these filters must match a JSON object in order for this OR filter to match that object.

Parameters:
orFilters - The set of filters for this OR filter. At least one of these filters must match a JSON object in order for this OR filter to match that object. If this is null or empty, then this OR filter will never match any JSON object.

setORFilters

public void setORFilters(java.util.Collection<JSONObjectFilter> orFilters)
Specifies the set of filters for this OR filter. At least one of these filters must match a JSON object in order for this OR filter to match that object.

Parameters:
orFilters - The set of filters for this OR filter. At least one of these filters must match a JSON object in order for this OR filter to match that object. If this is null or empty, then this OR filter will never match any JSON object.

exclusive

public boolean exclusive()
Indicates whether this filter should be treated as an exclusive OR, in which it will only match a JSON object if exactly one of the embedded filters matches that object.

Returns:
true if this filter should be treated as an exclusive OR and will only match a JSON object if exactly one of the embedded filters matches that object, or false if this filter will be non-exclusive and will match a JSON object as long as at least one of the embedded filters matches that object.

setExclusive

public void setExclusive(boolean exclusive)
Specifies whether this filter should be treated as an exclusive OR, in which it will only match a JSON object if exactly one of the embedded filters matches that object.

Parameters:
exclusive - Indicates whether this filter should be treated as an exclusive OR.

getFilterType

public java.lang.String getFilterType()
Retrieves the value that must appear in the filterType field for this filter.

Specified by:
getFilterType in class JSONObjectFilter
Returns:
The value that must appear in the filterType field for this filter.

getRequiredFieldNames

protected java.util.Set<java.lang.String> getRequiredFieldNames()
Retrieves the names of all fields (excluding the filterType field) that must be present in the JSON object representing a filter of this type.

Specified by:
getRequiredFieldNames in class JSONObjectFilter
Returns:
The names of all fields (excluding the filterType field) that must be present in the JSON object representing a filter of this type.

getOptionalFieldNames

protected java.util.Set<java.lang.String> getOptionalFieldNames()
Retrieves the names of all fields that may optionally be present but are not required in the JSON object representing a filter of this type.

Specified by:
getOptionalFieldNames in class JSONObjectFilter
Returns:
The names of all fields that may optionally be present but are not required in the JSON object representing a filter of this type.

matchesJSONObject

public boolean matchesJSONObject(JSONObject o)
Indicates whether this JSON object filter matches the provided JSON object.

Specified by:
matchesJSONObject in class JSONObjectFilter
Parameters:
o - The JSON object for which to make the determination.
Returns:
true if this JSON object filter matches the provided JSON object, or false if not.

toJSONObject

public JSONObject toJSONObject()
Retrieves a JSON object that represents this filter.

Specified by:
toJSONObject in class JSONObjectFilter
Returns:
A JSON object that represents this filter.

decodeFilter

protected ORJSONObjectFilter decodeFilter(JSONObject filterObject)
                                   throws JSONException
Decodes the provided JSON object as a filter of this type.

Specified by:
decodeFilter in class JSONObjectFilter
Parameters:
filterObject - The JSON object to be decoded. The caller will have already validated that all required fields are present, and that it does not have any fields that are neither required nor optional.
Returns:
The decoded JSON object filter.
Throws:
JSONException - If the provided JSON object cannot be decoded as a valid filter of this type.