use of com.unboundid.util.json.JSONArray in project ldapsdk by pingidentity.
the class GreaterThanJSONObjectFilter method matchesJSONObject.
/**
* {@inheritDoc}
*/
@Override()
public boolean matchesJSONObject(@NotNull final JSONObject o) {
final List<JSONValue> candidates = getValues(o, field);
if (candidates.isEmpty()) {
return false;
}
for (final JSONValue v : candidates) {
if (v instanceof JSONArray) {
boolean matchOne = false;
boolean matchAll = true;
for (final JSONValue arrayValue : ((JSONArray) v).getValues()) {
if (matches(arrayValue)) {
if (!matchAllElements) {
return true;
}
matchOne = true;
} else {
matchAll = false;
if (matchAllElements) {
break;
}
}
}
if (matchAllElements && matchOne && matchAll) {
return true;
}
} else if (matches(v)) {
return true;
}
}
return false;
}
use of com.unboundid.util.json.JSONArray in project ldapsdk by pingidentity.
the class JSONObjectFilter method getValues.
/**
* Retrieves the set of values that match the provided field name specifier.
*
* @param o The JSON object to examine.
* @param fieldName The field name specifier for the values to
* retrieve.
* @param fieldNameIndex The current index into the field name specifier.
* @param values The list into which matching values should be
* added.
*/
private static void getValues(@NotNull final JSONObject o, @NotNull final List<String> fieldName, final int fieldNameIndex, @NotNull final List<JSONValue> values) {
final JSONValue v = o.getField(fieldName.get(fieldNameIndex));
if (v == null) {
return;
}
final int nextIndex = fieldNameIndex + 1;
if (nextIndex < fieldName.size()) {
// objects.
if (v instanceof JSONObject) {
getValues((JSONObject) v, fieldName, nextIndex, values);
} else if (v instanceof JSONArray) {
getValuesFromArray((JSONArray) v, fieldName, nextIndex, values);
}
return;
}
// If we've gotten here, then there is no more of the field specifier, so
// the value we retrieved matches the specifier. Add it to the list of
// values.
values.add(v);
}
use of com.unboundid.util.json.JSONArray in project ldapsdk by pingidentity.
the class ORJSONObjectFilter method toJSONObject.
/**
* {@inheritDoc}
*/
@Override()
@NotNull()
public JSONObject toJSONObject() {
final LinkedHashMap<String, JSONValue> fields = new LinkedHashMap<>(StaticUtils.computeMapCapacity(3));
fields.put(FIELD_FILTER_TYPE, new JSONString(FILTER_TYPE));
final ArrayList<JSONValue> filterValues = new ArrayList<>(orFilters.size());
for (final JSONObjectFilter f : orFilters) {
filterValues.add(f.toJSONObject());
}
fields.put(FIELD_OR_FILTERS, new JSONArray(filterValues));
if (exclusive) {
fields.put(FIELD_EXCLUSIVE, JSONBoolean.TRUE);
}
return new JSONObject(fields);
}
use of com.unboundid.util.json.JSONArray in project ldapsdk by pingidentity.
the class EqualsAnyJSONObjectFilter method decodeFilter.
/**
* {@inheritDoc}
*/
@Override()
@NotNull()
protected EqualsAnyJSONObjectFilter decodeFilter(@NotNull final JSONObject filterObject) throws JSONException {
final List<String> fieldPath = getStrings(filterObject, FIELD_FIELD_PATH, false, null);
final boolean isCaseSensitive = getBoolean(filterObject, FIELD_CASE_SENSITIVE, false);
final JSONValue arrayValue = filterObject.getField(FIELD_VALUES);
if (arrayValue instanceof JSONArray) {
return new EqualsAnyJSONObjectFilter(fieldPath, ((JSONArray) arrayValue).getValues(), isCaseSensitive);
} else {
throw new JSONException(ERR_OBJECT_FILTER_VALUE_NOT_ARRAY.get(String.valueOf(filterObject), FILTER_TYPE, FIELD_VALUES));
}
}
use of com.unboundid.util.json.JSONArray in project ldapsdk by pingidentity.
the class EqualsAnyJSONObjectFilter method toJSONObject.
/**
* {@inheritDoc}
*/
@Override()
@NotNull()
public JSONObject toJSONObject() {
final LinkedHashMap<String, JSONValue> fields = new LinkedHashMap<>(StaticUtils.computeMapCapacity(4));
fields.put(FIELD_FILTER_TYPE, new JSONString(FILTER_TYPE));
if (field.size() == 1) {
fields.put(FIELD_FIELD_PATH, new JSONString(field.get(0)));
} else {
final ArrayList<JSONValue> fieldNameValues = new ArrayList<>(field.size());
for (final String s : field) {
fieldNameValues.add(new JSONString(s));
}
fields.put(FIELD_FIELD_PATH, new JSONArray(fieldNameValues));
}
fields.put(FIELD_VALUES, new JSONArray(values));
if (caseSensitive) {
fields.put(FIELD_CASE_SENSITIVE, JSONBoolean.TRUE);
}
return new JSONObject(fields);
}
Aggregations