@Override public Set<SearchFilter> visitLessThanFilter( Set<SearchFilter> filters, JsonPointer field, Object valueAssertion) { filters.add( comparison(field.leaf(), SearchFilter.Operator.LESS_THAN_OPERATOR, valueAssertion)); return filters; }
@Override public Set<SearchFilter> visitGreaterThanOrEqualToFilter( Set<SearchFilter> filters, JsonPointer field, Object valueAssertion) { filters.add( comparison( field.leaf(), SearchFilter.Operator.GREATER_THAN_OR_EQUAL_OPERATOR, valueAssertion)); return filters; }
/** * Returns a JSON object containing only the specified fields from the provided JSON value. If the * list of fields is empty then the value is returned unchanged. * * <p><b>NOTE:</b> this method only performs a shallow copy of extracted fields, so changes to the * filtered JSON value may impact the original JSON value, and vice-versa. * * @param resource The JSON value whose fields are to be filtered. * @param fields The list of fields to be extracted. * @return The filtered JSON value. */ public static JsonValue filterResource( final JsonValue resource, final Collection<JsonPointer> fields) { if (fields.isEmpty() || resource.isNull() || resource.size() == 0) { return resource; } else { final Map<String, Object> filtered = new LinkedHashMap<String, Object>(fields.size()); for (JsonPointer field : fields) { if (field.isEmpty()) { // Special case - copy resource fields (assumes Map). filtered.putAll(resource.asMap()); } else { // FIXME: what should we do if the field refers to an array element? final JsonValue value = resource.get(field); if (value != null) { final String key = field.leaf(); filtered.put(key, value.getObject()); } } } return new JsonValue(filtered); } }
@Override public Set<SearchFilter> visitEqualsFilter( Set<SearchFilter> filters, JsonPointer field, Object valueAssertion) { filters.add(comparison(field.leaf(), SearchFilter.Operator.EQUALS_OPERATOR, valueAssertion)); return filters; }